• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import argparse
2
3from .pgen import ParserGenerator
4
5
6def main():
7    parser = argparse.ArgumentParser(description="Parser generator main program.")
8    parser.add_argument(
9        "grammar", type=str, help="The file with the grammar definition in EBNF format"
10    )
11    parser.add_argument(
12        "tokens", type=str, help="The file with the token definitions"
13    )
14    parser.add_argument(
15        "graminit_h",
16        type=argparse.FileType('w'),
17        help="The path to write the grammar's non-terminals as #defines",
18    )
19    parser.add_argument(
20        "graminit_c",
21        type=argparse.FileType('w'),
22        help="The path to write the grammar as initialized data",
23    )
24
25    parser.add_argument("--verbose", "-v", action="count")
26    args = parser.parse_args()
27
28    p = ParserGenerator(args.grammar, args.tokens, verbose=args.verbose)
29    grammar = p.make_grammar()
30    grammar.produce_graminit_h(args.graminit_h.write)
31    grammar.produce_graminit_c(args.graminit_c.write)
32
33
34if __name__ == "__main__":
35    main()
36