openpectus.lang.model.parser
Attributes
Classes
Generates node ids from line ids in source method |
|
Generates incremental negative ids for use with injected code lines. |
|
Functions
|
Create the default parser that applies line ids to nodes. |
|
Create a parser that applies negative ids to nodes. Used for injecting pcode into a method. |
|
Provides a fast one-line parse for lsp completions. |
Module Contents
- openpectus.lang.model.parser.logger
- openpectus.lang.model.parser.create_method_parser(method, uod_command_names=[])
Create the default parser that applies line ids to nodes.
- Parameters:
method (ParserMethod)
uod_command_names (list[str])
- Return type:
- openpectus.lang.model.parser.create_inject_parser(uod_command_names=[])
Create a parser that applies negative ids to nodes. Used for injecting pcode into a method.
- Parameters:
uod_command_names (list[str])
- Return type:
- class openpectus.lang.model.parser.ParserMethod(lines)
- Parameters:
lines (list[ParserMethodLine])
- empty: ParserMethod
- version = 0
- lines: list[ParserMethodLine]
- __str__()
- Return type:
str
- static create_empty()
- Return type:
- is_empty()
- Return type:
bool
- static from_pcode(pcode)
- Parameters:
pcode (str)
- Return type:
- as_pcode()
- Return type:
str
- as_pcode_w_id()
- Return type:
str
- class openpectus.lang.model.parser.IncrementalIdGenerator
Bases:
openpectus.lang.model.ast.NodeIdGenerator- next_id = 1
- create_id(node)
- Parameters:
- class openpectus.lang.model.parser.MethodLineIdGenerator(method)
Bases:
openpectus.lang.model.ast.NodeIdGeneratorGenerates node ids from line ids in source method
- Parameters:
method (ParserMethod)
- method
- create_id(node)
find source line for the node in method
- Parameters:
- Return type:
str
- class openpectus.lang.model.parser.NegativeIdGenerator
Bases:
openpectus.lang.model.ast.NodeIdGeneratorGenerates incremental negative ids for use with injected code lines.
- id = -1
- create_id(node)
- openpectus.lang.model.parser.count_leading_spaces(s)
- Parameters:
s (str)
- Return type:
int
- openpectus.lang.model.parser.count_trailing_spaces(s)
- Parameters:
s (str)
- Return type:
int
- class openpectus.lang.model.parser.Grammar
- indent_re = '(?P<indent>\\s+)?'
- threshold_re = '((?P<threshold>\\d+(\\.\\d+)?)\\s)?'
- instruction_re = '(?P<instruction_name>\\b[a-zA-Z_0-9][^:#]*)'
- argument_re = '(: (?P<argument>[^#]+))?'
- comment_re = '(\\s*(?P<has_comment>#)\\s*(?P<comment>.*$))?'
- full_line_re = '(?P<indent>\\s+)?((?P<threshold>\\d+(\\.\\d+)?)\\s)?(?P<instruction_name>\\b[a-zA-Z_0-9][^:#]*)(...
- instruction_line_pattern
- float_re = '(?P<float>[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?)'
- unit_re = '(?P<unit>[a-zA-Z%\\/23\\*]+)'
- condition_rhs_re = '^(?P<float>[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?)\\s*(?P<unit>[a-zA-Z%\\/23\\*]+)$'
- condition_rhs_pattern
- condition_rhs_no_unit_re = '^(?P<float>[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?)\\s*$'
- condition_rhs_no_unit_pattern
- class openpectus.lang.model.parser.LspParseResult(indentation, threshold, instruction_name, argument)
- Parameters:
indentation (str)
threshold (str)
instruction_name (str)
argument (str)
- indentation: str
- threshold: str
- instruction_name: str
- argument: str
- openpectus.lang.model.parser.lsp_parse_line(pcode_query)
Provides a fast one-line parse for lsp completions.
- Parameters:
pcode_query (str)
- Return type:
LspParseResult | None
- class openpectus.lang.model.parser.PcodeParser(id_generator=IncrementalIdGenerator(), uod_command_names=[])
- Parameters:
id_generator (openpectus.lang.model.ast.NodeIdGenerator)
uod_command_names (list[str])
- id_generator: openpectus.lang.model.ast.NodeIdGenerator
- instruction_name_map
- uod_command_names = []
- parse_pcode(pcode)
- Parameters:
pcode (str)
- Return type:
- parse_method(method)
- Parameters:
method (ParserMethod)
- Return type:
- _parse_line(line, line_no)
- Parameters:
line (str)
line_no (int)
- Return type:
- static _parse_tag_operator_value(node)
- Parameters:
- _inspect_instruction_node_types()
Build ‘instruction_name => node constructor’ map based on Node sub classes and their instruction_names class field.
- Return type:
dict[str, type[openpectus.lang.model.ast.Node]]
- _create_node(instruction_name, line, line_number)
- Parameters:
instruction_name (str)
line (str)
line_number (int)
- Return type: