@sdeverywhere/compile 0.7.13 → 0.7.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ export function expandVarNames(canonical) {
|
|
|
43
43
|
* @returns {string[]} An array of expanded names for the given variable.
|
|
44
44
|
*/
|
|
45
45
|
function namesForVar(v) {
|
|
46
|
-
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE
|
|
46
|
+
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE === '0') {
|
|
47
47
|
// TODO: When the old parsing code is active, use the old ModelLHSReader. This code path
|
|
48
48
|
// will be removed when the old parsing code is removed.
|
|
49
49
|
let modelLHSReader = new ModelLHSReader()
|
package/src/model/model.js
CHANGED
|
@@ -800,7 +800,7 @@ function vensimName(cVarName) {
|
|
|
800
800
|
function cName(vensimVarName) {
|
|
801
801
|
// Convert a Vensim variable name to a C name.
|
|
802
802
|
// This function requires model analysis to be completed first when the variable has subscripts.
|
|
803
|
-
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE
|
|
803
|
+
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE === '0') {
|
|
804
804
|
// TODO: For now we use the legacy VarNameReader when the old parser is active; this
|
|
805
805
|
// code will be removed once the old parser is removed
|
|
806
806
|
return new VarNameReader().read(vensimVarName)
|
|
@@ -67,12 +67,12 @@ function generateSmoothLevel(v, context, argInput, argDelay, argInit, levelNumbe
|
|
|
67
67
|
// `equation-reader.js` and modified to work with the AST instead of directly depending
|
|
68
68
|
// on antlr4-vensim constructs. This logic is pretty complex so we should try to refactor
|
|
69
69
|
// or at least add some more fine-grained unit tests for it.
|
|
70
|
-
let subs = context.extractSubscriptsFromVarNames(argInput, argDelay, argInit)
|
|
71
70
|
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
// Preserve the original subscript/dimension names that were passed in. In the case of
|
|
72
|
+
// separated variables, the `subs` array will be replaced to include the separated subscript
|
|
73
|
+
// names, but we still need the original subscript/dimension names.
|
|
74
|
+
const origSubs = context.extractSubscriptsFromVarNames(argInput, argDelay, argInit)
|
|
75
|
+
let subs = origSubs
|
|
76
76
|
|
|
77
77
|
let levelVarBaseName
|
|
78
78
|
let levelLHS
|
|
@@ -129,5 +129,8 @@ function generateSmoothLevel(v, context, argInput, argDelay, argInit, levelNumbe
|
|
|
129
129
|
context.defineVariable(levelEqn)
|
|
130
130
|
context.addVarReference(levelVarRefId)
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
// The name of the level variable returned here includes the original subscript/dimension names
|
|
133
|
+
// (not the separated subscript names) so that the `argInput` is correct for the 2nd and 3rd levels
|
|
134
|
+
const levelVarFullName = `${levelVarBaseName}${origSubs}`
|
|
135
|
+
return [levelVarRefId, levelVarFullName]
|
|
133
136
|
}
|
|
@@ -148,7 +148,7 @@ class Context {
|
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
if (result.size > 1) {
|
|
151
|
-
|
|
151
|
+
throw new Error(`Subscripts do not agree in extractSubscriptsFromVarNames: ${[...varNames]}`)
|
|
152
152
|
}
|
|
153
153
|
return [...result][0] || ''
|
|
154
154
|
}
|
|
@@ -131,7 +131,7 @@ export function printNames(namesPathname, operation) {
|
|
|
131
131
|
* @return {*} A parsed tree representation of the model.
|
|
132
132
|
*/
|
|
133
133
|
export function parseModel(input, modelDir, sort = false) {
|
|
134
|
-
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE
|
|
134
|
+
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE === '0') {
|
|
135
135
|
// Use the legacy parser
|
|
136
136
|
return {
|
|
137
137
|
kind: 'vensim-legacy',
|