Open ryanking1809 opened 3 years ago
Short version: the RegEx character class \s
for whitespace is not supported, because it includes newlines, and Moo uses multiline RegExps.
I, too, had the issue with \s
not working online at https://omrelli.ug/nearley-playground/ (which supports moo).
So I tried moo.compile({whitespace: /\s/});
locally with Nodejs, which gives: Uncaught Error: Rule should declare lineBreaks: /(?:(?:\s))/
.
This comes from https://github.com/no-context/moo/blob/main/moo.js#L274.
Finally, https://github.com/no-context/moo#on-regular-expressions states:
Moo uses multiline RegExps. This has a few quirks: for example, the dot /./ doesn't include newlines. Use [^] instead if you want to match newlines too.
Since an excluding character ranges like /[^ ]/ (which matches anything but a space) will include newlines, you have to be careful not to include them by accident! In particular, the whitespace metacharacter \s includes newlines.
I'm just playing around with https://ablingeroscar.github.io/moo-playground/ and I don't understand why replacing
WS: /[ \t]+/
withWS: /[\s]+/
doesn't work. Shouldn't that pick up any white space?Similarly, I'm not sure why
String: /[^]+/
(I'm just testing matching everything) doesn't work either.Am I missing something?