INITIAL : "{ID}" : idcnt += 1 return "Identifier" "abc*" : return "pattern1"
This section specifies two patterns within the INITIAL
start state.
When the first pattern is matched, two lines of code are executed.
When the second line is matched, just one line of code is executed.
Start states specify seperate state machines. Most lexers will only
need one start state, and it may be given any name (excluding
definitions
and code
)
as long as it is the first start state in the file.
Occasionally a lexer may need to match some patterns in one context
and other patterns in another context. Multiple start states provide
a mechanism for achieving this. The lexer always starts off in the
first start state encountered in the spec file. Helper methods
are provided which lexer actions can call to switch the start state.
See the PyGgy Home Page.