示例#1
0
 def inner(loc: LocatedText) -> State:
     res = re.match(rex, loc.remaining())
     if res is None:
         return State(ParseError("不满足正则条件"), loc)
     else:
         e = res.end()
         loc.advance(e)
         return State(Success(Result(res.group())), loc)
示例#2
0
 def inner(loc: LocatedText) -> State:
     if loc.isEOF():
         return State(ParseError("再无输入可解析"), loc)
     else:
         c = loc.remaining()[0]
         if pred(c):
             loc.advance()
             return State(Success(Result(c)), loc)
         else:
             return State(ParseError("不满足条件"), loc)
示例#3
0
 def inner(loc: LocatedText) -> State:
     pre_text = copy.copy(loc)
     state = parser.fn(loc)
     if state.is_successful():
         return state
     else:
         return State(state.result, pre_text)
示例#4
0
 def inner(loc: LocatedText) -> State:
     return State(Success(r), loc)
示例#5
0
 def inner(loc: LocatedText) -> State:
     loc.back(back_step)
     return State(ParseError(msg), loc)
示例#6
0
 def inner(loc: LocatedText) -> State:
     return State(Success(Result(v)), loc)
示例#7
0
 def inner(loc: LocatedText) -> State:
     state = parser.fn(loc)
     if state.is_successful():
         return state
     else:
         return State(ParseError(msg), state.text)
示例#8
0
 def inner(loc: LocatedText) -> State:
     if loc.isEOF():
         return State(Success(Result()), loc)
     else:
         return State(ParseError("Excepted: <EOF>"), loc)