Пример #1
0
 def preParse(self, string, loc):
     if col(loc, string) != self.col:
         instrlen = len(string)
         loc = self._skipIgnorables(string, loc)
         while (loc < instrlen and string[loc].isspace()
                and col(loc, string) != self.col):
             loc += 1
     return loc
Пример #2
0
 def parseImpl(self, string, loc, doActions=True):
     thiscol = col(loc, string)
     if thiscol > self.col:
         raise ParseException("Text not in expected column", loc, string)
     newloc = loc + self.col - thiscol
     ret = string[loc:newloc]
     return newloc, ret
Пример #3
0
 def nodent_stack(t, l, s):
     curCol = col(l, s)
     if curCol == _indent_stack[-1][0]:
         PEER << Empty().addParseAction(peer_stack(curCol))
         DEDENT << Empty().addParseAction(dedent_stack(curCol))
         _indent_stack.append((curCol, PEER, DEDENT))
     else:
         raise ParseException(t.type, s, l, "not a subentry")
Пример #4
0
 def output(t, l, s):
     if l >= len(s):
         return
     curCol = col(l, s)
     if curCol != expectedCol:
         if curCol > expectedCol:
             raise ParseException(t.type, s, l, "illegal nesting")
         raise ParseException(t.type, l, s, "not a peer entry")
Пример #5
0
 def parseImpl(self, string, start, doActions=True):
     thiscol = col(start, string)
     if thiscol > self.col:
         raise ParseException(self, start, string,
                              "Text not in expected column")
     newloc = start + self.col - thiscol
     ret = string[start:newloc]
     return newloc, ret
Пример #6
0
 def output(t, l, s):
     if l >= len(s):
         return
     curCol = col(l, s)
     if curCol not in (i for i, _, _ in _indent_stack):
         raise ParseException(s, l, "not an unindent")
     if curCol < _indent_stack[-1][0]:
         oldCol, oldPeer, oldDedent = _indent_stack.pop()
         PEER << oldPeer
         DEDENT << oldDedent
Пример #7
0
 def __getattr__(self, aname):
     """supported attributes by name are:
     - lineno - returns the line number of the exception text
     - col - returns the column number of the exception text
     - line - returns the line containing the exception text
     """
     if aname == "lineno":
         return lineno(self.loc, self.pstr)
     elif aname in ("col", "column"):
         return col(self.loc, self.pstr)
     elif aname == "line":
         return line(self.loc, self.pstr)
     else:
         raise AttributeError(aname)
Пример #8
0
def _try(expr, start, string):
    print("  Attempt " + quote(string, start) + " at loc " + text(start) +
          "(%d,%d)" % (lineno(start, string), col(start, string)) + " for " +
          " " * stack_depth() + text(expr))
Пример #9
0
def _defaultSuccessDebugAction(expr, start, end, string, tokens):
    print("> Matched " + quote(string[start:end]) + " at loc " + text(start) +
          "(%d,%d)" % (lineno(start, string), col(start, string)) + " for " +
          " " * stack_depth() + text(expr) + " -> " + str(tokens))
Пример #10
0
def _defaultStartDebugAction(expr, loc, string):
    print("  Attempt " + quote(string[loc:loc + 10] + "...") + " at loc " +
          text(loc) + "(%d,%d)" % (lineno(loc, string), col(loc, string)) +
          " for " + " " * stack_depth() + text(expr))
Пример #11
0
 def verifyCol(strg, locn, toks):
     if col(locn, strg) != n:
         raise ParseException(strg, locn, "matched token not at column %d" % n)
Пример #12
0
 def column(self):
     return col(self.loc, self.string)
Пример #13
0
 def parseImpl(self, string, start, doActions=True):
     if col(start, string) == 1:
         return ParseResults(self, start, start, [])
     raise ParseException(self, start, string)
Пример #14
0
 def parseImpl(self, string, loc, doActions=True):
     if col(loc, string) == 1:
         return loc, ParseResults(self, [])
     raise ParseException(self, loc, string)