very powerful and optional parser framework for python
Project description
EBNFParser
Parse Many, Any, Every
P.S: Everything except THIS README is out of date, you can refer here for more information..
Install
Python
pip
pip installl -U EBNFParser
setup
git clone https://github.com/thautwarm/EBNFParser cd EBNFParser/Python python setup.py install
An Introduce to EBNFParser
Here is an example for you to get a knowledge of Ruikowa for parsing Java switch syntax.
deftoken Token.Java # use the token definition at source file `./Token/Java`.
ignore [Space] # ignore tokens like Space;
Space := R'\s+'; # define tokenizer(s) with specific name `Space`
switch ::= 'switch' '(' expression ')' newline*
'{'
case*
[default]
'}' ;
case ::= 'case' ':' body ;
default ::= 'default' ':' body ;
body ::= block | statement ;
block ::= '{' statement* '}' ;
...
Now I’m going to tell you how to use EBNFParser to write a parser for Lisp quickly.
Install
pip install -U EBNFParser
Write a file and name it as lispGrammar with following content.
ignore [N] N := R'\n', R'\t', ' '; Atom := R'[^\(\)\s\`]?'; # use Regex Expr ::= Atom | Quote | '(' Expr* ')'; Quote ::= '`' Expr ; Stmt ::= Expr*;
Generate your parser and tokenizer.
ruiko ./lispGrammar ./lispParser.py
Test your parser.
python testLang.py Stmt "(+ 1 2)" -o test.ast Stmt[ Expr[ "(" Expr[ "+" ] Expr[ "1" ] Expr[ "2" ] ")" ] ]
Moreover, here is a result in JSON format at test.json.
Usage
Command Line Tools
ruiko.
ruiko ./<grammar File> ./<output Python File(endswith ".py")> [--testTk] # print tokenized words or not
Use command ruiko to generate parser and token files, and then you can use testLang.py to test your parser.
python ./test_lang.py Stmt " (+ 1 2) " -o test.json --testTk
Use EBNFParser in your own project.
Here are some examples to refer:
EBNFParser 2.0
Rem The Rem programming language.
Before EBNFParser 1.1.
- A DSL for SQL development in Python areas.
- A full featured modern language to enhance program readability based on CPython.
- An attempt to making ASDL in CPython(unfinished yet)
Source
Will support C# and Rem.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.