// This is a TextMate grammar distributed by `starry-night`. // This grammar is developed at // // and licensed `apache-2.0`. // See for more info. /** * @import {Grammar} from '@wooorm/starry-night' */ /** @type {Grammar} */ const grammar = { extensions: ['.typ'], names: ['typst', 'typ'], patterns: [{include: '#shebang'}, {include: '#markup'}], repository: { arrayOrDict: { patterns: [ { captures: { 1: {name: 'meta.brace.round.typst'}, 2: {name: 'meta.brace.round.typst'} }, match: '(\\()\\s*(\\))' }, { captures: { 1: {name: 'meta.brace.round.typst'}, 2: {name: 'punctuation.separator.colon.typst'}, 3: {name: 'meta.brace.round.typst'} }, match: '(\\()\\s*(:)\\s*(\\))' }, { begin: '\\(', beginCaptures: {0: {name: 'meta.brace.round.typst'}}, end: '\\)|(?=[;\\}\\]])', endCaptures: {0: {name: 'meta.brace.round.typst'}}, patterns: [{include: '#literalContent'}] } ] }, blockComment: { begin: '\\/\\*', beginCaptures: {0: {name: 'punctuation.definition.comment.typst'}}, end: '\\*\\/', name: 'comment.block.typst', patterns: [{include: '#blockComment'}] }, blockRaw: {patterns: [{include: '#blockRawGeneral'}]}, blockRawGeneral: { begin: '(`{3,})([\\p{L}\\p{Nl}__][\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}_\\-]*\\b)?', beginCaptures: { 1: {name: 'punctuation.definition.raw.begin.typst'}, 2: {name: 'fenced_code.block.language.typst'} }, end: '(\\1)', endCaptures: {1: {name: 'punctuation.definition.raw.end.typst'}}, name: 'markup.raw.block.typst' }, callArgs: { begin: '\\(', beginCaptures: {0: {name: 'meta.brace.round.typst'}}, end: '\\)|(?=[;\\}\\]])', endCaptures: {0: {name: 'meta.brace.round.typst'}}, patterns: [{include: '#patternOrArgsBody'}] }, code: { patterns: [ {include: '#common'}, {include: '#comments'}, {match: ';', name: 'punctuation.terminator.statement.typst'}, {include: '#expression'} ] }, codeBlock: { begin: '\\{', beginCaptures: {0: {name: 'meta.brace.curly.typst'}}, end: '\\}', endCaptures: {0: {name: 'meta.brace.curly.typst'}}, patterns: [{include: '#code'}] }, comments: { patterns: [{include: '#blockComment'}, {include: '#lineComment'}] }, common: { patterns: [ {include: '#strictComments'}, {include: '#blockRaw'}, {include: '#inlineRaw'} ] }, constants: { patterns: [ { match: '(?:\\d+\\.(?!\\d)|\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)(?', name: 'storage.type.function.arrow.typst'}, {match: '==|!=|<=|<|>=|>', name: 'keyword.operator.relational.typst'}, { begin: '(\\+=|-=|\\*=|\\/=|=)', beginCaptures: {1: {name: 'keyword.operator.assignment.typst'}}, end: '(?=[\\n;\\}\\]\\)])', patterns: [{include: '#expression'}] }, {match: '\\+|\\\\|\\/|\\*|-', name: 'keyword.operator.arithmetic.typst'} ] }, forClause: { begin: '(for\\b)\\s*', beginCaptures: {1: {name: 'keyword.control.loop.typst'}}, end: '(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)', patterns: [{include: '#expression'}] }, forStatement: { begin: '(?=(?:(for\\b(?!-))\\s*))', end: '(?<=[\\}\\]])(?![\\{\\[])|(?=[;\\}\\]\\)\\n]|$)', name: 'meta.expr.for.typst', patterns: [ {include: '#comments'}, {include: '#forClause'}, {include: '#codeBlock'}, {include: '#contentBlock'} ] }, identifier: { match: '(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)', patterns: [{include: '#expression'}] }, ifStatement: { begin: '(?=(?:(else\\s+)?(if\\b(?!-))))', end: '(?<=\\}|\\])(?!\\s*(else)\\b(?!-)|[\\[\\{])|(?<=else)(?!\\s*(?:if\\b(?!-)|[\\[\\{]))|(?=[;\\}\\]\\)\\n]|$)', name: 'meta.expr.if.typst', patterns: [ {include: '#comments'}, {include: '#ifClause'}, {include: '#elseClause'}, {include: '#codeBlock'}, {include: '#contentBlock'} ] }, importAsClause: { begin: '(\\bas\\b)\\s*', beginCaptures: {1: {name: 'keyword.control.import.typst'}}, end: '(?=[\\s;\\}\\]\\)\\:])', patterns: [{include: '#comments'}, {include: '#identifier'}] }, importPathClause: { begin: '(\\bimport\\b(?!-))\\s*', beginCaptures: {1: {name: 'keyword.control.import.typst'}}, end: '(?=\\:|as)', patterns: [{include: '#comments'}, {include: '#expression'}] }, importStatement: { begin: '(\\bimport\\b(?!-))\\s*', beginCaptures: {1: {name: 'keyword.control.import.typst'}}, end: '(?=[\\n;\\}\\]\\)])', name: 'meta.expr.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'} ] }, includeStatement: { begin: '(\\binclude\\b(?!-))\\s*', beginCaptures: {1: {name: 'keyword.control.import.typst'}}, end: '(?=[\\n;\\}\\]\\)])', name: 'meta.expr.include.typst', patterns: [{include: '#comments'}, {include: '#expression'}] }, inlineRaw: { begin: '`', beginCaptures: {0: {name: 'punctuation.definition.raw.inline.typst'}}, end: '`', endCaptures: {0: {name: 'punctuation.definition.raw.inline.typst'}}, name: 'markup.raw.inline.typst string.other.raw.typst' }, keywordConstants: { patterns: [ { match: '(?', name: 'string.other.label.typst' }, markupLink: { begin: '(?:https?):\\/\\/', end: "(?=[\\s\\]\\)]|(?=[!,.:;?'](?:[\\s\\]\\)]|$)))", name: 'markup.underline.link.typst', patterns: [ {include: '#markupLinkParen'}, {include: '#markupLinkBracket'}, { match: "(^|\\G)(?:[0-9a-zA-Z#$%&*\\+\\-\\/\\=\\@\\_\\~]+|(?:[!,.:;?']+(?![\\s\\]\\)]|$)))" } ] }, markupLinkBracket: { begin: '\\[', end: '\\]|(?=[\\s\\)])', patterns: [{include: '#markupLink'}] }, markupLinkParen: { begin: '\\(', end: '\\)|(?=[\\s\\]])', patterns: [{include: '#markupLink'}] }, markupMath: { begin: '\\$', beginCaptures: { 0: {name: 'punctuation.definition.string.begin.math.typst'} }, end: '\\$', endCaptures: {0: {name: 'punctuation.definition.string.end.math.typst'}}, name: 'markup.math.typst', patterns: [{include: '#math'}] }, markupReference: { captures: {1: {name: 'punctuation.definition.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}_\\-\\.:])))*', name: 'string.other.reference.typst' }, math: { patterns: [ {include: '#markupEscape'}, {include: '#stringLiteral'}, {include: '#markupEnterCode'}, { begin: '([_^\\/√∛∜])\\s*([\\[\\(\\{⌈⌊⌜⌞❲⟦⟨⟪⟬⟮⦃⦅⦇⦉⦋⦍⦏⦑⦓⦕⦗⧘⧚⧼])', beginCaptures: { 1: {name: 'punctuation.math.operator.typst'}, 2: {name: 'constant.other.symbol.typst'} }, end: '([\\]\\)\\}⌉⌋⌝⌟❳⟧⟩⟫⟭⟯⦄⦆⦈⦊⦌⦎⦐⦒⦔⦖⦘⧙⧛⧽])|(?=\\$)|$', endCaptures: {0: {name: 'constant.other.symbol.typst'}}, patterns: [{include: '#mathParen'}, {include: '#math'}] }, {match: "[_^'&\\/√∛∜]", name: 'punctuation.math.operator.typst'}, {include: '#strictMathFuncCallOrPropAccess'}, {include: '#mathPrimary'}, {include: '#mathMoreBrace'} ] }, mathBrace: {match: '[{}]', name: 'markup.content.brace.typst'}, mathCallArgs: { begin: '\\(', beginCaptures: {0: {name: 'meta.brace.round.typst'}}, end: '\\)|(?=\\$)', endCaptures: {0: {name: 'meta.brace.round.typst'}}, patterns: [ {include: '#comments'}, {include: '#mathParen'}, {match: ',', name: 'punctuation.separator.comma.typst'}, {include: '#math'} ] }, mathIdentifier: { match: '(?:(?<=_)|\\b)(?:(?!_)[\\p{L}\\p{Nl}_])(?:(?!_)[\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}])+', name: 'variable.other.readwrite.typst' }, mathMoreBrace: {match: '[{}()\\[\\]]', name: 'markup.content.brace.typst'}, mathParen: { begin: '[\\[\\(\\{⌈⌊⌜⌞❲⟦⟨⟪⟬⟮⦃⦅⦇⦉⦋⦍⦏⦑⦓⦕⦗⧘⧚⧼]', beginCaptures: {0: {name: 'markup.content.brace.typst'}}, end: '([\\]\\)\\}⌉⌋⌝⌟❳⟧⟩⟫⟭⟯⦄⦆⦈⦊⦌⦎⦐⦒⦔⦖⦘⧙⧛⧽])|(?=\\$)|$', endCaptures: {0: {name: 'markup.content.brace.typst'}}, patterns: [{include: '#mathParen'}, {include: '#math'}] }, mathPrimary: { begin: '(?:(?<=_)|\\b)(?:(?!_)[\\p{L}\\p{Nl}_])(?:(?!_)[\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}])+', beginCaptures: {0: {name: 'variable.other.readwrite.typst'}}, end: '(?!(?:\\(|\\.[\\p{L}\\p{Nl}_]))|(?=\\$)', patterns: [ {include: '#strictMathFuncCallOrPropAccess'}, { captures: { 1: {name: 'keyword.operator.accessor.typst'}, 2: {name: 'variable.other.readwrite.typst'} }, match: '(\\.)((?:(?!_)[\\p{L}\\p{Nl}_])(?:(?!_)[\\p{L}\\p{Nl}\\p{Mn}\\p{Mc}\\p{Nd}\\p{Pc}])*)' }, {include: '#mathCallArgs'}, {include: '#mathIdentifier'} ] }, paramOrArgName: { captures: { 2: {name: 'variable.other.readwrite.typst'}, 3: {name: 'punctuation.separator.colon.typst'} }, match: '(?!(show|import|include)\\s*\\:)((?=|<|>|\\+|-|\\*|\\/|=|\\+=|-=|\\*=|\\/=)(?!\\s*(?:and|or|not|in|!=|==|<=|>=|<|>|\\+|-|\\*|\\/|=|\\+=|-=|\\*=|\\/=|\\.))|(?=[\\n;\\}\\]\\)])', patterns: [{include: '#comments'}, {include: '#expression'}] }, setStatement: { begin: '(?=(?:(set\\b(?!-))\\s*(?\\+\\-\\*\\/])|(?:[\\s\\S]{3}[=<>\\+\\-\\*\\/]\\s)|(?:[\\s\\S]{2}[=<>\\+\\-\\*\\/]\\s{2})|(?:[\\s\\S][=<>\\+\\-\\*\\/]\\s{3})|(?:[=<>\\+\\-\\*\\/]\\s{4}))(?=[\\[\\{])|(?=[;,\\}\\]\\)\\#\\n]|$)', patterns: [{include: '#expression'}] }, whileStatement: { begin: '(?=(?:(while\\b(?!-))))', end: '(?<=[\\}\\]])(?![\\{\\[])|(?=[;\\}\\]\\)\\n]|$)', name: 'meta.expr.while.typst', patterns: [ {include: '#comments'}, {include: '#whileClause'}, {include: '#codeBlock'}, {include: '#contentBlock'} ] } }, scopeName: 'source.typst' } export default grammar