class Crass::TokenScanner
Like {Scanner}, but for tokens!
Attributes
current[R]
pos[R]
tokens[R]
Public Class Methods
new(tokens)
click to toggle source
# File lib/crass/token-scanner.rb, line 9 def initialize(tokens) @tokens = tokens.to_a reset end
Public Instance Methods
collect() { || ... }
click to toggle source
Executes the given block, collects all tokens that are consumed during its execution, and returns them.
# File lib/crass/token-scanner.rb, line 16 def collect start = @pos yield @tokens[start...@pos] || [] end
consume()
click to toggle source
Consumes the next token and returns it, advancing the pointer. Returns `nil` if there is no next token.
# File lib/crass/token-scanner.rb, line 24 def consume @current = @tokens[@pos] @pos += 1 if @current @current end
peek()
click to toggle source
Returns the next token without consuming it, or `nil` if there is no next token.
# File lib/crass/token-scanner.rb, line 32 def peek @tokens[@pos] end
reconsume()
click to toggle source
Reconsumes the current token, moving the pointer back one position.
www.w3.org/TR/2013/WD-css-syntax-3-20130919/#reconsume-the-current-input-token
# File lib/crass/token-scanner.rb, line 39 def reconsume @pos -= 1 if @pos > 0 end
reset()
click to toggle source
Resets the pointer to the first token in the list.
# File lib/crass/token-scanner.rb, line 44 def reset @current = nil @pos = 0 end