-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: remove inline comments in the preprocessor #74
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
a[A1] | ||
0 0 | ||
a[A2] | ||
0 1 | ||
a[A3] | ||
0 2 | ||
b | ||
0 3 | ||
c | ||
0 4 | ||
d | ||
0 8760 | ||
e | ||
0 42 | ||
1 42 | ||
FINAL TIME | ||
0 1 | ||
INITIAL TIME | ||
0 0 | ||
SAVEPER | ||
0 1 | ||
TIME STEP | ||
0 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
{UTF-8} | ||
DimA: A1, A2, A3 ~~| | ||
|
||
a[DimA]= | ||
0, {transportation sector} | ||
1, {electricity sector} | ||
2 {geoengineering sector - NOT USED} | ||
~ | ||
~ ~ :SUPPLEMENTARY | ||
| | ||
|
||
b = 3 {transportation sector} | ||
~ | ||
~ ~ :SUPPLEMENTARY | ||
| | ||
|
||
c = 4 | ||
{first part and | ||
the second part} | ||
~ | ||
~ ~ :SUPPLEMENTARY | ||
| | ||
|
||
d= | ||
8760 | ||
|
||
{ | ||
We ignore leap years so that we can get consistent results | ||
for various values used in the model that should not change | ||
every four years. If we want to change this value for leap | ||
years, instead use the following code: | ||
|
||
|
||
IF THEN ELSE( | ||
(MODULO(Time, 4) = 0 :AND: MODULO(Time, 100) <> 0) :OR: MODULO(Time, 400) = 0, | ||
8784 {leap year}, | ||
8760 {normal year} | ||
) | ||
} | ||
~ hours | ||
~ Calculates the number of hours in the year, ignoring leap years. | ||
~ :SUPPLEMENTARY | ||
| | ||
|
||
e = 41 {first part} + 1 {second part} | ||
~ | ||
~ ~ :SUPPLEMENTARY | ||
| | ||
|
||
INITIAL TIME = 0 ~~| | ||
FINAL TIME = 1 ~~| | ||
SAVEPER = 1 ~~| | ||
TIME STEP = 1 ~~| |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
a[DimA]: const (non-apply-to-all) | ||
= 0,1,2 | ||
refId(_a[_a1]) | ||
families(_dima) | ||
subscripts(_a1) | ||
separationDims(_dima) | ||
hasInitValue(false) | ||
|
||
a[DimA]: const (non-apply-to-all) | ||
= 0,1,2 | ||
refId(_a[_a2]) | ||
families(_dima) | ||
subscripts(_a2) | ||
separationDims(_dima) | ||
hasInitValue(false) | ||
|
||
a[DimA]: const (non-apply-to-all) | ||
= 0,1,2 | ||
refId(_a[_a3]) | ||
families(_dima) | ||
subscripts(_a3) | ||
separationDims(_dima) | ||
hasInitValue(false) | ||
|
||
b: const | ||
= 3 | ||
refId(_b) | ||
hasInitValue(false) | ||
|
||
c: const | ||
= 4 | ||
refId(_c) | ||
hasInitValue(false) | ||
|
||
d: const | ||
= 8760 | ||
refId(_d) | ||
hasInitValue(false) | ||
|
||
e: const | ||
= 41+1 | ||
refId(_e) | ||
hasInitValue(false) | ||
|
||
FINAL TIME: const | ||
= 1 | ||
refId(_final_time) | ||
hasInitValue(false) | ||
|
||
INITIAL TIME: const | ||
= 0 | ||
refId(_initial_time) | ||
hasInitValue(false) | ||
|
||
SAVEPER: const | ||
= 1 | ||
refId(_saveper) | ||
hasInitValue(false) | ||
|
||
Time: const | ||
= | ||
refId(_time) | ||
hasInitValue(false) | ||
|
||
TIME STEP: const | ||
= 1 | ||
refId(_time_step) | ||
hasInitValue(false) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ const sh = require('shelljs') | |
const split = require('split-string') | ||
const byline = require('byline') | ||
const XLSX = require('xlsx') | ||
const num = require('numbro') | ||
const B = require('bufx') | ||
|
||
// Set true to print a stack trace in vlog | ||
|
@@ -379,6 +378,34 @@ let matchRegexCaptures = (str, regex) => { | |
return [] | ||
} | ||
} | ||
// Match delimiters recursively. Replace delimited strings globally. | ||
let replaceDelimitedStrings = (str, open, close, newStr) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think (from inspection and from running the test) that this works as advertised, but (note to selves) at some point we should set up Jest so that we can have more isolated unit tests for these sorts of helper functions. Not a blocking thing; just something that's been on my mind for a long time but haven't had time to work on. |
||
// str is the string to operate on. | ||
// open and close are the opening and closing delimiter characters. | ||
// newStr is the string to replace delimited substrings with. | ||
let result = '' | ||
let start = 0 | ||
let depth = 0 | ||
let n = str.length | ||
for (let i = 0; i < n; i++) { | ||
if (str.charAt(i) === open) { | ||
if (depth === 0) { | ||
result += str.substring(start, i) | ||
} | ||
depth++ | ||
} else if (str.charAt(i) === close && depth > 0) { | ||
depth-- | ||
if (depth === 0) { | ||
result += newStr | ||
start = i + 1 | ||
} | ||
} | ||
} | ||
if (start < n) { | ||
result += str.substring(start) | ||
} | ||
return result | ||
} | ||
|
||
/** | ||
* Return the cartesian product of the given array of arrays. | ||
|
@@ -474,6 +501,7 @@ module.exports = { | |
readDat, | ||
readXlsx, | ||
replaceInArray, | ||
replaceDelimitedStrings, | ||
rest, | ||
splitEquations, | ||
strings, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to say that it would be nice if we had a way to verify that the mdl output of the preprocessor doesn't contain the comments, but then I remembered that I added such a thing to the test harness a few months ago. I added a check script for the
comments
test and the output mdl file is as expected, so I'll push that to this branch shortly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed that script in b42e664 and verified that the build passes.