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
81415bb0
Commit
81415bb0
authored
Mar 21, 2012
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added identifier possibility parser concerning syntax 'log_g(x)'.
parent
d7329b8d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
src/parser.py
src/parser.py
+9
-4
tests/test_parser.py
tests/test_parser.py
+5
-0
No files found.
src/parser.py
View file @
81415bb0
...
@@ -398,10 +398,15 @@ class Parser(BisonParser):
...
@@ -398,10 +398,15 @@ class Parser(BisonParser):
if
op
==
OP_VALUE_MAP
[
OP_LOG
]:
if
op
==
OP_VALUE_MAP
[
OP_LOG
]:
return
Node
(
OP_LOG
,
values
[
1
],
Leaf
(
DEFAULT_LOGARITHM_BASE
))
return
Node
(
OP_LOG
,
values
[
1
],
Leaf
(
DEFAULT_LOGARITHM_BASE
))
m
=
re
.
match
(
r'^log_([0-9]+)'
,
op
)
m
=
re
.
match
(
r'^log_([0-9]+
|[a-zA-Z]
)'
,
op
)
if
m
:
if
m
:
return
Node
(
OP_LOG
,
values
[
1
],
Leaf
(
int
(
m
.
group
(
1
))))
value
=
m
.
group
(
1
)
if
value
.
isdigit
():
value
=
int
(
value
)
return
Node
(
OP_LOG
,
values
[
1
],
Leaf
(
value
))
return
Node
(
op
,
values
[
1
])
return
Node
(
op
,
values
[
1
])
...
@@ -534,8 +539,8 @@ class Parser(BisonParser):
...
@@ -534,8 +539,8 @@ class Parser(BisonParser):
"[" { returntoken(LBRACKET); }
"[" { returntoken(LBRACKET); }
"]" { returntoken(RBRACKET); }
"]" { returntoken(RBRACKET); }
"'" { returntoken(APOSTROPH); }
"'" { returntoken(APOSTROPH); }
log_
[0-9]+
"*(" { returntoken(FUNCTION_LPAREN); }
log_
([0-9]+|[a-zA-Z])
"*(" { returntoken(FUNCTION_LPAREN); }
log_
[0-9]+
"*" { returntoken(FUNCTION); }
log_
([0-9]+|[a-zA-Z])
"*" { returntoken(FUNCTION); }
"""
+
operators
+
r"""
"""
+
operators
+
r"""
"raise" { returntoken(RAISE); }
"raise" { returntoken(RAISE); }
"graph" { returntoken(GRAPH); }
"graph" { returntoken(GRAPH); }
...
...
tests/test_parser.py
View file @
81415bb0
...
@@ -84,3 +84,8 @@ class TestParser(unittest.TestCase):
...
@@ -84,3 +84,8 @@ class TestParser(unittest.TestCase):
self
.
assertEqual
(
tree
(
'log(x, 10)'
),
log
(
x
))
self
.
assertEqual
(
tree
(
'log(x, 10)'
),
log
(
x
))
self
.
assertEqual
(
tree
(
'log(x, 2)'
),
log
(
x
,
2
))
self
.
assertEqual
(
tree
(
'log(x, 2)'
),
log
(
x
,
2
))
self
.
assertEqual
(
tree
(
'log(x, g)'
),
log
(
x
,
g
))
self
.
assertEqual
(
tree
(
'log(x, g)'
),
log
(
x
,
g
))
self
.
assertEqual
(
tree
(
'log_2(x)'
),
log
(
x
,
2
))
self
.
assertEqual
(
tree
(
'log_10(x)'
),
log
(
x
))
self
.
assertEqual
(
tree
(
'log_g(x)'
),
log
(
x
,
g
))
self
.
assertEqual
(
tree
(
'log_g x'
),
log
(
x
,
g
))
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