Exemplo n.º 1
0
    def copyTokenToRepeater(s, l, t):
        matchTokens = _flatten(t.asList())

        def mustMatchTheseTokens(s, l, t):
            theseTokens = _flatten(t.asList())
            if theseTokens != matchTokens:
                raise ParseException("", 0, "")

        rep.setParseAction(mustMatchTheseTokens, callDuringTry=True)
Exemplo n.º 2
0
 def copyTokenToRepeater(s, l, t):
     if t:
         if len(t) == 1:
             rep << t[0]
         else:
             # flatten t tokens
             tflat = _flatten(t.asList())
             rep << And(Literal(tt) for tt in tflat)
     else:
         rep << Empty()
Exemplo n.º 3
0
 def equation_hook(tokens):
     """ Render 'equation' expression for moodle interpreter.
     """
     out = []
     for tok in tokens:
         if isinstance(tok, ParseResults):
             out += tok.asList()
         elif isinstance(tok, list):
             out += tok
         else:
             out.append(tok)
     # call ParseResults _flatten to un-nest the list before the final rendering
     out = ''.join(_flatten(out))
     return "{=" + out + "}"
Exemplo n.º 4
0
 def equation_hook(tokens):
     """ Render 'equation' expression for FP package
     """
     out = []
     for tok in tokens:
         if isinstance(tok, ParseResults):
             out += tok.asList()
         elif isinstance(tok, list):
             out += tok
         else:
             out.append(tok)
     # call ParseResults _flatten to un-nest the list before the final rendering
     out = ''.join(_flatten(out))
     return "\\FPprint{\\FPeval{\\out}{clip(" + out + ")}\\out}"
Exemplo n.º 5
0
 def mustMatchTheseTokens(s, l, t):
     theseTokens = _flatten(t.asList())
     if theseTokens != matchTokens:
         raise ParseException("", 0, "")