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)
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)
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)
def inner(loc: LocatedText) -> State: return State(Success(r), loc)
def inner(loc: LocatedText) -> State: loc.back(back_step) return State(ParseError(msg), loc)
def inner(loc: LocatedText) -> State: return State(Success(Result(v)), loc)
def inner(loc: LocatedText) -> State: state = parser.fn(loc) if state.is_successful(): return state else: return State(ParseError(msg), state.text)
def inner(loc: LocatedText) -> State: if loc.isEOF(): return State(Success(Result()), loc) else: return State(ParseError("Excepted: <EOF>"), loc)