Class: RemLint::LogicalLine
- Inherits:
-
Struct
- Object
- Struct
- RemLint::LogicalLine
- Defined in:
- lib/remlint/logical_line.rb
Overview
One Remind command, after backslash continuations have been joined.
text is byte-for-byte what Remind's own LineBuffer would hold: each
continuing backslash replaced by a newline and the following line appended
verbatim (src/files.c ReadLineFromFile). Keeping the newline rather than
collapsing to a space costs nothing -- Remind's tokeniser treats it as
whitespace either way -- and buys exact column arithmetic, because every
character of every continued line still sits where it sat in the file.
line is the physical line the command starts on, in the enclosing file;
physical_lines lists every line it spans; raw keeps the untouched bytes,
because the whitespace rules care about what the join threw away.
Instance Attribute Summary collapse
-
#line ⇒ Object
Returns the value of attribute line.
-
#physical_lines ⇒ Object
Returns the value of attribute physical_lines.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #continued? ⇒ Boolean
- #last_line ⇒ Object
-
#position_at(offset) ⇒ Object
Map a character offset in
textback to a physical [line, column] in the file. -
#squashed ⇒ Object
The command on one line, for a message or for a rule that would rather not think about continuations at all.
Instance Attribute Details
#line ⇒ Object
Returns the value of attribute line
18 19 20 |
# File 'lib/remlint/logical_line.rb', line 18 def line @line end |
#physical_lines ⇒ Object
Returns the value of attribute physical_lines
18 19 20 |
# File 'lib/remlint/logical_line.rb', line 18 def physical_lines @physical_lines end |
#raw ⇒ Object
Returns the value of attribute raw
18 19 20 |
# File 'lib/remlint/logical_line.rb', line 18 def raw @raw end |
#text ⇒ Object
Returns the value of attribute text
18 19 20 |
# File 'lib/remlint/logical_line.rb', line 18 def text @text end |
Instance Method Details
#continued? ⇒ Boolean
25 26 27 |
# File 'lib/remlint/logical_line.rb', line 25 def continued? physical_lines.length > 1 end |
#last_line ⇒ Object
29 30 31 |
# File 'lib/remlint/logical_line.rb', line 29 def last_line physical_lines.last end |
#position_at(offset) ⇒ Object
Map a character offset in text back to a physical [line, column] in the
file. Column is 1-based, so position_at(0) is the first column of the
line the command starts on.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/remlint/logical_line.rb', line 42 def position_at(offset) before = text[0, offset].to_s crossed = before.count("\n") last_break = before.rindex("\n") if last_break column = offset - last_break else column = offset + 1 end [physical_lines.fetch(crossed, last_line), column] end |
#squashed ⇒ Object
The command on one line, for a message or for a rule that would rather not think about continuations at all.
35 36 37 |
# File 'lib/remlint/logical_line.rb', line 35 def squashed text.tr("\n", " ") end |