Class: 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.
12 13 14 15 16 17 18 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 12 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
8 9 10 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 8 def self.from_file(file) new File.read(file), file end |
Instance Method Details
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 40 def empty? @tokens.empty? end |
#make_parser(set, platforms) ⇒ Object
20 21 22 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 20 def make_parser(set, platforms) Gem::RequestSet::Lockfile::Parser.new self, set, platforms, @filename end |
#next_token ⇒ Object Also known as: shift
48 49 50 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 48 def next_token @tokens.shift end |
#peek ⇒ Object
53 54 55 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 53 def peek @tokens.first || EOF end |
#skip(type) ⇒ Object
28 29 30 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 28 def skip(type) @tokens.shift while not @tokens.empty? and peek.type == type end |
#to_a ⇒ Object
24 25 26 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 24 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
.
36 37 38 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 36 def token_pos(byte_offset) # :nodoc: [byte_offset - @line_pos, @line] end |
#unshift(token) ⇒ Object
44 45 46 |
# File 'lib/rubygems/request_set/lockfile/tokenizer.rb', line 44 def unshift(token) @tokens.unshift token end |