Lexeme¶
- class understand.Lexeme¶
Bases:
object
A token recieved from a
lexer
.It has an associated range represented with
line_begin
,column_begin
,line_end
, andcolumn_end
. A lexeme also has thetext
for the range and atoken
describing the kind (comment, whitespace, etc). Theinactive
method can be used to test if the lexeme is in inactive code.If a corresponding
entity
and/orreference
exists for the lexeme, it can be retrieved withent
andref
respectively. Lexemes can be navigated withnext
andprevious
.Lexeme line and column numbers are 1-based.
Methods Summary
Return the beginning column number of the lexeme.
Return the ending column number of the lexeme.
Return the entity associated with the lexeme or None if none.
Return True if the lexeme is part of inactive code.
Return the beginning line number of the lexeme.
Return the ending line number of the lexeme.
Return the next lexeme, or None if no lexemes remain.
Return the previous lexeme, or None if beginning of file.
Return the reference associated with the lexeme, or None if none.
Return the text for the lexeme, which may be empty ("").
Return the token kind of the lexeme.
Methods Documentation
- column_begin() int ¶
Return the beginning column number of the lexeme.
- Return type:
int
- Returns:
the beginning column
- column_end() int ¶
Return the ending column number of the lexeme.
- Return type:
int
- Returns:
the ending column
- ent() understand.Ent ¶
Return the entity associated with the lexeme or None if none.
- Return type:
- Returns:
the associated entity or None if none
- inactive() bool ¶
Return True if the lexeme is part of inactive code.
- Return type:
bool
- Returns:
True if the lexeme is part of inactive code
- line_begin() int ¶
Return the beginning line number of the lexeme.
- Return type:
int
- Returns:
the beginning line
- line_end() int ¶
Return the ending line number of the lexeme.
- Return type:
int
- Returns:
the ending line
- next([ignore_whitespace[, ignore_comments]]) understand.Lexeme ¶
Return the next lexeme, or None if no lexemes remain.
- Parameters:
ignore_whitespace (bool or None) – if True, skip whitespace lexemes. False by default.
ignore_comments (bool or None) – if True, skip comment lexemes. False by default.
- Return type:
- Returns:
the next lexeme if it exists
- previous([ignore_whitespace[, ignore_comments]]) understand.Lexeme ¶
Return the previous lexeme, or None if beginning of file.
- Parameters:
ignore_whitespace (bool or None) – if True, skip whitespace lexemes. False by default.
ignore_comments (bool or None) – if True, skip comment lexemes. False by default.
- Return type:
- Returns:
the previous lexeme if it exists
- ref() understand.Ref ¶
Return the reference associated with the lexeme, or None if none.
- Return type:
- Returns:
the associated reference or None if none
- text() str ¶
Return the text for the lexeme, which may be empty (“”).
- Return type:
str
- Returns:
the associated text which may be empty
- token() str ¶
Return the token kind of the lexeme.
- Return type:
str
- Returns:
a token value
Values include:
Comment
Continuation
EndOfStatement
Identifier
Keyword
Label
Literal
Newline
Operator
Preprocessor
Punctuation
String
Whitespace
Indent
Dedent