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
ast
parser_callbacks.py
Go to the documentation of this file.
1
''' @file examples/ast/parser_callbacks.py
2
@brief The parser call back functions for the AST example.
3
'''
4
5
6
import
sys
7
import
os
8
# add the current working directory to the path
9
# DO NOT MOVE THE FOLLOWING STATEMENT
10
# if using autopep8 formatter, for example, set argument '--ignore=E402'
11
sys.path.append(os.getcwd())
12
from
apg_py.lib
import
utilities
as
utils
13
from
apg_py.lib
import
identifiers
as
id
14
15
16
def
A_rule
(cb_data):
17
if(cb_data[
'state'
] == id.MATCH):
18
index = cb_data[
'phrase_index'
]
19
end = index + cb_data[
'phrase_length'
]
20
matched = utils.tuple_to_string(cb_data[
'input'
][index:end])
21
cb_data[
'user_data'
].append(
'"'
+ matched +
'" found by rule A'
)
22
23
24
def
B_rule
(cb_data):
25
if(cb_data[
'state'
] == id.MATCH):
26
index = cb_data[
'phrase_index'
]
27
end = index + cb_data[
'phrase_length'
]
28
matched = utils.tuple_to_string(cb_data[
'input'
][index:end])
29
cb_data[
'user_data'
].append(
'"'
+ matched +
'" found by rule B'
)
30
31
32
def
X_rule
(cb_data):
33
if(cb_data[
'state'
] == id.MATCH):
34
index = cb_data[
'phrase_index'
]
35
end = index + cb_data[
'phrase_length'
]
36
matched = utils.tuple_to_string(cb_data[
'input'
][index:end])
37
cb_data[
'user_data'
].append(
'"'
+ matched +
'" found by rule X'
)
38
39
40
def
alt1_rule
(cb_data):
41
if(cb_data[
'state'
] == id.MATCH):
42
cb_data[
'user_data'
].append(
'in rule alt1'
)
43
44
45
def
alt2_rule
(cb_data):
46
if(cb_data[
'state'
] == id.MATCH):
47
cb_data[
'user_data'
].append(
'in rule alt2'
)
apg_py.lib
Definition:
__init__.py:1
examples.ast.parser_callbacks.X_rule
def X_rule(cb_data)
Definition:
parser_callbacks.py:32
examples.ast.parser_callbacks.alt2_rule
def alt2_rule(cb_data)
Definition:
parser_callbacks.py:45
examples.ast.parser_callbacks.alt1_rule
def alt1_rule(cb_data)
Definition:
parser_callbacks.py:40
examples.ast.parser_callbacks.B_rule
def B_rule(cb_data)
Definition:
parser_callbacks.py:24
examples.ast.parser_callbacks.A_rule
def A_rule(cb_data)
Definition:
parser_callbacks.py:16
Generated by
1.9.1
Python APG, Version 1.0, is licensed under the
2-Clause BSD License
,
an
Open Source Initiative
Approved License.