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
1e753b0b
Commit
1e753b0b
authored
Feb 25, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added PI to parser and Node stringification.
parent
6139bd82
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
4 deletions
+18
-4
src/node.py
src/node.py
+13
-0
src/parser.py
src/parser.py
+5
-4
No files found.
src/node.py
View file @
1e753b0b
...
@@ -45,6 +45,9 @@ OP_HINT = 17
...
@@ -45,6 +45,9 @@ OP_HINT = 17
OP_REWRITE_ALL
=
18
OP_REWRITE_ALL
=
18
OP_REWRITE
=
19
OP_REWRITE
=
19
# Special identifierd
PI
=
'pi'
TYPE_MAP
=
{
TYPE_MAP
=
{
int
:
TYPE_INTEGER
,
int
:
TYPE_INTEGER
,
...
@@ -352,7 +355,17 @@ class ExpressionLeaf(Leaf, ExpressionBase):
...
@@ -352,7 +355,17 @@ class ExpressionLeaf(Leaf, ExpressionBase):
return
self
.
negated
==
other
.
negated
and
self
.
type
==
other
.
type
\
return
self
.
negated
==
other
.
negated
and
self
.
type
==
other
.
type
\
and
self
.
value
==
other
.
value
and
self
.
value
==
other
.
value
def
__str__
(
self
):
val
=
str
(
self
.
value
)
# Replace PI leaf by the Greek character
if
val
==
PI
:
val
=
'π'
return
'-'
*
self
.
negated
+
val
def
__repr__
(
self
):
def
__repr__
(
self
):
return
str
(
self
)
return
'-'
*
self
.
negated
+
str
(
self
.
value
)
return
'-'
*
self
.
negated
+
str
(
self
.
value
)
def
equals
(
self
,
other
,
ignore_negation
=
False
):
def
equals
(
self
,
other
,
ignore_negation
=
False
):
...
...
src/parser.py
View file @
1e753b0b
...
@@ -15,7 +15,7 @@ from pybison import BisonParser, BisonSyntaxError
...
@@ -15,7 +15,7 @@ from pybison import BisonParser, BisonSyntaxError
from
graph_drawing.graph
import
generate_graph
from
graph_drawing.graph
import
generate_graph
from
node
import
ExpressionNode
as
Node
,
ExpressionLeaf
as
Leaf
,
OP_MAP
,
\
from
node
import
ExpressionNode
as
Node
,
ExpressionLeaf
as
Leaf
,
OP_MAP
,
\
TOKEN_MAP
,
TYPE_OPERATOR
,
OP_COMMA
,
OP_NEG
,
OP_MUL
,
Scope
TOKEN_MAP
,
TYPE_OPERATOR
,
OP_COMMA
,
OP_NEG
,
OP_MUL
,
Scope
,
PI
from
rules
import
RULES
from
rules
import
RULES
from
possibilities
import
filter_duplicates
,
pick_suggestion
,
apply_suggestion
from
possibilities
import
filter_duplicates
,
pick_suggestion
,
apply_suggestion
...
@@ -156,7 +156,7 @@ class Parser(BisonParser):
...
@@ -156,7 +156,7 @@ class Parser(BisonParser):
left, right = filter(None, match.groups())
left, right = filter(None, match.groups())
# Filter words (otherwise they will be preprocessed as well)
# Filter words (otherwise they will be preprocessed as well)
if (left + right).upper() in self.tokens:
if (left + right).upper() in self.tokens
+ [PI.upper()]
:
return left + right
return left + right
# If all characters on the right are numbers. e.g. "a4", the
# If all characters on the right are numbers. e.g. "a4", the
...
@@ -405,9 +405,10 @@ class Parser(BisonParser):
...
@@ -405,9 +405,10 @@ class Parser(BisonParser):
%
(
option
,
target
))
# pragma: nocover
%
(
option
,
target
))
# pragma: nocover
# -----------------------------------------
# -----------------------------------------
# operator tokens
#
PI and
operator tokens
# -----------------------------------------
# -----------------------------------------
operators
=
''
operators
=
'"%s"%s{ returntoken(IDENTIFIER); }
\
n
'
\
%
(
PI
,
' '
*
(
8
-
len
(
PI
)))
for
op_str
,
op
in
OP_MAP
.
iteritems
():
for
op_str
,
op
in
OP_MAP
.
iteritems
():
operators
+=
'"%s"%s{ returntoken(%s); }
\
n
'
\
operators
+=
'"%s"%s{ returntoken(%s); }
\
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