Path: blob/master/tools/net/sunrpc/xdrgen/subcmds/lint.py
26292 views
#!/usr/bin/env python31# ex: set filetype=python:23"""Translate an XDR specification into executable code that4can be compiled for the Linux kernel."""56import logging78from argparse import Namespace9from lark import logger10from lark.exceptions import UnexpectedInput1112from xdr_parse import xdr_parser13from xdr_ast import transform_parse_tree1415logger.setLevel(logging.DEBUG)161718def handle_parse_error(e: UnexpectedInput) -> bool:19"""Simple parse error reporting, no recovery attempted"""20print(e)21return True222324def subcmd(args: Namespace) -> int:25"""Lexical and syntax check of an XDR specification"""2627parser = xdr_parser()28with open(args.filename, encoding="utf-8") as f:29parse_tree = parser.parse(f.read(), on_error=handle_parse_error)30transform_parse_tree(parse_tree)3132return 0333435