Class: RemLint::LogicalLine

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



18
19
20
# File 'lib/remlint/logical_line.rb', line 18

def line
  @line
end

#physical_linesObject

Returns the value of attribute physical_lines

Returns:

  • (Object)

    the current value of physical_lines



18
19
20
# File 'lib/remlint/logical_line.rb', line 18

def physical_lines
  @physical_lines
end

#rawObject

Returns the value of attribute raw

Returns:

  • (Object)

    the current value of raw



18
19
20
# File 'lib/remlint/logical_line.rb', line 18

def raw
  @raw
end

#textObject

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



18
19
20
# File 'lib/remlint/logical_line.rb', line 18

def text
  @text
end

Instance Method Details

#continued?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/remlint/logical_line.rb', line 25

def continued?
  physical_lines.length > 1
end

#last_lineObject



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

#squashedObject

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