[antlr-interest] Python support for ANTLR
Ric Klaren
klaren at cs.utwente.nl
Mon Nov 1 05:37:29 PST 2004
On Mon, Nov 01, 2004 at 09:13:02AM -0000, marqkole wrote:
> Explanation: instead of braces, Python uses indentation to mark blocks of
> code.
Once more *sigh* It would have been such a nice language without it ;)
> In the case of the generated code, the opening brace could be replaced by
> an if statement that is always open (example: "if True:") followed by an
> increased indentation level, while the closing brace can be replaced by
> just a decreased indentation level.
> My problem is that I just can't find where to do this for a single action
> item, such as a pair of spurious braces. Just have a look at the generated
> code in the lexertester examples to see what I mean.
It looks like it's related to to method
public void gen(AlternativeBlock blk);
and single alternatives. E.g. try remove the () around the 'A' alternative
in simplelexer2.g this will fix the output for the 2nd lexer. Adding an
extra "if True:" to the start of the gen() method does not work 100% of the
cases. There's another "if True:" cropping up from somewhere else.. hrmm..
Looks like it's fixed with commenting inside:
protected void genAlt(Alternative alt, AlternativeBlock blk)
The lines:
// else
// if (!(elem.next instanceof BlockEndElement) && (grammar instanceof LexerGrammar)) {
// println("if True: # needed to get the indents right genalt");
// }
Now all the lexertest things run without indentation errors.
I wonder how stringtemplate would deal with this kind off stuff for
antlr3...
Cheers,
Ric
--
-----+++++*****************************************************+++++++++-------
---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755 ----
-----+++++*****************************************************+++++++++-------
Chaos is found in greatest abundance wherever order is being sought.
--- Terry Pratchet
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/antlr-interest/
<*> To unsubscribe from this group, send an email to:
antlr-interest-unsubscribe at yahoogroups.com
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list