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
exp
main.py
Go to the documentation of this file.
1
''' @file examples/exp/main.py
2
@brief Driver function for demonstrating a large set of
3
pattern matching examples.
4
Execute
5
> python3 %examples/exp/main.py --help
6
to see all examples.
7
@dir examples/exp A large set of examples of using the pattern-matching engine.
8
'''
9
import
sys
10
import
os
11
# add the current working directory to the path
12
# DO NOT MOVE THE FOLLOWING STATEMENT
13
# if using autopep8 formatter, for example, set argument '--ignore=E402'
14
sys.path.append(os.getcwd())
15
16
17
def
usage
():
18
display =
'usage: python3 examples/exp/main.py option\n'
19
display +=
' option must be one of the following\n'
20
display +=
' -h, --help display this help screen\n'
21
display +=
' --ast demostrate using the AST for complex translations\n'
22
display +=
' --basic demonstrates basic matching and testing a pattern\n'
23
display +=
' --csv matching fields in Microsoft\'s Comma Separated Value(CSV) format\n'
24
display +=
' --flags demonstrates the use of all flags, "cgyt"\n'
25
display +=
' --limits setting limits on the number of node hits and parse tree depth\n'
26
display +=
' --multiline how to handle the multi-line mode of regex\n'
27
display +=
' --recursive matching pairs of parentheses - recursive patterns\n'
28
display +=
' --replace demonstrates the use of the replace function\n'
29
display +=
' --rules demonstrates capturing the phrases for specific rule names\n'
30
display +=
' --split demonstrates the use of the split function\n'
31
display +=
' --udts demonstrates the use of User-Defined Terminals (hand-written code snippets)\n'
32
return
display
33
34
35
if(
len
(sys.argv) == 1
or
sys.argv[1] ==
'-h'
or
sys.argv[1] ==
'--help'
):
36
print(
usage
())
37
exit()
38
39
if(sys.argv[1] ==
'--ast'
):
40
import
examples.exp.ast_translate
41
exit()
42
43
if(sys.argv[1] ==
'--basic'
):
44
import
examples.exp.basic
45
exit()
46
47
if(sys.argv[1] ==
'--csv'
):
48
import
examples.exp.csv
49
exit()
50
51
if(sys.argv[1] ==
'--flags'
):
52
import
examples.exp.flags
53
exit()
54
55
if(sys.argv[1] ==
'--limits'
):
56
import
examples.exp.limits
57
exit()
58
59
if(sys.argv[1] ==
'--multiline'
):
60
import
examples.exp.multiline
61
exit()
62
63
if(sys.argv[1] ==
'--recursive'
):
64
import
examples.exp.recursive
65
exit()
66
67
if(sys.argv[1] ==
'--replace'
):
68
import
examples.exp.replace
69
exit()
70
71
if(sys.argv[1] ==
'--rules'
):
72
import
examples.exp.rules
73
exit()
74
75
if(sys.argv[1] ==
'--split'
):
76
import
examples.exp.split
77
exit()
78
79
if(sys.argv[1] ==
'--udts'
):
80
import
examples.exp.udts
81
exit()
82
83
print(
'argument '
+ sys.argv[1] +
' not recognized'
)
84
print(
usage
())
examples.basics.substrings.len
int len
Definition:
substrings.py:27
examples.exp.ast_translate
Definition:
ast_translate.py:1
examples.exp.basic
Definition:
basic.py:1
examples.exp.csv
Definition:
csv.py:1
examples.exp.flags
Definition:
flags.py:1
examples.exp.limits
Definition:
limits.py:1
examples.exp.main.usage
def usage()
Definition:
main.py:17
examples.exp.multiline
Definition:
multiline.py:1
examples.exp.recursive
Definition:
recursive.py:1
examples.exp.replace
Definition:
replace.py:1
examples.exp.rules
Definition:
rules.py:1
examples.exp.split
Definition:
split.py:1
examples.exp.udts
Definition:
udts.py:1
Generated by
1.9.1
Python APG, Version 1.0, is licensed under the
2-Clause BSD License
,
an
Open Source Initiative
Approved License.