diff --git a/package-lock.json b/package-lock.json index 5df7aee9..19e2b91f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -42,8 +42,8 @@ "integrity": "sha512-UjMSlenUORL+a+6g4RNZxRh5LcFWybRi2g0ASDBpgXBY6nlavg0BRVAVEQF0dz8jH6SyX3lV7uP5y/krJzc+Hw==" }, "antlr4-vensim": { - "version": "git+https://github.com/climateinteractive/antlr4-vensim.git#5baa4cf6477221ebcbd0efc4b4e9ea98ec721fd7", - "from": "git+https://github.com/climateinteractive/antlr4-vensim.git#5baa4cf", + "version": "git+https://github.com/climateinteractive/antlr4-vensim.git#b7b90e3cdfe31981762fe96ff3e34b3ab1ea0b5c", + "from": "git+https://github.com/climateinteractive/antlr4-vensim.git#b7b90e3", "requires": { "antlr4": "4.9.2" } diff --git a/package.json b/package.json index 1c3c8c81..0bf92a2d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "dependencies": { "antlr4": "4.9.2", - "antlr4-vensim": "https://github.com/climateinteractive/antlr4-vensim#5baa4cf", + "antlr4-vensim": "https://github.com/climateinteractive/antlr4-vensim#b7b90e3", "bufx": "^1.0.5", "byline": "^5.0.0", "chart.js": "^2.9.4", diff --git a/src/EquationReader.js b/src/EquationReader.js index 9f37863d..c1816a00 100644 --- a/src/EquationReader.js +++ b/src/EquationReader.js @@ -122,7 +122,9 @@ export default class EquationReader extends ModelReader { let level = this.expandTrendFunction(fn, args) let genSubs = this.genSubs(input, avgTime, init) let aux = newAuxVarName() - this.addVariable(`${aux}${genSubs} = ZIDZ(${input} - ${level}${genSubs}, ${avgTime} * ABS(${level}${genSubs}))`) + this.addVariable( + `${aux}${genSubs} = ZIDZ(${input} - ${level}${genSubs}, ${avgTime} * ABS(${level}${genSubs})) ~~|` + ) this.var.trendVarName = canonicalName(aux) this.var.references.push(this.var.trendVarName) } else if (isNpvFunction(fn)) { @@ -137,7 +139,7 @@ export default class EquationReader extends ModelReader { let genSubs = this.genSubs(stream, discountRate, initVal, factor) let aux = newAuxVarName() // npv = (ncum + stream * TIME STEP * df) * factor - this.addVariable(`${aux}${genSubs} = (${level.ncum} + ${stream} * TIME STEP * ${level.df}) * ${factor}`) + this.addVariable(`${aux}${genSubs} = (${level.ncum} + ${stream} * TIME STEP * ${level.df}) * ${factor} ~~|`) this.var.npvVarName = canonicalName(aux) this.var.references.push(this.var.npvVarName) } else if (isDelayFunction(fn)) { @@ -388,7 +390,7 @@ export default class EquationReader extends ModelReader { generateLookupArg(lookupArgCtx) { // Generate a variable for a lookup argument found in the RHS. let varName = newLookupVarName() - let eqn = `${varName}${lookupArgCtx.getText()}` + let eqn = `${varName}${lookupArgCtx.getText()} ~~|` this.addVariable(eqn) return canonicalName(varName) } @@ -455,7 +457,7 @@ export default class EquationReader extends ModelReader { // If it has subscripts, the refId is still just the var name, because it is an apply-to-all array. levelRefId = canonicalName(level) } - let eqn = `${levelLHS} = INTEG((${input} - ${levelLHS}) / ${delay}, ${init})` + let eqn = `${levelLHS} = INTEG((${input} - ${levelLHS}) / ${delay}, ${init}) ~~|` if (isSeparatedVar(this.var)) { Model.addNonAtoAVar(canonicalName(level), [true]) } @@ -482,7 +484,7 @@ export default class EquationReader extends ModelReader { let genSubs = this.genSubs(input, avgTime, init) let level = newLevelVarName() let levelLHS = level + genSubs - let eqn = `${levelLHS} = INTEG((${input} - ${levelLHS}) / ${avgTime}, ${input} / (1 + ${init} * ${avgTime}))` + let eqn = `${levelLHS} = INTEG((${input} - ${levelLHS}) / ${avgTime}, ${input} / (1 + ${init} * ${avgTime})) ~~|` this.addVariable(eqn) // Add a reference to the new level var. // If it has subscripts, the refId is still just the var name, because it is an apply-to-all array. @@ -498,12 +500,12 @@ export default class EquationReader extends ModelReader { // df = INTEG((-df * discount rate) / (1 + discount rate * TIME STEP), 1) let df = newLevelVarName() let dfLHS = df + genSubs - let dfEqn = `${dfLHS} = INTEG((-${dfLHS} * ${discountRate}) / (1 + ${discountRate} * TIME STEP), 1)` + let dfEqn = `${dfLHS} = INTEG((-${dfLHS} * ${discountRate}) / (1 + ${discountRate} * TIME STEP), 1) ~~|` this.addVariable(dfEqn) // ncum = INTEG(stream * df, init val) let ncum = newLevelVarName() let ncumLHS = ncum + genSubs - let ncumEqn = `${ncumLHS} = INTEG(${stream} * ${dfLHS}, ${initVal})` + let ncumEqn = `${ncumLHS} = INTEG(${stream} * ${dfLHS}, ${initVal}) ~~|` this.addVariable(ncumEqn) // Add references to the new level vars. // If they have subscripts, the refIds are still just the var name, because they are apply-to-all arrays. @@ -562,7 +564,7 @@ export default class EquationReader extends ModelReader { if (isSeparatedVar(this.var)) { Model.addNonAtoAVar(this.var.delayTimeVarName, [true]) } - let delayTimeEqn = `${delayTimeVarName}${genSubs} = ${delay}` + let delayTimeEqn = `${delayTimeVarName}${genSubs} = ${delay} ~~|` this.addVariable(delayTimeEqn) // Add a reference to the var, since it won't show up until code gen time. this.var.references.push(canonicalVensimName(`${delayTimeVarName}${genSubs}`)) @@ -644,15 +646,15 @@ export default class EquationReader extends ModelReader { this.generateDelayLevel(level2LHS, level2RefId, aux1LHS, aux2LHS, init) this.generateDelayLevel(level1LHS, level1RefId, input, aux1LHS, init) // Generate equations for the aux vars using the subs in the generated level var. - this.addVariable(`${aux1LHS} = ${level1LHS} / ${delay3}`) - this.addVariable(`${aux2LHS} = ${level2LHS} / ${delay3}`) - this.addVariable(`${aux3LHS} = ${level3LHS} / ${delay3}`) + this.addVariable(`${aux1LHS} = ${level1LHS} / ${delay3} ~~|`) + this.addVariable(`${aux2LHS} = ${level2LHS} / ${delay3} ~~|`) + this.addVariable(`${aux3LHS} = ${level3LHS} / ${delay3} ~~|`) // Generate an aux var to hold the delay time expression. this.var.delayTimeVarName = canonicalName(aux4) if (isSeparatedVar(this.var)) { Model.addNonAtoAVar(this.var.delayTimeVarName, [true]) } - this.addVariable(`${aux4LHS} = ${delay3}`) + this.addVariable(`${aux4LHS} = ${delay3} ~~|`) // Add a reference to the var, since it won't show up until code gen time. this.var.references.push(canonicalVensimName(`${aux4}${genSubs}`)) } @@ -660,7 +662,7 @@ export default class EquationReader extends ModelReader { generateDelayLevel(levelLHS, levelRefId, input, aux, init) { // Generate a level equation to implement DELAY. // The parameters are model names. Return the refId of the generated level var. - let eqn = `${levelLHS} = INTEG(${input} - ${aux}, ${init})` + let eqn = `${levelLHS} = INTEG(${input} - ${aux}, ${init}) ~~|` this.addVariable(eqn) // Add a reference to the new level var. this.refId = levelRefId