[ruby/syntax_suggest] Update docs, clean up PR
Removes or updates mentions of Ripper https://github.com/ruby/syntax_suggest/commit/08aaa3f50a
This commit is contained in:
parent
62c9695911
commit
6d39d6d214
@ -227,9 +227,6 @@ require_relative "lex_all"
|
|||||||
require_relative "code_line"
|
require_relative "code_line"
|
||||||
require_relative "code_block"
|
require_relative "code_block"
|
||||||
require_relative "block_expand"
|
require_relative "block_expand"
|
||||||
if !SyntaxSuggest.use_prism_parser?
|
|
||||||
require_relative "ripper_errors"
|
|
||||||
end
|
|
||||||
require_relative "priority_queue"
|
require_relative "priority_queue"
|
||||||
require_relative "unvisited_lines"
|
require_relative "unvisited_lines"
|
||||||
require_relative "around_block_scan"
|
require_relative "around_block_scan"
|
||||||
|
@ -47,9 +47,9 @@ module SyntaxSuggest
|
|||||||
# ## Heredocs
|
# ## Heredocs
|
||||||
#
|
#
|
||||||
# A heredoc is an way of defining a multi-line string. They can cause many
|
# A heredoc is an way of defining a multi-line string. They can cause many
|
||||||
# problems. If left as a single line, Ripper would try to parse the contents
|
# problems. If left as a single line, the parser would try to parse the contents
|
||||||
# as ruby code rather than as a string. Even without this problem, we still
|
# as ruby code rather than as a string. Even without this problem, we still
|
||||||
# hit an issue with indentation
|
# hit an issue with indentation:
|
||||||
#
|
#
|
||||||
# 1 foo = <<~HEREDOC
|
# 1 foo = <<~HEREDOC
|
||||||
# 2 "Be yourself; everyone else is already taken.""
|
# 2 "Be yourself; everyone else is already taken.""
|
||||||
|
@ -81,7 +81,7 @@ module SyntaxSuggest
|
|||||||
# lines then the result cannot be invalid
|
# lines then the result cannot be invalid
|
||||||
#
|
#
|
||||||
# That means there's no reason to re-check all
|
# That means there's no reason to re-check all
|
||||||
# lines with ripper (which is expensive).
|
# lines with the parser (which is expensive).
|
||||||
# Benchmark in commit message
|
# Benchmark in commit message
|
||||||
@valid = if lines.all? { |l| l.hidden? || l.empty? }
|
@valid = if lines.all? { |l| l.hidden? || l.empty? }
|
||||||
true
|
true
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
require_relative "left_right_lex_count"
|
require_relative "left_right_lex_count"
|
||||||
|
|
||||||
|
if !SyntaxSuggest.use_prism_parser?
|
||||||
|
require_relative "ripper_errors"
|
||||||
|
end
|
||||||
|
|
||||||
module SyntaxSuggest
|
module SyntaxSuggest
|
||||||
class GetParseErrors
|
class GetParseErrors
|
||||||
def self.errors(source)
|
def self.errors(source)
|
||||||
@ -25,8 +29,8 @@ module SyntaxSuggest
|
|||||||
# # => "Unmatched keyword, missing `end' ?"
|
# # => "Unmatched keyword, missing `end' ?"
|
||||||
#
|
#
|
||||||
# When the error cannot be determined by lexical counting
|
# When the error cannot be determined by lexical counting
|
||||||
# then ripper is run against the input and the raw ripper
|
# then the parser is run against the input and the raw
|
||||||
# errors returned.
|
# errors are returned.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
@ -101,7 +105,7 @@ module SyntaxSuggest
|
|||||||
# Returns an array of syntax error messages
|
# Returns an array of syntax error messages
|
||||||
#
|
#
|
||||||
# If no missing pairs are found it falls back
|
# If no missing pairs are found it falls back
|
||||||
# on the original ripper error messages
|
# on the original error messages
|
||||||
def errors
|
def errors
|
||||||
if missing.empty?
|
if missing.empty?
|
||||||
return GetParseErrors.errors(@code_lines.map(&:original).join)
|
return GetParseErrors.errors(@code_lines.map(&:original).join)
|
||||||
|
@ -3,10 +3,18 @@
|
|||||||
module SyntaxSuggest
|
module SyntaxSuggest
|
||||||
# Ripper.lex is not guaranteed to lex the entire source document
|
# Ripper.lex is not guaranteed to lex the entire source document
|
||||||
#
|
#
|
||||||
# lex = LexAll.new(source: source)
|
# This class guarantees the whole document is lex-ed by iteratively
|
||||||
# lex.each do |value|
|
# lexing the document where ripper stopped.
|
||||||
# puts value.line
|
#
|
||||||
# end
|
# Prism likely doesn't have the same problem. Once ripper support is removed
|
||||||
|
# we can likely reduce the complexity here if not remove the whole concept.
|
||||||
|
#
|
||||||
|
# Example usage:
|
||||||
|
#
|
||||||
|
# lex = LexAll.new(source: source)
|
||||||
|
# lex.each do |value|
|
||||||
|
# puts value.line
|
||||||
|
# end
|
||||||
class LexAll
|
class LexAll
|
||||||
include Enumerable
|
include Enumerable
|
||||||
|
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module SyntaxSuggest
|
module SyntaxSuggest
|
||||||
# Capture parse errors from ripper
|
# Capture parse errors from Ripper
|
||||||
|
#
|
||||||
|
# Prism returns the errors with their messages, but Ripper
|
||||||
|
# does not. To get them we must make a custom subclass.
|
||||||
#
|
#
|
||||||
# Example:
|
# Example:
|
||||||
#
|
#
|
||||||
|
@ -17,9 +17,6 @@ module SyntaxSuggest
|
|||||||
end # 9
|
end # 9
|
||||||
EOM
|
EOM
|
||||||
|
|
||||||
# raw_lex = Ripper.lex(source)
|
|
||||||
# expect(raw_lex.to_s).to_not include("dog")
|
|
||||||
|
|
||||||
lex = LexAll.new(source: source)
|
lex = LexAll.new(source: source)
|
||||||
expect(lex.map(&:token).to_s).to include("dog")
|
expect(lex.map(&:token).to_s).to include("dog")
|
||||||
expect(lex.first.line).to eq(1)
|
expect(lex.first.line).to eq(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user