Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/net/sunrpc/xdrgen/subcmds/lint.py
26292 views
1
#!/usr/bin/env python3
2
# ex: set filetype=python:
3
4
"""Translate an XDR specification into executable code that
5
can be compiled for the Linux kernel."""
6
7
import logging
8
9
from argparse import Namespace
10
from lark import logger
11
from lark.exceptions import UnexpectedInput
12
13
from xdr_parse import xdr_parser
14
from xdr_ast import transform_parse_tree
15
16
logger.setLevel(logging.DEBUG)
17
18
19
def handle_parse_error(e: UnexpectedInput) -> bool:
20
"""Simple parse error reporting, no recovery attempted"""
21
print(e)
22
return True
23
24
25
def 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
35