Closed Ghabriel closed 6 years ago
Moo doesnât support this by design, but you can wrap the lexer yourself to do whatever you want.
Perhaps try replacing your Lexerâs next()
method?
lexer.next = (next => {
let tok
while ((tok = next()) && toktype === âcommentâ) {}
return tok
})(lexer.next)
(Untested; I only just came up with this!)
Sent with GitHawk
This works:
lexer.next = (next => () => {
let tok;
while ((tok = next.call(lexer)) && tok.type === "comment") {}
return tok;
})(lexer.next);
However, things like cla/*comment*/ss
become cla
and ss
instead of class
. I don't think wrapping the lexer can solve this specific case without basically reimplementing the entire lexer, can it?
For most cases this version is enough though, so thanks for your help!
Ignored tokens in most languages I am aware of are not normally treated as if they did not exist instead they are not passed to the parser and can still be used as "separators" imagine whitespace:
"public static class Foo extends Bar..."
Whitespace is ignored in Java, but this is not read a single huge identifier:
"publicstaticclassFooextendsBar"
I initially thought that comments were in fact treated as if they didn't exist (I was aware about whitespaces, though), but I ran some tests and indeed every language I've tried showed a syntax error on things like cla/*comment*/ss
. I'll close this issue, thanks everyone!
I'm using moo + nearley and I want to support comments (//... and / ... /) in arbitrary places without polluting my grammar. How can I achieve this?