python - pyPEG2 giving wrong result -


i have created grammar pypeg2 parsing such statements as:

a loves b b hates a, hates b , loves d while b loves c

here code below:

import pypeg2 pp   class person(str):     grammar = pp.word  class action(pp.keyword):     grammar = pp.enum(pp.k('loves'), pp.k('hates'))  class separator(pp.keyword):     grammar = pp.enum(pp.k(','), pp.k('\n'), pp.k('but'), pp.k('and'), pp.k('while'))  relation = person, action, person  class relations(pp.namespace):     grammar = relation, pp.maybe_some(separator, relation) 

however when try following:

>>> love = pp.parse('a loves b b hates , b loves c, relations) 

i get:

traceback (most recent call last):   file "<pyshell#64>", line 1, in <module>     love = pp.parse('a loves b b hates , b loves c', relations)   file "/home/michael/.local/lib/python3.5/site-packages/pypeg2/__init__.py", line 669, in parse     raise parser.last_error   file "<string>", line 1     es b b hates , b loves c                        ^ syntaxerror: expecting separator >>>  

if change statement one:

>>> love = pp.parse('a loves b b hates , b loves c', relations) 

there no error, last block missed reasons:

>>> pp.compose(love) 'a loves b b hates a' 

so doing wrong way, documentation described, can`t find mistake did there.

hope can this. in advance!!!


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -