brintos

brintos / linux-shallow public Read only

0
0
Text · 825 B · 36cc437 Raw
34 lines · python
1#!/usr/bin/env python32# ex: set filetype=python:3 4"""Translate an XDR specification into executable code that5can be compiled for the Linux kernel."""6 7import logging8 9from argparse import Namespace10from lark import logger11from lark.exceptions import UnexpectedInput12 13from xdr_parse import xdr_parser14from xdr_ast import transform_parse_tree15 16logger.setLevel(logging.DEBUG)17 18 19def handle_parse_error(e: UnexpectedInput) -> bool:20    """Simple parse error reporting, no recovery attempted"""21    print(e)22    return True23 24 25def subcmd(args: Namespace) -> int:26    """Lexical and syntax check of an XDR specification"""27 28    parser = xdr_parser()29    with open(args.filename, encoding="utf-8") as f:30        parse_tree = parser.parse(f.read(), on_error=handle_parse_error)31        transform_parse_tree(parse_tree)32 33    return 034