Hi All,
While writing a grammar for programs written in the Racket language, I have stumbled upon a problem.
In Racket #| starts a multiline comment and |# ends it.
The problem is that multiline comments can be nested:
#| a comment #| still a comment |# even more comment |#
Here is my non-working attempt:
repository: multilinecomment: begin: #| end: |# name: comment contentName: comment patterns: - include: "#multilinecomment" name: comment - match: ([^|]||(?=[^#]))* name: comment
The intent of the match patterns are:
"#multilinecomment" A multiline comment can contain another multiline comment.
([^|]||(?=[^#]))* The meaning of the subexpressions:
[^|] any characters not an `|` |(?=[^#]) an `|` followed by a non-`#`
The entire expression thus matches a string not containg |#
Is it possible to match nested multiline comments correctly?
-- Jens Axel Søgaard
On 6 Jan 2015, at 1:17, Jens Axel Søgaard wrote:
Here is my non-working attempt:
repository: multilinecomment: begin: #| end: |# name: comment contentName: comment patterns:
- include: "#multilinecomment" name: comment
- match: ([^|]||(?=[^#]))* name: comment
I don’t understand why you have the last match rule.
Without it, it should work fine to match nested multi-line comments.
2015-01-07 6:34 GMT+01:00 Allan Odgaard mailinglist@textmate.org:
On 6 Jan 2015, at 1:17, Jens Axel Søgaard wrote:
Here is my non-working attempt:
repository: multilinecomment: begin: #| end: |# name: comment contentName: comment patterns:
- include: "#multilinecomment" name: comment
- match: ([^|]||(?=[^#]))* name: comment
I don’t understand why you have the last match rule.
Without it, it should work fine to match nested multi-line comments.
That works - takker!
As for the reason I put the last match rule in, I simply thought a rule was needed to match the "inside" of a comment.
If anyone on this list uses Racket, the grammar is available here:
https://github.com/soegaard/racket-highlight-for-github
-- Jens Axel Søgaard