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

Fixed preprocessor with updated keyword list.

parent 07aceae5
No related branches found
No related tags found
No related merge requests found
......@@ -80,11 +80,11 @@ OP_CBRACKETS = 31
UNARY_FUNCTIONS = [OP_INT, OP_DXDER, OP_LOG]
# Special identifiers
PI = 'pi'
E = 'e'
PI = 'pi'
INFINITY = 'oo'
SPECIAL_TOKENS = [PI, E, INFINITY]
SPECIAL_TOKENS = [E, PI, INFINITY]
# Default base to use in parsing 'log(...)'
DEFAULT_LOGARITHM_BASE = 10
......
......@@ -182,16 +182,18 @@ class Parser(BisonParser):
# Replace known keywords with escape sequences.
words = list(self.words)
words.insert(10, '\n')
words.insert(13, '\r')
words.insert(0xa, '\n')
words.insert(0xd, '\r')
for i, keyword in enumerate(words):
# FIXME: Why case-insensitivity?
data = re.sub(keyword, chr(i), data, flags=re.I)
rsv = '\x00-\x09\x0b-\x0c\x0e-\x19'
pattern = ('(?:(\))\s*([([])' # )( -> ) * (
pattern = ('(?:([)\]])\s*([([])' # )( -> ) * (
# )[ -> ) * [
# ]( -> [ * (
# ][ -> [ * [
+ '|([' + rsv + 'a-z0-9])\s*([([])' # a( -> a * (
# a[ -> a * [
+ '|(\))\s*([' + rsv + 'a-z0-9])' # )a -> ) * a
......@@ -210,9 +212,9 @@ class Parser(BisonParser):
# Make sure there are no multiplication and exponentiation signs
# inserted between a function and its argument(s): "sin x" should
# 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)
if o <= 0x9 or 0x0b <= o <= 0x0d or 0x0f <= o <= 0x19:
if o <= 0x9 or 0xb <= o <= 0xc:
return left + ' ' + right
# If all characters on the right are numbers. e.g. "a4", the
......@@ -222,7 +224,7 @@ class Parser(BisonParser):
# return '%s^%s' % (left, right)
# 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
data_before = data
......
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