Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
… an
A
BNF
P
arser
G
enerator
Main Page
Related Pages
Packages
Packages
Package Functions
All
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
x
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
x
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
p
r
s
t
u
v
Classes
Class List
Class Index
Class Members
All
_
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
w
Functions
_
a
c
d
e
f
g
h
i
o
p
r
s
t
u
w
Variables
a
b
c
e
f
g
h
i
l
m
n
o
p
r
s
t
u
Files
File List
•
All
Classes
Namespaces
Files
Functions
Variables
Pages
examples
grammar_object
use.py
Go to the documentation of this file.
1
''' @file examples/grammar_object/use.py
2
@brief Demonstrates how to use a saved a grammar object.
3
4
For grammars that are used often,
5
saving the grammar object prevents the repeated and redundant
6
re-generation of the grammar object from the SABNF syntax over and over.
7
8
This example must be preceeded by examples/grammar_object/save.py.
9
This example uses the saved object from that example.
10
'''
11
import
sys
12
import
os
13
# add the current working directory to the path
14
# DO NOT MOVE THE FOLLOWING STATEMENT
15
# if using autopep8 formatter, for example, set argument '--ignore=E402'
16
sys.path.append(os.getcwd())
17
from
apg_py.lib.parser
import
Parser
18
import
examples.grammar_object.abnf
as
grammar
19
20
21
def
use_grammar
():
22
title =
'''Demonstrate how to use a saved grammar object.
23
Uses the grammar object saved by the companion example,
24
save_grammar_object.py.
25
'''
26
print()
27
print(title)
28
# display the original grammar
29
print(
'the ABNF syntax of the previously saved grammar object, '
, end=
''
)
30
print(
'examples/abnf.py'
)
31
print(grammar.to_string())
32
33
# construct a parser and parse a string
34
parser =
Parser
(grammar)
35
result = parser.parse((128, 200, 255))
36
print(result)
apg_py.lib.parser.Parser
The Parser class for parsing an APG grammar.
Definition:
parser.py:60
apg_py.lib.parser
Definition:
parser.py:1
examples.grammar_object.abnf
Definition:
abnf.py:1
examples.grammar_object.use.use_grammar
def use_grammar()
Definition:
use.py:21
Generated by
1.9.1
Python APG, Version 1.0, is licensed under the
2-Clause BSD License
,
an
Open Source Initiative
Approved License.