MCPcopy
hub / github.com/autoNumeric/autoNumeric / getNextToken

Method getNextToken

src/maths/Lexer.js:67–104  ·  view source on GitHub ↗

* Return the next token object * * @param {string} decimalCharacter The decimal character to use in the float numbers * @returns {Token}

(decimalCharacter = '.')

Source from the content-addressed store, hash-verified

65 * @returns {Token}
66 */
67 getNextToken(decimalCharacter = '.') {
68 this._skipSpaces();
69
70 // Test for the end of text
71 if (this.textLength === this.index) {
72 this.token.type = 'EOT'; // End of text
73
74 return this.token;
75 }
76
77 // If the current character is a digit read a number
78 if (AutoNumericHelper.isDigit(this.text[this.index])) {
79 this.token.type = 'num';
80 this.token.value = this._getNumber(decimalCharacter);
81
82 return this.token;
83 }
84
85 // Check if the current character is an operator or parentheses
86 this.token.type = 'Error';
87 switch (this.text[this.index]) {
88 case '+': this.token.type = '+'; break;
89 case '-': this.token.type = '-'; break;
90 case '*': this.token.type = '*'; break;
91 case '/': this.token.type = '/'; break;
92 case '(': this.token.type = '('; break;
93 case ')': this.token.type = ')'; break;
94 }
95
96 if (this.token.type !== 'Error') {
97 this.token.symbol = this.text[this.index];
98 this.index++;
99 } else {
100 throw new Error(`Unexpected token '${this.token.symbol}' at position '${this.token.index}' in the token function`);
101 }
102
103 return this.token;
104 }
105
106 /**
107 * Return the integer or float number starting from the `this.index` string index

Callers 6

testTokenizerFunction · 0.95
constructorMethod · 0.80
_moreExpMethod · 0.80
_moreTermsMethod · 0.80
_factorMethod · 0.80
_matchMethod · 0.80

Calls 3

_skipSpacesMethod · 0.95
_getNumberMethod · 0.95
isDigitMethod · 0.80

Tested by 1

testTokenizerFunction · 0.76