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
9 10 11 12 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 9 def initialize #: void @line_comments = {} @trailing_comments = {} end |
Instance Attribute Details
#line_comments ⇒ Object (readonly)
: Hash[Integer, String]
6 7 8 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 6 def line_comments @line_comments end |
#trailing_comments ⇒ Object (readonly)
: Hash[Integer, String]
7 8 9 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 7 def trailing_comments @trailing_comments end |
Instance Method Details
#parse(string) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rbs_activesupport/parser/comment_parser.rb', line 15 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 |