Lexer
lexer
Position = int
module-attribute
A position in a file. The position correspond to the character index in the file.
TokenKindT = TypeVar('TokenKindT', bound=Enum)
module-attribute
Location
Bases: NamedTuple
Structure definition a location in a file.
Source code in xdsl/utils/lexer.py
18 19 20 21 22 23 24 25 26 27 28 | |
file: str
instance-attribute
line: int
instance-attribute
1-index of line in file
col: int
instance-attribute
1-index of column in file
__str__() -> str
Source code in xdsl/utils/lexer.py
27 28 | |
Input
dataclass
Used to keep track of the input when parsing.
Source code in xdsl/utils/lexer.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | |
content: str = field(repr=False)
class-attribute
instance-attribute
name: str
instance-attribute
len: int = field(init=False, repr=False)
class-attribute
instance-attribute
__init__(content: str, name: str) -> None
__post_init__()
Source code in xdsl/utils/lexer.py
41 42 | |
__len__()
Source code in xdsl/utils/lexer.py
44 45 | |
get_start_of_line(pos: Position) -> Position
Returns the location of the last newline before pos, or 0 if there are no
previous newlines.
Source code in xdsl/utils/lexer.py
47 48 49 50 51 52 53 54 55 | |
get_end_of_line(pos: Position) -> Position
Returns the position of the first newline after pos, or the length of the
file if there are no more newlines.
Source code in xdsl/utils/lexer.py
57 58 59 60 61 62 63 64 65 | |
at(i: Position) -> str | None
Source code in xdsl/utils/lexer.py
67 68 69 70 | |
slice(start: Position, end: Position) -> str | None
Source code in xdsl/utils/lexer.py
72 73 74 75 | |
Span
dataclass
Parts of the input are always passed around as spans, so we know where they originated.
Source code in xdsl/utils/lexer.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
start: Position
instance-attribute
Start of tokens location in source file, global byte offset in file
end: Position
instance-attribute
End of tokens location in source file, global byte offset in file
input: Input
instance-attribute
The input being operated on
line_offset: int = 0
class-attribute
instance-attribute
A line offset, to just add to ht file number in input when printed.
len
property
text
property
__init__(start: Position, end: Position, input: Input, line_offset: int = 0) -> None
__len__()
Source code in xdsl/utils/lexer.py
103 104 | |
get_location() -> Location
Source code in xdsl/utils/lexer.py
114 115 116 117 118 119 | |
print_with_context(msg: str | None = None) -> str
returns a string containing lines relevant to the span. The Span's contents
are highlighted by up-carets beneath them (^). The message msg is printed
along these.
Source code in xdsl/utils/lexer.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
__repr__()
Source code in xdsl/utils/lexer.py
151 152 | |
Token
dataclass
Bases: Generic[TokenKindT]
Source code in xdsl/utils/lexer.py
158 159 160 161 162 163 164 165 166 167 | |
kind: TokenKindT
instance-attribute
span: Span
instance-attribute
text
property
The text composing the token.
__init__(kind: TokenKindT, span: Span) -> None
Lexer
dataclass
Bases: ABC, Generic[TokenKindT]
Source code in xdsl/utils/lexer.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
input: Input
instance-attribute
Input that is currently being lexed.
pos: Position = field(init=False, default=0)
class-attribute
instance-attribute
Current position in the input. The position can be out of bounds, in which case the lexer is in EOF state.
__init__(input: Input) -> None
lex() -> Token[TokenKindT]
abstractmethod
Lex a token from the input, and returns it.
Source code in xdsl/utils/lexer.py
187 188 189 190 191 192 | |