constjs: P.Parser<P.Unit> = P.loop(0)( ifProgress( P.oneOf( P.lineComment("//"), P.multiComment("/*")("* /")(P.Nestable.NotNestable), P.chompWhile((c) =>c == " " || c == "\n" || c == "\r" || c == "\t") ) ) );
"* /" is incorrect, it should be "*/" but that requires me to use a
zero with space character,
confusing anyone who copies the code as to why the example doesn't work.
Note: The fact that spaces comes last in the definition of elm is very
important! It can succeed without consuming any characters, so if it were
the first option, it would always succeed and bypass the others! (Same is
true of chompWhile in js.) This possibility of success without consumption
is also why we need the ifProgress helper. It detects if there is no
more whitespace to consume.
Parse multi-line comments. So if you wanted to parse Elm whitespace or JS whitespace, you could say:
"* /"is incorrect, it should be"*/"but that requires me to use a zero with space character, confusing anyone who copies the code as to why the example doesn't work.Note: The fact that
spacescomes last in the definition ofelmis very important! It can succeed without consuming any characters, so if it were the first option, it would always succeed and bypass the others! (Same is true ofchompWhileinjs.) This possibility of success without consumption is also why we need theifProgresshelper. It detects if there is no more whitespace to consume.