{
  "fileTypes": ["mermaid"],
  "patterns": [
    {
      "include": "#mermaid"
    }
  ],
  "repository": {
    "mermaid": {
      "patterns": [
        {
          "comment": "Class Diagram",
          "begin": "^\\s*(classDiagram)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "comment": "(class name) (\"multiplicity relationship\")? (relationship) (\"multiplicity relationship\")? (class name) :? (labelText)?",
              "match": "([\\w-]+)\\s(\"(?:\\d+|\\*|0..\\d+|1..\\d+|1..\\*)\")?\\s?(--o|--\\*|\\<--|--\\>|<\\.\\.|\\.\\.\\>|\\<\\|\\.\\.|\\.\\.\\|\\>|\\<\\|--|--\\|>|--\\*|--|\\.\\.|\\*--|o--)\\s(\"(?:\\d+|\\*|0..\\d+|1..\\d+|1..\\*)\")?\\s?([\\w-]+)\\s?(:)?\\s(.*)$",
              "captures": {
                "1": {
                  "name": "entity.name.type.class.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "entity.name.type.class.mermaid"
                },
                "6": {
                  "name": "keyword.control.mermaid"
                },
                "7": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(class name) : (visibility)?(function)( (function param/generic param)? )(classifier)? (return/generic return)?$",
              "match": "([\\w-]+)\\s?(:)\\s([\\+~#-])?([\\w-]+)(\\()([\\w-]+)?(~)?([\\w-]+)?(~)?\\s?([\\w-]+)?(\\))([*\\$])?\\s?([\\w-]+)?(~)?([\\w-]+)?(~)?$",
              "captures": {
                "1": {
                  "name": "entity.name.type.class.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "entity.name.function.mermaid"
                },
                "5": {
                  "name": "punctuation.parenthesis.open.mermaid"
                },
                "6": {
                  "name": "storage.type.mermaid"
                },
                "7": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "8": {
                  "name": "storage.type.mermaid"
                },
                "9": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                },
                "10": {
                  "name": "entity.name.variable.parameter.mermaid"
                },
                "11": {
                  "name": "punctuation.parenthesis.closed.mermaid"
                },
                "12": {
                  "name": "keyword.control.mermaid"
                },
                "13": {
                  "name": "storage.type.mermaid"
                },
                "14": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "15": {
                  "name": "storage.type.mermaid"
                },
                "16": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                }
              }
            },
            {
              "comment": "(class name) : (visibility)?(datatype/generic data type) (attribute name)$",
              "match": "([\\w-]+)\\s?(:)\\s([\\+~#-])?([\\w-]+)(~)?([\\w-]+)?(~)?\\s([\\w-]+)?$",
              "captures": {
                "1": {
                  "name": "entity.name.type.class.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "storage.type.mermaid"
                },
                "5": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "6": {
                  "name": "storage.type.mermaid"
                },
                "7": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                },
                "8": {
                  "name": "entity.name.variable.field.mermaid"
                }
              }
            },
            {
              "comment": "<<(Annotation)>> (class name)",
              "match": "(<<)([\\w-]+)(>>)\\s?([\\w-]+)?",
              "captures": {
                "1": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "2": {
                  "name": "storage.type.mermaid"
                },
                "3": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                },
                "4": {
                  "name": "entity.name.type.class.mermaid"
                }
              }
            },
            {
              "comment": "class (class name) ~?(generic type)?~? ({)",
              "begin": "(class)\\s+([\\w-]+)(~)?([\\w-]+)?(~)?\\s?({)",
              "beginCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.type.class.mermaid"
                },
                "3": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "4": {
                  "name": "storage.type.mermaid"
                },
                "5": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                },
                "6": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "match": "\\%%.*",
                  "name": "comment"
                },
                {
                  "comment": "(visibility)?(function)( (function param/generic param)? )(classifier)? (return/generic return)?$",
                  "begin": "\\s([\\+~#-])?([\\w-]+)(\\()",
                  "beginCaptures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "entity.name.function.mermaid"
                    },
                    "3": {
                      "name": "punctuation.parenthesis.open.mermaid"
                    }
                  },
                  "patterns": [
                    {
                      "comment": "(TBD)",
                      "match": "\\s*,?\\s*([\\w-]+)?(~)?([\\w-]+)?(~)?\\s?([\\w-]+)?",
                      "captures": {
                        "1": {
                          "name": "storage.type.mermaid"
                        },
                        "2": {
                          "name": "punctuation.definition.typeparameters.begin.mermaid"
                        },
                        "3": {
                          "name": "storage.type.mermaid"
                        },
                        "4": {
                          "name": "punctuation.definition.typeparameters.end.mermaid"
                        },
                        "5": {
                          "name": "entity.name.variable.parameter.mermaid"
                        }
                      }
                    }
                  ],
                  "end": "(\\))([*\\$])?\\s?([\\w-]+)?(~)?([\\w-]+)?(~)?$",
                  "endCaptures": {
                    "1": {
                      "name": "punctuation.parenthesis.closed.mermaid"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "storage.type.mermaid"
                    },
                    "4": {
                      "name": "punctuation.definition.typeparameters.begin.mermaid"
                    },
                    "5": {
                      "name": "storage.type.mermaid"
                    },
                    "6": {
                      "name": "punctuation.definition.typeparameters.end.mermaid"
                    }
                  }
                },
                {
                  "comment": "(visibility)?(datatype/generic data type) (attribute name)$",
                  "match": "\\s([\\+~#-])?([\\w-]+)(~)?([\\w-]+)?(~)?\\s([\\w-]+)?$",
                  "captures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "storage.type.mermaid"
                    },
                    "3": {
                      "name": "punctuation.definition.typeparameters.begin.mermaid"
                    },
                    "4": {
                      "name": "storage.type.mermaid"
                    },
                    "5": {
                      "name": "punctuation.definition.typeparameters.end.mermaid"
                    },
                    "6": {
                      "name": "entity.name.variable.field.mermaid"
                    }
                  }
                },
                {
                  "comment": "<<(Annotation)>> (class name)",
                  "match": "(<<)([\\w-]+)(>>)\\s?([\\w-]+)?",
                  "captures": {
                    "1": {
                      "name": "punctuation.definition.typeparameters.begin.mermaid"
                    },
                    "2": {
                      "name": "storage.type.mermaid"
                    },
                    "3": {
                      "name": "punctuation.definition.typeparameters.end.mermaid"
                    },
                    "4": {
                      "name": "entity.name.type.class.mermaid"
                    }
                  }
                }
              ],
              "end": "(})",
              "endCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "class (class name) ~?(generic type)?~?",
              "match": "(class)\\s+([\\w-]+)(~)?([\\w-]+)?(~)?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.type.class.mermaid"
                },
                "3": {
                  "name": "punctuation.definition.typeparameters.begin.mermaid"
                },
                "4": {
                  "name": "storage.type.mermaid"
                },
                "5": {
                  "name": "punctuation.definition.typeparameters.end.mermaid"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Entity Relationship Diagram",
          "begin": "^\\s*(erDiagram)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "comment": "(entity)",
              "match": "^\\s*([\\w-]+)$",
              "name": "variable"
            },
            {
              "comment": "(entity) {",
              "begin": "\\s+([\\w-]+)\\s+({)",
              "beginCaptures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "(type) (name) (PK|FK)? (\"comment\")?",
                  "match": "\\s*([\\w-]+)\\s+([\\w-]+)\\s+(PK|FK)?\\s*(\"[\"\\($&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*\")?\\s*",
                  "captures": {
                    "1": {
                      "name": "storage.type.mermaid"
                    },
                    "2": {
                      "name": "variable"
                    },
                    "3": {
                      "name": "keyword.control.mermaid"
                    },
                    "4": {
                      "name": "string"
                    }
                  }
                }
              ],
              "end": "(})",
              "endCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(entity) (relationship) (entity) : (label)",
              "match": "\\s*([\\w-]+)\\s+((?:\\|o|\\|\\||}o|}\\|)(?:..|--)(?:o\\||\\|\\||o{|\\|{))\\s+([\\w-]+)\\s+(:)\\s+((?:\"[\\w\\s]*\")|(?:[\\w-]+))",
              "captures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "variable"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "string"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Gantt Diagram",
          "begin": "^\\s*(gantt)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "match": "(dateFormat)\\s+([\\w\\-\\.]+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.function.mermaid"
                }
              }
            },
            {
              "match": "(axisFormat)\\s+([\\w\\%\\/\\\\\\-\\.]+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.function.mermaid"
                }
              }
            },
            {
              "match": "(title)\\s+(\\s*[\"\\(\\)$&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "match": "(excludes)\\s+((?:[\\d\\-,\\s]+|monday|tuesday|wednesday|thursday|friday|saturday|sunday|weekends)+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "match": "^\\s+(todayMarker)\\s+(.*)$",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "match": "(section)\\s+(\\s*[\"\\(\\)$&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "begin": "^\\s(.*)(:)",
              "beginCaptures": {
                "1": {
                  "name": "string"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "match": "(crit|done|active|after)",
                  "name": "entity.name.function.mermaid"
                },
                {
                  "match": "\\%%.*",
                  "name": "comment"
                }
              ],
              "end": "$"
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Git Graph",
          "begin": "^\\s*(gitGraph)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "comment": "commit",
              "begin": "\\s*(commit)",
              "beginCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "(id)(:) (\"id\")",
                  "match": "\\s*(id)(:)\\s?(\"[^\"\\n]*\")",
                  "captures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "string"
                    }
                  }
                },
                {
                  "comment": "(type)(:) (COMMIT_TYPE)",
                  "match": "\\s*(type)(:)\\s?(NORMAL|REVERSE|HIGHLIGHT)",
                  "captures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "entity.name.function.mermaid"
                    }
                  }
                },
                {
                  "comment": "(tag)(:) (\"tag\")",
                  "match": "\\s*(tag)(:)\\s?(\"[\\($&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*\")",
                  "captures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "string"
                    }
                  }
                }
              ],
              "end": "$"
            },
            {
              "comment": "(checkout) (branch-name)",
              "match": "\\s*(checkout)\\s*([^\\s\"]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                }
              }
            },
            {
              "comment": "(branch) (branch-name) (order)?(:) (number)",
              "match": "\\s*(branch)\\s*([^\\s\"]*)\\s*(?:(order)(:)\\s?(\\d+))?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "constant.numeric.decimal.mermaid"
                }
              }
            },
            {
              "comment": "(merge) (branch-name) (tag: \"tag-name\")?",
              "match": "\\s*(merge)\\s*([^\\s\"]*)\\s*(?:(tag)(:)\\s?(\"[^\"\\n]*\"))?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(cherry-pick) (id)(:)(\"commit-id\")",
              "match": "\\s*(cherry-pick)\\s+(id)(:)\\s*(\"[^\"\\n]*\")",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "string"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Graph",
          "begin": "^\\s*(graph|flowchart)\\s+([\\p{Letter}\\ 0-9]+)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            },
            "2": {
              "name": "entity.name.function.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "match": "\\b(subgraph)\\s+([\\p{Letter}\\ 0-9]+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.function.mermaid"
                }
              },
              "name": "meta.function.mermaid"
            },
            {
              "match": "\\b(end|RB|BT|RL|TD|LR)\\b",
              "name": "keyword.control.mermaid"
            },
            {
              "comment": "(Entity)(Edge/Shape)(Text)(Edge/Shape)",
              "begin": "(\\b(?:(?!--|==)[-\\w])+\\b\\s*)(\\(\\[|\\[\\[|\\[\\(|\\[|\\(+|\\>|\\{|\\(\\()",
              "beginCaptures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "string"
                }
              },
              "patterns": [
                {
                  "comment": "(\"multi-line text\")",
                  "begin": "\\s*(\")",
                  "beginCaptures": {
                    "1": {
                      "name": "string"
                    }
                  },
                  "patterns": [
                    {
                      "comment": "capture inner text between quotes",
                      "begin": "([^\"]*)",
                      "beginCaptures": {
                        "1": {
                          "name": "string"
                        }
                      },
                      "patterns": [
                        {
                          "match": "([^\"]*)",
                          "captures": {
                            "1": {
                              "name": "comment"
                            }
                          }
                        }
                      ],
                      "end": "(?=\")"
                    }
                  ],
                  "end": "(\")",
                  "endCaptures": {
                    "1": {
                      "name": "string"
                    }
                  }
                },
                {
                  "comment": "(single line text)",
                  "match": "\\s*([$&%\\^/#.,?!;:*+<>_\\'\\\\\\w\\s]+)",
                  "captures": {
                    "1": {
                      "name": "string"
                    }
                  }
                }
              ],
              "end": "(\\]\\)|\\]\\]|\\)\\]|\\]|\\)+|\\}|\\)\\))",
              "endCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(Graph Link)(\"Multiline text\")(Graph Link)",
              "begin": "\\s*((?:-{2,5}|={2,5})[xo>]?\\|)",
              "beginCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "(\"multi-line text\")",
                  "begin": "\\s*(\")",
                  "beginCaptures": {
                    "1": {
                      "name": "string"
                    }
                  },
                  "patterns": [
                    {
                      "comment": "capture inner text between quotes",
                      "begin": "([^\"]*)",
                      "beginCaptures": {
                        "1": {
                          "name": "string"
                        }
                      },
                      "patterns": [
                        {
                          "match": "([^\"]*)",
                          "captures": {
                            "1": {
                              "name": "comment"
                            }
                          }
                        }
                      ],
                      "end": "(?=\")"
                    }
                  ],
                  "end": "(\")",
                  "endCaptures": {
                    "1": {
                      "name": "string"
                    }
                  }
                },
                {
                  "comment": "(single line text)",
                  "match": "\\s*([$&%\\^/#.,?!;:*+<>_\\'\\\\\\w\\s]+)",
                  "captures": {
                    "1": {
                      "name": "string"
                    }
                  }
                }
              ],
              "end": "(\\|)",
              "endCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(Graph Link Start Arrow)(Text)(Graph Link End Arrow)",
              "match": "\\s*([xo<]?(?:-{2,5}|={2,5}|-\\.{1,3}|-\\.))((?:(?!--|==)[\\w\\s*+%=\\\\/:\\.\\-'`,\"&^#$!?])*)((?:-{2,5}|={2,5}|\\.{1,3}-|\\.-)[xo>]?)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(Graph Link)",
              "match": "\\s*([ox<]?(?:-.{1,3}-|-{1,3}|={1,3})[ox>]?)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "Entity",
              "match": "(\\b(?:(?!--|==)[-\\w])+\\b\\s*)",
              "name": "variable"
            },
            {
              "comment": "(Class)(Node(s))(ClassName)",
              "match": "\\s*(class)\\s+(\\b[-,\\w]+)\\s+(\\b\\w+\\b)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(ClassDef)(ClassName)(Styles)",
              "match": "\\s*(classDef)\\s+(\\b\\w+\\b)\\s+(\\b[-,:;#\\w]+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(Click)(Entity)(Link)?(Tooltip)",
              "match": "\\s*(click)\\s+(\\b[-\\w]+\\b\\s*)(\\b\\w+\\b)?\\s(\"*.*\")",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "variable"
                },
                "4": {
                  "name": "string"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Pie Chart",
          "begin": "^\\s*(pie)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "match": "(title)\\s+(\\s*[\"\\(\\)$&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "begin": "\\s(.*)(:)",
              "beginCaptures": {
                "1": {
                  "name": "string"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "match": "\\%%.*",
                  "name": "comment"
                }
              ],
              "end": "$"
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "Sequence Diagram",
          "begin": "^\\s*(sequenceDiagram)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "(\\%%|#).*",
              "name": "comment"
            },
            {
              "comment": "(title)(title text)",
              "match": "(title)\\s*(:)?\\s+(\\s*[\"\\(\\)$&%\\^/#.,?!:*+=<>\\'\\\\\\-\\w\\s]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(participant)(Actor)(as)?(Label)?",
              "match": "\\s*(participant|actor)\\s+((?:(?! as )[\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s])+)\\s*(as)?\\s([\"\\(\\)$&%\\^/#.,?!*=<>\\'\\\\\\w\\s]+)?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(activate/deactivate)(Actor)",
              "match": "\\s*((?:de)?activate)\\s+(\\b[\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s]+\\b\\s*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                }
              }
            },
            {
              "comment": "(Note)(direction)(Actor)(,)?(Actor)?(:)(Message)",
              "match": "\\s*(Note)\\s+((?:left|right)\\sof|over)\\s+(\\b[\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s]+\\b\\s*)(,)?(\\b[\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s]+\\b\\s*)?(:)(?:\\s+([^;#]*))?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "entity.name.function.mermaid"
                },
                "3": {
                  "name": "variable"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "variable"
                },
                "6": {
                  "name": "keyword.control.mermaid"
                },
                "7": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(loop)(loop text)",
              "match": "\\s*(loop)(?:\\s+([^;#]*))?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(end)",
              "match": "\\s*(end)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(alt/else/opt/par/and/autonumber)(text)",
              "match": "\\s*(alt|else|opt|par|and|rect|autonumber)(?:\\s+([^#;]*))?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "(Actor)(Arrow)(Actor)(:)(Message)",
              "match": "\\s*(\\b[\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s]+\\b)\\s*(-?-(?:\\>|x|\\))\\>?[+-]?)\\s*([\"\\(\\)$&%\\^/#.?!*=<>\\'\\\\\\w\\s]+\\b)\\s*(:)\\s*([^;#]*)",
              "captures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "variable"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "string"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "State Diagram",
          "begin": "^\\s*(stateDiagram(?:-v2)?)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "comment": "}",
              "match": "\\s+(})\\s+",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "--",
              "match": "\\s+(--)\\s+",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            },
            {
              "comment": "(state)",
              "match": "^\\s*([\\w-]+)$",
              "name": "variable"
            },
            {
              "comment": "(state) : (description)",
              "match": "([\\w-]+)\\s+(:)\\s+(\\s*[-\\w\\s]+\\b)",
              "captures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "state",
              "begin": "(state)",
              "beginCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "\"(description)\" as (state)",
                  "match": "\\s+(\"[-\\w\\s]+\\b\")\\s+(as)\\s+([\\w-]+)",
                  "captures": {
                    "1": {
                      "name": "string"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "variable"
                    }
                  }
                },
                {
                  "comment": "(state name) {",
                  "match": "\\s+([\\w-]+)\\s+({)",
                  "captures": {
                    "1": {
                      "name": "variable"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    }
                  }
                },
                {
                  "comment": "(state name) <<fork|join>>",
                  "match": "\\s+([\\w-]+)\\s+(<<(?:fork|join)>>)",
                  "captures": {
                    "1": {
                      "name": "variable"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    }
                  }
                }
              ],
              "end": "$"
            },
            {
              "comment": "(state) -->",
              "begin": "([\\w-]+)\\s+(-->)",
              "beginCaptures": {
                "1": {
                  "name": "variable"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "(state) (:)? (transition text)?",
                  "match": "\\s+([\\w-]+)\\s*(:)?\\s*([^\\n:]+)?",
                  "captures": {
                    "1": {
                      "name": "variable"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "string"
                    }
                  }
                },
                {
                  "comment": "[*] (:)? (transition text)?",
                  "match": "(\\[\\*\\])\\s*(:)?\\s*([^\\n:]+)?",
                  "captures": {
                    "1": {
                      "name": "keyword.control.mermaid"
                    },
                    "2": {
                      "name": "keyword.control.mermaid"
                    },
                    "3": {
                      "name": "string"
                    }
                  }
                }
              ],
              "end": "$"
            },
            {
              "comment": "[*] --> (state) (:)? (transition text)?",
              "match": "(\\[\\*\\])\\s+(-->)\\s+([\\w-]+)\\s*(:)?\\s*([^\\n:]+)?",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "variable"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                },
                "5": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "note left|right of (state name)",
              "match": "(note (?:left|right) of)\\s+([\\w-]+)\\s+(:)\\s*([^\\n:]+)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                },
                "3": {
                  "name": "keyword.control.mermaid"
                },
                "4": {
                  "name": "string"
                }
              }
            },
            {
              "comment": "note left|right of (state name) (note text) end note",
              "begin": "(note (?:left|right) of)\\s+([\\w-]+)(.|\\n)",
              "beginCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "variable"
                }
              },
              "contentName": "string",
              "end": "(end note)",
              "endCaptures": {
                "1": {
                  "name": "keyword.control.mermaid"
                }
              }
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        },
        {
          "comment": "User Journey",
          "begin": "^\\s*(journey)",
          "beginCaptures": {
            "1": {
              "name": "keyword.control.mermaid"
            }
          },
          "patterns": [
            {
              "match": "\\%%.*",
              "name": "comment"
            },
            {
              "match": "(title|section)\\s+(\\s*[\"\\(\\)$&%\\^/#.,?!;:*+=<>\\'\\\\\\-\\w\\s]*)",
              "captures": {
                "1": {
                  "name": "keyword.control.mermaid"
                },
                "2": {
                  "name": "string"
                }
              }
            },
            {
              "begin": "\\s*([\"\\(\\)$&%\\^/.,?!*+=<>\\'\\\\\\-\\w\\s]*)\\s*(:)\\s*(\\d+)\\s*(:)",
              "beginCaptures": {
                "1": {
                  "name": "string"
                },
                "2": {
                  "name": "keyword.control.mermaid"
                },
                "3": {
                  "name": "constant.numeric.decimal.mermaid"
                },
                "4": {
                  "name": "keyword.control.mermaid"
                }
              },
              "patterns": [
                {
                  "comment": "(taskName)",
                  "match": "\\s*,?\\s*([^,#\\n]+)",
                  "captures": {
                    "1": {
                      "name": "variable"
                    }
                  }
                }
              ],
              "end": "$"
            }
          ],
          "end": "(^|\\G)(?=\\s*[`:~]{3,}\\s*$)"
        }
      ]
    }
  },
  "scopeName": "source.mermaid",
  "name": "mermaid"
}
