summaryrefslogtreecommitdiff
path: root/lib/prism/parse_result.rb
AgeCommit message (Collapse)Author
33 min.[ruby/prism] Add Prism::Source#line_to_byte_offset and replace direct ↵HEADmasterBenoit Daloze
accesses to offsets https://github.com/ruby/prism/commit/ff81a29ba5
2025-11-29[ruby/prism] Optimize `Prism::Source#find_line`Earlopain
This is more concise and ruby does a better job performance-wise. This used to be `bsearch_index` already but https://github.com/ruby/prism/commit/6d8358c08395438d5924777c1fc3001a5ebf0aa3 changed it. https://github.com/ruby/prism/pull/1733#discussion_r1373702087 said: > Yeah the edge case was that the value matched an element exactly But surely there would be a test to show this behaviour? Gets called as part of pretty-printing nodes. Further reduces the time for `SnapshotsTest` by ~16% for me. https://github.com/ruby/prism/commit/f448e2b995
2025-05-29[ruby/prism] [DOC] Specify markdown mode to RDocNobuyoshi Nakada
https://github.com/ruby/prism/commit/12af4e144e
2025-01-14[ruby/prism] Support forwarding flags on scopesKevin Newton
When parent scopes around an eval are forwarding parameters (like *, **, &, or ...) we need to know that information when we are in the parser. As such, we need to support passing that information into the scopes option. In order to do this, unfortunately we need a bunch of changes. The scopes option was previously an array of array of strings. These corresponded to the names of the locals in the parent scopes. We still support this, but now additionally support passing in a Prism::Scope instance at each index in the array. This Prism::Scope class holds both the names of the locals as well as an array of forwarding parameter names (symbols corresponding to the forwarding parameters). There is convenience function on the Prism module that creates a Prism::Scope object using Prism.scope. In JavaScript, we now additionally support an object much the same as the Ruby side. In Java, we now have a ParsingOptions.Scope class that holds that information. In the dump APIs, these objects in all 3 languages will add an additional byte for the forwarding flags in the middle of the scopes serialization. All of this is in service of properly parsing the following code: ```ruby def foo(*) = eval("bar(*)") ``` https://github.com/ruby/prism/commit/21abb6b7c4
2025-01-14[ruby/prism] Refactor serializerKevin Newton
https://github.com/ruby/prism/commit/8ab2532f09
2024-12-11[ruby/prism] Bump typechecking depsKevin Newton
https://github.com/ruby/prism/commit/230c8b8a48
2024-10-10[ruby/prism] Prism::CodeUnitsCacheKevin Newton
Calculating code unit offsets for a source can be very expensive, especially when the source is large. This commit introduces a new class that wraps the source and desired encoding into a cache that reuses pre-computed offsets. It performs quite a bit better. There are still some problems with this approach, namely character boundaries and the fact that the cache is unbounded, but both of these may be addressed in subsequent commits. https://github.com/ruby/prism/commit/2e3e1a4d4d
2024-10-09[ruby/prism] Attempt to assume binary is UTF-8Kevin Newton
https://github.com/ruby/prism/commit/343197e4ff
2024-10-09[ruby/prism] Avoid breaking code units offset on binary encodingVinicius Stock
https://github.com/ruby/prism/commit/25a4cf6794 Co-authored-by: Kevin Newton <kddnewton@users.noreply.github.com>
2024-09-04[ruby/prism] essentialy ==> essentiallyydah
https://github.com/ruby/prism/commit/9c68c01bcd
2024-08-14[ruby/prism] Tweak inspect representation of `Prism::Location`Koichi ITO
This PR tweaks inspect representation of `Prism::Location`. ## Before During debugging, the meaning of `@location=https://github.com/ruby/prism/commit/21474836481` was unclear: ```console $ ruby -Ilib -rprism -e 'p Prism.lex("puts :hi").value.map(&:first)[1]' #<Prism::Token:0x000000010cd74e40 @source=#<Prism::ASCIISource:0x000000010cb5f808 @source="puts :hi", @start_line=1, @offsets=[0]>, @type=:SYMBOL_BEGIN, @value=":", @location=https://github.com/ruby/prism/commit/21474836481> ``` ## After This PR clarifies the contents of the location object, aligning with what I think user expects: ```console $ ruby -Ilib -rprism -e 'p Prism.lex("puts :hi").value.map(&:first)[1]' #<Prism::Token:0x000000010e174d50 @source=#<Prism::ASCIISource:0x000000010df5efe8 @source="puts :hi", @start_line=1, @offsets=[0]>, @type=:SYMBOL_BEGIN, @value=":", @location=#<Prism::Location @start_offset=5 @length=1 start_line=1>> ``` Although it is uncertain whether Prism will accept this change in the inspect representation, it is submitted here as a suggestion. https://github.com/ruby/prism/commit/e7421ce1c5
2024-07-11[ruby/prism] Various cleanup for initializers and typechecksKevin Newton
https://github.com/ruby/prism/commit/86cf82794a
2024-07-11[ruby/prism] Move location to second position for node initializersKevin Newton
https://github.com/ruby/prism/commit/4cc0eda4ca
2024-07-11[ruby/prism] Reconfigure error testsKevin Newton
https://github.com/ruby/prism/commit/fb7e1ebb7f
2024-05-13[ruby/prism] Autoload newlines and comment visitorsKevin Newton
Having the @newline instance variable in every node adds up, and since it is so rarely used, we only want to add it when necessary. Moving this into an autoloaded file and moving the instance variable out of the default initializers reduces allocated memory because the nodes are now smaller and some fit into the compact list. On my machine, I'm seeing about an 8% drop. https://github.com/ruby/prism/commit/eea92c07d2
2024-05-03[ruby/prism] Prism::Location#adjoinKevin Newton
https://github.com/ruby/prism/commit/a298db68e3
2024-05-03[ruby/prism] Create specialized `ASCIISource` with asciionly optimizationsVinicius Stock
https://github.com/ruby/prism/commit/40993166a8
2024-05-02[ruby/prism] Node#script_lines and supporting infraKevin Newton
https://github.com/ruby/prism/commit/cb4a8ab772
2024-04-26[ruby/prism] Location#slice_lines, Node#slice_linesKevin Newton
https://github.com/ruby/prism/commit/9b61f6fdb3
2024-04-19[ruby/prism] Split parse result based on typeKevin Newton
https://github.com/ruby/prism/commit/17194e096d
2024-04-11[ruby/prism] Add Location#chopKevin Newton
https://github.com/ruby/prism/commit/5dd57f4b84
2024-03-06[ruby/prism] Use the diagnostic types in the parser translation layerKevin Newton
https://github.com/ruby/prism/commit/1a8a0063dc
2024-03-06[ruby/prism] Expose types on diagnosticsKevin Newton
https://github.com/ruby/prism/commit/a735c2262f
2024-03-06[ruby/prism] Small changes to make type-checking passUfuk Kayserilioglu
https://github.com/ruby/prism/commit/5b2970e75b
2024-03-06[ruby/prism] Fix some type-checking errors by using different method callsUfuk Kayserilioglu
For example, use `.fetch` or `.dig` instead of `[]`, and use `===` instead of `is_a?` for checking types of objects. https://github.com/ruby/prism/commit/548b54915f
2024-02-24[ruby/prism] Rebase against mainKevin Newton
https://github.com/ruby/prism/commit/813e20d449
2024-02-24[ruby/prism] Less code modifications. More steep:ignore for nowGopal Patel
https://github.com/ruby/prism/commit/7905bdbf83
2024-02-24[ruby/prism] Add documentation for Location#source!Gopal Patel
https://github.com/ruby/prism/commit/467e1cc2c4
2024-02-24[ruby/prism] Relax Location#source to be optionalGopal Patel
https://github.com/ruby/prism/commit/9f00fe7510
2024-02-24[ruby/prism] Remove Ripper from public RBS, type-assert remaining issuesGopal Patel
https://github.com/ruby/prism/commit/5fda7a0760
2024-02-24[ruby/prism] Split private typesGopal Patel
https://github.com/ruby/prism/commit/0209d093ec
2024-02-19[ruby/prism] Fix up comment stateKevin Newton
https://github.com/ruby/prism/commit/c6561becf0
2024-02-18[ruby/prism] Split up comments between leading and trailingKevin Newton
Also make them lazy to allocate the array, and also expose ParseResult#encoding. https://github.com/ruby/prism/commit/08ec7683ae
2024-02-15[ruby/prism] Make location methods thread-safeBenoit Daloze
* Before it could result in NoMethodError if multiple threads were calling location methods: https://gist.github.com/eregon/b78b7f266d7ee0a278a389cfd1782232 https://github.com/ruby/prism/commit/ff762dcccd
2024-02-15[ruby/prism] Speed up creating Ruby ASTKevin Newton
When creating the Ruby AST, we were previously allocating Location objects for every node and every inner location. Instead, this commit changes it to pack both the start offset and length into a single u64 and pass that into the nodes. Then, when the locations are requested via a reader method, we lazily allocate the Location objects. https://github.com/ruby/prism/commit/de203dca83 Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2024-02-14Initialize the Prism::Source directly with all 3 fields for the C extensionBenoit Daloze
* Faster that way: $ ruby -Ilib -rprism -rbenchmark/ips -e 'Benchmark.ips { |x| x.report("parse") { Prism.parse("1 + 2") } }' 195.722k (± 0.5%) i/s rb_iv_set(): 179.609k (± 0.5%) i/s rb_funcall(): 190.030k (± 0.3%) i/s before this PR: 183.319k (± 0.4%) i/s
2024-02-14[ruby/prism] Remove attr_writer's for ParseResult#start_line and #offsetsBenoit Daloze
* As the user should not set these. * Use #instance_variable_set/rb_iv_set() instead internally. https://github.com/ruby/prism/commit/cace09fb8c
2024-02-14[ruby/prism] Serialize the newline_list to avoid recomputing it again laterBenoit Daloze
* Fixes https://github.com/ruby/prism/issues/2380 https://github.com/ruby/prism/commit/4eaaa90114
2024-02-13[ruby/prism] Add code unit APIs to locationKevin Newton
LSPs need this because the protocol dictates that you return code units for offsets. None of our existing APIs provided that information, and since we hid the source it's not nearly as useful for them. Now they can pass an encoding directly to: * Location#start_code_units_offset * Location#end_code_units_offset * Location#start_code_units_column * Location#end_code_units_column https://github.com/ruby/prism/commit/4757a2cc06 Co-Authored-By: Vinicius Stock <vinicius.stock@shopify.com>
2024-02-07[ruby/prism] Support for Ruby 2.7Kevin Newton
https://github.com/ruby/prism/commit/1a15b70a8e
2024-01-27[ruby/prism] Error follow-upKevin Newton
Split up the diagnostic levels so that error and warning levels aren't mixed. Also fix up deconstruct_keys implementation. https://github.com/ruby/prism/commit/bd3eeb308d Co-authored-by: Benoit Daloze <eregontp@gmail.com>
2024-01-27[ruby/prism] Call #inspect on diagnostic levelsBenoit Daloze
* So it's clear it is a Symbol. Before: ... @level=warning_verbose_true> After: ... @level=:warning_verbose_true> https://github.com/ruby/prism/commit/84503643b9
2024-01-26[ruby/prism] Add level to warnings and errors to categorize themBenoit Daloze
* Fixes https://github.com/ruby/prism/issues/2082 https://github.com/ruby/prism/commit/7a74576357
2024-01-09[ruby/prism] Clarify __END__ commentKevin Newton
https://github.com/ruby/prism/commit/3e36d5eabc
2023-11-28[ruby/prism] Move DATA parsing into its own parse result fieldKevin Newton
https://github.com/ruby/prism/commit/42b60b6e95
2023-11-20[ruby/prism] Add character APIs for locationsKevin Newton
(https://github.com/ruby/prism/pull/1809) https://github.com/ruby/prism/commit/d493ccd093
2023-11-03[ruby/prism] Split commentKevin Newton
We were previously holding a type field on Comment to tell what kind of comment it was. Instead, let's just use actual classes for this. https://github.com/ruby/prism/commit/e76830ca6e
2023-11-03[ruby/prism] Wire up options through the Java parserKevin Newton
https://github.com/ruby/prism/commit/13fa262669
2023-11-03[ruby/prism] Properly support the start line optionKevin Newton
https://github.com/ruby/prism/commit/33cc75a4b7
2023-11-01[ruby/prism] More Ruby docsKevin Newton
https://github.com/ruby/prism/commit/ca9a660f52