I'm having a play with tree top and I just can't get a simple grammar to work and generate the AST I expect.
My rules are
1: LINE can be made up of one or more PIPED COMMANDs separated by ; 2: a PIPED COMMAND is one or more COMMANDs separated by | 3: a COMMAND is one or more IDENTIFIERS separated by whitespace
I'd expect a tree like this for
hello | abc | def ; abc | test ; cats ;
to generate a tree like this
Line
PipedCommand
Command
Identifier hello
Command
Identifier abc
Command
Identifier def
PipedCommand
Command
Identifier abc
Command
Identifier test
PipedCommand
Command
Identifier cats
However I can't get it even just returning piped commands properly, if i specify more than 2, the result is messed up
> test | abc
[Command+Command0 offset=0, "test " (identifier):
Identifier+Identifier0 offset=0, "test",
Command+Command0 offset=6, " abc" (identifier):
Identifier+Identifier0 offset=7, "abc"]
> test | abc | def
[Command+Command0 offset=0, "test " (identifier):
Identifier+Identifier0 offset=0, "test"]
>
Grammar currently looks like:
grammar Line
rule commands
(command space? '|' commands space?) <Commands> / command
end
rule command
space? identifier space? <Command>
end
rule identifier
[a-zA-Z] [a-zA-Z0-9_]* <Identifier>
end
rule space
[\s]+
end
end
Hopefully someone can help with a bit!
Thanks