Splitting definition over multiple files

15 views
Skip to first unread message

Le GEC

unread,
Sep 16, 2009, 5:51:08 AM9/16/09
to ply-hack
Hello everybody,

How can I split a grammar definition for PLY over multiple files? What
would you suggest?

The first method I see to do this, is to have a nested hierarchy of
classes for the parser :

BaseParser = class(PLYParser) -> in file baseParser.py
p_rule_dotted_ident
"""dotted_ident : ident
| dotted_ident DOT ident"""
<blahblah>


ExprParser = class(BaseParser) -> in file exprParser.py
p_expr_add
"""add_expr : dotted_ident PLUS dotted_ident"""



Would this work? What do I have to look out for?

Do you have other suggestions?

Thanks in advance,
*GV*

D.Hendriks (Dennis)

unread,
Sep 16, 2009, 6:35:10 AM9/16/09
to ply-...@googlegroups.com
Hello *GV*,

> Would this work? What do I have to look out for?

Yes, it would work. You may have to look out for the token list, unless
the base class and derived class have the same lexer tokens...

We've used this approach in our tooling for quite some time now.

Best,
Dennis Hendriks
Reply all
Reply to author
Forward
0 new messages