openpectus.lang.model.parser

Attributes

logger

Classes

ParserMethodLine

ParserMethod

IncrementalIdGenerator

MethodLineIdGenerator

Generates node ids from line ids in source method

NegativeIdGenerator

Generates incremental negative ids for use with injected code lines.

Grammar

LspParseResult

PcodeParser

Functions

create_method_parser(method[, uod_command_names])

Create the default parser that applies line ids to nodes.

create_inject_parser([uod_command_names])

Create a parser that applies negative ids to nodes. Used for injecting pcode into a method.

count_leading_spaces(s)

count_trailing_spaces(s)

lsp_parse_line(pcode_query)

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:
Return type:

PcodeParser

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:

PcodeParser

class openpectus.lang.model.parser.ParserMethodLine
id: str
content: str
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:

ParserMethod

is_empty()
Return type:

bool

static from_pcode(pcode)
Parameters:

pcode (str)

Return type:

ParserMethod

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:

node (openpectus.lang.model.ast.Node)

class openpectus.lang.model.parser.MethodLineIdGenerator(method)

Bases: openpectus.lang.model.ast.NodeIdGenerator

Generates node ids from line ids in source method

Parameters:

method (ParserMethod)

method
create_id(node)

find source line for the node in method

Parameters:

node (openpectus.lang.model.ast.Node)

Return type:

str

class openpectus.lang.model.parser.NegativeIdGenerator

Bases: openpectus.lang.model.ast.NodeIdGenerator

Generates 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
instruction_name_map
uod_command_names = []
parse_pcode(pcode)
Parameters:

pcode (str)

Return type:

openpectus.lang.model.ast.ProgramNode

parse_method(method)
Parameters:

method (ParserMethod)

Return type:

openpectus.lang.model.ast.ProgramNode

_parse_line(line, line_no)
Parameters:
  • line (str)

  • line_no (int)

Return type:

openpectus.lang.model.ast.Node

static _parse_tag_operator_value(node)
Parameters:

node (openpectus.lang.model.ast.NodeWithTagOperatorValue)

_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:

openpectus.lang.model.ast.Node