Class: ParsingParcels
Overview
This is a collection of parsing aids to be used in other modules
Instance Method Summary collapse
-
#code_lines(input) {|line| ... } ⇒ Object
This parser accepts a collection of lines which it will sweep through and tidy, giving the purified lines to the block (one line at a time) for further analysis.
-
#code_lines_with_num(input) {|line, line_num| ... } ⇒ Object
This parser accepts a collection of lines which it will sweep through and tidy, giving the purified lines to the block (one line at a time) for further analysis along with the line number.
Instance Method Details
#code_lines(input) {|line| ... } ⇒ Object
This parser accepts a collection of lines which it will sweep through and tidy, giving the purified lines to the block (one line at a time) for further analysis. It analyzes a single line at a time, which is far more memory efficient and faster for large files. However, this requires it to also handle backslash line continuations as a single line at this point.
20 21 22 |
# File 'lib/ceedling/parsing_parcels.rb', line 20 def code_lines(input) code_lines_with_num(input) { |line, _line_num| yield(line) } end |
#code_lines_with_num(input) {|line, line_num| ... } ⇒ Object
This parser accepts a collection of lines which it will sweep through and tidy, giving the purified lines to the block (one line at a time) for further analysis along with the line number. It analyzes a single line at a time, which is far more memory efficient and faster for large files. However, this requires it to also handle backslash line continuations as a single line at this point.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ceedling/parsing_parcels.rb', line 35 def code_lines_with_num(input) comment_block = false full_line = '' line_num = 0 continuation_start_line = 0 input.each_line do |line| line_num += 1 m = line.clean_encoding.match /(.*)\\\s*$/ if (!m.nil?) full_line += m[1] continuation_start_line = line_num if full_line == m[1] elsif full_line.empty? _line, comment_block = clean_code_line( line, comment_block ) yield( _line, line_num ) else _line, comment_block = clean_code_line( full_line + line, comment_block ) yield( _line, continuation_start_line ) full_line = '' continuation_start_line = 0 end end end |