mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-12-23 08:47:50 +00:00
fix: continue parsing expression on func/method call (#909)
This commit is contained in:
parent
5423976278
commit
adef0381be
7 changed files with 106 additions and 5 deletions
|
|
@ -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 =
|
||||
/(?<!(?:if|and|or|not|in|!=|==|<=|>=|<|>|\+|-|\*|\/|=|\+=|-=|\*=|\/=)\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),
|
||||
// `?=(?<![\d#])\.[^\p{XID_Start}_]`: This means that we are on a dot and the next character is not a valid identifier start, but we are not at the beginning of hash or number
|
||||
end: /(?<=;)|(?<=[\)\]\}])(?![;\(\[\$])|(?<!#)(?=")|(?=\.(?:[^0-9\p{XID_Start}_]|$))|(?=[\s\}\]\)\$]|$)|(;)/u
|
||||
.source,
|
||||
end: oneOf(
|
||||
/(?<=;)/,
|
||||
// Ends unless we are in a call or method call
|
||||
new RegExp(
|
||||
/(?<=[\)\]\}])(?![;\(\[\$]|(?:\.method-continue))/.source.replace(
|
||||
/method-continue/g,
|
||||
IDENTIFIER.source + /(?=[\(\[])/.source
|
||||
)
|
||||
),
|
||||
/(?<!#)(?=")/,
|
||||
// This means that we are on a dot and the next character is not a valid identifier start, but we are not at the beginning of hash or number
|
||||
/(?=\.(?:[^0-9\p{XID_Start}_]|$))/u,
|
||||
/(?=[\s\}\]\)\$]|$)/,
|
||||
/(;)/
|
||||
).source,
|
||||
beginCaptures: {
|
||||
"0": {
|
||||
name: kind,
|
||||
|
|
@ -631,7 +657,6 @@ const expressions = (): textmate.Grammar => {
|
|||
},
|
||||
},
|
||||
/// parentheisized expressions: (...)
|
||||
// todo: This is invocable
|
||||
{
|
||||
begin: /\(/,
|
||||
end: /\)/,
|
||||
|
|
|
|||
1
syntaxes/textmate/tests/unit/basic/call-array.typ
Normal file
1
syntaxes/textmate/tests/unit/basic/call-array.typ
Normal file
|
|
@ -0,0 +1 @@
|
|||
#(module,).at(0).push(); ()
|
||||
20
syntaxes/textmate/tests/unit/basic/call-array.typ.snap
Normal file
20
syntaxes/textmate/tests/unit/basic/call-array.typ.snap
Normal file
|
|
@ -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
|
||||
>
|
||||
2
syntaxes/textmate/tests/unit/basic/call-chain.typ
Normal file
2
syntaxes/textmate/tests/unit/basic/call-chain.typ
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#let a = (1,);
|
||||
#a.map(it => it).map(it => it); ()
|
||||
37
syntaxes/textmate/tests/unit/basic/call-chain.typ.snap
Normal file
37
syntaxes/textmate/tests/unit/basic/call-chain.typ.snap
Normal file
|
|
@ -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
|
||||
1
syntaxes/textmate/tests/unit/basic/call-content.typ
Normal file
1
syntaxes/textmate/tests/unit/basic/call-content.typ
Normal file
|
|
@ -0,0 +1 @@
|
|||
#[test].at("text") ()
|
||||
15
syntaxes/textmate/tests/unit/basic/call-content.typ.snap
Normal file
15
syntaxes/textmate/tests/unit/basic/call-content.typ.snap
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue