| 1 | """
 | 
| 2 | foil/pgen_ast.py -- Parse pgen.asdl and dynamically create classes on this
 | 
| 3 | module.
 | 
| 4 | 
 | 
| 5 | Similar to osh/ast_.py.
 | 
| 6 | """
 | 
| 7 | 
 | 
| 8 | import os
 | 
| 9 | import sys
 | 
| 10 | 
 | 
| 11 | from asdl import py_meta
 | 
| 12 | from asdl import asdl_ as asdl
 | 
| 13 | 
 | 
| 14 | def _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 | 
 | 
| 25 | bin_dir = os.path.dirname(os.path.abspath(sys.argv[0]))  # ~/git/oil/bin
 | 
| 26 | schema_path = os.path.join(bin_dir, '../foil/pgen.asdl')  # ~/git/oil/osh
 | 
| 27 | 
 | 
| 28 | root = sys.modules[__name__]
 | 
| 29 | 
 | 
| 30 | _ParseAndMakeTypes(schema_path, root)
 |