Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/net/sunrpc/xdrgen/xdr_parse.py
26289 views
1
#!/usr/bin/env python3
2
# ex: set filetype=python:
3
4
"""Common parsing code for xdrgen"""
5
6
from lark import Lark
7
8
9
# Set to True to emit annotation comments in generated source
10
annotate = False
11
12
13
def set_xdr_annotate(set_it: bool) -> None:
14
"""Set 'annotate' if --annotate was specified on the command line"""
15
global annotate
16
annotate = set_it
17
18
19
def get_xdr_annotate() -> bool:
20
"""Return True if --annotate was specified on the command line"""
21
return annotate
22
23
24
def xdr_parser() -> Lark:
25
"""Return a Lark parser instance configured with the XDR language grammar"""
26
27
return Lark.open(
28
"grammars/xdr.lark",
29
rel_to=__file__,
30
start="specification",
31
debug=True,
32
strict=True,
33
propagate_positions=True,
34
parser="lalr",
35
lexer="contextual",
36
)
37
38