Hello,
This is probably something easy I'm missing... I want to have a grammar that matches certain words at the beginning of the line, but then any other words are just collected as "notes".
I can get it to work but only with :consume_all_input set to false. Whenever I set :consume_all_input to true it fails to parse because it expects another "word" when there is no more input.
Here is the simplest grammar to reproduce the issue:
grammar AnimalGrammar
rule animals
animal+ notes
end
rule animal
"cat " / "dog "
end
rule notes
word*
end
rule word
([a-zA-Z0-9]+ [ \t\n!.]+) {
def content
text_value.strip
end
}
end
end
So, for the input "cat and dog can get along" I would like it to parse and have "cat dog " as animals and "can get along" as notes, but it returns:
"Expected one of [a-zA-Z0-9], [ \\t\\n!.] at line 1, column 22 (byte 22) after along"
I'm sure I have to tell it that a "word" is done matching if there is no more input (which I tried to do with !.) but must be doing that wrong.
Other things I would like it to parse:
"dog cat" (animal: "dog cat " notes empty)
Any help on how to deal with this "nothing left" condition would be most appreciated!
Thanks!
Dave