Class: Mdlint::Parser::State
- Inherits:
-
Object
- Object
- Mdlint::Parser::State
- Defined in:
- lib/mdlint/parser/state.rb,
sig/internal.rbs
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#line ⇒ Object
Returns the value of attribute line.
-
#line_offsets ⇒ Object
readonly
Returns the value of attribute line_offsets.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#pos ⇒ Object
Returns the value of attribute pos.
-
#raw_lines ⇒ Object
readonly
Returns the value of attribute raw_lines.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
-
#tokens ⇒ Object
Returns the value of attribute tokens.
Instance Method Summary collapse
- #blank_line?(line_num = @line) ⇒ Boolean
- #build_line_offsets ⇒ Object
- #current_line ⇒ Object
- #eof? ⇒ Boolean
- #expand_tabs(line) ⇒ String
-
#initialize(src) ⇒ State
constructor
A new instance of State.
- #next_line ⇒ Object
- #peek_line(offset = 1) ⇒ Object
- #raw_line ⇒ Object
- #remaining_lines ⇒ Object
- #skip_blank_lines ⇒ Object
Constructor Details
#initialize(src) ⇒ State
Returns a new instance of State.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mdlint/parser/state.rb', line 9 def initialize(src) @src = src @raw_lines = src.split("\n", -1) @lines = @raw_lines.map { |line| (line) } @line_offsets = build_line_offsets @line = 0 @pos = 0 @tokens = [] @level = 0 end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
7 8 9 |
# File 'lib/mdlint/parser/state.rb', line 7 def level @level end |
#line ⇒ Object
Returns the value of attribute line.
7 8 9 |
# File 'lib/mdlint/parser/state.rb', line 7 def line @line end |
#line_offsets ⇒ Object (readonly)
Returns the value of attribute line_offsets.
6 7 8 |
# File 'lib/mdlint/parser/state.rb', line 6 def line_offsets @line_offsets end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
6 7 8 |
# File 'lib/mdlint/parser/state.rb', line 6 def lines @lines end |
#pos ⇒ Object
Returns the value of attribute pos.
7 8 9 |
# File 'lib/mdlint/parser/state.rb', line 7 def pos @pos end |
#raw_lines ⇒ Object (readonly)
Returns the value of attribute raw_lines.
6 7 8 |
# File 'lib/mdlint/parser/state.rb', line 6 def raw_lines @raw_lines end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
6 7 8 |
# File 'lib/mdlint/parser/state.rb', line 6 def src @src end |
#tokens ⇒ Object
Returns the value of attribute tokens.
7 8 9 |
# File 'lib/mdlint/parser/state.rb', line 7 def tokens @tokens end |
Instance Method Details
#blank_line?(line_num = @line) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/mdlint/parser/state.rb', line 42 def blank_line?(line_num = @line) return true if line_num >= @lines.length @lines[line_num].match?(/\A\s*\z/) end |
#build_line_offsets ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/mdlint/parser/state.rb', line 72 def build_line_offsets offsets = [0] @lines.each do |line| offsets << offsets.last + line.length + 1 end offsets end |
#current_line ⇒ Object
24 25 26 |
# File 'lib/mdlint/parser/state.rb', line 24 def current_line @lines[@line] end |
#eof? ⇒ Boolean
20 21 22 |
# File 'lib/mdlint/parser/state.rb', line 20 def eof? @line >= @lines.length end |
#expand_tabs(line) ⇒ String
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mdlint/parser/state.rb', line 58 def (line) column = 0 line.each_char.with_object(+'') do |character, | if character == "\t" spaces = 4 - (column % 4) << (" " * spaces) column += spaces else << character column += 1 end end end |
#next_line ⇒ Object
32 33 34 |
# File 'lib/mdlint/parser/state.rb', line 32 def next_line @line += 1 end |
#peek_line(offset = 1) ⇒ Object
52 53 54 |
# File 'lib/mdlint/parser/state.rb', line 52 def peek_line(offset = 1) @lines[@line + offset] end |
#raw_line ⇒ Object
28 29 30 |
# File 'lib/mdlint/parser/state.rb', line 28 def raw_line @raw_lines[@line] end |
#remaining_lines ⇒ Object
48 49 50 |
# File 'lib/mdlint/parser/state.rb', line 48 def remaining_lines @lines[@line..] end |
#skip_blank_lines ⇒ Object
36 37 38 39 40 |
# File 'lib/mdlint/parser/state.rb', line 36 def skip_blank_lines while !eof? && blank_line?(@line) @line += 1 end end |