{
  "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
  "name": "KScript (code)",
  "scopeName": "source.kscript-code",
  "comment": "The brace-and-newline .kscript format. XML scripts (.ks.xml, .ks) use kscript.tmLanguage.json.",
  "patterns": [
    {
      "include": "#statement"
    }
  ],
  "repository": {
    "statement": {
      "patterns": [
        {
          "include": "#comments"
        },
        {
          "include": "#fn"
        },
        {
          "include": "#construct"
        },
        {
          "include": "#typeDeclaration"
        },
        {
          "include": "#typeRule"
        },
        {
          "include": "#import"
        },
        {
          "include": "#declaration"
        },
        {
          "include": "#keywords"
        },
        {
          "include": "#assignment"
        },
        {
          "include": "#element"
        },
        {
          "include": "#expression"
        }
      ]
    },
    "comments": {
      "patterns": [
        {
          "name": "comment.line.documentation.kscript",
          "begin": "///",
          "end": "$",
          "patterns": [
            {
              "match": "(?:^|\\G)\\s*(@(?:param|argument|arg))\\s+(\\$?[A-Za-z_][\\w-]*)",
              "captures": {
                "1": {
                  "name": "storage.type.class.doc.kscript"
                },
                "2": {
                  "name": "variable.parameter.kscript"
                }
              }
            },
            {
              "match": "(?:^|\\G)\\s*(@(?:returns?|throws|example|deprecated|see|public|llm|prefer|avoid|pitfall|agent|param|argument|arg))(?![\\w-])",
              "captures": {
                "1": {
                  "name": "storage.type.class.doc.kscript"
                }
              }
            },
            {
              "match": "`[^`]*`",
              "name": "markup.inline.raw.kscript"
            }
          ],
          "comment": "Tags (@param, @arg, @returns, @example, @llm, ...) count only at the start of a line, as in DocComment.Parse, so '@greet' in the text stays plain."
        },
        {
          "name": "comment.line.double-slash.kscript",
          "begin": "(?<!https:|http:|wss:|ws:|ftp:)//",
          "end": "$"
        },
        {
          "name": "comment.block.kscript",
          "begin": "/\\*",
          "end": "\\*/"
        }
      ]
    },
    "construct": {
      "match": "(?:^|(?<=[{;]))\\s*(construct)(?=\\s*\\()",
      "captures": {
        "1": {
          "name": "storage.type.function.kscript"
        }
      }
    },
    "fn": {
      "match": "\\b(?:(override|private)\\s+)?(fn)\\s+([A-Za-z_][\\w-]*)",
      "captures": {
        "1": {
          "name": "storage.modifier.kscript"
        },
        "2": {
          "name": "storage.type.function.kscript"
        },
        "3": {
          "name": "entity.name.function.kscript"
        }
      }
    },
    "import": {
      "begin": "(?<![\\w$@.-])(import)\\b",
      "beginCaptures": {
        "1": {
          "name": "keyword.control.import.kscript"
        }
      },
      "end": "(?=;|$)",
      "patterns": [
        {
          "match": "(?<![\\w$@.-])(from|as)(?![\\w-])",
          "name": "keyword.control.import.kscript"
        },
        {
          "include": "#expression"
        }
      ]
    },
    "declaration": {
      "patterns": [
        {
          "match": "^\\s*(private)(?=\\s+[A-Za-z_])",
          "captures": {
            "1": {
              "name": "storage.modifier.kscript"
            }
          }
        },
        {
          "match": "\\b(const)\\s+(\\$?[A-Za-z_][\\w-]*)",
          "captures": {
            "1": {
              "name": "storage.modifier.kscript"
            },
            "2": {
              "name": "variable.other.constant.kscript"
            }
          }
        },
        {
          "match": "\\b(echo)\\b",
          "name": "support.function.builtin.kscript"
        },
        {
          "match": "(?<![\\w$@.-])(throw)\\s+([A-Z][\\w.]*)(?=\\s*\\\")",
          "captures": {
            "1": {
              "name": "keyword.control.flow.kscript"
            },
            "2": {
              "name": "entity.name.type.kscript"
            }
          }
        }
      ]
    },
    "keywords": {
      "patterns": [
        {
          "match": "(?<![\\w$@.-])(extends)(?![\\w-])(?:[ \\t]+([A-Z]\\w*))?",
          "captures": {
            "1": {
              "name": "storage.modifier.kscript"
            },
            "2": {
              "name": "entity.name.type.kscript"
            }
          }
        },
        {
          "match": "(?<![\\w$@.-])(if|guard|elif|else|for|in|at|while|match|when|try|catch|finally|throw|return|exit|break|continue|wait)(?![\\w-])",
          "name": "keyword.control.flow.kscript"
        },
        {
          "comment": "The arm of a match that takes anything: _ => ... or _ when $n > 9 => ...",
          "match": "(?<![\\w$@.-])_(?=\\s*(?:=>|when(?![\\w-])))",
          "name": "keyword.control.flow.kscript"
        }
      ]
    },
    "assignment": {
      "match": "^\\s*(\\$?[A-Za-z_][\\w-]*)(?=\\s*(?::\\s*[\\w.]+(?:\\([^)]*\\))?[\\[\\]?]*\\s*)?(?:=(?![=>])|\\+=|-=|\\*=|/=|%=|\\?\\?=|\\+\\+|--))",
      "captures": {
        "1": {
          "name": "variable.other.assignment.kscript"
        }
      }
    },
    "element": {
      "patterns": [
        {
          "begin": "(?:^|(?<=[{;]))\\s*(?!(?:if|guard|elif|else|for|in|at|while|match|when|try|catch|finally|throw|return|exit|break|continue|wait|fn|construct|const|import|from|as|echo|let|set|and|or|not|is|true|false|null)(?![\\w-]))([A-Za-z_][\\w.:-]*)(?<!:)\\s*(\\()",
          "beginCaptures": {
            "1": {
              "name": "entity.name.tag.kscript"
            },
            "2": {
              "name": "punctuation.definition.attributes.begin.kscript"
            }
          },
          "end": "\\)",
          "endCaptures": {
            "0": {
              "name": "punctuation.definition.attributes.end.kscript"
            }
          },
          "patterns": [
            {
              "comment": "A named argument whose value is a built-in type name, Field(type: string) or AddField(type: int[]?): the type is coloured as a type.",
              "match": "(?:(?<=[(,])|^)\\s*([A-Za-z_][\\w-]*)\\s*(:)\\s*((?:string|int|float|number|bool|list|map|fn|date|any|email|password|handle|uuid|regex|url|domain|ip|cidr|mac|port|slug|slash_path|file_path|semver|mime|hex|base64|jwt|json|csv|phone|country|currency|locale|timezone|duration|date_format|cron|color|iban|card|money|markdown|latex|formatted_file|document)(?![\\w-])(?:\\[\\])?\\??)(?=\\s*(?:,|\\)|$|//))",
              "captures": {
                "1": {
                  "name": "entity.other.attribute-name.kscript"
                },
                "2": {
                  "name": "punctuation.separator.key-value.kscript"
                },
                "3": {
                  "patterns": [
                    {
                      "include": "#typeName"
                    }
                  ]
                }
              }
            },
            {
              "comment": "A migration column's type: enum (Field(type: enum, values: [...])) is a column type, coloured like type: string. enum isn't a value type anywhere else.",
              "match": "(?:(?<=[(,])|^)\\s*(type)\\s*(:)\\s*(enum)(?![\\w-])(?=\\s*(?:,|\\)|$|//))",
              "captures": {
                "1": {
                  "name": "entity.other.attribute-name.kscript"
                },
                "2": {
                  "name": "punctuation.separator.key-value.kscript"
                },
                "3": {
                  "name": "support.type.builtin.kscript"
                }
              }
            },
            {
              "match": "([A-Za-z_][\\w-]*)\\s*(:)",
              "captures": {
                "1": {
                  "name": "entity.other.attribute-name.kscript"
                },
                "2": {
                  "name": "punctuation.separator.key-value.kscript"
                }
              }
            },
            {
              "comment": "A list in the arguments (values: [yellow, pink], columns: [owner]) holds values, not flags: its words are left alone, even across lines.",
              "begin": "\\[",
              "end": "\\]",
              "patterns": [
                {
                  "include": "#expression"
                }
              ]
            },
            {
              "comment": "A bare flag argument (AddField(optional, ...)) is an option switched on: coloured like a named argument, in italics.",
              "match": "(?:(?<=[(,])|^)\\s*(?!(?:true|false|null|yes|no|not)(?![\\w-]))([A-Za-z_][\\w-]*)\\s*(?=,|\\)|$|//)",
              "captures": {
                "1": {
                  "name": "entity.other.attribute-name.flag.kscript"
                }
              }
            },
            {
              "include": "#arguments"
            },
            {
              "include": "#expression"
            }
          ]
        },
        {
          "match": "(?:^|(?<=[{;]))\\s*(?!(?:if|guard|elif|else|for|in|at|while|match|when|try|catch|finally|throw|return|exit|break|continue|wait|fn|construct|const|import|from|as|echo|let|set|and|or|not|is|true|false|null)(?![\\w-]))([A-Za-z_][\\w.:-]*)(?<!:)(?=\\s*(?:\\\"|\\{|$))",
          "captures": {
            "1": {
              "name": "entity.name.tag.kscript"
            }
          }
        }
      ]
    },
    "expression": {
      "patterns": [
        {
          "include": "#namedArgument"
        },
        {
          "name": "keyword.control.kscript",
          "match": "(?<![\\w$@.-])(try|catch)(?![\\w-])"
        },
        {
          "include": "#typeAnnotation"
        },
        {
          "include": "#comments"
        },
        {
          "include": "#textBlock"
        },
        {
          "include": "#nativeString"
        },
        {
          "include": "#text"
        },
        {
          "include": "#string"
        },
        {
          "include": "#literals"
        },
        {
          "include": "#variable"
        },
        {
          "include": "#member"
        },
        {
          "include": "#command"
        },
        {
          "include": "#method"
        },
        {
          "include": "#constants"
        },
        {
          "include": "#cast"
        },
        {
          "include": "#operators"
        },
        {
          "include": "#braces"
        }
      ]
    },
    "text": {
      "name": "string.quoted.double.kscript",
      "begin": "\\\"",
      "end": "\\\"",
      "beginCaptures": {
        "0": {
          "name": "punctuation.definition.string.begin.kscript"
        }
      },
      "endCaptures": {
        "0": {
          "name": "punctuation.definition.string.end.kscript"
        }
      },
      "patterns": [
        {
          "match": "\\\\$",
          "name": "constant.character.escape.line-continuation.kscript"
        },
        {
          "match": "\\\\[\\\"\\\\]",
          "name": "constant.character.escape.kscript"
        },
        {
          "include": "#escapedBraces"
        },
        {
          "include": "#interpolation"
        }
      ]
    },
    "interpolation": {
      "name": "meta.interpolation.kscript",
      "contentName": "meta.embedded.expression.kscript",
      "begin": "\\{",
      "end": "\\}",
      "beginCaptures": {
        "0": {
          "name": "punctuation.section.interpolation.begin.kscript"
        }
      },
      "endCaptures": {
        "0": {
          "name": "punctuation.section.interpolation.end.kscript"
        }
      },
      "patterns": [
        {
          "include": "#expression"
        }
      ]
    },
    "braces": {
      "begin": "\\{",
      "end": "\\}",
      "patterns": [
        {
          "include": "#statement"
        }
      ]
    },
    "string": {
      "comment": "Single quotes keep text as written: no escapes. A backslash at the end of a line still joins it to the next.",
      "name": "string.quoted.single.kscript",
      "begin": "'",
      "end": "'",
      "patterns": [
        {
          "match": "\\\\$",
          "name": "constant.character.escape.line-continuation.kscript"
        }
      ]
    },
    "variable": {
      "match": "\\$(?:\\.)?[A-Za-z_]\\w*",
      "name": "variable.other.kscript"
    },
    "command": {
      "match": "@[A-Za-z_][\\w.-]*",
      "name": "entity.name.function.kscript"
    },
    "method": {
      "match": "(?:(?<=->)|(?<=->!))\\s*([A-Za-z_][\\w]*)",
      "captures": {
        "1": {
          "name": "support.function.kscript"
        }
      }
    },
    "constants": {
      "patterns": [
        {
          "match": "(?<![\\w$.])(true|false|null)(?![\\w-])",
          "name": "constant.language.kscript"
        },
        {
          "match": "(?<![\\w$])(?:\\d+(?:\\.\\d+)?(?:ms|min|mo|y|w|d|h|m|s))+(?![\\w-])",
          "name": "constant.numeric.duration.kscript"
        },
        {
          "match": "(?<![\\w$])-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?\\b",
          "name": "constant.numeric.kscript"
        }
      ]
    },
    "operators": {
      "patterns": [
        {
          "comment": "Logic is written in words. Comparisons are symbols in a .kscript file (lt, gt, eq and the rest are the XML spellings).",
          "match": "(?<![\\w$@.-])(and|or|not|is|in)(?![\\w-])",
          "name": "keyword.operator.word.kscript"
        },
        {
          "comment": "1..10 step 2. Not an argument named step (@range(step: 2)).",
          "match": "(?<![\\w$@.-])(step)(?![\\w-]|\\s*:)",
          "name": "keyword.operator.word.kscript"
        },
        {
          "match": "=>",
          "name": "storage.type.function.arrow.kscript"
        },
        {
          "match": "%%=?|%=|\\*\\*=?|~/=?|->|\\|>|\\?\\?=?|\\?\\.|\\.\\.=?|===|!==|==|!=|<=|>=|\\+=|-=|\\*=|/=|[-+*/%<>=?!]",
          "name": "keyword.operator.kscript"
        }
      ]
    },
    "typeDeclaration": {
      "patterns": [
        {
          "begin": "\\b(type)\\s+([A-Za-z_]\\w*)\\s+(with)\\s*(\\[)",
          "beginCaptures": {
            "1": {
              "name": "storage.type.kscript"
            },
            "2": {
              "name": "entity.name.type.kscript"
            },
            "3": {
              "name": "storage.modifier.kscript"
            },
            "4": {
              "name": "punctuation.section.brackets.kscript"
            }
          },
          "end": "\\]",
          "endCaptures": {
            "0": {
              "name": "punctuation.section.brackets.kscript"
            }
          },
          "patterns": [
            {
              "include": "#typeName"
            }
          ]
        },
        {
          "match": "\\b(policy|listener)[ \\t]+(for)[ \\t]+([A-Za-z_]\\w*)",
          "captures": {
            "1": {
              "name": "storage.type.kscript"
            },
            "2": {
              "name": "keyword.other.kscript"
            },
            "3": {
              "name": "entity.name.type.kscript"
            }
          }
        },
        {
          "match": "\\b(type|model|enum|extend|error|job|event)\\s+([A-Za-z_]\\w*)",
          "captures": {
            "1": {
              "name": "storage.type.kscript"
            },
            "2": {
              "name": "entity.name.type.kscript"
            }
          }
        }
      ]
    },
    "typeName": {
      "patterns": [
        {
          "match": "(?<![\\w$@.-])(string|int|float|number|bool|list|map|fn|date|any|email|password|handle|uuid|regex|url|domain|ip|cidr|mac|port|slug|slash_path|file_path|semver|mime|hex|base64|jwt|json|csv|phone|country|currency|locale|timezone|duration|date_format|cron|color|iban|card|money|markdown|latex|formatted_file|document)(?![\\w-])",
          "name": "support.type.builtin.kscript"
        },
        {
          "match": "(?<![\\w$@.-])[A-Z]\\w*",
          "name": "entity.name.type.kscript"
        }
      ]
    },
    "typeAnnotation": {
      "match": "(?<=[\\w?])\\s*(:)\\s*(?!(?:not|true|false|null|yes|no)\\b)((?:string|int|float|number|bool|list|map|fn|date|any|email|password|handle|uuid|regex|url|domain|ip|cidr|mac|port|slug|slash_path|file_path|semver|mime|hex|base64|jwt|json|csv|phone|country|currency|locale|timezone|duration|date_format|cron|color|iban|card|money|markdown|latex|formatted_file|document)(?![\\w-])|[A-Z]\\w*)(?=\\s*(?:\\(|\\[\\]|\\?|=|,|\\)|$|from\\b|=>|;|\\}|//))",
      "captures": {
        "1": {
          "name": "punctuation.separator.type.kscript"
        },
        "2": {
          "patterns": [
            {
              "include": "#typeName"
            }
          ]
        }
      }
    },
    "typeRule": {
      "match": "^\\s*(min|max|pattern|one_of|not|validate|normalize|parse)\\s*(:)(?!\\s*(?:[A-Za-z_][\\w.\\[\\]?]*)\\s*(?:=|$|from\\b|//))",
      "captures": {
        "1": {
          "name": "keyword.other.rule.kscript"
        },
        "2": {
          "name": "punctuation.separator.kscript"
        }
      }
    },
    "literals": {
      "patterns": [
        {
          "comment": "A file path: ./data/input.txt, ../shared/rates.json, ~/notes.md, ./ on its own (the lexer's FilePathEnd).",
          "match": "(?<![\\w)\\]$'\\\".~])(?:\\.\\.?|~)/(?:(?:\\{[^}\\n]*\\}|\\$[A-Za-z_]\\w*|(?:[\\w.~%]|-(?!>))+)(?:/(?:\\{[^}\\n]*\\}|\\$[A-Za-z_]\\w*|(?:[\\w.~%]|-(?!>))+))*/?)?",
          "name": "string.unquoted.path.kscript"
        },
        {
          "comment": "A path that ends at a comma or bracket, when the next / is inside a later argument's quotes: @api(/, options: { c: 'a/b' }). Not a regex (the lexer's RegexClosesInsideLaterText).",
          "match": "(?<![\\w)\\]$'\\\"./])/(?:(?:\\{[A-Za-z_]\\w*[?*]?\\}|(?:[\\w.~%]|-(?!>))+)(?:/(?:\\{[A-Za-z_]\\w*[?*]?\\}|(?:[\\w.~%]|-(?!>))+))*/?)?(?=[,)\\]}][^/'\\\"\\n]*?[:,(\\[{=]\\s*(['\\\"])(?:(?!\\1)[^\\n])*?/)",
          "name": "string.unquoted.path.kscript"
        },
        {
          "match": "(?<![\\w)\\]$'\"])/(?![\\s/*])(?:\\\\.|\\[(?:\\\\.|[^\\]\\\\\\n])*\\]|[^/\\\\\\n\\[])+/[imsx]*(?!\\w)",
          "name": "string.regexp.kscript"
        },
        {
          "match": "(?<![\\w)\\]$'\"./])/(?:\\{[A-Za-z_]\\w*[?*]?\\}|(?:[\\w.~%]|-(?!>))+)(?:/(?:\\{[A-Za-z_]\\w*[?*]?\\}|(?:[\\w.~%]|-(?!>))+))*(?:/(?![/*]))?(?![\\w])",
          "name": "string.unquoted.path.kscript"
        },
        {
          "match": "(?<![\\w$@.])(?i:https?|wss?|ftp)://[^\\s'\",()\\[\\]{};<>`]+?(?=[.!?:]*(?:[\\s'\",()\\[\\]{};<>`]|->|$))",
          "name": "string.unquoted.url.kscript"
        },
        {
          "match": "(?<![\\w.%+-])[A-Za-z0-9._%+-]+@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+(?![\\w]|-(?!>))",
          "name": "string.unquoted.email.kscript"
        },
        {
          "match": "(?<![\\w-])[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}(?![\\w-]|-(?!>))",
          "name": "constant.other.uuid.kscript"
        }
      ]
    },
    "textBlock": {
      "comment": "```lang blocks: a plain word is a language, <Type> parses the block as JSON. The closing fence ends it.",
      "patterns": [
        {
          "begin": "(`{3,})[ \\t]*(sql)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.sql",
          "patterns": [
            {
              "include": "source.sql"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(html)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.html",
          "patterns": [
            {
              "include": "text.html.basic"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(json)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.json",
          "patterns": [
            {
              "include": "source.json"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(css)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.css",
          "patterns": [
            {
              "include": "source.css"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(ps1)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.powershell",
          "patterns": [
            {
              "include": "source.powershell"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(js|javascript)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.javascript",
          "patterns": [
            {
              "include": "source.js"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*((?:md|markdown)?)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.markdown",
          "patterns": [
            {
              "include": "text.html.markdown"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(latex|tex)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.latex",
          "patterns": [
            {
              "include": "text.tex.latex"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(ya?ml)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.yaml",
          "patterns": [
            {
              "include": "source.yaml"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(xml)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.xml",
          "patterns": [
            {
              "include": "text.xml"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(kscript)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.kscript",
          "patterns": [
            {
              "include": "$self"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(scss)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.scss",
          "patterns": [
            {
              "include": "source.css.scss"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(ks\\.css)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.kscript-css",
          "patterns": [
            {
              "include": "source.kscript-css"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(ks\\.scss)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.kscript-scss",
          "patterns": [
            {
              "include": "source.kscript-scss"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(ts|typescript)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.typescript",
          "patterns": [
            {
              "include": "source.ts"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(jsonc)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.jsonc",
          "patterns": [
            {
              "include": "source.json.comments"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*(<[ \\t]*[A-Za-z_][\\w.-]*[ \\t]*>)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.type.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "meta.embedded.block.json",
          "patterns": [
            {
              "include": "source.json"
            }
          ]
        },
        {
          "begin": "(`{3,})[ \\t]*([\\w+#.-]*)[ \\t]*$",
          "end": "^[ \\t]*(\\1)(?!`)",
          "beginCaptures": {
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "entity.name.tag.language.kscript"
            }
          },
          "endCaptures": {
            "1": {
              "name": "punctuation.definition.string.end.kscript"
            }
          },
          "name": "meta.block.fenced.kscript",
          "contentName": "string.unquoted.block.kscript",
          "patterns": [
            {
              "include": "#escapedBraces"
            },
            {
              "include": "#interpolation"
            },
            {
              "include": "#textVariable"
            },
            {
              "include": "#textCall"
            }
          ]
        }
      ]
    },
    "cast": {
      "match": "(?<![\\w$@.-])(as)[ \\t]+([A-Za-z_]\\w*)",
      "captures": {
        "1": {
          "name": "keyword.operator.word.kscript"
        },
        "2": {
          "name": "entity.name.type.kscript"
        }
      }
    },
    "escapedBraces": {
      "match": "\\{\\{|\\}\\}",
      "name": "constant.character.escape.kscript"
    },
    "member": {
      "match": "(?<!\\.)(\\??\\.)([A-Za-z_]\\w*)",
      "captures": {
        "1": {
          "name": "keyword.operator.kscript"
        },
        "2": {
          "name": "variable.other.property.kscript"
        }
      }
    },
    "textVariable": {
      "match": "(?<![\\w.])\\$(?:\\.)?[A-Za-z_]\\w*(?:(?:\\??\\.)[A-Za-z_]\\w*)*",
      "captures": {
        "0": {
          "patterns": [
            {
              "include": "#variable"
            },
            {
              "include": "#member"
            }
          ]
        }
      }
    },
    "textCall": {
      "begin": "(?<![\\w.])(@[A-Za-z_]\\w*)(\\()",
      "beginCaptures": {
        "1": {
          "name": "entity.name.function.kscript"
        }
      },
      "end": "\\)",
      "patterns": [
        {
          "include": "#arguments"
        },
        {
          "include": "#expression"
        }
      ]
    },
    "arguments": {
      "begin": "\\(",
      "end": "\\)",
      "patterns": [
        {
          "include": "#arguments"
        },
        {
          "include": "#expression"
        }
      ]
    },
    "namedArgument": {
      "comment": "A named argument or map key: @range(step: 2), @on-click(call: $add, with: [...]), { name: 'x' }, or a key on its own line in a multi-line map. Not a typed parameter (a: int), which typeAnnotation colours.",
      "match": "(?:(?<=[(,{])|^)\\s*([A-Za-z_]\\w*)\\s*(:)(?![:=])(?!\\s*(?!(?:not|true|false|null|yes|no)\\b)((?:string|int|float|number|bool|list|map|fn|date|any|email|password|handle|uuid|regex|url|domain|ip|cidr|mac|port|slug|slash_path|file_path|semver|mime|hex|base64|jwt|json|csv|phone|country|currency|locale|timezone|duration|date_format|cron|color|iban|card|money|markdown|latex|formatted_file|document)(?![\\w-])|[A-Z]\\w*)(?=\\s*(?:\\(|\\[\\]|\\?|=|,|\\)|$|from\\b|=>|;|\\}|//)))",
      "captures": {
        "1": {
          "name": "entity.other.attribute-name.kscript"
        },
        "2": {
          "name": "punctuation.separator.key-value.kscript"
        }
      }
    },
    "nativeString": {
      "comment": "A quoted value in a native type's literal form: 'application/octet-stream', '/docs', 'ada@example.com', '1.4.2', '2026-11-30', '#ff8800', '5m'. Coloured like a bare native (/api/health), not like text. Mirrors KScript.Language NativeLiterals.",
      "patterns": [
        {
          "match": "(')((?:(?:application|audio|font|image|message|model|multipart|text|video)/[A-Za-z0-9][\\w.+-]*(?:\\s*;\\s*[\\w-]+=[\\w.-]+)*|/(?:[\\w.~%-]+|\\{[A-Za-z_]\\w*[?*]?\\})(?:/(?:[\\w.~%-]+|\\{[A-Za-z_]\\w*[?*]?\\}))*/?|/|(?i:https?|wss?|ftp)://[^\\s'\"]+|[A-Za-z0-9._%+-]+@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?|\\d{1,3}(?:\\.\\d{1,3}){3}(?:/\\d{1,2})?|\\d{4}-\\d{2}-\\d{2}(?:[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?)?|#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|(?:\\d+(?:\\.\\d+)?(?:ms|min|mo|y|w|d|h|m|s))+))(')",
          "captures": {
            "0": {
              "name": "string.quoted.single.kscript"
            },
            "2": {
              "name": "constant.other.native.kscript"
            }
          }
        },
        {
          "match": "(\")((?:(?:application|audio|font|image|message|model|multipart|text|video)/[A-Za-z0-9][\\w.+-]*(?:\\s*;\\s*[\\w-]+=[\\w.-]+)*|/(?:[\\w.~%-]+|\\{[A-Za-z_]\\w*[?*]?\\})(?:/(?:[\\w.~%-]+|\\{[A-Za-z_]\\w*[?*]?\\}))*/?|/|(?i:https?|wss?|ftp)://[^\\s'\"]+|[A-Za-z0-9._%+-]+@[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?(?:\\.[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?)+|[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}|v?\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?|\\d{1,3}(?:\\.\\d{1,3}){3}(?:/\\d{1,2})?|\\d{4}-\\d{2}-\\d{2}(?:[T ]\\d{2}:\\d{2}(?::\\d{2}(?:\\.\\d+)?)?(?:Z|[+-]\\d{2}:?\\d{2})?)?|#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|(?:\\d+(?:\\.\\d+)?(?:ms|min|mo|y|w|d|h|m|s))+))(\")",
          "captures": {
            "0": {
              "name": "string.quoted.double.kscript"
            },
            "1": {
              "name": "punctuation.definition.string.begin.kscript"
            },
            "2": {
              "name": "constant.other.native.kscript"
            },
            "3": {
              "name": "punctuation.definition.string.end.kscript"
            }
          }
        }
      ]
    }
  }
}
