On 10 Feb 2014, at 11:36, Tom Hall <
thatto...@gmail.com> wrote:
> whenever I add spaces around the sexps in the program definition, nothing works
I assume this means you've changed
rule program
expressions:sexp* {
def to_ast
Program.new(*expressions.elements.map{|el| el.to_ast})
end
}
end
to
rule program
expressions:(sexp ' '*)* {
def to_ast
Program.new(*expressions.elements.map{|el| el.to_ast})
end
}
end
i.e. just replaced `sexp` with `(sexp ' '*)` in the parsing expression. That's the correct change to the parsing expression, but it affects the shape of the concrete syntax tree nodes inside `expressions`. Each element of `expressions` now includes both the `sexp` and the whitespace, so you also need to update your `#to_ast` implementation to pick out just the `sexp` as the receiver of the recursive call:
rule program
expressions:(sexp ' '*)* {
def to_ast
Program.new(*expressions.elements.map{|el| el.sexp.to_ast})
end
}
end
This is (vaguely, confusingly) covered by the "Automatically-Defined Element Accessor Methods" section of
http://treetop.rubyforge.org/semantic_interpretation.html.
Cheers,
-Tom