Implementing a peg.js based parser, I get stuck adding code to to handle c-style comments /* like this */.
I need to find the end marker without eating it.
this not working:
multi = '/*' .* '*/'
The message is:
line: 14
Expected "*/" or any character but end of input found.
I do understand why this is not working, but unfortunately I have no clue how to make comment parsing functional.
Here's the code so far:
start = item*
item = comment / content_line
content_line = _ p:content _ {return ['CONTENT',p]}
content = 'some' / 'legal' / 'values'
comment = _ p:(single / multi) {return ['COMMENT',p]}
single = '//' p:([^\n]*) {return p.join('')}
multi = 'TODO'
_ = [ \t\r\n]* {return null}
and some sample input:
// line comment, no problems here
/*
how to parse this ??
*/
values
// another comment
some legal