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/basics/main.py
2 @brief Driver function for demonstrating Python APG basic operations.
3 Run
4 <pre>python3 examples/basic/main.py --help</pre>
5 to see all of the basic options.
6 @dir examples
7 @brief Examples of using all aspects of the parser, parser generator
8 and pattern-matching engine.
9 In each sub-directory has a "main.py" file. Execute this file
10 to run the example. e.g. from your project directory
11 <pre>python3 examples/basic/main.py --help</pre>
12 will give all of the basic example options.
13 Examine any of the other files in the directory to study the examples
14 or run them in a debugger to further understand the examples lessons.
15 @dir examples/basics
16 @brief All of the examples of basic parsing operations.
17 Run
18 <pre>python3 examples/basic/main.py --help</pre>
19 to see all of the basic options.
20 Examine any of the other files in the directory to study the examples
21 or run them in a debugger to further understand the examples lessons.
22 '''
23 import sys
24 import os
25 # add the current working directory to the path
26 # DO NOT MOVE THE FOLLOWING STATEMENT
27 # if using autopep8 formatter, for example, set argument '--ignore=E402'
28 sys.path.append(os.getcwd())
29 
30 
31 def usage():
32  display = 'usage: python3 examples/basics/main.py option\n'
33  display += ' option must be one of the following\n'
34  display += ' --back_reference demonstrates back referencing\n'
35  display += ' --look_ahead demonstrates use of look ahead operators, & and !\n'
36  display += ' --look_behind demonstrates use of look behind operators, && and !!\n'
37  display += ' --parser demonstrates basic grammar generation and parsing\n'
38  display += ' --stats demonstrates displaying the parser\'s statistics\n'
39  display += ' --substrings demonstrates parsing a substring of the full input string\n'
40  display += ' --trace demonstrated displaying a trace of the parser\'s parse tree\n'
41  display += ' --udts demonstrates the use of User_Defined Terminals, handwritten phrase matching\n'
42  return display
43 
44 
45 if(len(sys.argv) == 1):
46  print(usage())
47  exit()
48 
49 if(sys.argv[1] == '--parser'):
51  exit()
52 
53 if(sys.argv[1] == '--back_reference'):
55  exit()
56 
57 if(sys.argv[1] == '--look_ahead'):
59  exit()
60 
61 if(sys.argv[1] == '--look_behind'):
63  exit()
64 
65 if(sys.argv[1] == '--stats'):
67  exit()
68 
69 if(sys.argv[1] == '--trace'):
71  exit()
72 
73 if(sys.argv[1] == '--substrings'):
75  exit()
76 
77 if(sys.argv[1] == '--udts'):
79  exit()
80 
81 print(usage())
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.