|
@@ -23,6 +23,7 @@ Modifications by Daniel Riegelhaupt:
|
|
|
"""
|
|
|
|
|
|
import re
|
|
|
+import sys
|
|
|
|
|
|
from copy import deepcopy
|
|
|
|
|
@@ -30,6 +31,13 @@ from hutn_compiler.position import Position
|
|
|
|
|
|
line_cache = {}
|
|
|
|
|
|
+def get_buffer(base, start):
|
|
|
+ if sys.version_info >= (3, ):
|
|
|
+ # TODO find an efficient implementation for Python3...
|
|
|
+ return base[start:]
|
|
|
+ else:
|
|
|
+ return buffer(base, start)
|
|
|
+
|
|
|
class Tree(object):
|
|
|
def __init__(self, head, tail, startpos, endpos, inputfile = None):
|
|
|
self.head = head
|
|
@@ -505,7 +513,8 @@ class Parser(object):
|
|
|
#lr = Parser.LR([], rule, None, deepcopy(self.lrstack))
|
|
|
lr = Parser.LR([], rule, None, None if not self.lrstack else self.lrstack.copy())
|
|
|
self.lrstack = lr
|
|
|
- self.memotable.update({(rule, j): [{'tree': lr, 'startpos': j, 'endpos': j}]})
|
|
|
+ #self.memotable.update({(rule, j): [{'tree': lr, 'startpos': j, 'endpos': j}]})
|
|
|
+ self.memotable[(rule, j)] = [{'tree': lr, 'startpos': j, 'endpos': j}]
|
|
|
|
|
|
newresults = self.eval(rule, j)
|
|
|
self.lrstack = self.lrstack.next
|
|
@@ -645,7 +654,7 @@ class Parser(object):
|
|
|
|
|
|
rule = self.tokens[rulename]
|
|
|
#mobj = re.match(rule['reg'], self.input[j:])
|
|
|
- mobj = re.match(rule['reg'], buffer(self.input, j))
|
|
|
+ mobj = re.match(rule['reg'], get_buffer(self.input, j))
|
|
|
#Changed by daniel instead of re.match(reg) did re.match(re.compile(reg).patern)
|
|
|
#this is to avoid problems with \ before i did this i had the match the character \ by doing [\\\\]
|
|
|
# because to write only two slashes it would have to be r'[\\]' which cant be done directly in hte grammar so it had to be in string form
|