logos
logos copied to clipboard
Document how to create // style comments in Logos
Hi,
I have looked at the tests and the ReadMe, and I can't quite figure out how to create a Regex to collect the contents of a c# // style comment. (goes to end of line, or end of input).
Could you please explain how to do that, particularly in a test or the ReadMe?
If you don't want to capture the newline, then //[^\r\n]*
and //[^\n]*
work, if you want to capture the newline then use //.*\n
and //.*\n
We should probably have an examples
folder with sample lexers for JS and CSS.
Thanks for the example, but what about when the comment ends at the end of the string, but without a newline? How do I handle that? IE does Logos handle the $ character, and does it work like a multiline Regex?
Like:
"This is // a test\n" "This is // a test\r\n" "This is // a test"
I would like to be able to match all three with the simplest Regex possible.
Thanks for the help.
r"//[^\r\n]*(\r\n|\n)?"
should work.
IE does Logos handle the $ character, and does it work like a multiline Regex?
It is multiline, ^
and $
are not supported atm.
Okay, I got that working, but how do I do C style comments now: /* .... */ ?
I've tried the below, but it's not seeming to work for me, I keep getting the Error token:
#[regex(r#"/*.\/"#)] CComment,
I imagine an assembler style comment (i.e. ; blah blah blah) would be similar to a c-style // in terms of regex?
what about nested c-like block comments?
@thetayloredman you should match the start and end of block comments with two separate tokens. Then the role of some parser function would be to skip treat all the tokens in between as comments, and handle possible nested blocks.