diff --git a/syntaxes/textmate/main.mts b/syntaxes/textmate/main.mts index 1169991bd..0ca205596 100644 --- a/syntaxes/textmate/main.mts +++ b/syntaxes/textmate/main.mts @@ -33,11 +33,25 @@ function braceMatch(pattern: RegExp) { return ("(?x)" + pattern.source) as unknown as RegExp; } +function oneOf(...patterns: RegExp[]) { + return new RegExp( + patterns + .map((p) => { + const src = p.source; + if (src.startsWith("(")) { + return src; + } + + return `(?:${src})`; + }) + .join("|") + ); +} + const PAREN_BLOCK = generatePattern(6, "\\(", "\\)"); const exprEndReg = /(?=|<|>|\+|-|\*|\/|=|\+=|-=|\*=|\/=)\s*)(?=[\[\{\n])|(?=[;\}\]\)\n]|$)/; -// todo: This is invocable const codeBlock: textmate.Pattern = { // name: "meta.block.continuous.typst", begin: /\{/, @@ -350,9 +364,21 @@ const enterExpression = (kind: string, seek: RegExp): textmate.Pattern => { return { /// name: 'markup.expr.typst' begin: new RegExp("#" + seek.source), - // `?=(? { }, }, /// parentheisized expressions: (...) - // todo: This is invocable { begin: /\(/, end: /\)/, diff --git a/syntaxes/textmate/tests/unit/basic/call-array.typ b/syntaxes/textmate/tests/unit/basic/call-array.typ new file mode 100644 index 000000000..c822e4e57 --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-array.typ @@ -0,0 +1 @@ +#(module,).at(0).push(); () diff --git a/syntaxes/textmate/tests/unit/basic/call-array.typ.snap b/syntaxes/textmate/tests/unit/basic/call-array.typ.snap new file mode 100644 index 000000000..a9ea8659d --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-array.typ.snap @@ -0,0 +1,20 @@ +>#(module,).at(0).push(); () +#^ source.typst keyword.control.hash.typst +# ^ source.typst meta.brace.round.typst +# ^^^^^^ source.typst variable.other.readwrite.typst +# ^ source.typst punctuation.separator.comma.typst +# ^ source.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst keyword.operator.accessor.typst +# ^^ source.typst meta.expr.call.typst entity.name.function.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst constant.numeric.integer.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst keyword.operator.accessor.typst +# ^^^^ source.typst meta.expr.call.typst entity.name.function.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst punctuation.terminator.statement.typst +# ^ source.typst +# ^ source.typst markup.content.brace.typst +# ^ source.typst markup.content.brace.typst +> \ No newline at end of file diff --git a/syntaxes/textmate/tests/unit/basic/call-chain.typ b/syntaxes/textmate/tests/unit/basic/call-chain.typ new file mode 100644 index 000000000..35606dcca --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-chain.typ @@ -0,0 +1,2 @@ +#let a = (1,); +#a.map(it => it).map(it => it); () \ No newline at end of file diff --git a/syntaxes/textmate/tests/unit/basic/call-chain.typ.snap b/syntaxes/textmate/tests/unit/basic/call-chain.typ.snap new file mode 100644 index 000000000..e135379aa --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-chain.typ.snap @@ -0,0 +1,37 @@ +>#let a = (1,); +#^ source.typst keyword.control.hash.typst +# ^^^ source.typst meta.expr.let.typst storage.type.typst +# ^ source.typst meta.expr.let.typst +# ^ source.typst meta.expr.let.typst variable.other.readwrite.typst +# ^ source.typst meta.expr.let.typst +# ^^ source.typst meta.expr.let.typst keyword.operator.assignment.typst +# ^ source.typst meta.expr.let.typst meta.brace.round.typst +# ^ source.typst meta.expr.let.typst constant.numeric.integer.typst +# ^ source.typst meta.expr.let.typst punctuation.separator.comma.typst +# ^ source.typst meta.expr.let.typst meta.brace.round.typst +# ^ source.typst punctuation.terminator.statement.typst +>#a.map(it => it).map(it => it); () +#^ source.typst variable.other.readwrite.hash.typst +# ^ source.typst variable.other.readwrite.typst +# ^ source.typst meta.expr.call.typst keyword.operator.accessor.typst +# ^^^ source.typst meta.expr.call.typst entity.name.function.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^^ source.typst meta.expr.call.typst variable.parameter.typst +# ^ source.typst meta.expr.call.typst +# ^^ source.typst meta.expr.call.typst storage.type.function.arrow.typst +# ^ source.typst meta.expr.call.typst +# ^^ source.typst meta.expr.call.typst variable.other.readwrite.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst keyword.operator.accessor.typst +# ^^^ source.typst meta.expr.call.typst entity.name.function.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^^ source.typst meta.expr.call.typst variable.parameter.typst +# ^ source.typst meta.expr.call.typst +# ^^ source.typst meta.expr.call.typst storage.type.function.arrow.typst +# ^ source.typst meta.expr.call.typst +# ^^ source.typst meta.expr.call.typst variable.other.readwrite.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst punctuation.terminator.statement.typst +# ^ source.typst +# ^ source.typst markup.content.brace.typst +# ^ source.typst markup.content.brace.typst \ No newline at end of file diff --git a/syntaxes/textmate/tests/unit/basic/call-content.typ b/syntaxes/textmate/tests/unit/basic/call-content.typ new file mode 100644 index 000000000..098f3f7e8 --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-content.typ @@ -0,0 +1 @@ +#[test].at("text") () \ No newline at end of file diff --git a/syntaxes/textmate/tests/unit/basic/call-content.typ.snap b/syntaxes/textmate/tests/unit/basic/call-content.typ.snap new file mode 100644 index 000000000..f722ef761 --- /dev/null +++ b/syntaxes/textmate/tests/unit/basic/call-content.typ.snap @@ -0,0 +1,15 @@ +>#[test].at("text") () +#^ source.typst keyword.control.hash.typst +# ^ source.typst meta.brace.square.typst +# ^^^^ source.typst +# ^ source.typst meta.brace.square.typst +# ^ source.typst meta.expr.call.typst keyword.operator.accessor.typst +# ^^ source.typst meta.expr.call.typst entity.name.function.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst meta.expr.call.typst string.quoted.double.typst punctuation.definition.string.typst +# ^^^^ source.typst meta.expr.call.typst string.quoted.double.typst +# ^ source.typst meta.expr.call.typst string.quoted.double.typst punctuation.definition.string.typst +# ^ source.typst meta.expr.call.typst meta.brace.round.typst +# ^ source.typst +# ^ source.typst markup.content.brace.typst +# ^ source.typst markup.content.brace.typst \ No newline at end of file