Class: Habaki::FormalSyntax::Matcher
- Inherits:
-
Object
- Object
- Habaki::FormalSyntax::Matcher
- Defined in:
- lib/habaki/formal_syntax.rb
Overview
formal syntax matcher
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
- #matches ⇒ Array<Match>
Instance Method Summary collapse
-
#initialize(declaration, tree = Tree.tree) ⇒ Matcher
constructor
A new instance of Matcher.
- #match ⇒ Boolean
- #match? ⇒ Boolean
Constructor Details
#initialize(declaration, tree = Tree.tree) ⇒ Matcher
Returns a new instance of Matcher.
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
#debug ⇒ Object
Returns the value of attribute debug.
259 260 261 |
# File 'lib/habaki/formal_syntax.rb', line 259 def debug @debug end |
#matches ⇒ Array<Match>
258 259 260 |
# File 'lib/habaki/formal_syntax.rb', line 258 def matches @matches end |
Instance Method Details
#match ⇒ 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
293 294 295 |
# File 'lib/habaki/formal_syntax.rb', line 293 def match? @match ||= match end |