Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #12 from maxprokopiev/fix-multibyte-comments
Browse files Browse the repository at this point in the history
Use offset_cache while building comments as well
  • Loading branch information
kddnewton authored Feb 13, 2024
2 parents 3259598 + 780ce36 commit 8c2312e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/parser/prism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def tokenize(source_buffer, _recover = false)

[
build_ast(program, offset_cache),
build_comments(result.comments),
build_comments(result.comments, offset_cache),
build_tokens(tokens, offset_cache)
]
ensure
Expand Down Expand Up @@ -110,10 +110,10 @@ def build_ast(program, offset_cache)
end

# Build the parser gem comments from the prism comments.
def build_comments(comments)
def build_comments(comments, offset_cache)
comments.map do |comment|
location = comment.location
Source::Comment.new(Source::Range.new(source_buffer, location.start_offset, location.end_offset))
Source::Comment.new(Source::Range.new(source_buffer, offset_cache[location.start_offset], offset_cache[location.end_offset]))
end
end

Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/multibyte.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# credits to https://github.com/minimaxir/big-list-of-naughty-strings/blob/master/blns.txt

# πŸ₯²

a = "😍"
b = "πŸ‘©πŸ½"
c = "πŸ‘¨β€πŸ¦° πŸ‘¨πŸΏβ€πŸ¦° πŸ‘¨β€πŸ¦± πŸ‘¨πŸΏβ€πŸ¦± πŸ¦ΉπŸΏβ€β™‚οΈ"
Expand Down

0 comments on commit 8c2312e

Please sign in to comment.