How can I disambiguate a grammar.
I have this a?0.1 0.3 that returns this two parses:
{:parses
([:pattern
[:cat [:degrade [:word "a"] [:op-degrade]] [:float "0.1"] [:float "0.3"]]]
[:pattern
[:cat
[:degrade [:word "a"] [:op-degrade [:degrade-amount "0.1"]]]
[:float "0.3"]]])}
I would just like to have the latter.
Relevant parts of my grammar look like this:
pattern = cat (<ws> <'.'> <ws> cat)*
ws = #"\s+"
word = #"[a-zA-Z0-9]([a-zA-Z0-9]*)"
int = #"[0-9]+"
float = #"(?<!\?)\d+(\.\d+)"
<token> = word | int | float | degrade
cat = token (<ws>? token)*
degrade-amount = #"([0-9]*[.])?[0-9]+"
op-degrade = <'?'> degrade-amount?
degrade = token op-degrade
I am trying to have different regexes for float and degrade-amount , but it’s not actually working. I also tried this: float = (!'?' #"\d+(\.\d+)") but doesn’t seem to work.