Class: AdLint::StringContent

Inherits:
Content
  • Object
show all
Defined in:
lib/adlint/lexer.rb

Overview

DESCRIPTION

Object represents the whole content of the string.

Direct Known Subclasses

SourceContent

Instance Method Summary collapse

Constructor Details

#initialize(str, tab_width = 8, fpath = nil, line_no = 1, column_no = 1) ⇒ StringContent

DESCRIPTION

Constructs the content object of the string.

PARAMETER

str

String – Target string.

fpath

Pathname – File path name contains the target string.

line_no

Integer – Initial line-no of the target string.



84
85
86
87
88
89
# File 'lib/adlint/lexer.rb', line 84

def initialize(str, tab_width = 8, fpath = nil, line_no = 1, column_no = 1)
  @scanner = StringScanner.new(str)
  @tab_width = tab_width
  @fpath, @line_no, @column_no = fpath, line_no, column_no
  @appearance_column_no = column_no
end

Instance Method Details

#_debug_inspectObject



139
140
141
# File 'lib/adlint/lexer.rb', line 139

def _debug_inspect
  @scanner.rest
end

#check(regexp) ⇒ Object



114
115
116
# File 'lib/adlint/lexer.rb', line 114

def check(regexp)
  @scanner.check(regexp)
end

#eat!(len = 1) ⇒ Object

DESCRIPTION

Skips a content.

PARAMETER

len

Integer – Skipping content length.

RETURN VALUE

String – Eaten string.



126
127
128
# File 'lib/adlint/lexer.rb', line 126

def eat!(len = 1)
  self.scan(/.{#{len}}/m)
end

#empty?Boolean

DESCRIPTION

Checks whether this content is currently empty or not.

RETURN VALUE

Boolean – Returns true if already empty.

Returns:

  • (Boolean)


135
136
137
# File 'lib/adlint/lexer.rb', line 135

def empty?
  @scanner.eos?
end

#locationObject



91
92
93
# File 'lib/adlint/lexer.rb', line 91

def location
  Location.new(@fpath, @line_no, @column_no, @appearance_column_no)
end

#scan(regexp) ⇒ Object

DESCRIPTION

Scans a token.

PARAMETER

regexp

Regexp – Token pattern.

RETURN VALUE

String – Token string or nil.



104
105
106
107
108
109
110
111
112
# File 'lib/adlint/lexer.rb', line 104

def scan(regexp)
  tok = @scanner.scan(regexp)
  if tok
    update_location(tok)
    tok
  else
    nil
  end
end