Class: Solargraph::Parser::CommentRipper
- Inherits:
-
Ripper::SexpBuilderPP
- Object
- Ripper::SexpBuilderPP
- Solargraph::Parser::CommentRipper
- Defined in:
- lib/solargraph/parser/comment_ripper.rb
Instance Method Summary collapse
- #create_snippet(result) ⇒ void
-
#initialize(src, filename = '(ripper)', lineno = 0) ⇒ CommentRipper
constructor
A new instance of CommentRipper.
- #on_comment(*args) ⇒ Object
- #on_embdoc(*args) ⇒ Object
- #on_embdoc_beg(*args) ⇒ Object
- #on_embdoc_end(*args) ⇒ Object
- #parse ⇒ Hash{Integer => String}
Constructor Details
#initialize(src, filename = '(ripper)', lineno = 0) ⇒ CommentRipper
Returns a new instance of CommentRipper.
9 10 11 12 13 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 9 def initialize src, filename = '(ripper)', lineno = 0 super @buffer = src @buffer_lines = @buffer.lines end |
Instance Method Details
#create_snippet(result) ⇒ void
This method returns an undefined value.
31 32 33 34 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 31 def create_snippet(result) chomped = result[1].chomp @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0] || 0, result[2][1] || 0, result[2][0] || 0, (result[2][1] || 0) + chomped.length), chomped) end |
#on_comment(*args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 15 def on_comment *args # @sg-ignore # @type [Array(Symbol, String, Array([Integer, nil], [Integer, nil]))] result = super if @buffer_lines[result[2][0]][0..result[2][1]].strip =~ /^#/ chomped = result[1].chomp if result[2][0] == 0 && chomped.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').match(/^#\s*frozen_string_literal:/) chomped = '#' end @comments[result[2][0]] = Snippet.new(Range.from_to(result[2][0], result[2][1], result[2][0], result[2][1] + chomped.length), chomped) end result end |
#on_embdoc(*args) ⇒ Object
42 43 44 45 46 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 42 def on_embdoc *args result = super create_snippet(result) result end |
#on_embdoc_beg(*args) ⇒ Object
36 37 38 39 40 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 36 def on_embdoc_beg *args result = super create_snippet(result) result end |
#on_embdoc_end(*args) ⇒ Object
48 49 50 51 52 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 48 def on_embdoc_end *args result = super create_snippet(result) result end |
#parse ⇒ Hash{Integer => String}
55 56 57 58 59 |
# File 'lib/solargraph/parser/comment_ripper.rb', line 55 def parse @comments = {} super @comments end |