Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
 … an ABNF Parser Generator
Public Member Functions | Public Attributes | List of all members
apg_py.lib.parser.Parser Class Reference

The Parser class for parsing an APG grammar. More...

Public Member Functions

def __init__ (self, grammar)
 The Parser class constructor. More...
 
def add_callbacks (self, callbacks)
 Add callback functions to the rule name (RNM) nodes. More...
 
def set_tree_depth_limit (self, maxt)
 Set a maximum tree depth. More...
 
def set_node_hit_limit (self, maxt)
 Set a maximum number of node hits. More...
 
def parse (self, input, start_rule=None, sub_begin=0, sub_length=0, user_data=None)
 Parses an input string. More...
 
def opALT (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opALTbehind (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opCAT (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opCATbehind (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opREP (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opRNM (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTLS (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTLSbehind (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTBS (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTBSbehind (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTRG (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opTRGbehind (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def UDTValidate (self, state, phrase_index, phrase_length, last_index, name, empty)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opUDT (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opUDTbehind (self, op_index)
 UDT operator not allowed in look behind mode. More...
 
def opAND (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opNOT (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opBKA (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opBKN (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opBKR (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opBKRbehind (self, op_index)
 Back references not allowed in look behind mode. More...
 
def opABG (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opAEN (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def opExecute (self, op_index)
 Only called internally by the parser, never called explicitly by the user. More...
 
def execDown (self, op)
 Only called internally by the parser, never called explicitly by the user. More...
 
def execUp (self, op, begin_index)
 Only called internally by the parser, never called explicitly by the user. More...
 

Public Attributes

 rules
 
 udts
 
 rule_count
 
 udt_count
 
 trace
 
 ast
 
 stats
 
 tree_depth_limit
 
 node_hits_limit
 
 max_tree_depth
 
 tree_depth
 
 node_hits
 
 max_phrase_length
 
 opSelect
 
 opSelectBehind
 
 rule_callbacks
 
 udt_callbacks
 
 rule_indexes
 
 udt_indexes
 
 bkru_stack
 
 bkrr_stack
 
 start_rule
 
 input
 
 sub_begin
 
 sub_end
 
 state
 
 phrase_index
 
 lookaround
 
 current_look_direction
 
 opcodes
 
 cbData
 

Detailed Description

The Parser class for parsing an APG grammar.

Definition at line 60 of file parser.py.

Constructor & Destructor Documentation

◆ __init__()

def apg_py.lib.parser.Parser.__init__ (   self,
  grammar 
)

The Parser class constructor.

Parameters
grammarThe grammar object generated from an SABNF grammar by the API (see api.py).

Definition at line 63 of file parser.py.

Member Function Documentation

◆ add_callbacks()

def apg_py.lib.parser.Parser.add_callbacks (   self,
  callbacks 
)

Add callback functions to the rule name (RNM) nodes.

Multiple calls to this function can be used to add multiple callbacks.

Parameters
callbacksA dictionary of named callback functions of the form {'rule1': func, 'rule2': func2, 'udt1': func3}. The functions should have the prototype
func(callback_data)
where callback_data is a dictionary of the form
  • 'state': ACTIVE, MATCH, EMPTY or NOMATCH (see identifiers.py). Note: UDT callback function must set state to MATCH, EMPTY or NOMATCH on return. If UDT name begins with "u_" an EMPTY return will raise an Exception.
  • 'sub_begin': The index of the first character of the sub-string of the input string that is being parsed.
  • 'sub_end': The index of the last character of the sub-string of the input string that is being parsed.
  • 'phrase_index': The offset to the first character of the matched phrase.
  • 'phrase_length: The number of characters in the matched phrase. Note: UDT callback functions must set phrase_length on return.
  • 'max_phrase_length': The maximum number of matched characters. (Used mainly in the syntax (syntax_callbacks.py) phase for error reporting.)
  • 'user_data': The data object passed to the parser by the user in parser().

Definition at line 148 of file parser.py.

◆ execDown()

def apg_py.lib.parser.Parser.execDown (   self,
  op 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 925 of file parser.py.

◆ execUp()

def apg_py.lib.parser.Parser.execUp (   self,
  op,
  begin_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 944 of file parser.py.

◆ opABG()

def apg_py.lib.parser.Parser.opABG (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 887 of file parser.py.

◆ opAEN()

def apg_py.lib.parser.Parser.opAEN (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 899 of file parser.py.

◆ opALT()

def apg_py.lib.parser.Parser.opALT (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 292 of file parser.py.

◆ opALTbehind()

def apg_py.lib.parser.Parser.opALTbehind (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 319 of file parser.py.

◆ opAND()

def apg_py.lib.parser.Parser.opAND (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 710 of file parser.py.

◆ opBKA()

def apg_py.lib.parser.Parser.opBKA (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 771 of file parser.py.

◆ opBKN()

def apg_py.lib.parser.Parser.opBKN (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 802 of file parser.py.

◆ opBKR()

def apg_py.lib.parser.Parser.opBKR (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 832 of file parser.py.

◆ opBKRbehind()

def apg_py.lib.parser.Parser.opBKRbehind (   self,
  op_index 
)

Back references not allowed in look behind mode.

Definition at line 877 of file parser.py.

◆ opCAT()

def apg_py.lib.parser.Parser.opCAT (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 338 of file parser.py.

◆ opCATbehind()

def apg_py.lib.parser.Parser.opCATbehind (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 367 of file parser.py.

◆ opExecute()

def apg_py.lib.parser.Parser.opExecute (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 911 of file parser.py.

◆ opNOT()

def apg_py.lib.parser.Parser.opNOT (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 741 of file parser.py.

◆ opREP()

def apg_py.lib.parser.Parser.opREP (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 388 of file parser.py.

◆ opRNM()

def apg_py.lib.parser.Parser.opRNM (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 441 of file parser.py.

◆ opTBS()

def apg_py.lib.parser.Parser.opTBS (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 557 of file parser.py.

◆ opTBSbehind()

def apg_py.lib.parser.Parser.opTBSbehind (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 576 of file parser.py.

◆ opTLS()

def apg_py.lib.parser.Parser.opTLS (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 504 of file parser.py.

◆ opTLSbehind()

def apg_py.lib.parser.Parser.opTLSbehind (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 530 of file parser.py.

◆ opTRG()

def apg_py.lib.parser.Parser.opTRG (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 596 of file parser.py.

◆ opTRGbehind()

def apg_py.lib.parser.Parser.opTRGbehind (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 610 of file parser.py.

◆ opUDT()

def apg_py.lib.parser.Parser.opUDT (   self,
  op_index 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 659 of file parser.py.

◆ opUDTbehind()

def apg_py.lib.parser.Parser.opUDTbehind (   self,
  op_index 
)

UDT operator not allowed in look behind mode.

Definition at line 700 of file parser.py.

◆ parse()

def apg_py.lib.parser.Parser.parse (   self,
  input,
  start_rule = None,
  sub_begin = 0,
  sub_length = 0,
  user_data = None 
)

Parses an input string.

Parameters
inputA tuple of positive integers representing the input string.
start_ruleName of the grammar's start rule (defaults to first rule of the SABNF grammar.)
sub_beginThe index of the first integer of the substring of the input to parse.
sub_lengthThe length of the substring to parse (<=0 indicates end of input string.)
user_dataData which will be passed to the callback functions strictly for user's use.

Definition at line 213 of file parser.py.

◆ set_node_hit_limit()

def apg_py.lib.parser.Parser.set_node_hit_limit (   self,
  maxt 
)

Set a maximum number of node hits.

The parser will raise an Exception if the number of node hits exceeds the specified maximum.

Parameters
maxtthe maximum allowed number of node hits

Definition at line 206 of file parser.py.

◆ set_tree_depth_limit()

def apg_py.lib.parser.Parser.set_tree_depth_limit (   self,
  maxt 
)

Set a maximum tree depth.

The parser will raise an Exception if the parse tree depth exceeds the specified maximum.

Parameters
maxtthe maximum allowed parse tree depth

Definition at line 198 of file parser.py.

◆ UDTValidate()

def apg_py.lib.parser.Parser.UDTValidate (   self,
  state,
  phrase_index,
  phrase_length,
  last_index,
  name,
  empty 
)

Only called internally by the parser, never called explicitly by the user.

Definition at line 624 of file parser.py.

Member Data Documentation

◆ ast

apg_py.lib.parser.Parser.ast

Definition at line 73 of file parser.py.

◆ bkrr_stack

apg_py.lib.parser.Parser.bkrr_stack

Definition at line 142 of file parser.py.

◆ bkru_stack

apg_py.lib.parser.Parser.bkru_stack

Definition at line 141 of file parser.py.

◆ cbData

apg_py.lib.parser.Parser.cbData

Definition at line 281 of file parser.py.

◆ current_look_direction

apg_py.lib.parser.Parser.current_look_direction

Definition at line 278 of file parser.py.

◆ input

apg_py.lib.parser.Parser.input

Definition at line 247 of file parser.py.

◆ lookaround

apg_py.lib.parser.Parser.lookaround

Definition at line 277 of file parser.py.

◆ max_phrase_length

apg_py.lib.parser.Parser.max_phrase_length

Definition at line 80 of file parser.py.

◆ max_tree_depth

apg_py.lib.parser.Parser.max_tree_depth

Definition at line 77 of file parser.py.

◆ node_hits

apg_py.lib.parser.Parser.node_hits

Definition at line 79 of file parser.py.

◆ node_hits_limit

apg_py.lib.parser.Parser.node_hits_limit

Definition at line 76 of file parser.py.

◆ opcodes

apg_py.lib.parser.Parser.opcodes

Definition at line 280 of file parser.py.

◆ opSelect

apg_py.lib.parser.Parser.opSelect

Definition at line 81 of file parser.py.

◆ opSelectBehind

apg_py.lib.parser.Parser.opSelectBehind

Definition at line 98 of file parser.py.

◆ phrase_index

apg_py.lib.parser.Parser.phrase_index

Definition at line 276 of file parser.py.

◆ rule_callbacks

apg_py.lib.parser.Parser.rule_callbacks

Definition at line 116 of file parser.py.

◆ rule_count

apg_py.lib.parser.Parser.rule_count

Definition at line 70 of file parser.py.

◆ rule_indexes

apg_py.lib.parser.Parser.rule_indexes

Definition at line 125 of file parser.py.

◆ rules

apg_py.lib.parser.Parser.rules

Definition at line 68 of file parser.py.

◆ start_rule

apg_py.lib.parser.Parser.start_rule

Definition at line 237 of file parser.py.

◆ state

apg_py.lib.parser.Parser.state

Definition at line 275 of file parser.py.

◆ stats

apg_py.lib.parser.Parser.stats

Definition at line 74 of file parser.py.

◆ sub_begin

apg_py.lib.parser.Parser.sub_begin

Definition at line 248 of file parser.py.

◆ sub_end

apg_py.lib.parser.Parser.sub_end

Definition at line 251 of file parser.py.

◆ trace

apg_py.lib.parser.Parser.trace

Definition at line 72 of file parser.py.

◆ tree_depth

apg_py.lib.parser.Parser.tree_depth

Definition at line 78 of file parser.py.

◆ tree_depth_limit

apg_py.lib.parser.Parser.tree_depth_limit

Definition at line 75 of file parser.py.

◆ udt_callbacks

apg_py.lib.parser.Parser.udt_callbacks

Definition at line 118 of file parser.py.

◆ udt_count

apg_py.lib.parser.Parser.udt_count

Definition at line 71 of file parser.py.

◆ udt_indexes

apg_py.lib.parser.Parser.udt_indexes

Definition at line 132 of file parser.py.

◆ udts

apg_py.lib.parser.Parser.udts

Definition at line 69 of file parser.py.


The documentation for this class was generated from the following file:
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.