Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
trs
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
trs
Commits
290f2847
Commit
290f2847
authored
Apr 18, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added operator for verbose rewrite_all (verbose means that each step is printed).
parent
fe3485a8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
src/node.py
src/node.py
+6
-3
src/parser.py
src/parser.py
+14
-7
No files found.
src/node.py
View file @
290f2847
...
@@ -50,7 +50,8 @@ OP_EQ = 21
...
@@ -50,7 +50,8 @@ OP_EQ = 21
OP_POSSIBILITIES
=
22
OP_POSSIBILITIES
=
22
OP_HINT
=
23
OP_HINT
=
23
OP_REWRITE_ALL
=
24
OP_REWRITE_ALL
=
24
OP_REWRITE
=
25
OP_REWRITE_ALL_VERBOSE
=
25
OP_REWRITE
=
26
# Special identifiers
# Special identifiers
PI
=
'pi'
PI
=
'pi'
...
@@ -90,8 +91,9 @@ OP_MAP = {
...
@@ -90,8 +91,9 @@ OP_MAP = {
'='
:
OP_EQ
,
'='
:
OP_EQ
,
'??'
:
OP_POSSIBILITIES
,
'??'
:
OP_POSSIBILITIES
,
'?'
:
OP_HINT
,
'?'
:
OP_HINT
,
'@@'
:
OP_REWRITE_ALL
,
'@'
:
OP_REWRITE
,
'@'
:
OP_REWRITE
,
'@@'
:
OP_REWRITE_ALL
,
'@@@'
:
OP_REWRITE_ALL_VERBOSE
,
}
}
OP_VALUE_MAP
=
dict
([(
v
,
k
)
for
k
,
v
in
OP_MAP
.
iteritems
()])
OP_VALUE_MAP
=
dict
([(
v
,
k
)
for
k
,
v
in
OP_MAP
.
iteritems
()])
...
@@ -120,8 +122,9 @@ TOKEN_MAP = {
...
@@ -120,8 +122,9 @@ TOKEN_MAP = {
OP_EQ
:
'EQ'
,
OP_EQ
:
'EQ'
,
OP_POSSIBILITIES
:
'POSSIBILITIES'
,
OP_POSSIBILITIES
:
'POSSIBILITIES'
,
OP_HINT
:
'HINT'
,
OP_HINT
:
'HINT'
,
OP_REWRITE_ALL
:
'REWRITE_ALL'
,
OP_REWRITE
:
'REWRITE'
,
OP_REWRITE
:
'REWRITE'
,
OP_REWRITE_ALL
:
'REWRITE_ALL'
,
OP_REWRITE_ALL_VERBOSE
:
'REWRITE_ALL_VERBOSE'
,
}
}
...
...
src/parser.py
View file @
290f2847
...
@@ -261,7 +261,7 @@ class Parser(BisonParser):
...
@@ -261,7 +261,7 @@ class Parser(BisonParser):
for i, p in enumerate(self.possibilities):
for i, p in enumerate(self.possibilities):
print '
%
d
%
s
' % (i, p)
print '
%
d
%
s
' % (i, p)
def rewrite(self, index=0):
def rewrite(self, index=0
, verbose=False
):
self.find_possibilities()
self.find_possibilities()
if not self.possibilities:
if not self.possibilities:
...
@@ -271,26 +271,33 @@ class Parser(BisonParser):
...
@@ -271,26 +271,33 @@ class Parser(BisonParser):
if self.verbose:
if self.verbose:
print '
Applying
suggestion
:
', suggestion
print '
Applying
suggestion
:
', suggestion
elif verbose:
print suggestion
expression = apply_suggestion(self.root_node, suggestion)
expression = apply_suggestion(self.root_node, suggestion)
if self.verbose:
if self.verbose:
print '
After
application
:
', expression
print '
After
application
:
', expression
elif verbose:
print expression
self.set_root_node(expression)
self.set_root_node(expression)
return True
return True
def rewrite_all(self):
def rewrite_all(self
, verbose=False
):
i = 0
i = 0
while self.rewrite():
while self.rewrite(
verbose=verbose
):
i += 1
i += 1
if i > 100:
if i > 100:
print '
Too
many
rewrite
steps
,
aborting
...
'
print '
Too
many
rewrite
steps
,
aborting
...
'
break
break
if not verbose:
return self.root_node
#def hook_run(self, filename, retval):
#def hook_run(self, filename, retval):
# return retval
# return retval
...
@@ -331,6 +338,7 @@ class Parser(BisonParser):
...
@@ -331,6 +338,7 @@ class Parser(BisonParser):
| REWRITE NEWLINE
| REWRITE NEWLINE
| REWRITE NUMBER NEWLINE
| REWRITE NUMBER NEWLINE
| REWRITE_ALL NEWLINE
| REWRITE_ALL NEWLINE
| REWRITE_ALL_VERBOSE NEWLINE
| RAISE NEWLINE
| RAISE NEWLINE
"""
"""
if
option
in
(
1
,
2
):
# rule: {exp,debug} NEWLINE
if
option
in
(
1
,
2
):
# rule: {exp,debug} NEWLINE
...
@@ -353,11 +361,10 @@ class Parser(BisonParser):
...
@@ -353,11 +361,10 @@ class Parser(BisonParser):
self
.
rewrite
(
int
(
values
[
1
]))
self
.
rewrite
(
int
(
values
[
1
]))
return
self
.
root_node
return
self
.
root_node
if
option
==
7
:
# rule: REWRITE_ALL NEWLINE
if
option
in
(
7
,
8
):
# rule: REWRITE_ALL NEWLINE
self
.
rewrite_all
()
return
self
.
rewrite_all
(
verbose
=
(
option
==
8
))
return
self
.
root_node
if
option
==
8
:
if
option
==
9
:
raise
RuntimeError
(
'on_line: exception raised'
)
raise
RuntimeError
(
'on_line: exception raised'
)
def
on_debug
(
self
,
target
,
option
,
names
,
values
):
def
on_debug
(
self
,
target
,
option
,
names
,
values
):
...
...
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