diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf371c1..61689a4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,12 @@ jobs: fail-fast: false matrix: ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }} + prism_version: + - 1.2.0 # Shipped with Ruby 3.4 as default parser https://www.ruby-lang.org/en/news/2024/12/25/ruby-3-4-0-released/ + - 1.8.0 + - head + env: + PRISM_VERSION: ${{ matrix.prism_version }} steps: - name: Checkout code uses: actions/checkout@v6 @@ -40,6 +46,9 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true + - name: Use latest prism version (head only) + if: matrix.prism_version == 'head' + run: bundle update prism - name: test run: bin/rake test continue-on-error: ${{ matrix.ruby == 'head' }} diff --git a/CHANGELOG.md b/CHANGELOG.md index ee4c4da..9302e75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## HEAD (unreleased) +- Fix: Correctly identify trailing slashes when using Prism > 1.8.0. (https://github.com/ruby/syntax_suggest/pull/243) +- Internal: Add tests to multiple versions of prism + ## 2.0.2 - Fix: Separate multiple parser errors by newline. (https://github.com/ruby/syntax_suggest/pull/232) diff --git a/Gemfile b/Gemfile index 6595e0b..c193614 100644 --- a/Gemfile +++ b/Gemfile @@ -12,4 +12,12 @@ gem "standard" gem "ruby-prof" gem "benchmark-ips" -gem "prism" + +case ENV["PRISM_VERSION"]&.strip&.downcase +when "head" + gem "prism", github: "ruby/prism" +when nil, "" + gem "prism" +else + gem "prism", ENV["PRISM_VERSION"] +end diff --git a/lib/syntax_suggest/code_line.rb b/lib/syntax_suggest/code_line.rb index 58197e9..76ca892 100644 --- a/lib/syntax_suggest/code_line.rb +++ b/lib/syntax_suggest/code_line.rb @@ -180,18 +180,17 @@ def ignore_newline_not_beg? # EOM # expect(lines.first.trailing_slash?).to eq(true) # - if SyntaxSuggest.use_prism_parser? - def trailing_slash? - last = @lex.last - last&.type == :on_tstring_end - end - else - def trailing_slash? - last = @lex.last - return false unless last - return false unless last.type == :on_sp + def trailing_slash? + last = @lex.last + # Older versions of prism diverged slightly from Ripper in compatibility mode + case last&.type + when :on_sp last.token == TRAILING_SLASH + when :on_tstring_end + true + else + false end end