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

Fixed preprocessor with updated keyword list.

parent 07aceae5
...@@ -80,11 +80,11 @@ OP_CBRACKETS = 31 ...@@ -80,11 +80,11 @@ OP_CBRACKETS = 31
UNARY_FUNCTIONS = [OP_INT, OP_DXDER, OP_LOG] UNARY_FUNCTIONS = [OP_INT, OP_DXDER, OP_LOG]
# Special identifiers # Special identifiers
PI = 'pi'
E = 'e' E = 'e'
PI = 'pi'
INFINITY = 'oo' INFINITY = 'oo'
SPECIAL_TOKENS = [PI, E, INFINITY] SPECIAL_TOKENS = [E, PI, INFINITY]
# Default base to use in parsing 'log(...)' # Default base to use in parsing 'log(...)'
DEFAULT_LOGARITHM_BASE = 10 DEFAULT_LOGARITHM_BASE = 10
......
...@@ -182,16 +182,18 @@ class Parser(BisonParser): ...@@ -182,16 +182,18 @@ 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(10, '\n') words.insert(0xa, '\n')
words.insert(13, '\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?
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'
pattern = ('(?:(\))\s*([([])' # )( -> ) * ( pattern = ('(?:([)\]])\s*([([])' # )( -> ) * (
# )[ -> ) * [ # )[ -> ) * [
# ]( -> [ * (
# ][ -> [ * [
+ '|([' + rsv + 'a-z0-9])\s*([([])' # a( -> a * ( + '|([' + rsv + 'a-z0-9])\s*([([])' # a( -> a * (
# a[ -> a * [ # a[ -> a * [
+ '|(\))\s*([' + rsv + 'a-z0-9])' # )a -> ) * a + '|(\))\s*([' + rsv + 'a-z0-9])' # )a -> ) * a
...@@ -210,9 +212,9 @@ class Parser(BisonParser): ...@@ -210,9 +212,9 @@ class Parser(BisonParser):
# Make sure there are no multiplication and exponentiation signs # Make sure there are no multiplication and exponentiation signs
# inserted between a function and its argument(s): "sin x" should # inserted between a function and its argument(s): "sin x" should
# not be written as "sin*x", because that is bogus. # not be written as "sin*x", because that is bogus.
# Bugfix: omit 0x0e (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 0x0b <= o <= 0x0d or 0x0f <= o <= 0x19: if o <= 0x9 or 0xb <= o <= 0xc:
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
...@@ -222,7 +224,7 @@ class Parser(BisonParser): ...@@ -222,7 +224,7 @@ class Parser(BisonParser):
# return '%s^%s' % (left, right) # return '%s^%s' % (left, right)
# match: ab | abc | abcd (where left = "a") # match: ab | abc | abcd (where left = "a")
return '*'.join([left] + list(right.lstrip())) return '*'.join([left] + list(re.sub('^ +', '', right)))
if self.verbose: # pragma: nocover if self.verbose: # pragma: nocover
data_before = data data_before = data
......
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