logos icon indicating copy to clipboard operation
logos copied to clipboard

Document how to create // style comments in Logos

Open rickprice opened this issue 4 years ago • 7 comments

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?

rickprice avatar Apr 20 '20 13:04 rickprice

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

Kixiron avatar Apr 20 '20 17:04 Kixiron

We should probably have an examples folder with sample lexers for JS and CSS.

maciejhirsz avatar Apr 20 '20 17:04 maciejhirsz

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.

rickprice avatar Apr 20 '20 21:04 rickprice

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.

maciejhirsz avatar Apr 20 '20 22:04 maciejhirsz

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,

rickprice avatar Apr 21 '20 02:04 rickprice

r"\/\*([^*]|\*[^\/])+\*\/"

I recommend playing on regex101.com to see if things work:

Screenshot from 2020-04-21 08-53-27

maciejhirsz avatar Apr 21 '20 06:04 maciejhirsz

I imagine an assembler style comment (i.e. ; blah blah blah) would be similar to a c-style // in terms of regex?

AshtonSnapp avatar Jul 12 '21 19:07 AshtonSnapp

what about nested c-like block comments?

thetayloredman avatar May 06 '23 23:05 thetayloredman

@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.

jeertmans avatar May 07 '23 06:05 jeertmans