Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Pest.rs, is there a way to store comments as tokens?

Pest.rs gives us a method of doing comments,

COMMENT - runs between rules and sub-rules

But if we're building a linter we may want the comments. Is there a way to have them saved on the tree?

like image 416
NO WAR WITH RUSSIA Avatar asked Sep 15 '25 01:09

NO WAR WITH RUSSIA


1 Answers

You'd use COMMENT but not make it silent.

For example this will handle C-like comments but they won't appear in the output (what most people want most of the time):

COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" }

While this will make them present in the output:

COMMENT = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" }
like image 182
mcarton Avatar answered Sep 16 '25 23:09

mcarton