Sublime Forum

Prototype Exclusion Failing

#1

I’ve got something that I think is almost identical to an example in the documentation but it doesn’t seem to be working as described so I figure I must be running into some interaction nuance that I don’t understand.

So, the issue is that I have a definition for a string literal and I would like to exclude comments from within the string context, however I’d like to apply comment matching throughout.

So I’ve got the following (in snippets):

contexts:
  prototype:
    - include: comments

  main:
    - include: block-statements
    - include: strings
    - include: constants
    - include: numbers
    - include: operators
...
  line-comment:
    # Line comment begin with double dash and continue to the end of the line.
    - match: '--'
      scope: punctuation.definition.comment.line.vhdl
      push:
        - meta_scope: comment.line.vhdl
        - match: \n
          pop: true
...
  comments:
    - include: line-comment
    - include: block-comment
...
  string-literal:
    # A sequence of characters enclosed in double quotation marks.  Must
    # fit entirely on one line.
    - meta_include_prototype: false
    - match: '(")'
      captures:
          1: punctuation.definition.string.begin.vhdl
      push:
          - meta_scope: string.quoted.double.vhdl
          - match: '(")'
            scope: punctuation.definition.string.end.vhdl
            pop: true
          - match: \n
            scope: invalid.illegal.unclosed-string.vhdl
            pop: true
          - include: escaped-char
...
  strings:
    - include: character-literal
    - include: binary-bit-string-literal
    - include: octal-bit-string-literal
    - include: hex-bit-string-literal
    - include: string-literal

So it occurred to me to test whether this worked and so I put a comment character in the middle of the string. Unfortunately the end of the string to EOL got commented out and then I did successfully get an unterminated string error on the next line. So error checking is great, but the meta_include_prototype doesn’t seem to be working.

Are there cases where that gets overridden in some fashion, or because this is a cascade of contexts and it’s included in the top level context, it’s incapable of excluding it on lower contexts?

EDIT: Alright, I solved it I think but I don’t understand why exactly. The solution was that I needed to put the meta_exclude_prototype in the pushed down context for the string (i.e. the contents of the string rather than the initiator). So… best I can figure is that the meta_exclude_prototype is not an inherited property of subsequent contexts?

0 Likes

#2

That is correct. The prototype was only excluded from the context string-literal, not the anonymous context pushed into when " was matched.

2 Likes