Class: Steep::AST::Ignore::BufferScanner

Inherits:
Object
  • Object
show all
Defined in:
lib/steep/ast/ignore.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ BufferScanner

Returns a new instance of BufferScanner.



7
8
9
10
11
# File 'lib/steep/ast/ignore.rb', line 7

def initialize(location)
  @location = location

  @scanner = StringScanner.new(location.source)
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/steep/ast/ignore.rb', line 5

def location
  @location
end

#scannerObject (readonly)

Returns the value of attribute scanner.



5
6
7
# File 'lib/steep/ast/ignore.rb', line 5

def scanner
  @scanner
end

Instance Method Details

#charposObject



17
18
19
# File 'lib/steep/ast/ignore.rb', line 17

def charpos
  scanner.charpos + offset
end

#eos?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/steep/ast/ignore.rb', line 33

def eos?
  scanner.eos?
end

#offsetObject



13
14
15
# File 'lib/steep/ast/ignore.rb', line 13

def offset
  @location.start_pos
end

#scan(regexp) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/steep/ast/ignore.rb', line 21

def scan(regexp)
  if matched = scanner.scan(regexp)
    end_pos = charpos()
    begin_pos = end_pos - matched.size
    RBS::Location.new(location.buffer, begin_pos, end_pos)
  end
end

#skip(regexp) ⇒ Object



29
30
31
# File 'lib/steep/ast/ignore.rb', line 29

def skip(regexp)
  scanner.skip(regexp)
end