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)
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()
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 + "}"
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}"
def mustMatchTheseTokens(s, l, t): theseTokens = _flatten(t.asList()) if theseTokens != matchTokens: raise ParseException("", 0, "")