소스 검색

Further improved special token handling in preprocessor.

Taddeus Kroes 13 년 전
부모
커밋
dadd40a4a9
3개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 1 1
      src/node.py
  2. 3 1
      src/parser.py
  3. 1 1
      tests/test_parser.py

+ 1 - 1
src/node.py

@@ -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

+ 3 - 1
src/parser.py

@@ -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

+ 1 - 1
tests/test_parser.py

@@ -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')