I've recently added a small class in my code -
SimpleVar -which makes it:
class IntLiteral(str): grammar = number class StringLiteral(str): grammar = string_re literal = [IntLiteral, StringLiteral] class SimpleVar(str): grammar = word class LetInExp(): grammar = K("let"), endl,\ indent(attr("decs", maybe_some(dec))), endl,\ K("in"), endl,\ indent(attr("exps", maybe_some(exp, endl))), endl,\ K("end") class FunctionCall(): call_parameter = [literal] call_parameters = optional(csl(call_parameter)) grammar = name(), '(', attr("parms", call_parameters), ')' FunctionCall.call_parameter.append(FunctionCall) class Code(List): grammar = exp exp.append(LetInExp) exp.append(SimpleVar) exp.append(literal)
So, in the exp list, we have
[LetInExp, SimpleVar, [IntLiteral, StringLiteral]]
According to the documentation, they are tested in sequence.
A list instance which is not derived from pypeg2.Concat represents different options. They're tested in their sequence. The first option which parses is chosen, the others are not tested any more.
When I remove
exp.append(SimpleVar) the expression
let in end is correctly parsed.
When I don't, however, I get the following error:
SyntaxError: expecting Keyword('end')
Shouldn't the parser try to go for the
LetInExp before the