{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "qsharp",
  "fileTypes": ["qs"],
  "patterns": [
    {
      "include": "#comments"
    },
    {
      "include": "#functions"
    },
    {
      "include": "#keywords"
    },
    {
      "include": "#operators"
    },
    {
      "include": "#types"
    },
    {
      "include": "#constants"
    },
    {
      "include": "#strings"
    },
    {
      "include": "#variables"
    }
  ],
  "repository": {
    "comments": {
      "patterns": [
        {
          "name": "comment.line.double-slash",
          "match": "\\/\\/.*$"
        },
        {
          "name": "comment.documentation",
          "match": "\\/\\/\\/.*$"
        }
      ]
    },
    "functions": {
      "patterns": [
        {
          "comment": "function definition",
          "name": "meta.function.definition.qsharp",
          "begin": "\\b(function)\\s+([A-Za-z0-9_]+)(\\()",
          "beginCaptures": {
            "1": {
              "name": "keyword.other.qsharp"
            },
            "2": {
              "name": "entity.name.function.qsharp"
            },
            "3": {
              "name": "punctuation.brackets.round.qsharp"
            }
          },
          "end": "\\)",
          "endCaptures": {
            "0": {
              "name": "punctuation.brackets.round.qsharp"
            }
          },
          "patterns": [
            {
              "include": "#comments"
            },
            {
              "include": "#functions"
            },
            {
              "include": "#keywords"
            },
            {
              "include": "#operators"
            },
            {
              "include": "#types"
            },
            {
              "include": "#constants"
            },
            {
              "include": "#strings"
            },
            {
              "include": "#variables"
            }
          ]
        },
        {
          "comment": "function calls",
          "name": "meta.function.call.qsharp",
          "begin": "\\b(?<!@)([A-Za-z0-9_]+)(\\()",
          "beginCaptures": {
            "1": {
              "name": "entity.name.function.qsharp"
            },
            "2": {
              "name": "punctuation.brackets.round.qsharp"
            }
          },
          "end": "\\)",
          "endCaptures": {
            "0": {
              "name": "punctuation.brackets.round.qsharp"
            }
          },
          "patterns": [
            {
              "include": "#comments"
            },
            {
              "include": "#functions"
            },
            {
              "include": "#keywords"
            },
            {
              "include": "#operators"
            },
            {
              "include": "#types"
            },
            {
              "include": "#constants"
            },
            {
              "include": "#strings"
            },
            {
              "include": "#variables"
            }
          ]
        }
      ]
    },
    "keywords": {
      "patterns": [
        {
          "name": "keyword.control.qsharp",
          "match": "\\b(use|borrow|mutable|let|set|if|elif|else|repeat|until|fixup|for|in|while|return|fail|within|apply)\\b"
        },
        {
          "name": "keyword.other.qsharp",
          "match": "\\b(namespace|open|import|export|as|internal|newtype|struct|operation|function|new|body|(a|A)djoint|(c|C)ontrolled|self|auto|distribute|invert|intrinsic)\\b"
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "name": "keyword.other.operator.qsharp",
          "match": "\\b(not|and|or)\\b|\\b(w/)|(=)|(!)|(<)|(>)|(\\+)|(-)|(\\*)|(\\/)|(\\^)|(%)|(\\|)|(\\&\\&\\&)|(\\~\\~\\~)|(\\.\\.\\.)|(\\.\\.)|(\\?)"
        }
      ]
    },
    "types": {
      "patterns": [
        {
          "name": "storage.type.qsharp",
          "match": "\\b(Int|BigInt|Double|Bool|Qubit|Pauli|Result|Range|String|Unit|Ctl|Adj|is)\\b"
        }
      ]
    },
    "constants": {
      "patterns": [
        {
          "name": "constant.language.qsharp",
          "match": "\\b(true|false|Pauli(I|X|Y|Z))\\b"
        },
        {
          "name": "constant.other.result.qsharp",
          "match": "\\b(One|Zero)\\b"
        },
        {
          "comment": "integers and decimals",
          "name": "constant.numeric.qsharp",
          "match": "\\b[\\d_]*\\.?[\\d_]\\b"
        }
      ]
    },
    "strings": {
      "patterns": [
        {
          "name": "string.quoted.double.qsharp",
          "begin": "(\\$|)\"",
          "end": "\"",
          "patterns": [
            {
              "name": "constant.character.escape.qsharp",
              "match": "\\\\."
            }
          ]
        }
      ]
    },
    "variables": {
      "patterns": [
        {
          "name": "variable.other.qsharp",
          "match": "\\b(?<!@)[A-Za-z0-9_]+\\b"
        }
      ]
    }
  },
  "scopeName": "source.qsharp"
}
