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
1b1498b4
Commit
1b1498b4
authored
Aug 28, 2007
by
Collin Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Idiom adjustment in the docs for the parser module.
parent
d1d9a890
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
8 deletions
+6
-8
Doc/library/parser.rst
Doc/library/parser.rst
+6
-8
No files found.
Doc/library/parser.rst
View file @
1b1498b4
...
...
@@ -474,19 +474,17 @@ representation to be ``['variable_name']``. A simple recursive function can
implement the pattern matching, returning a Boolean and a dictionary of variable
name to value mappings. (See file :file:`example.py`.) ::
from types import ListType, TupleType
def match(pattern, data, vars=None):
if vars is None:
vars = {}
if
type(pattern) is ListType
:
if
isinstance(pattern, list)
:
vars[pattern[0]] = data
return
1
, vars
if
type(pattern) is not TupleType
:
return
True
, vars
if
not instance(pattern, tuple)
:
return (pattern == data), vars
if len(data) != len(pattern):
return
0
, vars
for pattern, data in
map(None,
pattern, data):
return
False
, vars
for pattern, data in
zip(
pattern, data):
same, vars = match(pattern, data, vars)
if not same:
break
...
...
@@ -528,7 +526,7 @@ docstring from the parse tree created previously is easy::
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
>>> found
1
True
>>> vars
{'docstring': '"""Some documentation.\n"""'}
...
...
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