Class: LL::SourceLine

Inherits:
Object
  • Object
show all
Defined in:
lib/ll/source_line.rb

Overview

Class containing data of a lexer token’s source line source as the raw data, column, line number, etc.

Constant Summary

DEFAULT_FILE =

Returns:

  • (String)
'(ruby)'

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SourceLine) initialize(data, line = 1, column = 1, file = DEFAULT_FILE)

Returns a new instance of SourceLine

Parameters:

  • data (String)
  • line (Fixnum) (defaults to: 1)
  • column (Fixnum) (defaults to: 1)
  • file (String) (defaults to: DEFAULT_FILE)


20
21
22
23
24
25
# File 'lib/ll/source_line.rb', line 20

def initialize(data, line = 1, column = 1, file = DEFAULT_FILE)
  @file   = file
  @data   = data
  @line   = line
  @column = column
end

Instance Attribute Details

- (Object) column (readonly)

Returns the value of attribute column



7
8
9
# File 'lib/ll/source_line.rb', line 7

def column
  @column
end

- (Object) data (readonly)

Returns the value of attribute data



7
8
9
# File 'lib/ll/source_line.rb', line 7

def data
  @data
end

- (Object) file (readonly)

Returns the value of attribute file



7
8
9
# File 'lib/ll/source_line.rb', line 7

def file
  @file
end

- (Object) line (readonly)

Returns the value of attribute line



7
8
9
# File 'lib/ll/source_line.rb', line 7

def line
  @line
end

Instance Method Details

- (TrueClass|FalseClass) ==(other)

Returns:

  • (TrueClass|FalseClass)


37
38
39
40
41
42
43
44
# File 'lib/ll/source_line.rb', line 37

def ==(other)
  return false unless other.class == self.class

  return file == other.file &&
    data == other.data &&
    line == other.line &&
    column == other.column
end

- (String) source

Returns:

  • (String)


30
31
32
# File 'lib/ll/source_line.rb', line 30

def source
  return data.lines.to_a[line - 1].chomp
end