Class: Opulent::Tokens

Inherits:
Object
  • Object
show all
Defined in:
lib/opulent/tokens.rb

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object

Return the requested token to the parser

Parameters:

  • name (Symbol)

    Token requested by the parser accept method



163
164
165
# File 'lib/opulent/tokens.rb', line 163

def self.[](name)
  @tokens[name]
end

.[]=(name, token) ⇒ Object

Set a new token at runtime

Parameters:

  • name (Symboidentifierl)

    Identifier for the token

  • token (Token)

    Token data to be set



172
173
174
# File 'lib/opulent/tokens.rb', line 172

def self.[]=(name, token)
  @tokens[name] = token
end

.bracket(bracket) ⇒ Object

Return the matching closing bracket

Parameters:

  • bracket (String)

    Opening bracket for the capture group



150
151
152
153
154
155
156
157
# File 'lib/opulent/tokens.rb', line 150

def self.bracket(bracket)
  case bracket
  when '(' then return ')'
  when '[' then return ']'
  when '{' then return '}'
  when '<' then return '>'
  end
end