xref: /linux/tools/net/sunrpc/xdrgen/xdr_parse.py (revision 55d0969c451159cff86949b38c39171cab962069)
1#!/usr/bin/env python3
2# ex: set filetype=python:
3
4"""Common parsing code for xdrgen"""
5
6from lark import Lark
7
8
9# Set to True to emit annotation comments in generated source
10annotate = False
11
12
13def 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
19def get_xdr_annotate() -> bool:
20    """Return True if --annotate was specified on the command line"""
21    return annotate
22
23
24def 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