MCPcopy Create free account
hub / github.com/SplootCode/splootcode / parseExpression

Function parseExpression

packages/language-web/types/js/expression.ts:41–81  ·  view source on GitHub ↗
(
  lhs: ExpressionKind,
  tokens: SplootNode[],
  current: number,
  minPrecedence: number
)

Source from the content-addressed store, hash-verified

39}
40
41function parseExpression(
42 lhs: ExpressionKind,
43 tokens: SplootNode[],
44 current: number,
45 minPrecedence: number
46): [ExpressionKind, number] {
47 if (current >= tokens.length) {
48 return [lhs, current]
49 }
50
51 let lookahead = tokens[current]
52 while (
53 lookahead &&
54 lookahead.type === BINARY_OPERATOR &&
55 (lookahead as BinaryOperator).getPrecedence() >= minPrecedence
56 ) {
57 const operator = lookahead as BinaryOperator
58 current += 1
59 let rhs: ExpressionKind
60 ;[rhs, current] = parseLeaf(tokens, current)
61 if (current < tokens.length) {
62 lookahead = tokens[current]
63 while (
64 lookahead &&
65 lookahead.type === BINARY_OPERATOR &&
66 (lookahead as BinaryOperator).getPrecedence() > operator.getPrecedence()
67 ) {
68 ;[rhs, current] = parseExpression(rhs, tokens, current, (lookahead as BinaryOperator).getPrecedence())
69 if (current < tokens.length) {
70 lookahead = tokens[current]
71 } else {
72 lookahead = null
73 }
74 }
75 } else {
76 lookahead = null
77 }
78 lhs = recast.types.builders.binaryExpression(operator.getOperator(), lhs, rhs)
79 }
80 return [lhs, current]
81}
82
83export class SplootExpression extends JavaScriptSplootNode {
84 constructor(parentReference: ParentReference) {

Callers 1

generateJsAstMethod · 0.70

Calls 3

getPrecedenceMethod · 0.80
parseLeafFunction · 0.70
getOperatorMethod · 0.45

Tested by

no test coverage detected