[antlr-interest] Recognizing Indentation as blocks

Sven Busse mail at ghost23.de
Wed Mar 26 12:56:35 PDT 2008


uhm, has anybody an idea?

thanks
Sven

----------

Von: Sven Busse [mailto:mail at ghost23.de] 
Gesendet: Montag, 24. März 2008 11:56
An: antlr-interest at antlr.org
Betreff: [antlr-interest] Recognizing Indentation as blocks

Hi,

i am currently reading Terrence's book. I am currently at the chapter
"Emitting more than one token per Lexer rule". He gives an example from
python:

if foo:
	print "foo is true"
	f()
g()

He then discusses an exemplary INDENT lexer rule, which i am trying to
understand.

His INDENT rule aims to match Whitespace and Tabs if they start at the
beginning of the line. If the indentation is bigger than in a previous line,
an imaginary INDENT token is emitted. If it is smaller than in the previous
line, one or multiple DEDENT token are emitted.

Now my question is, would this actually work with an example like the little
python script? Because the line with "g()" has actually no whitespace at
all, so i would assume there would be no match and thus the logic of
emitting DEDENT would not even be invoked.

Is this correct or am i missing something? I am referring to the book "The
defintive ANTRL Reference", page 95.

Thank you
Sven





More information about the antlr-interest mailing list