File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ Unmatched `(', missing `)' ?
122122 5 end
123123```
124124
125- - Any ambiguous or unknown errors will be annotated by the original ripper error output:
125+ - Any ambiguous or unknown errors will be annotated by the original parser error output:
126126
127127<!--
128128class Dog
133133-->
134134
135135```
136- syntax error, unexpected end-of-input
136+ Expected an expression after the operator
137137
138138 1 class Dog
139139 2 def meals_last_month
Original file line number Diff line number Diff line change @@ -227,9 +227,6 @@ def self.valid?(source)
227227require_relative "code_line"
228228require_relative "code_block"
229229require_relative "block_expand"
230- if !SyntaxSuggest . use_prism_parser?
231- require_relative "ripper_errors"
232- end
233230require_relative "priority_queue"
234231require_relative "unvisited_lines"
235232require_relative "around_block_scan"
Original file line number Diff line number Diff line change @@ -47,9 +47,9 @@ module SyntaxSuggest
4747 # ## Heredocs
4848 #
4949 # A heredoc is an way of defining a multi-line string. They can cause many
50- # problems. If left as a single line, Ripper would try to parse the contents
50+ # problems. If left as a single line, the parser would try to parse the contents
5151 # as ruby code rather than as a string. Even without this problem, we still
52- # hit an issue with indentation
52+ # hit an issue with indentation:
5353 #
5454 # 1 foo = <<~HEREDOC
5555 # 2 "Be yourself; everyone else is already taken.""
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ def valid?
8181 # lines then the result cannot be invalid
8282 #
8383 # That means there's no reason to re-check all
84- # lines with ripper (which is expensive).
84+ # lines with the parser (which is expensive).
8585 # Benchmark in commit message
8686 @valid = if lines . all? { |l | l . hidden? || l . empty? }
8787 true
Original file line number Diff line number Diff line change 22
33require_relative "left_right_lex_count"
44
5+ if !SyntaxSuggest . use_prism_parser?
6+ require_relative "ripper_errors"
7+ end
8+
59module SyntaxSuggest
610 class GetParseErrors
711 def self . errors ( source )
@@ -25,8 +29,8 @@ def self.errors(source)
2529 # # => "Unmatched keyword, missing `end' ?"
2630 #
2731 # When the error cannot be determined by lexical counting
28- # then ripper is run against the input and the raw ripper
29- # errors returned.
32+ # then the parser is run against the input and the raw
33+ # errors are returned.
3034 #
3135 # Example:
3236 #
@@ -101,7 +105,7 @@ def why(miss)
101105 # Returns an array of syntax error messages
102106 #
103107 # If no missing pairs are found it falls back
104- # on the original ripper error messages
108+ # on the original error messages
105109 def errors
106110 if missing . empty?
107111 return GetParseErrors . errors ( @code_lines . map ( &:original ) . join )
Original file line number Diff line number Diff line change 33module SyntaxSuggest
44 # Ripper.lex is not guaranteed to lex the entire source document
55 #
6- # lex = LexAll.new(source: source)
7- # lex.each do |value|
8- # puts value.line
9- # end
6+ # This class guarantees the whole document is lex-ed by iteratively
7+ # lexing the document where ripper stopped.
8+ #
9+ # Prism likely doesn't have the same problem. Once ripper support is removed
10+ # we can likely reduce the complexity here if not remove the whole concept.
11+ #
12+ # Example usage:
13+ #
14+ # lex = LexAll.new(source: source)
15+ # lex.each do |value|
16+ # puts value.line
17+ # end
1018 class LexAll
1119 include Enumerable
1220
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33module SyntaxSuggest
4- # Capture parse errors from ripper
4+ # Capture parse errors from Ripper
5+ #
6+ # Prism returns the errors with their messages, but Ripper
7+ # does not. To get them we must make a custom subclass.
58 #
69 # Example:
710 #
Original file line number Diff line number Diff line change @@ -17,9 +17,6 @@ module SyntaxSuggest
1717 end # 9
1818 EOM
1919
20- # raw_lex = Ripper.lex(source)
21- # expect(raw_lex.to_s).to_not include("dog")
22-
2320 lex = LexAll . new ( source : source )
2421 expect ( lex . map ( &:token ) . to_s ) . to include ( "dog" )
2522 expect ( lex . first . line ) . to eq ( 1 )
You can’t perform that action at this time.
0 commit comments