Skip to content

Commit 08aaa3f

Browse files
committed
Update docs, clean up PR
Removes or updates mentions of Ripper
1 parent 7f4176a commit 08aaa3f

File tree

8 files changed

+28
-19
lines changed

8 files changed

+28
-19
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff 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
<!--
128128
class Dog
@@ -133,7 +133,7 @@ end
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

lib/syntax_suggest/api.rb

-3
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,6 @@ def self.valid?(source)
227227
require_relative "code_line"
228228
require_relative "code_block"
229229
require_relative "block_expand"
230-
if !SyntaxSuggest.use_prism_parser?
231-
require_relative "ripper_errors"
232-
end
233230
require_relative "priority_queue"
234231
require_relative "unvisited_lines"
235232
require_relative "around_block_scan"

lib/syntax_suggest/clean_document.rb

+2-2
Original file line numberDiff line numberDiff 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.""

lib/syntax_suggest/code_block.rb

+1-1
Original file line numberDiff line numberDiff 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

lib/syntax_suggest/explain_syntax.rb

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
require_relative "left_right_lex_count"
44

5+
if !SyntaxSuggest.use_prism_parser?
6+
require_relative "ripper_errors"
7+
end
8+
59
module 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)

lib/syntax_suggest/lex_all.rb

+12-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
module 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

lib/syntax_suggest/ripper_errors.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# frozen_string_literal: true
22

33
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.
58
#
69
# Example:
710
#

spec/unit/lex_all_spec.rb

-3
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)