Class: Catfriend::FileTokenStack
- Inherits:
-
Object
- Object
- Catfriend::FileTokenStack
- Defined in:
- lib/catfriend/filetokenstack.rb
Overview
Adapt a file to a stack of tokens.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Report if any tokens remain.
-
#initialize(file, token_match = /\S+/, comment_match = /#.*/) ⇒ FileTokenStack
constructor
Initialize the token stack with the path of the file, the given token match and comment skipping regexs.
-
#shift ⇒ Object
Shift the next token from the current stream position.
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
34 35 36 |
# File 'lib/catfriend/filetokenstack.rb', line 34 def empty? @stream.eof and @tokens.empty? end |
#shift ⇒ Object
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 |