Reputation: 329
Is there any built-in tag for block, line or in-line comments for the parser generator?
e.g.
comment blocks "(*" Exp "*)"
or inline comments "//" Exp
.
In a parser generator like menhir, I would normally handle comments by pattern matching with the lexer, so comments wouldn't be part of the AST. Is there an equivalent in K?
If not, what is the recommended way of implementing comments?
Upvotes: 1
Views: 48
Reputation: 798
You can declare the builtin sort #Layout
to be the concatenation via pipes of a set of regular expression terminals (i.e., r"//[^\\n]*"
). Any tokens which lex as one of these tokens are simply discarded by the lexer and the parser does not even see them. Note that this applies only to parsing terms using a generated parser or kast
; parsing rules in .k files will still require the usual K syntax for comments.
Note that this is also how whitespace is parsed, so unless your language is whitespace sensitive, make sure to include in #Layout
any whitespace characters which you want the parser to ignore.
Upvotes: 1