Fix included positions being wrong for the first token in a new file#1615
Fix included positions being wrong for the first token in a new file#1615
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1615 +/- ##
==========================================
+ Coverage 90.47% 90.49% +0.02%
==========================================
Files 65 65
Lines 10110 10112 +2
==========================================
+ Hits 9147 9151 +4
+ Misses 963 961 -2
🚀 New features to boost your workflow:
|
Perfectly balanced, as all things should be. The one becoming is incorrect is data {
#include data.stan
}where real x; // commentInterestingly, a blank line makes the problem go away data {
#include data.stan
} |
|
Thanks for the mwe @nhuurre. It is curious, the locations on the parsed file actually all look correct to me, so I think that comment being misplaced is due to the pretty printing code misbehaving, not a parser/lexer issue at this point. The only difference adding a newline makes is updating the |
|
Yes, I assume it's something like, |
|
I think it's actually as simple as deleting this other 'historical' workaround: Lines 69 to 75 in d9e4aa6 |
Bad(?) news, this PR is now strictly out-of-balance and only improves comment positions relative to master |
|
Thanks guys! Really appreciate it. |
Closes #1614.
After staring at the results of
--debug-parse --debug-lexon @rok-cesnovar's example, I realized that this was the issue, the very first token was reporting the wrong location.It turned out that us calling
lexer_lexbuf_to_supplierwas to blame, as this function interacted badly with the fact that our tokenizer can internally change lexbufs. The newinputinParse.mlis based on it, but accounts for this fact.It turns out that almost all of our previous location-munging was unnecessary once this small fix was applied.
This PR does change the location of two existing comments in our test cases. As far as I can tell, one is a previously-correct placement becoming incorrect, and the other is a previously-incorrect placement becoming correct. shrug
Submission Checklist
Release notes
Fixed a bug in the parser that could lead to crashes when auto-formatting files with many
#includes.Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)