2005-10-20 16:59:25 -03:00
|
|
|
"""An implementation of the Zephyr Abstract Syntax Definition Language.
|
|
|
|
|
|
|
|
See http://asdl.sourceforge.net/ and
|
2010-05-18 10:48:45 -03:00
|
|
|
http://www.cs.princeton.edu/research/techreps/TR-554-97
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
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.
|
2006-02-27 20:12:47 -04:00
|
|
|
|
|
|
|
Changes for Python: Add support for module versions
|
2005-10-20 16:59:25 -03:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
2007-05-07 19:24:25 -03:00
|
|
|
import sys
|
2005-10-20 16:59:25 -03:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
import spark
|
|
|
|
|
2013-09-26 10:31:32 -03:00
|
|
|
def output(*strings):
|
|
|
|
for s in strings:
|
|
|
|
sys.stdout.write(str(s) + "\n")
|
2007-05-07 19:24:25 -03:00
|
|
|
|
|
|
|
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
class Token(object):
|
2005-10-20 16:59:25 -03:00
|
|
|
# spark seems to dispatch in the parser based on a token's
|
|
|
|
# type attribute
|
|
|
|
def __init__(self, type, lineno):
|
|
|
|
self.type = type
|
|
|
|
self.lineno = lineno
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.type
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
class Id(Token):
|
|
|
|
def __init__(self, value, lineno):
|
|
|
|
self.type = 'Id'
|
|
|
|
self.value = value
|
|
|
|
self.lineno = lineno
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.value
|
2006-02-28 14:30:36 -04:00
|
|
|
|
2006-02-27 20:12:47 -04:00
|
|
|
class String(Token):
|
|
|
|
def __init__(self, value, lineno):
|
|
|
|
self.type = 'String'
|
|
|
|
self.value = value
|
|
|
|
self.lineno = lineno
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-07 19:24:25 -03:00
|
|
|
class ASDLSyntaxError(Exception):
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
def __init__(self, lineno, token=None, msg=None):
|
|
|
|
self.lineno = lineno
|
|
|
|
self.token = token
|
|
|
|
self.msg = msg
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.msg is None:
|
|
|
|
return "Error at '%s', line %d" % (self.token, self.lineno)
|
|
|
|
else:
|
|
|
|
return "%s, line %d" % (self.msg, self.lineno)
|
|
|
|
|
|
|
|
class ASDLScanner(spark.GenericScanner, object):
|
|
|
|
|
|
|
|
def tokenize(self, input):
|
|
|
|
self.rv = []
|
|
|
|
self.lineno = 1
|
|
|
|
super(ASDLScanner, self).tokenize(input)
|
|
|
|
return self.rv
|
|
|
|
|
|
|
|
def t_id(self, s):
|
|
|
|
r"[\w\.]+"
|
|
|
|
# XXX doesn't distinguish upper vs. lower, which is
|
|
|
|
# significant for ASDL.
|
|
|
|
self.rv.append(Id(s, self.lineno))
|
2006-02-28 14:30:36 -04:00
|
|
|
|
2006-02-27 20:12:47 -04:00
|
|
|
def t_string(self, s):
|
|
|
|
r'"[^"]*"'
|
|
|
|
self.rv.append(String(s, self.lineno))
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
def t_xxx(self, s): # not sure what this production means
|
|
|
|
r"<="
|
|
|
|
self.rv.append(Token(s, self.lineno))
|
|
|
|
|
|
|
|
def t_punctuation(self, s):
|
|
|
|
r"[\{\}\*\=\|\(\)\,\?\:]"
|
|
|
|
self.rv.append(Token(s, self.lineno))
|
|
|
|
|
|
|
|
def t_comment(self, s):
|
|
|
|
r"\-\-[^\n]*"
|
|
|
|
pass
|
|
|
|
|
|
|
|
def t_newline(self, s):
|
|
|
|
r"\n"
|
|
|
|
self.lineno += 1
|
|
|
|
|
|
|
|
def t_whitespace(self, s):
|
|
|
|
r"[ \t]+"
|
|
|
|
pass
|
|
|
|
|
|
|
|
def t_default(self, s):
|
|
|
|
r" . +"
|
2007-08-30 15:18:27 -03:00
|
|
|
raise ValueError("unmatched input: %r" % s)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
class ASDLParser(spark.GenericParser, object):
|
|
|
|
def __init__(self):
|
|
|
|
super(ASDLParser, self).__init__("module")
|
|
|
|
|
|
|
|
def typestring(self, tok):
|
|
|
|
return tok.type
|
|
|
|
|
|
|
|
def error(self, tok):
|
|
|
|
raise ASDLSyntaxError(tok.lineno, tok)
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_module_0(self, info):
|
2011-03-12 20:28:16 -04:00
|
|
|
" module ::= Id Id { } "
|
|
|
|
module, name, _0, _1 = info
|
2005-10-20 16:59:25 -03:00
|
|
|
if module.value != "module":
|
|
|
|
raise ASDLSyntaxError(module.lineno,
|
|
|
|
msg="expected 'module', found %s" % module)
|
2011-03-12 20:28:16 -04:00
|
|
|
return Module(name, None)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_module(self, info):
|
2011-03-12 20:28:16 -04:00
|
|
|
" module ::= Id Id { definitions } "
|
|
|
|
module, name, _0, definitions, _1 = info
|
2005-10-20 16:59:25 -03:00
|
|
|
if module.value != "module":
|
|
|
|
raise ASDLSyntaxError(module.lineno,
|
|
|
|
msg="expected 'module', found %s" % module)
|
2011-03-12 20:28:16 -04:00
|
|
|
return Module(name, definitions)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_definition_0(self, definition):
|
2005-10-20 16:59:25 -03:00
|
|
|
" definitions ::= definition "
|
2007-05-15 15:46:22 -03:00
|
|
|
return definition[0]
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_definition_1(self, definitions):
|
2005-10-20 16:59:25 -03:00
|
|
|
" definitions ::= definition definitions "
|
2007-05-15 15:46:22 -03:00
|
|
|
return definitions[0] + definitions[1]
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_definition(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" definition ::= Id = type "
|
2007-05-15 15:46:22 -03:00
|
|
|
id, _, type = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return [Type(id, type)]
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_type_0(self, product):
|
2005-10-20 16:59:25 -03:00
|
|
|
" type ::= product "
|
2007-05-15 15:46:22 -03:00
|
|
|
return product[0]
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_type_1(self, sum):
|
2005-10-20 16:59:25 -03:00
|
|
|
" type ::= sum "
|
2007-05-15 15:46:22 -03:00
|
|
|
return Sum(sum[0])
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_type_2(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" type ::= sum Id ( fields ) "
|
2007-05-15 15:46:22 -03:00
|
|
|
sum, id, _0, attributes, _1 = info
|
2005-10-20 16:59:25 -03:00
|
|
|
if id.value != "attributes":
|
|
|
|
raise ASDLSyntaxError(id.lineno,
|
|
|
|
msg="expected attributes, found %s" % id)
|
|
|
|
return Sum(sum, attributes)
|
|
|
|
|
2013-03-18 14:48:58 -03:00
|
|
|
def p_product_0(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" product ::= ( fields ) "
|
2007-05-15 15:46:22 -03:00
|
|
|
_0, fields, _1 = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return Product(fields)
|
|
|
|
|
2013-03-18 14:48:58 -03:00
|
|
|
def p_product_1(self, info):
|
|
|
|
" product ::= ( fields ) Id ( fields ) "
|
|
|
|
_0, fields, _1, id, _2, attributes, _3 = info
|
|
|
|
if id.value != "attributes":
|
|
|
|
raise ASDLSyntaxError(id.lineno,
|
|
|
|
msg="expected attributes, found %s" % id)
|
|
|
|
return Product(fields, attributes)
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_sum_0(self, constructor):
|
Merged revisions 68162,68166,68171,68176,68195-68196,68210,68232 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r68162 | ronald.oussoren | 2009-01-02 16:06:00 +0100 (Fri, 02 Jan 2009) | 3 lines
Fix for issue 4472 is incompatible with Cygwin, this patch
should fix that.
........
r68166 | benjamin.peterson | 2009-01-02 19:26:23 +0100 (Fri, 02 Jan 2009) | 1 line
document PyMemberDef
........
r68171 | georg.brandl | 2009-01-02 21:25:14 +0100 (Fri, 02 Jan 2009) | 3 lines
#4811: fix markup glitches (mostly remains of the conversion),
found by Gabriel Genellina.
........
r68176 | andrew.kuchling | 2009-01-02 22:00:35 +0100 (Fri, 02 Jan 2009) | 1 line
Add various items
........
r68195 | georg.brandl | 2009-01-03 14:45:15 +0100 (Sat, 03 Jan 2009) | 2 lines
Remove useless string literal.
........
r68196 | georg.brandl | 2009-01-03 15:29:53 +0100 (Sat, 03 Jan 2009) | 2 lines
Fix indentation.
........
r68210 | georg.brandl | 2009-01-03 20:10:12 +0100 (Sat, 03 Jan 2009) | 2 lines
Set eol-style correctly for mp_distributing.py.
........
r68232 | georg.brandl | 2009-01-03 22:52:16 +0100 (Sat, 03 Jan 2009) | 2 lines
Grammar fix.
........
2009-01-03 18:47:39 -04:00
|
|
|
" sum ::= constructor "
|
2007-05-15 15:46:22 -03:00
|
|
|
return [constructor[0]]
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2008-03-17 15:03:56 -03:00
|
|
|
def p_sum_1(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" sum ::= constructor | sum "
|
2007-05-15 15:46:22 -03:00
|
|
|
constructor, _, sum = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return [constructor] + sum
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_sum_2(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" sum ::= constructor | sum "
|
2007-05-15 15:46:22 -03:00
|
|
|
constructor, _, sum = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return [constructor] + sum
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_constructor_0(self, id):
|
2005-10-20 16:59:25 -03:00
|
|
|
" constructor ::= Id "
|
2007-05-15 15:46:22 -03:00
|
|
|
return Constructor(id[0])
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_constructor_1(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" constructor ::= Id ( fields ) "
|
2007-05-15 15:46:22 -03:00
|
|
|
id, _0, fields, _1 = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return Constructor(id, fields)
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_fields_0(self, field):
|
2005-10-20 16:59:25 -03:00
|
|
|
" fields ::= field "
|
2007-05-15 15:46:22 -03:00
|
|
|
return [field[0]]
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_fields_1(self, info):
|
2012-08-01 01:41:56 -03:00
|
|
|
" fields ::= fields , field "
|
|
|
|
fields, _, field = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return fields + [field]
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_0(self, type_):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id "
|
2007-05-15 15:46:22 -03:00
|
|
|
return Field(type_[0])
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_1(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id Id "
|
2007-05-15 15:46:22 -03:00
|
|
|
type, name = info
|
2005-10-20 16:59:25 -03:00
|
|
|
return Field(type, name)
|
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_2(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id * Id "
|
2007-05-15 15:46:22 -03:00
|
|
|
type, _, name = info
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
return Field(type, name, seq=True)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_3(self, info):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id ? Id "
|
2007-05-15 15:46:22 -03:00
|
|
|
type, _, name = info
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
return Field(type, name, opt=True)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_4(self, type_):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id * "
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
return Field(type_[0], seq=True)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2007-05-15 15:46:22 -03:00
|
|
|
def p_field_5(self, type_):
|
2005-10-20 16:59:25 -03:00
|
|
|
" field ::= Id ? "
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
return Field(type[0], opt=True)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2012-12-06 18:41:04 -04:00
|
|
|
builtin_types = ("identifier", "string", "bytes", "int", "object", "singleton")
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
# below is a collection of classes to capture the AST of an AST :-)
|
|
|
|
# not sure if any of the methods are useful yet, but I'm adding them
|
|
|
|
# piecemeal as they seem helpful
|
|
|
|
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
class AST(object):
|
2005-10-20 16:59:25 -03:00
|
|
|
pass # a marker class
|
|
|
|
|
|
|
|
class Module(AST):
|
2011-03-12 20:28:16 -04:00
|
|
|
def __init__(self, name, dfns):
|
2005-10-20 16:59:25 -03:00
|
|
|
self.name = name
|
|
|
|
self.dfns = dfns
|
|
|
|
self.types = {} # maps type name to value (from dfns)
|
|
|
|
for type in dfns:
|
|
|
|
self.types[type.name.value] = type.value
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Module(%s, %s)" % (self.name, self.dfns)
|
|
|
|
|
|
|
|
class Type(AST):
|
|
|
|
def __init__(self, name, value):
|
|
|
|
self.name = name
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Type(%s, %s)" % (self.name, self.value)
|
|
|
|
|
|
|
|
class Constructor(AST):
|
|
|
|
def __init__(self, name, fields=None):
|
|
|
|
self.name = name
|
|
|
|
self.fields = fields or []
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return "Constructor(%s, %s)" % (self.name, self.fields)
|
|
|
|
|
|
|
|
class Field(AST):
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
def __init__(self, type, name=None, seq=False, opt=False):
|
2005-10-20 16:59:25 -03:00
|
|
|
self.type = type
|
|
|
|
self.name = name
|
|
|
|
self.seq = seq
|
|
|
|
self.opt = opt
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
if self.seq:
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
extra = ", seq=True"
|
2005-10-20 16:59:25 -03:00
|
|
|
elif self.opt:
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
extra = ", opt=True"
|
2005-10-20 16:59:25 -03:00
|
|
|
else:
|
|
|
|
extra = ""
|
|
|
|
if self.name is None:
|
|
|
|
return "Field(%s%s)" % (self.type, extra)
|
|
|
|
else:
|
|
|
|
return "Field(%s, %s%s)" % (self.type, self.name, extra)
|
|
|
|
|
|
|
|
class Sum(AST):
|
|
|
|
def __init__(self, types, attributes=None):
|
|
|
|
self.types = types
|
|
|
|
self.attributes = attributes or []
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
if self.attributes is None:
|
|
|
|
return "Sum(%s)" % self.types
|
|
|
|
else:
|
|
|
|
return "Sum(%s, %s)" % (self.types, self.attributes)
|
|
|
|
|
|
|
|
class Product(AST):
|
2013-03-18 14:48:58 -03:00
|
|
|
def __init__(self, fields, attributes=None):
|
2005-10-20 16:59:25 -03:00
|
|
|
self.fields = fields
|
2013-03-18 14:48:58 -03:00
|
|
|
self.attributes = attributes or []
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
def __repr__(self):
|
2013-03-18 14:48:58 -03:00
|
|
|
if self.attributes is None:
|
|
|
|
return "Product(%s)" % self.fields
|
|
|
|
else:
|
|
|
|
return "Product(%s, %s)" % (self.fields, self.attributes)
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
class VisitorBase(object):
|
|
|
|
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
def __init__(self, skip=False):
|
2005-10-20 16:59:25 -03:00
|
|
|
self.cache = {}
|
|
|
|
self.skip = skip
|
|
|
|
|
|
|
|
def visit(self, object, *args):
|
|
|
|
meth = self._dispatch(object)
|
|
|
|
if meth is None:
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
meth(object, *args)
|
2007-05-07 19:24:25 -03:00
|
|
|
except Exception:
|
2009-07-17 02:35:59 -03:00
|
|
|
output("Error visiting" + repr(object))
|
|
|
|
output(str(sys.exc_info()[1]))
|
2005-10-20 16:59:25 -03:00
|
|
|
traceback.print_exc()
|
|
|
|
# XXX hack
|
|
|
|
if hasattr(self, 'file'):
|
|
|
|
self.file.flush()
|
|
|
|
os._exit(1)
|
|
|
|
|
|
|
|
def _dispatch(self, object):
|
|
|
|
assert isinstance(object, AST), repr(object)
|
|
|
|
klass = object.__class__
|
|
|
|
meth = self.cache.get(klass)
|
|
|
|
if meth is None:
|
|
|
|
methname = "visit" + klass.__name__
|
|
|
|
if self.skip:
|
|
|
|
meth = getattr(self, methname, None)
|
|
|
|
else:
|
|
|
|
meth = getattr(self, methname)
|
|
|
|
self.cache[klass] = meth
|
|
|
|
return meth
|
|
|
|
|
|
|
|
class Check(VisitorBase):
|
|
|
|
|
|
|
|
def __init__(self):
|
Merged revisions 73196,73278-73280,73299,73308,73312-73313,73317-73318,73321,73324,73331,73335,73340,73363 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r73196 | benjamin.peterson | 2009-06-03 20:40:29 -0500 (Wed, 03 Jun 2009) | 1 line
use the offical api
........
r73278 | benjamin.peterson | 2009-06-07 17:33:11 -0500 (Sun, 07 Jun 2009) | 1 line
inherit from object
........
r73279 | benjamin.peterson | 2009-06-07 17:35:00 -0500 (Sun, 07 Jun 2009) | 1 line
always inherit from an appropiate base class
........
r73280 | benjamin.peterson | 2009-06-07 17:54:35 -0500 (Sun, 07 Jun 2009) | 1 line
use booleans for flags
........
r73299 | georg.brandl | 2009-06-08 13:41:36 -0500 (Mon, 08 Jun 2009) | 1 line
Typo fix.
........
r73308 | benjamin.peterson | 2009-06-08 17:18:32 -0500 (Mon, 08 Jun 2009) | 1 line
remove useless assertion
........
r73312 | benjamin.peterson | 2009-06-08 18:44:13 -0500 (Mon, 08 Jun 2009) | 1 line
remove error checks already done in set_context()
........
r73313 | r.david.murray | 2009-06-08 19:44:22 -0500 (Mon, 08 Jun 2009) | 4 lines
Issue 2947: document how return code handling translates from
os.popen to subprocess. Also fixes reference link in the
os.spawn documentation.
........
r73317 | benjamin.peterson | 2009-06-09 12:24:26 -0500 (Tue, 09 Jun 2009) | 1 line
make ast.c depend on the grammar
........
r73318 | benjamin.peterson | 2009-06-09 12:29:51 -0500 (Tue, 09 Jun 2009) | 1 line
explain why keyword names are not just NAME
........
r73321 | benjamin.peterson | 2009-06-09 16:13:43 -0500 (Tue, 09 Jun 2009) | 1 line
update symbol.py from with statement changes
........
r73324 | amaury.forgeotdarc | 2009-06-09 17:53:16 -0500 (Tue, 09 Jun 2009) | 2 lines
Avoid invoking the parser/compiler just to test the presence of a function.
........
r73331 | benjamin.peterson | 2009-06-10 08:45:31 -0500 (Wed, 10 Jun 2009) | 1 line
fix spelling
........
r73335 | raymond.hettinger | 2009-06-10 11:15:40 -0500 (Wed, 10 Jun 2009) | 1 line
Fix signed/unsigned compiler warning.
........
r73340 | amaury.forgeotdarc | 2009-06-10 15:30:19 -0500 (Wed, 10 Jun 2009) | 2 lines
Fix a typo spotted by Nick Coghlan.
........
r73363 | benjamin.peterson | 2009-06-11 12:51:17 -0500 (Thu, 11 Jun 2009) | 1 line
use multi-with syntax
........
2009-06-11 19:54:11 -03:00
|
|
|
super(Check, self).__init__(skip=True)
|
2005-10-20 16:59:25 -03:00
|
|
|
self.cons = {}
|
|
|
|
self.errors = 0
|
|
|
|
self.types = {}
|
|
|
|
|
|
|
|
def visitModule(self, mod):
|
|
|
|
for dfn in mod.dfns:
|
|
|
|
self.visit(dfn)
|
|
|
|
|
|
|
|
def visitType(self, type):
|
|
|
|
self.visit(type.value, str(type.name))
|
|
|
|
|
|
|
|
def visitSum(self, sum, name):
|
|
|
|
for t in sum.types:
|
|
|
|
self.visit(t, name)
|
|
|
|
|
|
|
|
def visitConstructor(self, cons, name):
|
|
|
|
key = str(cons.name)
|
|
|
|
conflict = self.cons.get(key)
|
|
|
|
if conflict is None:
|
|
|
|
self.cons[key] = name
|
|
|
|
else:
|
2007-05-07 19:24:25 -03:00
|
|
|
output("Redefinition of constructor %s" % key)
|
|
|
|
output("Defined in %s and %s" % (conflict, name))
|
2005-10-20 16:59:25 -03:00
|
|
|
self.errors += 1
|
|
|
|
for f in cons.fields:
|
|
|
|
self.visit(f, key)
|
|
|
|
|
|
|
|
def visitField(self, field, name):
|
|
|
|
key = str(field.type)
|
|
|
|
l = self.types.setdefault(key, [])
|
|
|
|
l.append(name)
|
|
|
|
|
|
|
|
def visitProduct(self, prod, name):
|
|
|
|
for f in prod.fields:
|
|
|
|
self.visit(f, name)
|
|
|
|
|
|
|
|
def check(mod):
|
|
|
|
v = Check()
|
|
|
|
v.visit(mod)
|
|
|
|
|
|
|
|
for t in v.types:
|
2006-12-29 00:42:48 -04:00
|
|
|
if t not in mod.types and not t in builtin_types:
|
2005-10-20 16:59:25 -03:00
|
|
|
v.errors += 1
|
|
|
|
uses = ", ".join(v.types[t])
|
2007-05-07 19:24:25 -03:00
|
|
|
output("Undefined type %s, used in %s" % (t, uses))
|
2005-12-25 19:18:31 -04:00
|
|
|
|
2005-10-20 16:59:25 -03:00
|
|
|
return not v.errors
|
|
|
|
|
|
|
|
def parse(file):
|
|
|
|
scanner = ASDLScanner()
|
|
|
|
parser = ASDLParser()
|
|
|
|
|
2013-09-26 13:35:39 -03:00
|
|
|
f = open(file)
|
2013-09-26 10:41:36 -03:00
|
|
|
try:
|
2013-09-26 10:32:22 -03:00
|
|
|
buf = f.read()
|
2013-09-26 10:41:36 -03:00
|
|
|
finally:
|
|
|
|
f.close()
|
2005-10-20 16:59:25 -03:00
|
|
|
tokens = scanner.tokenize(buf)
|
|
|
|
try:
|
|
|
|
return parser.parse(tokens)
|
2007-05-07 19:24:25 -03:00
|
|
|
except ASDLSyntaxError:
|
2009-04-12 08:34:13 -03:00
|
|
|
err = sys.exc_info()[1]
|
|
|
|
output(str(err))
|
2005-10-20 16:59:25 -03:00
|
|
|
lines = buf.split("\n")
|
2007-05-07 19:24:25 -03:00
|
|
|
output(lines[err.lineno - 1]) # lines starts at 0, files at 1
|
2005-10-20 16:59:25 -03:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import glob
|
|
|
|
import sys
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
files = sys.argv[1:]
|
|
|
|
else:
|
|
|
|
testdir = "tests"
|
|
|
|
files = glob.glob(testdir + "/*.asdl")
|
2005-12-25 19:18:31 -04:00
|
|
|
|
2005-10-20 16:59:25 -03:00
|
|
|
for file in files:
|
2007-05-07 19:24:25 -03:00
|
|
|
output(file)
|
2005-10-20 16:59:25 -03:00
|
|
|
mod = parse(file)
|
2009-04-12 08:34:13 -03:00
|
|
|
if not mod:
|
|
|
|
break
|
2007-05-07 19:24:25 -03:00
|
|
|
output("module", mod.name)
|
|
|
|
output(len(mod.dfns), "definitions")
|
2005-10-20 16:59:25 -03:00
|
|
|
if not check(mod):
|
2007-05-07 19:24:25 -03:00
|
|
|
output("Check failed")
|
2005-10-20 16:59:25 -03:00
|
|
|
else:
|
|
|
|
for dfn in mod.dfns:
|
2013-09-26 10:31:32 -03:00
|
|
|
output(dfn.name, dfn.value)
|