OILS / opy / misc / pgen_ast.py View on Github | oilshell.org

30 lines, 14 significant
1"""
2foil/pgen_ast.py -- Parse pgen.asdl and dynamically create classes on this
3module.
4
5Similar to osh/ast_.py.
6"""
7
8import os
9import sys
10
11from asdl import py_meta
12from asdl import asdl_ as asdl
13
14def _ParseAndMakeTypes(schema_path, root):
15 module = asdl.parse(schema_path)
16
17 app_types = {}
18
19 # Check for type errors
20 if not asdl.check(module, app_types):
21 raise AssertionError('ASDL file is invalid')
22 py_meta.MakeTypes(module, root, app_types)
23
24
25bin_dir = os.path.dirname(os.path.abspath(sys.argv[0])) # ~/git/oil/bin
26schema_path = os.path.join(bin_dir, '../foil/pgen.asdl') # ~/git/oil/osh
27
28root = sys.modules[__name__]
29
30_ParseAndMakeTypes(schema_path, root)