-
Notifications
You must be signed in to change notification settings - Fork 20
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
Editorial: Use grammar for VLQ and Mappings and decode via SDO #180
Conversation
I attempted to re-express the DecodeBase64VLQ operation without using an accumulator, since the way fields are mutated in the accumulator is not super easy to keep track of (recursion + mutable state). Do you think this version would work, or am I missing something about shifting the values? And then you use it as "let value be the VLQSignedValue of Vlq". VLQSignedValue ( ) Vlq :: VlqDigitList
VLQUnsignedValue ( ) VlqDigitList :: DigitWithoutContinuationBit
VlqDigitList :: DigitWithContinuationBit VlqDigitList
|
Very nice! That looks much simpler. Although I think there is a bug: We need to slice the continuation bit off left and not off
Alternatively we could define |
You are right, the I think I have a slight preference for the SDO approach, but only with a name that implies "this isn't actually the base64-decoded value, but the base64-decoded value after trimming the VLQ continuation bit" :) Or, we remove |
With tc39/ecmarkup#637 still in-flight, I applied Nicolos idea but via an additional nonterminal indirection. Should be good enough to discuss this in tonights' meeting. |
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.
Second review pass. The VLQs look good now, and I finally reviewed the mappings definitions.
I would prefer this slightly different approach, based on the "informal" understanding that mappings contains one or more segments, one per line, separated by semicolons. A segment contains zero or more mappings, separated by commas. This avoids having to think about the "what if there are consecutive semicolons?" case, since they are just consecutive segments.
Mappings :
Segment
Segment `;` Mappings
Segment :
MappingList?
MappingList :
Mapping
Mapping `,` MappingList
Note that the above definitions makes "mappings": ""
valid, which matches the current spec.
DecodeMappingsSdo would then become
DecodeMappingsSdo ( ... )
Mappings : Segment ;
Mappings
MappingList : Mapping ,
MappingList
- For each child node child of this Parse Node, do ... (same as now)
Segment : MappingList?
- Set state.[[GeneratedLine]] to state.[[GeneratedLine]] + 1.
- Set state.[[GeneratedColumn]] to 0.
- If MappingList is present, perform DecodeMappingsSdo of MappingList with arguments ...
Mapping : GeneratedColumn (same as now)
Mapping : GeneratedColumn OriginalSource OriginalLine OriginalColumn Name? (same as now)
Maybe can we also rename Mappings to SegmentList, or MappingsSegmentList? It's a bit weird that "mappings" is a list of segments, and "segment" is a list of mappings, even though that's how we always referred to it 😅 |
Thanks for the new grammar, I love it!
IMO it would be nice to have consistent naming of the goal symbols w.r.t. to how the field is named in the source map JSON. What about renaming Mappings to SegmentList but then add a goal symbol MappingsField : SegmentList? |
Sounds good 👍 |
Co-authored-by: Nicolò Ribaudo <[email protected]>
Changed the grammar as per your suggestion. Also renamed the SDO to |
Co-authored-by: Justin Ridgewell <[email protected]>
Co-authored-by: Justin Ridgewell <[email protected]>
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 left minor some comments, but the rest looks good to me. I'll approve once rebased.
Oh also, per the last call we had, lets add a "Grammar notation" section in "Notational conventions". It should encourage readers to check out https://tc39.es/ecma262/#sec-grammar-notation, mentioning explicitly that:
|
Done. Might need some tweaking to the wording. |
Co-authored-by: Nicolò Ribaudo <[email protected]>
Draft that changes VLQ and mappings to use grammar plus "syntax-directed operations" for decoding rather than a pure algorithmic approach.
Only uploaded so we have a preview for discussion.
Preview: https://szuend.github.io/source-map/branch/mappings-grammar/#sec-mappings