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/grammar_object/main.py
2 @brief The main function for the save and use grammar object demonstratons.
3 @dir examples/grammar_object
4 @brief An example of saving a grammar object and using it at a future time.
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 examples.grammar_object.save import save_grammar
13 from examples.grammar_object.use import use_grammar
14 
15 
16 def usage():
17  display = 'usage: examples/grammar_object/main.py [--save | --use]\n'
18  display += ' --save save the grammar object (default)\n'
19  display += ' --use use the previously used grammar object\n'
20  return display
21 
22 
23 test = 'save'
24 if(len(sys.argv) > 1):
25  if(sys.argv[1] == '--use'):
26  # use the previously saved grammar object
27  use_grammar()
28  exit()
29  if(sys.argv[1] != '--save'):
30  print(usage())
31  exit()
32 
33 # default is to save the grammar object for future use
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.