diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2015-01-05 09:03:05 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2015-01-05 12:59:40 +0100 |
commit | d17b009ffec3077bf8db6e6902a7456ec90e9c38 (patch) | |
tree | 2a5ee305bd8c8a39faf7c2db342d399c689ae432 /wlp_parser.py | |
parent | a9e311030533ac6c175e2289e8928e4aae98b6c3 (diff) | |
download | pyg-d17b009ffec3077bf8db6e6902a7456ec90e9c38.tar.gz |
First draft of the pure Python parser done, we should be noarch.
Fixes #2
Diffstat (limited to 'wlp_parser.py')
-rw-r--r-- | wlp_parser.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/wlp_parser.py b/wlp_parser.py new file mode 100644 index 0000000..35da516 --- /dev/null +++ b/wlp_parser.py @@ -0,0 +1,68 @@ +import rply + +__lg = rply.LexerGenerator() +# Add takes a rule name, and a regular expression that defines the rule. +__lg.add("OWNER", r'<[a-zA-Z0-9_.+-]+@[a-zA-Z0-9._-]+>') +__lg.add("VAL", r'[\'`"][a-zA-Z0-9@_+.<>() -]+[\'`"]') +__lg.add("VAR", r'[a-zA-Z0-9_<>-]+[:]?') + +__lg.ignore(r"\s+") +__lg.ignore(r'[{}=]+') + +lexer = __lg.build() + +__pg = rply.ParserGenerator(['OWNER', 'VAL', 'VAR'], + cache_id='wlp_parser') + +""" + $accept ::= block $end + block ::= blockstatement + | block blockstatement + blockstatement ::= owner '{' commandline '}' + commandline ::= command + | commandline command + command ::= varpart '=' valpart + owner ::= OWNERID + varpart ::= VARID + valpart ::= VALID +""" + + +@__pg.production('main : block') +def main(p): + return p[0] + + +@__pg.production('block : blockstatement') +def block(p): + return p + + +@__pg.production('block : block blockstatement') +def block_blockstatement(p): + p[0].append(p[1]) + return p[0] + + +@__pg.production('blockstatement : OWNER commandline') +def blockstatement(p): + return [p[0], p[1]] + + +@__pg.production('commandline : command') +def commandline(p): + return p + + +@__pg.production('commandline : commandline command') +def commandline_command(p): + p[0].append(p[1]) + return p[0] + + +@__pg.production('command : VAR VAL') +def command(p): + return p + + +parser = __pg.build() |