Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
eae93b76
Commit
eae93b76
authored
Feb 28, 2006
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for version field on Modules
parent
a7446e34
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
8 deletions
+29
-8
Parser/Python.asdl
Parser/Python.asdl
+1
-1
Parser/asdl.py
Parser/asdl.py
+27
-7
Parser/asdl_c.py
Parser/asdl_c.py
+1
-0
No files found.
Parser/Python.asdl
View file @
eae93b76
-- ASDL's five builtin types are identifier, int, string, object, bool
module Python
module Python
version "$Revision$"
{
mod = Module(stmt* body)
| Interactive(stmt* body)
...
...
Parser/asdl.py
View file @
eae93b76
...
...
@@ -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
...
...
@@ -37,6 +39,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
:
def
__init__
(
self
,
lineno
,
token
=
None
,
msg
=
None
):
...
...
@@ -64,6 +72,10 @@ class ASDLScanner(spark.GenericScanner, object):
# 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"<="
self
.
rv
.
append
(
Token
(
s
,
self
.
lineno
))
...
...
@@ -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
...
...
Parser/asdl_c.py
View file @
eae93b76
...
...
@@ -524,6 +524,7 @@ class ASTModuleVisitor(PickleVisitor):
self
.
emit
(
'if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;'
,
1
)
self
.
emit
(
'if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)'
,
1
)
self
.
emit
(
"return;"
,
2
)
self
.
emit
(
"/* %s */"
%
mod
.
version
.
value
,
1
)
for
dfn
in
mod
.
dfns
:
self
.
visit
(
dfn
)
self
.
emit
(
"}"
,
0
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment