Search code examples
pegjs

Why is PEGjs / not working correctly?


I have a simple parser in PEGjs

start = val
ln = [\n\r]
float = digits:$[-0-9\.]+ { return parseFloat(digits, 10) }
str = str:$(!ln !"\"" .)+
val = float / str

and I try to match

-this

But instead of getting "str" it gives error on parsing "float"

Line 1, column 2: Expected [\-0-9.] or end of input but "t" found.

Solution

  • float = digits:$([-0-9.]+ !str) { return parseFloat(digits, 10) }

    That fixed it. But this is extremely counterintuitive to what I used to learn during writing a 350ish line parser...