Class: Catfriend::FileTokenStack

Inherits:
Object
  • Object
show all
Defined in:
lib/catfriend/filetokenstack.rb

Overview

Adapt a file to a stack of tokens.

Instance Method Summary collapse

Constructor Details

#initialize(file, token_match = /\S+/, comment_match = /#.*/) ⇒ FileTokenStack

Initialize the token stack with the path of the file, the given token match and comment skipping regexs.



7
8
9
10
11
12
13
# File 'lib/catfriend/filetokenstack.rb', line 7

def initialize file, token_match = /\S+/, comment_match = /#.*/
  @token_match   = token_match
  @comment_match = comment_match
  @stream = File.new file, "r"
  @tokens = []
  get_next_tokens
end

Instance Method Details

#empty?Boolean

Report if any tokens remain

Returns:

  • (Boolean)


34
35
36
# File 'lib/catfriend/filetokenstack.rb', line 34

def empty?
  @stream.eof and @tokens.empty?
end

#shiftObject

Shift the next token from the current stream position.



27
28
29
30
31
# File 'lib/catfriend/filetokenstack.rb', line 27

def shift
  ret = @tokens.shift
  get_next_tokens
  ret
end