Skip to content
Snippets Groups Projects
Commit dadd40a4 authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Further improved special token handling in preprocessor.

parent 492f3b52
No related branches found
No related tags found
No related merge requests found
......@@ -84,7 +84,7 @@ E = 'e'
PI = 'pi'
INFINITY = 'oo'
SPECIAL_TOKENS = [E, PI, INFINITY]
SPECIAL_TOKENS = [PI, INFINITY]
# Default base to use in parsing 'log(...)'
DEFAULT_LOGARITHM_BASE = 10
......
......@@ -183,10 +183,12 @@ class Parser(BisonParser):
# Replace known keywords with escape sequences.
words = list(self.words)
words.insert(0xa, '\n')
words.insert(0xc, '\f')
words.insert(0xd, '\r')
for i, keyword in enumerate(words):
# FIXME: Why case-insensitivity?
# FIXME: good question...
data = re.sub(keyword, chr(i), data, flags=re.I)
rsv = '\x00-\x09\x0b-\x0c\x0e-\x19'
......@@ -214,7 +216,7 @@ class Parser(BisonParser):
# not be written as "sin*x", because that is bogus.
# Bugfix: omit 0x0c (pi) to prevent "pi a" (should be "pi*a")
o = ord(left)
if o <= 0x9 or 0xb <= o <= 0xc:
if o <= 0x9 or o == 0xb:
return left + ' ' + right
# If all characters on the right are numbers. e.g. "a4", the
......
......@@ -148,7 +148,7 @@ class TestParser(RulesTestCase):
self.assertEqual(tree(token), Leaf(token))
a, t = Leaf('a'), Leaf(token)
self.assertEqual(tree('a' + token), a * t)
# FIXME: self.assertEqual(tree('a' + token + 'a'), a * t * a)
self.assertEqual(tree('a' + token + 'a'), a * t * a)
def test_integral(self):
x, y, dx, a, b, l2, oo = tree('x, y, dx, a, b, 2, oo')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment