config
Configuration
dataclass
Represents the configured rules of the scanner.
Source code in src/lectes/config/models.py
from_text(text)
classmethod
Build a configuration from grammar text.
The text has one rule per line: a name, whitespace, then the regex,
which is the rest of the line. Blank lines and lines starting with #
are ignored.
Example
from lectes import Configuration
config = Configuration.from_text(
'''
# arithmetic
INT [0-9]+
PLUS \+
WS \s+
'''
)
Raises:
| Type | Description |
|---|---|
GrammarError
|
if the text has any errors; every error found is
listed in its |
Warns:
| Type | Description |
|---|---|
GrammarWarning
|
once per rule that is valid but probably not what was intended, such as one that can match the empty string. |
Source code in src/lectes/config/models.py
Rule
dataclass
Represents a scanner configuration rule.
Is actually a proxy for a regular expression.
Example
Source code in src/lectes/config/models.py
GrammarError
Bases: LectesError
The grammar text passed to Configuration.from_text is invalid.
Every error found is available as problems, a list of (line, message)
pairs. line is 1-based, or None when the problem isn't tied to a line.
Source code in src/lectes/config/errors.py
GrammarWarning
Bases: UserWarning
The grammar text passed to Configuration.from_text is valid but probably
not what was intended.
The 1-based grammar line is available as line and the text as message.