File tree 8 files changed +28
-19
lines changed
8 files changed +28
-19
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ Unmatched `(', missing `)' ?
122
122
5 end
123
123
```
124
124
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:
126
126
127
127
<!--
128
128
class Dog
133
133
-->
134
134
135
135
```
136
- syntax error, unexpected end-of-input
136
+ Expected an expression after the operator
137
137
138
138
1 class Dog
139
139
2 def meals_last_month
Original file line number Diff line number Diff line change @@ -227,9 +227,6 @@ def self.valid?(source)
227
227
require_relative "code_line"
228
228
require_relative "code_block"
229
229
require_relative "block_expand"
230
- if !SyntaxSuggest . use_prism_parser?
231
- require_relative "ripper_errors"
232
- end
233
230
require_relative "priority_queue"
234
231
require_relative "unvisited_lines"
235
232
require_relative "around_block_scan"
Original file line number Diff line number Diff line change @@ -47,9 +47,9 @@ module SyntaxSuggest
47
47
# ## Heredocs
48
48
#
49
49
# 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
51
51
# 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:
53
53
#
54
54
# 1 foo = <<~HEREDOC
55
55
# 2 "Be yourself; everyone else is already taken.""
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ def valid?
81
81
# lines then the result cannot be invalid
82
82
#
83
83
# 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).
85
85
# Benchmark in commit message
86
86
@valid = if lines . all? { |l | l . hidden? || l . empty? }
87
87
true
Original file line number Diff line number Diff line change 2
2
3
3
require_relative "left_right_lex_count"
4
4
5
+ if !SyntaxSuggest . use_prism_parser?
6
+ require_relative "ripper_errors"
7
+ end
8
+
5
9
module SyntaxSuggest
6
10
class GetParseErrors
7
11
def self . errors ( source )
@@ -25,8 +29,8 @@ def self.errors(source)
25
29
# # => "Unmatched keyword, missing `end' ?"
26
30
#
27
31
# 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.
30
34
#
31
35
# Example:
32
36
#
@@ -101,7 +105,7 @@ def why(miss)
101
105
# Returns an array of syntax error messages
102
106
#
103
107
# If no missing pairs are found it falls back
104
- # on the original ripper error messages
108
+ # on the original error messages
105
109
def errors
106
110
if missing . empty?
107
111
return GetParseErrors . errors ( @code_lines . map ( &:original ) . join )
Original file line number Diff line number Diff line change 3
3
module SyntaxSuggest
4
4
# Ripper.lex is not guaranteed to lex the entire source document
5
5
#
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
10
18
class LexAll
11
19
include Enumerable
12
20
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
module 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.
5
8
#
6
9
# Example:
7
10
#
Original file line number Diff line number Diff line change @@ -17,9 +17,6 @@ module SyntaxSuggest
17
17
end # 9
18
18
EOM
19
19
20
- # raw_lex = Ripper.lex(source)
21
- # expect(raw_lex.to_s).to_not include("dog")
22
-
23
20
lex = LexAll . new ( source : source )
24
21
expect ( lex . map ( &:token ) . to_s ) . to include ( "dog" )
25
22
expect ( lex . first . line ) . to eq ( 1 )
You can’t perform that action at this time.
0 commit comments