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
apg_py
api
syntax.py
Go to the documentation of this file.
1
''' @file apg_py/api/syntax.py
2
@brief Parse the SABNF grammar for syntax errors.
3
4
Generate the AST for the semantic phase (@ref semantic.py)
5
'''
6
# for development debugging only
7
from
apg_py.lib.trace
import
Trace
8
9
10
def
syntax
(api, strict):
11
'''Parse the SABNF grammar.
12
@param api The api object (@ref api.py) for the given grammar syntax.
13
@param strict If True, strictly follow the ABNF conventions of RFCs 5234 & 7405
14
@returns Returns a list of error, if any. Each error in the list has
15
the dictionary form
16
- 'line': the line number where the error occurred
17
- 'index': the approximate relative index within the line
18
where the error occurred
19
- 'msg': as descriptive error message
20
'''
21
data = {}
22
data[
'find_line'
] = api.find_line
23
data[
'strict'
] = strict
24
data[
'errors'
] = []
25
data[
'max_index'
] = 0
26
# Trace(api.parser, mode='xc')
27
result = api.parser.parse(api.input, user_data=data)
28
if(result.success
is
False
):
29
# raise Exception('Internal Error: syntax parser should never fail')
30
msg =
'fatal syntax error encountered'
31
msg +=
' - parser stopped approximately here'
32
data[
'errors'
].append({
33
'line'
: api.find_line(result.max_phrase_length),
34
'index'
: result.max_phrase_length,
35
'msg'
: msg
36
})
37
return
data[
'errors'
]
apg_py.api.syntax.syntax
def syntax(api, strict)
Parse the SABNF grammar.
Definition:
syntax.py:10
apg_py.lib.trace
Definition:
trace.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.