Skip to content
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

Merged
merged 3 commits into from
Jul 15, 2021

Conversation

ToddFincannon
Copy link
Collaborator

@ToddFincannon ToddFincannon commented Jul 6, 2021

Fixes #73

This PR changes the preprocessor to remove inline comments from the model before parsing it. A test model is included that illustrates several use cases. A special string scanner function was required because a regular expression could not cover all cases. A regexp would need to be greedy to match the case with nested comments, but cannot be greedy to match the case with two comments in one string.

@chrispcampbell chrispcampbell changed the title feat: remove inline comments in the preprocessor (#73) feat: remove inline comments in the preprocessor Jul 15, 2021
@chrispcampbell chrispcampbell self-requested a review July 15, 2021 19:19
Copy link
Contributor

@chrispcampbell chrispcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I tested it with the En-ROADS model and verified that the preprocessor produces the same results after your fix as before. I also checked build time of the sde preprocess and sde flatten commands and verified that there was no significant performance hit. (I thought maybe the linear scans would be noticeably slow, but apparently not.)

I will push my additional "check" script for the new comments test to this branch shortly, then will merge it to develop once the build passes.

@@ -0,0 +1,53 @@
{UTF-8}
Copy link
Contributor

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.

Copy link
Contributor

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.

@@ -379,6 +378,34 @@ let matchRegexCaptures = (str, regex) => {
return []
}
}
// Match delimiters recursively. Replace delimited strings globally.
let replaceDelimitedStrings = (str, open, close, newStr) => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@chrispcampbell chrispcampbell merged commit d23b1c3 into develop Jul 15, 2021
@chrispcampbell chrispcampbell deleted the todd/73-remove-comments branch July 15, 2021 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove inline comments
2 participants