File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4343 - name : test
4444 run : bin/rake test
4545 continue-on-error : ${{ matrix.ruby == 'head' }}
46+
47+ test-disable-prism :
48+ needs : ruby-versions
49+ runs-on : ubuntu-latest
50+ strategy :
51+ fail-fast : false
52+ matrix :
53+ ruby : ${{ fromJson(needs.ruby-versions.outputs.versions) }}
54+ steps :
55+ - name : Checkout code
56+ uses : actions/checkout@v4.1.1
57+ - name : Set up Ruby
58+ uses : ruby/setup-ruby@v1
59+ with :
60+ ruby-version : ${{ matrix.ruby }}
61+ bundler-cache : true
62+ - name : test
63+ run : SYNTAX_SUGGEST_DISABLE_PRISM=1 bin/rake test
64+ continue-on-error : ${{ matrix.ruby == 'head' }}
Original file line number Diff line number Diff line change 11## HEAD (unreleased)
22
3+ - Support prism parser (https://github.com/ruby/syntax_suggest/pull/208 ).
34- No longer supports EOL versions of Ruby. (https://github.com/ruby/syntax_suggest/pull/210 )
45- Handle Ruby 3.3 new eval source location format (https://github.com/ruby/syntax_suggest/pull/200 ).
56
Original file line number Diff line number Diff line change 55require "tmpdir"
66require "stringio"
77require "pathname"
8+ require "timeout"
89
9- # rubocop:disable Style/IdenticalConditionalBranches
10- if ENV [ "SYNTAX_SUGGEST_DISABLE_PRISM" ] # For testing dual ripper/prism support
11- require "ripper"
10+ # We need Ripper loaded for `Prism.lex_compat` even if we're using Prism
11+ # for lexing and parsing
12+ require "ripper"
13+
14+ # Prism is the new parser, replacing Ripper
15+ #
16+ # We need to "dual boot" both for now because syntax_suggest
17+ # supports older rubies that do not ship with syntax suggest.
18+ #
19+ # We also need the ability to control loading of this library
20+ # so we can test that both modes work correctly in CI.
21+ if ( value = ENV [ "SYNTAX_SUGGEST_DISABLE_PRISM" ] )
22+ warn "Skipping loading prism due to SYNTAX_SUGGEST_DISABLE_PRISM=#{ value } "
1223else
13- # TODO remove require
14- # Allow both to be loaded to enable more atomic commits
15- require "ripper"
1624 begin
1725 require "prism"
1826 rescue LoadError
19- require "ripper"
2027 end
2128end
22- # rubocop:enable Style/IdenticalConditionalBranches
23-
24- require "timeout"
2529
2630module SyntaxSuggest
2731 # Used to indicate a default value that cannot
Original file line number Diff line number Diff line change @@ -180,12 +180,19 @@ def ignore_newline_not_beg?
180180 # EOM
181181 # expect(lines.first.trailing_slash?).to eq(true)
182182 #
183- def trailing_slash?
184- last = @lex . last
185- return false unless last
186- return false unless last . type == :on_sp
183+ if SyntaxSuggest . use_prism_parser?
184+ def trailing_slash?
185+ last = @lex . last
186+ last &.type == :on_tstring_end
187+ end
188+ else
189+ def trailing_slash?
190+ last = @lex . last
191+ return false unless last
192+ return false unless last . type == :on_sp
187193
188- last . token == TRAILING_SLASH
194+ last . token == TRAILING_SLASH
195+ end
189196 end
190197
191198 # Endless method detection
Original file line number Diff line number Diff line change @@ -32,18 +32,15 @@ def initialize(source:, source_lines: nil)
3232 }
3333 end
3434
35- # rubocop:disable Style/IdenticalConditionalBranches
3635 if SyntaxSuggest . use_prism_parser?
3736 def self . lex ( source , line_number )
38- # Prism.lex_compat(source, line: line_number).value.sort_by {|values| values[0] }
39- Ripper ::Lexer . new ( source , "-" , line_number ) . parse . sort_by ( &:pos )
37+ Prism . lex_compat ( source , line : line_number ) . value . sort_by { |values | values [ 0 ] }
4038 end
4139 else
4240 def self . lex ( source , line_number )
4341 Ripper ::Lexer . new ( source , "-" , line_number ) . parse . sort_by ( &:pos )
4442 end
4543 end
46- # rubocop:enable Style/IdenticalConditionalBranches
4744
4845 def to_a
4946 @lex
Original file line number Diff line number Diff line change 88
99module SyntaxSuggest
1010 RSpec . describe "Top level SyntaxSuggest api" do
11+ it "doesn't load prism if env var is set" do
12+ skip ( "SYNTAX_SUGGEST_DISABLE_PRISM not set" ) unless ENV [ "SYNTAX_SUGGEST_DISABLE_PRISM" ]
13+
14+ expect ( SyntaxSuggest . use_prism_parser? ) . to be_falsey
15+ end
16+
1117 it "has a `handle_error` interface" do
1218 fake_error = Object . new
1319 def fake_error . message
You can’t perform that action at this time.
0 commit comments