Ejemplo n.º 1
0
 def findPair(self, leftIndex, rightIndex, tokens):
   self.resetCounter()
   for num, token in getTokensRange(leftIndex, rightIndex, tokens):
     self.calculateCounter(token.word)
     if token.word in self.closeBrackets and self.checkZero():
       return num
   return -1
Ejemplo n.º 2
0
  def findPair(self, leftIndex, rightIndex, tokens):
    """
    tokens[leftIndex] must be opened bracket
    """
    self._resetCounters()
    # open bracket
    openBracket = tokens[leftIndex].word
    closeBracket = self._getCloseBracket(openBracket)
    # find closeBracket and check counters must be zero
    for num, token in getTokensRange(leftIndex, rightIndex, tokens):
      self._calculateCounters(token.word)
      # found close bracket
      if token.word == closeBracket and self._checkZero():
        return num

    return -1
Ejemplo n.º 3
0
 def check(self, leftIndex, rightIndex, source):
   self.source = source
   self._resetCounters()
   for num, token in getTokensRange(leftIndex, rightIndex, source.tokens):
     self._calculateCounters(token.word)
   self._checkCounters()
Ejemplo n.º 4
0
 def check(self, leftIndex, rightIndex, source):
   self.resetCounter()
   for num, token in getTokensRange(leftIndex, rightIndex, source.tokens):
     self.calculateCounter(token.word)
   if self.count != 0:
     raise Exception('tag open/closed brackets error, linenum "%d", source "%s"' % (source.tokens[leftIndex].linenum, source.filename))
Ejemplo n.º 5
0
def findWordIndex(word, leftIndex, rightIndex, tokens):
  for num, token in getTokensRange(leftIndex, rightIndex, tokens):
    if token.word == word:
      return num
  return -1