37 lines · python
1#!/usr/bin/env python32# ex: set filetype=python:3 4"""Common parsing code for xdrgen"""5 6from lark import Lark7 8 9# Set to True to emit annotation comments in generated source10annotate = False11 12 13def set_xdr_annotate(set_it: bool) -> None:14 """Set 'annotate' if --annotate was specified on the command line"""15 global annotate16 annotate = set_it17 18 19def get_xdr_annotate() -> bool:20 """Return True if --annotate was specified on the command line"""21 return annotate22 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