diff --git a/src/expression/node/SymbolNode.js b/src/expression/node/SymbolNode.js index da92197191..14abe6ce49 100644 --- a/src/expression/node/SymbolNode.js +++ b/src/expression/node/SymbolNode.js @@ -28,7 +28,7 @@ export const createSymbolNode = /* #__PURE__ */ factory(name, dependencies, ({ m * @param {string} name * @extends {Node} */ - constructor (name) { + constructor (name, index) { super() // validate input if (typeof name !== 'string') { @@ -36,6 +36,7 @@ export const createSymbolNode = /* #__PURE__ */ factory(name, dependencies, ({ m } this.name = name + this.tokenIndex = index; } get type () { return 'SymbolNode' } diff --git a/src/expression/parse.js b/src/expression/parse.js index 54ce64bfd1..ce2709d543 100644 --- a/src/expression/parse.js +++ b/src/expression/parse.js @@ -258,6 +258,7 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({ state.tokenType = TOKENTYPE.NULL state.token = '' state.comment = '' + state.tokenIndex = state.index; // skip over ignored characters: while (true) { @@ -668,9 +669,10 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({ if (isSymbolNode(node)) { // parse a variable assignment like 'a = 2/3' name = node.name + const symbolIndex = state.tokenIndex - name.length; getTokenSkipNewline(state) value = parseAssignment(state) - return new AssignmentNode(new SymbolNode(name), value) + return new AssignmentNode(new SymbolNode(name, symbolIndex), value) } else if (isAccessorNode(node)) { // parse a matrix subset assignment like 'A[1,2] = 4' getTokenSkipNewline(state) @@ -1331,7 +1333,8 @@ export const createParse = /* #__PURE__ */ factory(name, dependencies, ({ } else if (NUMERIC_CONSTANTS.indexOf(name) !== -1) { // NaN, Infinity node = new ConstantNode(numeric(name, 'number')) } else { - node = new SymbolNode(name) + const symbolIndex = state.tokenIndex - name.length; + node = new SymbolNode(name, symbolIndex) } // parse function parameters and matrix index