refex.parsed_file
¶
-
class
ParsedFile
(text: str, path: str, pragmas: Iterable[Pragma])¶ A wrapper for a file after preprocessing.
May be subclassed.
The base class contains common metadata and does not in fact represent the result of any parsing. Individual subclasses may contain detailed data about the structure of a file. (See, for example,
refex.python.matcher.PythonParsedFile
)-
text
¶ The unparsed file contents.
-
path
¶ The path to the file.
-
pragmas
¶ The pragmas for this file, in file order.
-
line_numbers
¶ A cache for line number <-> codepoint offset conversion.
-
-
class
Pragma
(tag: str, data: Mapping[str, str], start: int, end: int)¶ A pragma / directive for Refex to alter how it handles files.
-
tag
¶ The pragma namespace. This should be
"refex"
unless the pragma is actually parsed from a comment that targets another system (e.g. pylint.)
-
data
¶ The pragma payload, a set of key-value pairs.
-
start
¶ The start (codepoint offset) of the pragma in the file. Inclusive.
-
end
¶ The end (codepoint offset) of the pragma in the file. Exclusive.
-
classmethod
from_text
(text, start, end) → Optional[refex.parsed_file.Pragma]¶ Parses pragmas from the standard format:
tag: key=value, ...
.For example,
refex: disable=foo
becomesPragma(tag=refex, data={"disable": "foo"}, ...)
The pragma must end the string, although arbitrary leading text (usually an explanation for why the pragma was used) is allowed.
- Parameters
text – The candidate pragma text.
start – The start offset for the pragma.
end – The end offset for the pragma.
- Returns
end] parses as a pragma, otherwise
None
.- Return type
A
Pragma
if text[start
-