Class: RbsActivesupport::Parser::CommentParser
- Inherits:
-
Object
- Object
- RbsActivesupport::Parser::CommentParser
- Defined in:
- lib/rbs_activesupport/parser/comment_parser.rb
Instance Attribute Summary collapse
-
#line_comments ⇒ Object
readonly
: Hash[Integer, String].
-
#trailing_comments ⇒ Object
readonly
: Hash[Integer, String].
Instance Method Summary collapse
-
#initialize ⇒ CommentParser
constructor
: void.
- #parse(string) ⇒ Object
Constructor Details
#initialize ⇒ CommentParser
: void
11 12 13 14 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 11 def initialize #: void @line_comments = {} @trailing_comments = {} end |
Instance Attribute Details
#line_comments ⇒ Object (readonly)
: Hash[Integer, String]
8 9 10 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 8 def line_comments @line_comments end |
#trailing_comments ⇒ Object (readonly)
: Hash[Integer, String]
9 10 11 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 9 def trailing_comments @trailing_comments end |
Instance Method Details
#parse(string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 17 def parse(string) #: self # @type var code_lines: Hash[Integer, bool] code_lines = {} Ripper.lex(string).each do |(line, _), type, token, _| case type when :on_sp, :on_ignored_nl # ignore when :on_comment if code_lines[line] trailing_comments[line] = token.chomp else line_comments[line] = token.chomp end :here else code_lines[line] = true end end self end |