addNode in parser
@@ -50,6 +50,14 @@ class Parser:
self.grammarRowList = []
app.log.parser('__init__')
+ def __addNode(self, node):
+ if not len(self.grammarRowList[-1]):
+ self.grammarRowList[-1].append(node)
+ elif self.grammarRowList[-1][-1].begin == node.begin:
+ self.grammarRowList[-1][-1] = node
+ else:
+ self.grammarRowList[-1].append(node)
+
def grammarIndexFromRowCol(self, row, col):
"""
returns (index, node, preceding, remaining). |index| may then be passed to
@@ -96,13 +104,13 @@ class Parser:
node.begin = 0
self.grammarRowList = [[node]]
startTime = time.time()
- self.buildGrammarList()
+ self.__buildGrammarList()
totalTime = time.time() - startTime
if app.log.enabledChannels.get('parser', False):
self.debugLog(app.log.parser, data)
app.log.startup('parsing took', totalTime)
- def buildGrammarList(self):
+ def __buildGrammarList(self):
# An arbitrary limit to avoid run-away looping.
leash = 10000
cursor = 0
@@ -170,14 +178,7 @@ class Parser:
keywordNode = ParserNode()
keywordNode.grammar = app.prefs.grammars['keyword']
keywordNode.begin = cursor + reg[0]
-
- if not len(self.grammarRowList[-1]):
- self.grammarRowList[-1].append(keywordNode)
- elif self.grammarRowList[-1][-1].begin == keywordNode.begin:
- self.grammarRowList[-1][-1] = keywordNode
- else:
- self.grammarRowList[-1].append(keywordNode)
-
+ self.__addNode(keywordNode)
# Resume the current grammar.
child.grammar = grammarStack[-1]
child.begin = cursor + reg[1]
@@ -187,24 +188,12 @@ class Parser:
specialNode = ParserNode()
specialNode.grammar = app.prefs.grammars['special']
specialNode.begin = cursor + reg[0]
-
- if not len(self.grammarRowList[-1]):
- self.grammarRowList[-1].append(specialNode)
- elif self.grammarRowList[-1][-1].begin == specialNode.begin:
- self.grammarRowList[-1][-1] = specialNode
- else:
- self.grammarRowList[-1].append(specialNode)
-
+ self.__addNode(specialNode)
# Resume the current grammar.
child.grammar = grammarStack[-1]
child.begin = cursor + reg[1]
cursor += reg[1]
- if not len(self.grammarRowList[-1]):
- self.grammarRowList[-1].append(child)
- elif self.grammarRowList[-1][-1].begin == child.begin:
- self.grammarRowList[-1][-1] = child
- else:
- self.grammarRowList[-1].append(child)
+ self.__addNode(child)
def debugLog(self, out, data):
out('parser debug:')
