Class: Habaki::FormalSyntax::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/habaki/formal_syntax.rb

Overview

formal syntax matcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(declaration, tree = Tree.tree) ⇒ Matcher

Returns a new instance of Matcher.

Parameters:



262
263
264
265
266
267
268
269
# File 'lib/habaki/formal_syntax.rb', line 262

def initialize(declaration, tree = Tree.tree)
  @declaration = declaration
  @tree = tree
  @reference = nil
  @matches = []
  @debug = false
  @match = nil
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



259
260
261
# File 'lib/habaki/formal_syntax.rb', line 259

def debug
  @debug
end

#matchesArray<Match>

Returns:



258
259
260
# File 'lib/habaki/formal_syntax.rb', line 258

def matches
  @matches
end

Instance Method Details

#matchBoolean

Returns:

  • (Boolean)


272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/habaki/formal_syntax.rb', line 272

def match
  @idx = 0
  node = @tree.properties[@declaration.property]
  return false unless node

  puts "MATCH #{node} (#{node.type}) #{node.occurence} WITH #{@declaration.to_s}" if @debug
  @reference = @declaration.property
  # always add inherit keyword
  return true if @declaration.value == Habaki::Ident.new("inherit")

  res = rec_match(node)
  @matches.compact!
  @matches.each_with_index do |match, idx|
    match.value = @declaration.values[idx]
  end

  puts "MATCH? #{res} #{node.occurence}, #{@idx} / #{count_values}" if @debug
  res && calc_occurence(node).include?(@idx) && @idx >= count_values
end

#match?Boolean

Returns:

  • (Boolean)


293
294
295
# File 'lib/habaki/formal_syntax.rb', line 293

def match?
  @match ||= match
end