class Crass::TokenScanner
Like {Scanner}, but for tokens!
Attributes
Public Class Methods
Source
# File lib/crass/token-scanner.rb, line 9 def initialize(tokens) @tokens = tokens.to_a reset end
Public Instance Methods
Source
# File lib/crass/token-scanner.rb, line 16 def collect start = @pos yield @tokens[start...@pos] || [] end
Executes the given block, collects all tokens that are consumed during its execution, and returns them.
Source
# File lib/crass/token-scanner.rb, line 24 def consume @current = @tokens[@pos] @pos += 1 if @current @current end
Consumes the next token and returns it, advancing the pointer. Returns ‘nil` if there is no next token.
Source
# File lib/crass/token-scanner.rb, line 32 def peek @tokens[@pos] end
Returns the next token without consuming it, or ‘nil` if there is no next token.
Source
# File lib/crass/token-scanner.rb, line 39 def reconsume @pos -= 1 if @pos > 0 end
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
Source
# File lib/crass/token-scanner.rb, line 44 def reset @current = nil @pos = 0 end
Resets the pointer to the first token in the list.