aboutsummaryrefslogtreecommitdiffstats
path: root/wlp_yacc.py
diff options
context:
space:
mode:
Diffstat (limited to 'wlp_yacc.py')
-rw-r--r--wlp_yacc.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/wlp_yacc.py b/wlp_yacc.py
new file mode 100644
index 0000000..a16f530
--- /dev/null
+++ b/wlp_yacc.py
@@ -0,0 +1,98 @@
+import logging
+
+import rply
+
+logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
+ level=logging.DEBUG)
+
+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
+"""
+
+## Makes from this source
+##
+## <kame@innocent.com> {
+## From: = 'ME' Sender: = "Cosimo" Reply-to = "me"
+## }
+##
+## <alfarano@students.cs.unibo.it> {
+## From: = 'Cosimo Alfarano'
+## X-Firstname: = 'Cosimo'
+## }
+##
+## <kame@innocent.com> {
+## From: = 'kame@inwind.it'
+## Reply-to: = "KA"
+## Sender: = "Kalfa"
+## }
+##
+## this dictionary
+##
+## expected_dict = {'alfarano@students.cs.unibo.it': {
+## 'From:': 'Cosimo Alfarano',
+## 'X-Firstname:': 'Cosimo'
+## },
+## 'kame@innocent.com': {
+## 'From:': 'kame@inwind.it',
+## 'Reply-to': 'me',
+## 'Reply-to:': 'KA',
+## 'Sender:': 'Kalfa'}
+## }
+
+
+@pg.production('main : block')
+def main(p):
+ return p[0]
+
+
+# block:
+# blockstatement
+# | block blockstatement
+@pg.production('block : blockstatement')
+@pg.production('block : block blockstatement')
+def block(p):
+ logging.debug('block p = %s', p)
+
+
+# blockstatement:
+# owner '{' commandline '}'
+@pg.production('blockstatement : OWNER commandline')
+def blockstatement(p):
+ logging.debug('blockstatement p = %s', p)
+
+
+# commandline:
+# command | commandline command
+@pg.production('commandline : command')
+@pg.production('commandline : commandline command')
+def commandline(p):
+ logging.debug('commandline p = %s', p)
+
+
+# command:
+# varpart '=' valpart { found(left,right,owner); }
+@pg.production('command : VAR VAL')
+def command(p):
+ logging.debug('command p = %s', p)
+ return (p[0], p[1])
+
+parser = pg.build()