Parse attribute-style comments from source code #20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is the first stage of supporting compiling models; parsing some metadata out of the source code. See the new attributes in
inst/examples/sir.cpp
andexamples/walk.cpp
for examples of this.When we come to do code generation we will not attempt to parse C++ (which is hard) but instead inspect these attributes and generate code based on what we find. This is what we ended up doing in dust1 eventually, it's much easier than trying to be clever, and practically it's not very hard to do because most models are generated mechanically anyway.
At the same time I've updated the parameter- and data-reading functions to use some common code, which provides much nicer error messages.
We'll probably expand some of the attribute support here, in particular advertising parameter types and if the parameter is updateble, differentiable, or has a default. For now the bare minimum.
The error reporting could be improved and it would not be that hard to return line numbers etc. But the expectation is that most of the code is generated so these errors will probably never be seen