| 1 | """
 | 
| 2 | Wrapper for Python.asdl.
 | 
| 3 | """
 | 
| 4 | 
 | 
| 5 | import os
 | 
| 6 | import sys
 | 
| 7 | 
 | 
| 8 | from asdl import py_meta
 | 
| 9 | from asdl import asdl_ as asdl
 | 
| 10 | 
 | 
| 11 | # Dummy types for now
 | 
| 12 | class Identifier:
 | 
| 13 |   pass
 | 
| 14 | 
 | 
| 15 | class Bytes:
 | 
| 16 |   pass
 | 
| 17 | 
 | 
| 18 | class PyObject:
 | 
| 19 |   pass
 | 
| 20 | 
 | 
| 21 | class Constant:
 | 
| 22 |   pass
 | 
| 23 | 
 | 
| 24 | class Singleton:
 | 
| 25 |   pass
 | 
| 26 | 
 | 
| 27 | 
 | 
| 28 |   # TODO: Fill these in:
 | 
| 29 |   #
 | 
| 30 |   # Num(object n) -- a number as a PyObject.
 | 
| 31 |   # Bytes(bytes s)
 | 
| 32 |   # Constant(constant value)
 | 
| 33 |   # NameConstant(singleton value)
 | 
| 34 |   #
 | 
| 35 |   # singleton: None, True or False
 | 
| 36 |   # constant can be None, whereas None means "no value" for object.
 | 
| 37 |   #
 | 
| 38 |   # Hm do I want an LST?  Then it shouldn't have these typed values?  That
 | 
| 39 |   # comes later?
 | 
| 40 |   #
 | 
| 41 |   # identifier: this one is used a lot.  Why not string?
 | 
| 42 | 
 | 
| 43 | def _ParseAndMakeTypes(schema_path, root):
 | 
| 44 |   module = asdl.parse(schema_path)
 | 
| 45 | 
 | 
| 46 |   app_types = {
 | 
| 47 |       'identifier': asdl.UserType(Identifier),
 | 
| 48 |       'bytes': asdl.UserType(Bytes),
 | 
| 49 |       'object': asdl.UserType(PyObject),
 | 
| 50 |       'constant': asdl.UserType(Constant),
 | 
| 51 |       'singleton': asdl.UserType(Singleton),
 | 
| 52 |   }
 | 
| 53 | 
 | 
| 54 |   # Check for type errors
 | 
| 55 |   if not asdl.check(module, app_types):
 | 
| 56 |     raise AssertionError('ASDL file is invalid')
 | 
| 57 |   py_meta.MakeTypes(module, root, app_types)
 | 
| 58 | 
 | 
| 59 | 
 | 
| 60 | bin_dir = os.path.dirname(os.path.abspath(sys.argv[0]))  # ~/git/oil/bin
 | 
| 61 | schema_path = os.path.join(bin_dir, '../foil/Python.asdl')  # ~/git/oil/osh
 | 
| 62 | 
 | 
| 63 | root = sys.modules[__name__]
 | 
| 64 | 
 | 
| 65 | _ParseAndMakeTypes(schema_path, root)
 |