Commit dadd40a4 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Further improved special token handling in preprocessor.

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