bpruitt-goddard / vscode-mermaid-syntax-highlight

Markdown syntax support for the Mermaid charting language
MIT License
92 stars 36 forks source link

Use Variables For Matches #9

Closed bpruitt-goddard closed 2 years ago

bpruitt-goddard commented 5 years ago

Everything is declared in-line. Use some variables to get this going.

Example:

"repository": { 
 "comments": {
    "match": "%%.*",
    "name": "comment"
  }
},

Then use it like this:

"patterns": [
  {
    "include": "#comments"
  },
]
bpruitt-goddard commented 2 years ago

Currently, rules are written using the custom regex yaml type:

- match: !regex |-
    (title)\s+ # title
    (\s*["\(\)$&%\^/#.,?!;:*+=<>\'\\\-\w\s]*) # text
  captures:
    '1':
      name: keyword.control.mermaid
    '2':
      name: string

YAML supports variables, but only for a single value, not for both the match and the capture that we would desire. To implement something like this, we would need to diverge from the spec and add a bit of custom work inside the regex type, which would make it harder for new folks to contribute:

- match: !regex |-
    (title)\s+ # title
    &text_match
  captures:
    '1':
      name: keyword.control.mermaid
    '2':
      name: &text_capture

Instead, I think relying on the new test suite and trying to avoid duplication by using begin/end blocks in favor of multiple match blocks can help avoid this problem.

Closing this issue for now.