Lexer
Source code in pbi_parsers/base/lexer.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 76 77 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 |
|
advance
Advances the current position by the specified chunk size.
Generally used alongside peek to consume characters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk
|
int
|
The number of characters to advance the current position. |
1
|
Raises:
Type | Description |
---|---|
ValueError
|
If the current position exceeds a predefined MAX_POSITION (1,000,000 characters). This is to avoid errors with the lexer causing the process to hang |
Source code in pbi_parsers/base/lexer.py
at_end
Checks if the current position is at (or beyond) the end of the source.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the current position is at or beyond the end of the source, False otherwise. |
Source code in pbi_parsers/base/lexer.py
match
match(matcher: Callable[[str], bool] | str, chunk: int = 1, *, case_insensitive: bool = True) -> bool
Match a string or a callable matcher against the current position in the source.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
matcher
|
Callable[[str], bool] | str
|
A string to match or a callable that takes a string and returns a boolean. |
required |
chunk
|
int
|
The number of characters to check from the current position. |
1
|
case_insensitive
|
bool
|
If True, perform a case-insensitive match only for strings. |
True
|
Source code in pbi_parsers/base/lexer.py
peek
Returns the next section of text from the current position of length chunk
. Defaults to a single character.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
chunk
|
int
|
The number of characters to return from the current position. |
1
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The next chunk of text from the current position. |
Source code in pbi_parsers/base/lexer.py
remaining
Returns the remaining text from the current position to the end of the source.
Only used for testing and debugging purposes.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The remaining text from the current position to the end of the source. |
Source code in pbi_parsers/base/lexer.py
scan
Repeatedly calls scan_helper until the end of the source is reached.
Returns:
Type | Description |
---|---|
tuple[BaseToken, ...]
|
tuple[BaseToken, ...]: A tuple of tokens scanned from the source. |
Source code in pbi_parsers/base/lexer.py
scan_helper
Contains the orchestration logic for converting tokens into expressions.