diff --git a/src/TextMateSharp.Grammars/Resources/Grammars/typst/syntaxes/typst.tmLanguage.json b/src/TextMateSharp.Grammars/Resources/Grammars/typst/syntaxes/typst.tmLanguage.json index f43c768..aa830e4 100644 --- a/src/TextMateSharp.Grammars/Resources/Grammars/typst/syntaxes/typst.tmLanguage.json +++ b/src/TextMateSharp.Grammars/Resources/Grammars/typst/syntaxes/typst.tmLanguage.json @@ -1,576 +1,1584 @@ { - "name": "typst", - "patterns": [ + "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", + "scopeName": "source.typst", + "name": "typst", + "patterns": [ + { + "include": "#markup" + } + ], + "repository": { + "common": { + "patterns": [ + { + "include": "#strictComments" + }, + { + "include": "#blockRaw" + }, + { + "include": "#inlineRaw" + } + ] + }, + "math": { + "patterns": [ + { + "include": "#markupEscape" + }, + { + "include": "#stringLiteral" + }, + { + "include": "#markupEnterCode" + }, + { + "begin": "([_^\\/√∛∜])\\s*([\\[\\(\\{⌈⌊⌜⌞❲⟦⟨⟪⟬⟮⦃⦅⦇⦉⦋⦍⦏⦑⦓⦕⦗⧘⧚⧼])", + "end": "([\\]\\)\\}⌉⌋⌝⌟❳⟧⟩⟫⟭⟯⦄⦆⦈⦊⦌⦎⦐⦒⦔⦖⦘⧙⧛⧽])|(?=\\$)|$", + "beginCaptures": { + "1": { + "name": "punctuation.math.operator.typst" + }, + "2": { + "name": "constant.other.symbol.typst" + } + }, + "endCaptures": { + "0": { + "name": "constant.other.symbol.typst" + } + }, + "patterns": [ + { + "include": "#mathParen" + }, + { + "include": "#math" + } + ] + }, + { + "match": "[_^'&\\/√∛∜]", + "name": "punctuation.math.operator.typst" + }, + { + "include": "#strictMathFuncCallOrPropAccess" + }, + { + "include": "#mathPrimary" + }, + { + "include": "#mathMoreBrace" + } + ] + }, + "markup": { + "patterns": [ + { + "include": "#common" + }, + { + "include": "#markupEnterCode" + }, + { + "include": "#markupEscape" + }, + { + "name": "punctuation.definition.linebreak.typst", + "match": "\\\\" + }, + { + "name": "punctuation.definition.nonbreaking-space.typst", + "match": "\\~" + }, + { + "name": "punctuation.definition.shy.typst", + "match": "-\\?" + }, + { + "name": "punctuation.definition.em-dash.typst", + "match": "---" + }, + { + "name": "punctuation.definition.en-dash.typst", + "match": "--" + }, + { + "name": "punctuation.definition.ellipsis.typst", + "match": "\\.\\.\\." + }, + { + "include": "#markupBold" + }, + { + "include": "#markupItalic" + }, + { + "include": "#markupLink" + }, + { + "include": "#markupMath" + }, + { + "include": "#markupHeading" + }, + { + "name": "punctuation.definition.list.unnumbered.typst", + "match": "^\\s*-\\s+" + }, + { + "name": "punctuation.definition.list.numbered.typst", + "match": "^\\s*([0-9]+\\.|\\+)\\s+" + }, + { + "include": "#markupLabel" + }, + { + "include": "#markupReference" + }, + { + "include": "#markupBrace" + } + ] + }, + "code": { + "patterns": [ + { + "include": "#common" + }, + { + "include": "#comments" + }, + { + "name": "punctuation.terminator.statement.typst", + "match": ";" + }, + { + "include": "#expression" + } + ] + }, + "comments": { + "patterns": [ + { + "include": "#blockComment" + }, + { + "include": "#lineComment" + } + ] + }, + "codeBlock": { + "begin": "\\{", + "end": "\\}", + "beginCaptures": { + "0": { + "name": "meta.brace.curly.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.curly.typst" + } + }, + "patterns": [ + { + "include": "#code" + } + ] + }, + "contentBlock": { + "begin": "\\[", + "end": "\\]", + "beginCaptures": { + "0": { + "name": "meta.brace.square.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.square.typst" + } + }, + "patterns": [ + { + "include": "#contentBlock" + }, + { + "include": "#markup" + } + ] + }, + "keywordConstants": { + "patterns": [ + { + "name": "keyword.other.none.typst", + "match": "(?", - "captures": { - "1": { - "name": "punctuation.definition.label.typst" - } - } - }, - { - "name": "entity.other.reference.typst", - "match": "(@)[[:alpha:]_][[:alnum:]_-]*", - "captures": { - "1": { - "name": "punctuation.definition.reference.typst" - } - } - }, - { - "begin": "(#)(let|set|show)\\b", - "end": "\n|(;)|(?=])", - "beginCaptures": { - "0": { - "name": "keyword.other.typst" - }, - "1": { - "name": "punctuation.definition.keyword.typst" - } - }, - "endCaptures": { - "1": { - "name": "punctuation.terminator.statement.typst" - } - }, - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "name": "keyword.other.typst", - "match": "(#)(as|in)\\b", - "captures": { - "1": { - "name": "punctuation.definition.keyword.typst" - } - } - }, - { - "begin": "((#)if|(?<=(}|])\\s*)else)\\b", - "end": "\n|(?=])|(?<=}|])", - "beginCaptures": { - "0": { - "name": "keyword.control.conditional.typst" - }, - "2": { - "name": "punctuation.definition.keyword.typst" - } - }, - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "begin": "(#)(for|while)\\b", - "end": "\n|(?=])|(?<=}|])", - "beginCaptures": { - "0": { - "name": "keyword.control.loop.typst" - }, - "1": { - "name": "punctuation.definition.keyword.typst" - } - }, - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "name": "keyword.control.loop.typst", - "match": "(#)(break|continue)\\b", - "captures": { - "1": { - "name": "punctuation.definition.keyword.typst" - } - } - }, - { - "begin": "(#)(import|include|export)\\b", - "end": "\n|(;)|(?=])", - "beginCaptures": { - "0": { - "name": "keyword.control.import.typst" - }, - "1": { - "name": "punctuation.definition.keyword.typst" - } - }, - "endCaptures": { - "1": { - "name": "punctuation.terminator.statement.typst" - } - }, - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "name": "keyword.control.flow.typst", - "match": "(#)(return)\\b", - "captures": { - "1": { - "name": "punctuation.definition.keyword.typst" - } - } - }, - { - "comment": "Function name", - "name": "entity.name.function.typst", - "match": "((#)[[:alpha:]_][[:alnum:]_-]*!?)(?=\\[|\\()", - "captures": { - "2": { - "name": "punctuation.definition.function.typst" - } - } - }, - { - "comment": "Function arguments", - "begin": "(?<=#[[:alpha:]_][[:alnum:]_-]*!?)\\(", - "end": "\\)", - "captures": { - "0": { - "name": "punctuation.definition.group.typst" - } - }, - "patterns": [ - { - "include": "#arguments" - } - ] - }, - { - "name": "entity.other.interpolated.typst", - "match": "(#)[[:alpha:]_][.[:alnum:]_-]*", - "captures": { - "1": { - "name": "punctuation.definition.variable.typst" - } - } - }, - { - "name": "meta.block.content.typst", - "begin": "#", - "end": "\\s", - "patterns": [ - { - "include": "#code" - } - ] - } - ] + { + "include": "#primitiveTypes" }, - "code": { - "patterns": [ - { - "include": "#common" - }, - { - "name": "meta.block.code.typst", - "begin": "{", - "end": "}", - "captures": { - "0": { - "name": "punctuation.definition.block.code.typst" - } - }, - "patterns": [ - { - "include": "#code" - } - ] - }, - { - "name": "meta.block.content.typst", - "begin": "\\[", - "end": "\\]", - "captures": { - "0": { - "name": "punctuation.definition.block.content.typst" - } - }, - "patterns": [ - { - "include": "#markup" - } - ] - }, - { - "name": "comment.line.double-slash.typst", - "begin": "//", - "end": "\n", - "beginCaptures": { - "0": { - "name": "punctuation.definition.comment.typst" - } - } - }, - { - "name": "punctuation.separator.colon.typst", - "match": ":" - }, - { - "name": "punctuation.separator.comma.typst", - "match": "," - }, - { - "name": "keyword.operator.typst", - "match": "=>|\\.\\." - }, - { - "name": "keyword.operator.relational.typst", - "match": "==|!=|<=|<|>=|>" - }, - { - "name": "keyword.operator.assignment.typst", - "match": "\\+=|-=|\\*=|/=|=" - }, - { - "name": "keyword.operator.arithmetic.typst", - "match": "\\+|\\*|/|(?" + }, + "markupReference": { + "name": "string.other.reference.typst", + "match": "(@)[\\p{L}\\p{Nl}__](?:[\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}_\\-]|[\\.:](?!:\\s|$|([\\.:]*[^\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}_\\-\\.:])))*", + "captures": { + "1": { + "name": "punctuation.definition.reference.typst" + } + } + }, + "markupEscape": { + "name": "constant.character.escape.content.typst", + "match": "\\\\(?:[^u]|u\\{?[0-9a-zA-Z]*\\}?)" + }, + "markupHeading": { + "name": "markup.heading.typst", + "begin": "^\\s*(=+)(?:(?=[\\r\\n]|$)|[^\\S\\n]+)", + "end": "\\n|(?=<)", + "beginCaptures": { + "1": { + "name": "punctuation.definition.heading.typst" + } + }, + "patterns": [ + { + "include": "#markup" + } + ] + }, + "markupEnterCode": { + "patterns": [ + { + "match": "(#)\\s", + "captures": { + "1": { + "name": "punctuation.definition.hash.typst" + } + } + }, + { + "match": "(#)(;)", + "captures": { + "1": { + "name": "punctuation.definition.hash.typst" + }, + "2": { + "name": "punctuation.terminator.statement.typst" + } + } + }, + { + "begin": "#(?=(?:break|continue|and|or|not|return|as|in|include|import|let|else|if|for|while|context|set|show)\\b(?!-))", + "end": "(?<=;)|(?<=[\\}\\]\\)])(?![;\\(\\[\\$]|(?:\\.(?", + "name": "storage.type.function.arrow.typst" + }, + { + "match": "==|!=|<=|<|>=|>", + "name": "keyword.operator.relational.typst" + }, + { + "begin": "(\\+=|-=|\\*=|\\/=|=)", + "end": "(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "1": { + "name": "keyword.operator.assignment.typst" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + { + "match": "\\+|\\\\|\\/|\\*|-", + "name": "keyword.operator.arithmetic.typst" + } + ] + }, + "arrayOrDict": { + "patterns": [ + { + "match": "(\\()\\s*(\\))", + "captures": { + "1": { + "name": "meta.brace.round.typst" + }, + "2": { + "name": "meta.brace.round.typst" + } + } + }, + { + "match": "(\\()\\s*(:)\\s*(\\))", + "captures": { + "1": { + "name": "meta.brace.round.typst" + }, + "2": { + "name": "punctuation.separator.colon.typst" + }, + "3": { + "name": "meta.brace.round.typst" + } + } + }, + { + "begin": "\\(", + "end": "\\)|(?=[;\\}\\]])", + "beginCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "patterns": [ + { + "include": "#literalContent" + } + ] + } + ] + }, + "literalContent": { + "patterns": [ + { + "include": "#paramOrArgName" + }, + { + "include": "#expression" + } + ] + }, + "contextStatement": { + "name": "meta.expr.context.typst", + "begin": "\\bcontext\\b(?!-)", + "end": "(?<=[\\}\\]\\d])|(?=[;\\}\\]\\)#\\n]|$)", + "beginCaptures": { + "0": { + "name": "keyword.control.other.typst" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + "includeStatement": { + "name": "meta.expr.include.typst", + "begin": "(\\binclude\\b(?!-))\\s*", + "end": "(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "1": { + "name": "keyword.control.import.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expression" + } + ] + }, + "importStatement": { + "name": "meta.expr.import.typst", + "begin": "(\\bimport\\b(?!-))\\s*", + "end": "(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "1": { + "name": "keyword.control.import.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#importPathClause" + }, + { + "match": "\\:", + "name": "punctuation.separator.colon.typst" + }, + { + "match": "\\*", + "name": "keyword.operator.wildcard.typst" + }, + { + "match": "\\,", + "name": "punctuation.separator.comma.typst" + }, + { + "include": "#importAsClause" + }, + { + "include": "#expression" + } + ] + }, + "importPathClause": { + "begin": "(\\bimport\\b(?!-))\\s*", + "end": "(?=\\:|as)", + "beginCaptures": { + "1": { + "name": "keyword.control.import.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expression" + } + ] + }, + "importAsClause": { + "begin": "(\\bas\\b)\\s*", + "end": "(?=[\\s;\\}\\]\\)\\:])", + "beginCaptures": { + "1": { + "name": "keyword.control.import.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#identifier" + } + ] + }, + "letStatement": { + "name": "meta.expr.let.typst", + "begin": "(?=(?:(let\\b(?!-))))", + "end": "(?!\\=)(?=[\\s;\\}\\]\\)])", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#letBindingClause" + }, + { + "include": "#letInitClause" + } + ] + }, + "letBindingClause": { + "begin": "(let\\b(?!-))\\s*", + "end": "(?=[=;\\]}\\n])", + "beginCaptures": { + "1": { + "name": "storage.type.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "begin": "(\\b[\\p{L}\\p{Nl}__][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}_\\-]*)(\\()", + "end": "\\)|(?=[;\\}\\]])", + "beginCaptures": { + "1": { + "name": "entity.name.function.typst", + "patterns": [ + { + "include": "#primitiveFunctions" + } + ] + }, + "2": { + "name": "meta.brace.round.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "patterns": [ + { + "include": "#patternOrArgsBody" + } + ] + }, + { + "begin": "\\(", + "end": "\\)|(?=[;\\}\\]])", + "beginCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "patterns": [ + { + "include": "#patternOrArgsBody" + } + ] + }, + { + "include": "#identifier" + } + ] + }, + "letInitClause": { + "begin": "=\\s*", + "end": "(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "0": { + "name": "keyword.operator.assignment.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expression" + } + ] + }, + "ifStatement": { + "name": "meta.expr.if.typst", + "begin": "(?=(?:(else\\s+)?(if\\b(?!-))))", + "end": "(?<=\\}|\\])(?!\\s*(else)\\b(?!-)|[\\[\\{])|(?<=else)(?!\\s*(?:if\\b(?!-)|[\\[\\{]))|(?=[;\\}\\]\\)\\n]|$)", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#ifClause" + }, + { + "include": "#elseClause" + }, + { + "include": "#codeBlock" + }, + { + "include": "#contentBlock" + } + ] + }, + "ifClause": { + "begin": "\\bif\\b(?!-)", + "end": "(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)", + "beginCaptures": { + "0": { + "name": "keyword.control.conditional.typst" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + "elseClause": { + "match": "\\belse\\b(?!-)", + "name": "keyword.control.conditional.typst" + }, + "forStatement": { + "name": "meta.expr.for.typst", + "begin": "(?=(?:(for\\b(?!-))\\s*))", + "end": "(?<=[\\}\\]])(?![\\{\\[])|(?=[;\\}\\]\\)\\n]|$)", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#forClause" + }, + { + "include": "#codeBlock" + }, + { + "include": "#contentBlock" + } + ] + }, + "forClause": { + "begin": "(for\\b)\\s*", + "end": "(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)", + "beginCaptures": { + "1": { + "name": "keyword.control.loop.typst" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + "whileStatement": { + "name": "meta.expr.while.typst", + "begin": "(?=(?:(while\\b(?!-))))", + "end": "(?<=[\\}\\]])(?![\\{\\[])|(?=[;\\}\\]\\)\\n]|$)", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#whileClause" + }, + { + "include": "#codeBlock" + }, + { + "include": "#contentBlock" + } + ] + }, + "whileClause": { + "begin": "(while\\b)\\s*", + "end": "(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)", + "beginCaptures": { + "1": { + "name": "keyword.control.loop.typst" + } + }, + "patterns": [ + { + "include": "#expression" + } + ] + }, + "setStatement": { + "name": "meta.expr.set.typst", + "begin": "(?=(?:(set\\b(?!-))\\s*(?=|<|>|\\+|-|\\*|\\/|=|\\+=|-=|\\*=|\\/=)(?!\\s*(?:and|or|not|in|!=|==|<=|>=|<|>|\\+|-|\\*|\\/|=|\\+=|-=|\\*=|\\/=|\\.))|(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "1": { + "name": "keyword.control.conditional.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expression" + } + ] + }, + "showStatement": { + "name": "meta.expr.show.typst", + "begin": "(?=(?:(show\\b(?!-))))", + "end": "(?=[\\s;\\{\\[\\}\\]\\)])", + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#showAnyClause" + }, + { + "include": "#showSelectClause" + }, + { + "include": "#showSubstClause" + } + ] + }, + "showAnyClause": { + "match": "(show\\b)\\s*(?=\\:)", + "captures": { + "1": { + "name": "keyword.control.other.typst" + } + } + }, + "showSelectClause": { + "begin": "(show\\b)\\s*", + "end": "(?=[:;\\}\\]\\n])", + "beginCaptures": { + "1": { + "name": "keyword.control.other.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#markupLabel" + }, + { + "include": "#expression" + } + ] + }, + "showSubstClause": { + "begin": "(\\:)\\s*", + "end": "(?=[\\n;\\}\\]\\)])", + "beginCaptures": { + "1": { + "name": "punctuation.separator.colon.typst" + } + }, + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#expression" + } + ] + }, + "callArgs": { + "begin": "\\(", + "end": "\\)|(?=[;\\}\\]])", + "beginCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "endCaptures": { + "0": { + "name": "meta.brace.round.typst" + } + }, + "patterns": [ + { + "include": "#patternOrArgsBody" + } + ] + }, + "patternOrArgsBody": { + "patterns": [ + { + "include": "#comments" + }, + { + "include": "#paramOrArgName" + }, + { + "include": "#expression" + } + ] + }, + "strictFuncCallOrPropAccess": { + "name": "meta.expr.call.typst", + "begin": "(?=(?:(\\.)?(?