Skip to content

Commit

Permalink
annotate delimiter pairing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Nov 16, 2024
1 parent 817c39a commit d3ca783
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 8 additions & 3 deletions lib/coffeescript/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,18 @@ exports.Lexer = class Lexer
tag = 'INDEX_START'
switch prev[0]
when '?' then prev[0] = 'INDEX_SOAK'
token = @makeToken tag, value

# Match up paired delimiters.
switch value
when '(', '{', '[' then @ends.push {tag: INVERSES[value], origin: token}
# Upon opening a pair, provide the requisite close token, and record the "origin" as
# a separate token.
when '(', '{', '['
# TODO: this concept of "origin" is somewhat overloaded and makes it difficult to introspect
# a token stream. Is it the source of a generated token, or the "parent" node for
# a context-sensitive match like paired delimiters?
@ends.push {tag: INVERSES[value], origin: @makeToken tag, value}
when ')', '}', ']' then @pair value

@tokens.push @makeToken tag, value
value.length

Expand Down

0 comments on commit d3ca783

Please sign in to comment.