MCPcopy
hub / github.com/baidu/amis / parse

Function parse

packages/amis-formula/src/parser.ts:23–875  ·  view source on GitHub ↗
(input: string, options?: ParserOptions)

Source from the content-addressed store, hash-verified

21};
22
23export function parse(input: string, options?: ParserOptions): ASTNode {
24 let token: Token;
25 const lexer = createLexer(input, options);
26 const tokens: Array<Token> = [];
27 const tokenChunk: Array<Token> = [];
28
29 // 允许的变量名字空间
30 let variableNamespaces: Array<string> = options?.variableNamespaces ?? [
31 'window',
32 'cookie',
33 'ls',
34 'ss'
35 ];
36 if (!Array.isArray(variableNamespaces)) {
37 variableNamespaces = [];
38 }
39
40 function next() {
41 token = tokenChunk.length ? tokenChunk.shift()! : lexer.next();
42
43 if (!token) {
44 throw new TypeError('next token is undefined');
45 }
46 tokens.push(token);
47 }
48
49 function back() {
50 tokenChunk.unshift(tokens.pop()!);
51 token = tokens[tokens.length - 1];
52 }
53
54 function matchPunctuator(operator: string | Array<string>) {
55 return (
56 token.type === TokenName[TokenEnum.Punctuator] &&
57 (Array.isArray(operator)
58 ? ~operator.indexOf(token.value!)
59 : token.value === operator)
60 );
61 }
62
63 function fatal() {
64 throw TypeError(
65 `Unexpected token ${token!.value || token.type} in ${token!.start.line}:${
66 token!.start.column
67 }`
68 );
69 }
70
71 function assert(result: any) {
72 if (!result) {
73 fatal();
74 }
75 return result;
76 }
77
78 function expression(): ASTNodeOrNull {
79 return assignmentExpression();
80 }

Callers 13

evaluateFunction · 0.90
evaluateForAsyncFunction · 0.90
memoParseFunction · 0.90
memoryParseFunction · 0.90
autoMarkMethod · 0.90
parser.test.tsFile · 0.50
pasteMethod · 0.50
str2objMethod · 0.50
validateMethod · 0.50
runCodeMethod · 0.50
handleEditorConfirmMethod · 0.50
validateMethod · 0.50

Calls 5

nextFunction · 0.85
postfixExpressionFunction · 0.85
contentsFunction · 0.85
assertFunction · 0.85
expressionFunction · 0.70

Tested by

no test coverage detected