xref: /linux/tools/net/sunrpc/xdrgen/subcmds/lint.py (revision 55d0969c451159cff86949b38c39171cab962069)
1#!/usr/bin/env python3
2# ex: set filetype=python:
3
4"""Translate an XDR specification into executable code that
5can be compiled for the Linux kernel."""
6
7import logging
8
9from argparse import Namespace
10from lark import logger
11from lark.exceptions import UnexpectedInput
12
13from xdr_parse import xdr_parser
14from xdr_ast import transform_parse_tree
15
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 True
23
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 0
34