Class: Namarara::Parser

Inherits:
Rly::Yacc
  • Object
show all
Defined in:
lib/namarara/parser.rb

Overview

Cut HERE 8< —- 8< —- …

Defined Under Namespace

Classes: MissingNamesError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Parser

Initialize names hash



188
189
190
191
# File 'lib/namarara/parser.rb', line 188

def initialize(*args)
  @names = nil
  super(*args)
end

Instance Attribute Details

#names=(value) ⇒ Object (writeonly)

Sets the attribute names

Parameters:

  • value

    the value to set the attribute names to.



185
186
187
# File 'lib/namarara/parser.rb', line 185

def names=(value)
  @names = value
end

Instance Method Details

#check_grammar(line, tokens) ⇒ Object

Check if grammar is valid



201
202
203
204
205
206
207
208
209
210
# File 'lib/namarara/parser.rb', line 201

def check_grammar(line, tokens)
  grammar = tokens.to_s.split(/=|AND|OR/)
  expr = line.split(/=|AND|OR/)
  return if grammar.size == expr.size
  return if grammar.empty?

  tokens.errors << Errors::InvalidGrammar.new(
    message: 'Invalid Grammar'
  )
end

#parse(str) ⇒ Object

Make sure names are filled in

Raises:



194
195
196
197
198
# File 'lib/namarara/parser.rb', line 194

def parse(str)
  raise MissingNamesError if @names.nil?

  super(str)
end