MCPcopy
hub / github.com/plotly/dash / parser

Function parser

components/dash-table/src/core/syntax-tree/syntaxer.ts:19–62  ·  view source on GitHub ↗
(lexs: ILexemeResult[])

Source from the content-addressed store, hash-verified

17}
18
19const parser = (lexs: ILexemeResult[]): ISyntaxTree => {
20 let nesting = 0;
21
22 const nestedLexs = lexs.map(lex => {
23 const res = Object.assign({}, lex, {nesting});
24
25 nesting += lex.lexeme.nesting || 0;
26
27 return res;
28 });
29
30 // find lowest priority 0-nesting lex
31 const pivot = nestedLexs
32 .filter(
33 lex => lex.nesting === 0 && typeof lex.lexeme.priority === 'number'
34 )
35 .sort(
36 (a, b) => (b.lexeme.priority || -1) - (a.lexeme.priority || -1)
37 )[0];
38
39 Logger.trace('parser -> pivot', pivot, lexs);
40
41 const pivotIndex = nestedLexs.indexOf(pivot);
42
43 if (pivot.lexeme.syntaxer) {
44 const tree = pivot.lexeme.syntaxer(lexs, pivot, pivotIndex);
45
46 if (Array.isArray(tree.left)) {
47 tree.left = parser(tree.left);
48 }
49
50 if (Array.isArray(tree.right)) {
51 tree.right = parser(tree.right);
52 }
53
54 if (Array.isArray(tree.block)) {
55 tree.block = parser(tree.block);
56 }
57
58 return tree;
59 } else {
60 throw new Error(pivot.lexeme.type);
61 }
62};
63
64export default (lexerResult: ILexerResult): ISyntaxerResult => {
65 const {lexemes} = lexerResult;

Callers 1

syntaxer.tsFile · 0.85

Calls 4

assignMethod · 0.80
filterMethod · 0.80
indexOfMethod · 0.80
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…