fix: fix bracket match
This commit is contained in:
parent
d3e91e6f74
commit
e446fc0435
@ -35,25 +35,32 @@ function lexer(input: string): Token[] {
|
|||||||
/**
|
/**
|
||||||
* 过滤函数内容
|
* 过滤函数内容
|
||||||
*/
|
*/
|
||||||
const matchFunction = (currentChar: string, validator: RegExp) => {
|
const matchFunction = () => {
|
||||||
let value = currentChar;
|
const bracketNum = [current];
|
||||||
const start = current;
|
for (let i = current + 1; i < input.length; i++) {
|
||||||
do {
|
const currentChar = input[i];
|
||||||
if (currentChar === '\n') {
|
if (currentChar === '\n') {
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
|
if (TokenReg.LeftSmallBracket.test(currentChar)) {
|
||||||
currentChar = input[++current];
|
bracketNum.push(i);
|
||||||
value += currentChar;
|
}
|
||||||
} while (!validator.test(currentChar)); // 处理转义字符
|
if (TokenReg.RightSmallBracket.test(currentChar)) {
|
||||||
|
const start = bracketNum.pop();
|
||||||
|
const end = i + 1;
|
||||||
|
if (bracketNum.length === 0) {
|
||||||
|
current = end;
|
||||||
tokens.push({
|
tokens.push({
|
||||||
type: TokenType.FunctionArguments,
|
type: TokenType.FunctionArguments,
|
||||||
value,
|
value: input.slice(start, end),
|
||||||
start: start,
|
start,
|
||||||
lineNumber: line,
|
lineNumber: line,
|
||||||
end: current,
|
end,
|
||||||
});
|
});
|
||||||
++current;
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,7 +90,7 @@ function lexer(input: string): Token[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (TokenReg.LeftSmallBracket.test(char)) {
|
if (TokenReg.LeftSmallBracket.test(char)) {
|
||||||
matchFunction(char, TokenReg.RightSmallBracket);
|
matchFunction();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user