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

220 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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)* ~ "*/" }