File: xdr_parse.py

package info (click to toggle)
linux 6.18.15-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,742,528 kB
  • sloc: ansic: 26,787,393; asm: 272,099; sh: 148,804; python: 79,243; makefile: 57,755; perl: 36,527; xml: 19,542; cpp: 5,913; yacc: 4,939; lex: 2,950; awk: 1,607; sed: 30; ruby: 25
file content (36 lines) | stat: -rw-r--r-- 826 bytes parent folder | download | duplicates (28)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# ex: set filetype=python:

"""Common parsing code for xdrgen"""

from lark import Lark


# Set to True to emit annotation comments in generated source
annotate = False


def set_xdr_annotate(set_it: bool) -> None:
    """Set 'annotate' if --annotate was specified on the command line"""
    global annotate
    annotate = set_it


def get_xdr_annotate() -> bool:
    """Return True if --annotate was specified on the command line"""
    return annotate


def xdr_parser() -> Lark:
    """Return a Lark parser instance configured with the XDR language grammar"""

    return Lark.open(
        "grammars/xdr.lark",
        rel_to=__file__,
        start="specification",
        debug=True,
        strict=True,
        propagate_positions=True,
        parser="lalr",
        lexer="contextual",
    )