summaryrefslogtreecommitdiffstats
path: root/Parser/asdl.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2006-02-28 00:12:47 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2006-02-28 00:12:47 (GMT)
commiteae93b763cf84ef4fa44357190c7fdca3b8695fc (patch)
treec4be51df1b1dd568847f5802c6628935b195b9e2 /Parser/asdl.py
parenta7446e3438194e8abdfe75c2667b03a219e22a0b (diff)
downloadcpython-eae93b763cf84ef4fa44357190c7fdca3b8695fc.zip
cpython-eae93b763cf84ef4fa44357190c7fdca3b8695fc.tar.gz
cpython-eae93b763cf84ef4fa44357190c7fdca3b8695fc.tar.bz2
Add support for version field on Modules
Diffstat (limited to 'Parser/asdl.py')
-rw-r--r--Parser/asdl.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/Parser/asdl.py b/Parser/asdl.py
index 5b856dd..2128732 100644
--- a/Parser/asdl.py
+++ b/Parser/asdl.py
@@ -6,6 +6,8 @@ http://www.cs.princeton.edu/~danwang/Papers/dsl97/dsl97-abstract.html.
Only supports top level module decl, not view. I'm guessing that view
is intended to support the browser and I'm not interested in the
browser.
+
+Changes for Python: Add support for module versions
"""
#__metaclass__ = type
@@ -36,6 +38,12 @@ class Id(Token):
def __str__(self):
return self.value
+
+class String(Token):
+ def __init__(self, value, lineno):
+ self.type = 'String'
+ self.value = value
+ self.lineno = lineno
class ASDLSyntaxError:
@@ -63,6 +71,10 @@ class ASDLScanner(spark.GenericScanner, object):
# XXX doesn't distinguish upper vs. lower, which is
# significant for ASDL.
self.rv.append(Id(s, self.lineno))
+
+ def t_string(self, s):
+ r'"[^"]*"'
+ self.rv.append(String(s, self.lineno))
def t_xxx(self, s): # not sure what this production means
r"<="
@@ -98,19 +110,26 @@ class ASDLParser(spark.GenericParser, object):
def error(self, tok):
raise ASDLSyntaxError(tok.lineno, tok)
- def p_module_0(self, (module, name, _0, _1)):
- " module ::= Id Id { } "
+ def p_module_0(self, (module, name, version, _0, _1)):
+ " module ::= Id Id version { } "
if module.value != "module":
raise ASDLSyntaxError(module.lineno,
msg="expected 'module', found %s" % module)
- return Module(name, None)
+ return Module(name, None, version)
- def p_module(self, (module, name, _0, definitions, _1)):
- " module ::= Id Id { definitions } "
+ def p_module(self, (module, name, version, _0, definitions, _1)):
+ " module ::= Id Id version { definitions } "
if module.value != "module":
raise ASDLSyntaxError(module.lineno,
msg="expected 'module', found %s" % module)
- return Module(name, definitions)
+ return Module(name, definitions, version)
+
+ def p_version(self, (version, V)):
+ "version ::= Id String"
+ if version.value != "version":
+ raise ASDLSyntaxError(version.lineno,
+ msg="expected 'version', found %" % version)
+ return V
def p_definition_0(self, (definition,)):
" definitions ::= definition "
@@ -209,9 +228,10 @@ class AST:
pass # a marker class
class Module(AST):
- def __init__(self, name, dfns):
+ def __init__(self, name, dfns, version):
self.name = name
self.dfns = dfns
+ self.version = version
self.types = {} # maps type name to value (from dfns)
for type in dfns:
self.types[type.name.value] = type.value