Lexer¶
- class understand.Lexer¶
Bases:
objectA lexical stream generated for a file
entity.The original file must exist and be unchanged from the last database reparse. The first
lexeme(token) in the stream can be accessed usingfirst. A lexer can be iterated over, where each item returned is alexeme.import understand db = understand.open("test.und") file = db.lookup("test.cpp")[0] for lexeme in file.lexer(): print(lexeme.text(), end="") if lexeme.ent(): print("@", end="")
Lexer and lexeme line and column numbers are 1-based.
Methods Summary
Return the first lexeme for the lexer.
Return the lexeme at the specified line and column.
Return a list of lexemes.
Return the number of lines in the lexer.
Methods Documentation
- first() understand.Lexeme¶
Return the first lexeme for the lexer.
- Return type:
- Returns:
the first understand.Lexeme
- lexeme(line, column) understand.Lexeme¶
Return the lexeme at the specified line and column.
- Parameters:
line (integer) – the line number
column (integer) – the column number
- Return type:
- Returns:
the lexeme at the location
- lexemes(start_line=None, end_line=None) list[understand.Lexeme]¶
Return a list of lexemes.
If the optional parameters start_line or end_line are specified, only the lexemes within these lines are returned.
- Parameters:
start_line (integer or None) – Optional start line
end_line (integer or None) – Optional start line
- Return type:
list[understand.Lexeme]
- Returns:
a list of lexemes
- lines() int¶
Return the number of lines in the lexer.
- Return type:
int
- Returns:
the number of lines