Version 1.0
Copyright © 2022 Lowell D. Thomas
Python APG
 … an ABNF Parser Generator
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')
Python APG, Version 1.0, is licensed under the 2-Clause BSD License,
an Open Source Initiative Approved License.