Class: Gem::RequestSet::Lockfile::Tokenizer
- Inherits:
-
Object
- Object
- Gem::RequestSet::Lockfile::Tokenizer
- Defined in:
- lib/rubygems/request_set/lockfile/tokenizer.rb
Defined Under Namespace
Classes: Token
Constant Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(input, filename = nil, line = 0, pos = 0) ⇒ Tokenizer
constructor
A new instance of Tokenizer.
- #make_parser(set, platforms) ⇒ Object
- #next_token ⇒ Object (also: #shift)
- #peek ⇒ Object
- #skip(type) ⇒ Object
- #to_a ⇒ Object
-
#token_pos(byte_offset) ⇒ Object
Calculates the column (by byte) and the line of the current token based on
byte_offset
. - #unshift(token) ⇒ Object
Constructor Details
#initialize(input, filename = nil, line = 0, pos = 0) ⇒ Tokenizer
Returns a new instance of Tokenizer.
13 14 15 16 17 18 19 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 13 def initialize(input, filename = nil, line = 0, pos = 0) @line = line @line_pos = pos @tokens = [] @filename = filename tokenize input end |
Class Method Details
.from_file(file) ⇒ Object
9 10 11 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 9 def self.from_file(file) new File.read(file), file end |
Instance Method Details
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 41 def empty? @tokens.empty? end |
#make_parser(set, platforms) ⇒ Object
21 22 23 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 21 def make_parser(set, platforms) Gem::RequestSet::Lockfile::Parser.new self, set, platforms, @filename end |
#next_token ⇒ Object Also known as: shift
49 50 51 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 49 def next_token @tokens.shift end |
#peek ⇒ Object
54 55 56 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 54 def peek @tokens.first || EOF end |
#skip(type) ⇒ Object
29 30 31 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 29 def skip(type) @tokens.shift while not @tokens.empty? and peek.type == type end |
#to_a ⇒ Object
25 26 27 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 25 def to_a @tokens.map { |token| [token.type, token.value, token.column, token.line] } end |
#token_pos(byte_offset) ⇒ Object
Calculates the column (by byte) and the line of the current token based on byte_offset
.
37 38 39 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 37 def token_pos(byte_offset) # :nodoc: [byte_offset - @line_pos, @line] end |
#unshift(token) ⇒ Object
45 46 47 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 45 def unshift(token) @tokens.unshift token end |