MCPcopy
hub / github.com/autoNumeric/autoNumeric / _factor

Method _factor

src/maths/Parser.js:125–150  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

123 }
124
125 _factor() {
126 let expression;
127 let factor;
128 let value;
129 switch (this.token.type) {
130 case 'num':
131 value = this.token.value;
132 this.token = this.lexer.getNextToken(this.decimalCharacter);
133
134 return ASTNode.createLeaf(value);
135 case '-':
136 this.token = this.lexer.getNextToken(this.decimalCharacter);
137 factor = this._factor();
138
139 return ASTNode.createUnaryNode(factor);
140 case '(':
141 this.token = this.lexer.getNextToken(this.decimalCharacter);
142 expression = this._exp();
143 this._match(')');
144
145 return expression;
146 default: {
147 throw new Error(`Unexpected token '${this.token.symbol}' with type '${this.token.type}' at position '${this.token.index}' in the factor function`);
148 }
149 }
150 }
151
152 _match(expected) {
153 const index = this.lexer.getIndex() - 1;

Callers 2

_termMethod · 0.95
_moreTermsMethod · 0.95

Calls 5

_expMethod · 0.95
_matchMethod · 0.95
getNextTokenMethod · 0.80
createLeafMethod · 0.80
createUnaryNodeMethod · 0.80

Tested by

no test coverage detected