Skip to content

Conversation

szuend
Copy link
Collaborator

@szuend szuend commented Sep 10, 2025

…text-sensitive.

While working on the proposal-scopes branch and the decoding of scope information, I was contemplating how we could keep the algorithms somewhat readable while also accounting for malformed source maps without having to sprinkle "if condition, optionally report an error" everywhere.

As such I suggest the following:

  • We keep the grammar simple and context-sensitive
  • We liberally use asserts to express invariant in the format
  • Decoders may rewrite asserts as "optionally report an error".

As an example, I'd find the former much easier to read then the latter:

<emu-grammar>
  OriginalScopeStart :
    `B` ScopeFlags ScopeLine ScopeColumn ScopeName? ScopeKind?
</emu-grammar>
<emu-alg>
  1. Let _flags_ be the VLQUnsignedValue of |ScopeFlags|.
  1. Assert: _flags_ & 0x2 = 0x2 iff, |ScopeKind| is present.
  1. Return RelativeName(|ScopeKind|, _accumulator_, _names_).
</emu-alg>

versus

<emu-grammar>
  OriginalScopeStart :
    `B` ScopeFlags ScopeLine ScopeColumn ScopeNameOrKind? ScopeKind?
</emu-grammar>
<emu-alg>
  1. Let _flags_ be the VLQUnsignedValue of |ScopeFlags|.
  1. If _flags_ & 0x2 ≠ 0x2, return *null*.
  1. If |ScopeNameOrKind| is not present, then
    1. optionally report an error.
    1. return *null*.
  1. If _flags_ & 0x1 = 0x1, then
    1. If |ScopeKind| is not present, then
      1. optionally report an error.
      1. return *null*.
    1. Return RelativeName(|ScopeKind|, _accumulator_, _names_).
  1. Return RelativeName(|ScopeNameOrKind|, _accumulator_, _names_).
</emu-alg>

IMO we are specifying a wire format and not a programming language. I eluded to this in the scopes meeting that we shouldn't tailor the specification text so an engineer can follow it line-by-line and implement it, but rather to convey how the format works.

Just a proposal though. If folks feel strongly about keeping it as-is and trying to spell out how to handle the context-sensitive aspects of the grammar in the decoding steps, then we can do that as well :)

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.

1 participant