Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:47:33+00:00 2026-06-17T13:47:33+00:00

Am a ruby guy basically, and got into a situation where I need to

  • 0

Am a ruby guy basically, and got into a situation where I need to make a small dsl in py as follows, I know in ruby following is doable, am looking for exactly same in py

from_a_dsl_file = "
   take_this 'abc'
   and_process_it
   and_give_me_the_output
"

class A
   def take_this abc
   end

   def and_process_it
   end

   def and_give_me_the_output
     'desired'
   end
end

A.new.instance_eval from_a_dsl_file
# => 'desired'

Any hints, or great to have a working example please

thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:47:35+00:00Added an answer on June 17, 2026 at 1:47 pm

    As I understand it, in Ruby there are some tricky things you can do with function calls that don’t require parentheses:

    x y
    

    In Ruby, that could be a function call where function x is called with y for the argument.

    Well, in Python, we don’t have those tricks; if you are calling a function, you need parentheses after the function name. So, I don’t think you will have much luck trying to play games with eval() for this.

    Better is just to write a parser that parses the language for you and figures out what the language is trying to do. For that, Python has a particularly good library: pyparsing

    http://pyparsing.wikispaces.com/

    P.S. Just doing a Google search for “Python domain specific language” finds some good links, many in StackOverflow. Here is the best one I found:

    Mini-languages in Python

    EDIT: Okay, you asked for an example and here you go. This is my first-ever program in PyParsing and it was pretty easy. I didn’t even read the documentation; I just worked from the examples in a presentation I found on the web.

    Here’s the URL of the presentation: http://www.ptmcg.com/geo/python/confs/TxUnconf2008Pyparsing.html

    from pyparsing import *
    
    def give_desired_output(s):
        return "desired"
    
    TAKE_THIS = Suppress("take_this") + Suppress(Word(printables))
    AND_PROC = Suppress("and_process_it")
    AND_GIVE = Keyword("and_give_me_the_output")
    AND_GIVE.setParseAction(give_desired_output)
    
    LANGUAGE_LINE = TAKE_THIS | AND_PROC | AND_GIVE
    
    LANGUAGE = ZeroOrMore(LANGUAGE_LINE)
    
    
    def parse_language(text):
        lst = LANGUAGE.parseString(text)
        assert len(lst) == 1  # trivial language returns a single value
        return lst[0]
    
    if __name__ == "__main__":
        from_a_dsl_file = \
    """
       take_this 'abc'
       and_process_it
       and_give_me_the_output
    """
    
        print(parse_language(from_a_dsl_file))  # prints the word: desired
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a Ruby on Rails / PHP guy, and my company got me to
I've got pretty much the same problem as this guy: http://www.ruby-forum.com/topic/197440 . I'm trying
I'm following the guides in a Lynda program teaching Ruby on Rails. The guy
I'm primarily a Ruby guy, but lately I've been working on a lot of
I'm not a Ruby guy, I just play one on television. I have to
I am a new guy in Ruby, and I have tables with these primary
I'm looking at the below URL to see how a popular ruby gem maps
I'm a new Ruby/Rails guy. Here's one question puzzling me: Can we find the
I am a DevOps guy and presently I am running my Ruby on Rails
I have watched a video that introduce to Jruby and the guy there make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.