Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
 … an ABNF Parser Generator
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'):
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'):
61  exit()
62 
63 if(sys.argv[1] == '--recursive'):
65  exit()
66 
67 if(sys.argv[1] == '--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())
def usage()
Definition: main.py:17
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.