Ejemplo n.º 1
0
 def processor(state):
     newstate = self(state)
     if isParseSuccess(newstate):
         return newstate
     # fail if any input has been consumed
     if not self.arbitraryLookAhead() and inputConsumed(newstate, state):
         return newstate
     newstate2 = other(state)
     return newstate2 if isParseSuccess(newstate2) else mergeErrors(newstate, newstate2)
Ejemplo n.º 2
0
 def processor(state):
     newstate = self(state)
     if isParseSuccess(newstate):
         return newstate
     # fail if any input has been consumed
     if not self.arbitraryLookAhead() and inputConsumed(
             newstate, state):
         return newstate
     newstate2 = other(state)
     return newstate2 if isParseSuccess(newstate2) else mergeErrors(
         newstate, newstate2)
Ejemplo n.º 3
0
 def processor(state):
     newstate = parser(state)
     if isParseSuccess(newstate):
         tree = parseSuccessTree(newstate)
         return setParseSuccessTree(newstate, transform(tree))
     else:
         return newstate
Ejemplo n.º 4
0
 def processor(state):
     newstate = parser(state)
     if isParseSuccess(newstate):
         tree = parseSuccessTree(newstate)
         return setParseSuccessTree(newstate, transform(tree))
     else:
         return newstate
Ejemplo n.º 5
0
def parse(parser, input, sourceName=None):
    '''Runs a 'parser' over the 'input'. A 'parser' is either one of the
    many parsers provided by the library, or built by user with the help of
    library's combinators; 'input' is a string to parse; 'sourceName' is
    only used when displaying error messages (defaulted to None)
    '''

    state = parser(initialParseState(sourceName, input))

    return parseSuccessTree(state) if isParseSuccess(state) else showParseError(state)
Ejemplo n.º 6
0
def parse(parser, input, sourceName=None):
    '''Runs a 'parser' over the 'input'. A 'parser' is either one of the
    many parsers provided by the library, or built by user with the help of
    library's combinators; 'input' is a string to parse; 'sourceName' is
    only used when displaying error messages (defaulted to None)
    '''

    state = parser(initialParseState(sourceName, input))

    return parseSuccessTree(state) if isParseSuccess(
        state) else showParseError(state)
Ejemplo n.º 7
0
 def processor(state):
     errors = []
     for pr in parsers:
         newstate = pr(state)
         if isParseSuccess(newstate):
             return newstate
         # fail if any input has been consumed
         if not pr.arbitraryLookAhead() and inputConsumed(newstate, state):
             return newstate
         errors.append(newstate)
     return mergeErrorsMany(*errors)
Ejemplo n.º 8
0
 def processor(state):
     errors = []
     for pr in parsers:
         newstate = pr(state)
         if isParseSuccess(newstate):
             return newstate
         # fail if any input has been consumed
         if not pr.arbitraryLookAhead() and inputConsumed(newstate, state):
             return newstate
         errors.append(newstate)
     return mergeErrorsMany(*errors)
Ejemplo n.º 9
0
 def processor(state):
     newstate = many(parser)(state)
     if isParseSuccess(newstate):
         newstate = setParseSuccessTree(newstate, None)
     return newstate
Ejemplo n.º 10
0
 def processor(state):
     newstate = many(parser)(state)
     if isParseSuccess(newstate):
         newstate = setParseSuccessTree(newstate, None)
     return newstate