The API class. More...
Classes | |
class | NameList |
A helper class to keep track of rule and UDT names. More... | |
Public Member Functions | |
def | __init__ (self) |
API constructor. More... | |
def | generate (self, source, strict=False, phase='all') |
Generate a grammar object from an SABNF grammar syntax. More... | |
def | write_grammar (self, fname) |
Write the APG grammar to a file in format for later use by a parser. More... | |
def | display_rule_attributes (self, sort='index') |
Display the rule attributes. More... | |
def | display_rule_dependencies (self, sort='index') |
Display the rule dependencies. More... | |
def | find_line (self, index) |
Find the line number of the line in which the given character occurs. More... | |
def | display_errors (self) |
Display the list of SABNF errors, if any. More... | |
def | display_grammar (self) |
Displays an annotated version of the SABNF grammar syntax. More... | |
def | display_line (self, line_no) |
Displays a line with special characters accounted for. More... | |
def | display_underline (self, line_no, index) |
Displays a syntax line, underlined with carrets highlightling error locations. More... | |
def | display_rules (self, sort='index') |
Display the syntax rules and UDTs, if available. More... | |
Public Attributes | |
parser | |
ast | |
errors | |
lines | |
grammar | |
source | |
input | |
rules | |
udts | |
rule_names | |
udt_names | |
rule_deps | |
attributes | |
The API class.
Houses all of the facilities needed to process an SABNF grammar syntax into a grammar object that can be used by an APG parser.
def apg_py.api.api.Api.__init__ | ( | self | ) |
API constructor.
self.errors is a list of errors. Each item, error, contains:
self.lines is a list of the text lines in the input grammar. Each item, line, contains:
def apg_py.api.api.Api.display_errors | ( | self | ) |
def apg_py.api.api.Api.display_grammar | ( | self | ) |
def apg_py.api.api.Api.display_line | ( | self, | |
line_no | |||
) |
def apg_py.api.api.Api.display_rule_attributes | ( | self, | |
sort = 'index' |
|||
) |
def apg_py.api.api.Api.display_rule_dependencies | ( | self, | |
sort = 'index' |
|||
) |
Display the rule dependencies.
For each rule R, list both the list of rules that R refers to (both directly and indirectly) and the list of rules that refer to R (both directly and indirectly).
sort | Determines the order of display of the rules, R.
|
def apg_py.api.api.Api.display_rules | ( | self, | |
sort = 'index' |
|||
) |
def apg_py.api.api.Api.display_underline | ( | self, | |
line_no, | |||
index | |||
) |
def apg_py.api.api.Api.find_line | ( | self, | |
index | |||
) |
def apg_py.api.api.Api.generate | ( | self, | |
source, | |||
strict = False , |
|||
phase = 'all' |
|||
) |
Generate a grammar object from an SABNF grammar syntax.
Works its way through multiple steps.
source | An SABNF grammar syntax as a Python string. |
strict | If True, source must be constrained to strictly follow the ABNF conventions of RFCs 5234 & 7405. If False, SABNF operators and line ending conventions are followed. |
phase | Used primarily for debugging. |
grammar = api.generator(...) if(not grammar): if(api.errors): print(api.display_errors()) raise Exception('api.generate() failed') # use the generated grammar
def apg_py.api.api.Api.write_grammar | ( | self, | |
fname | |||
) |