Making your own statements

后端 未结 5 491
情深已故
情深已故 2020-12-21 15:03

Is there a way to define new statements like def, with, for of my own in Python? Of course, I don\'t mean to override the existing sta

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-21 15:29

    While you can't modify the syntax of Python itself (without recompiling as Alex has mentioned), you can use metaprogramming techniques. Below is a link to a presentation on creating a DSL in Python.

    http://blog.brianbeck.com/post/53538107/python-dsl-i

    If you're not married to Python, Ruby is a great language for defining DSL's, as it has broader metaprogramming capabilities.

    http://www.themomorohoax.com/2009/02/25/how-to-write-a-clean-ruby-dsl-rails

提交回复
热议问题