Class: Sexpr::Matcher::Reference

Inherits:
Object
  • Object
show all
Includes:
Sexpr::Matcher
Defined in:
lib/sexpr/matcher/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sexpr::Matcher

#===

Constructor Details

#initialize(rule_name, grammar) ⇒ Reference

Returns a new instance of Reference.



9
10
11
12
# File 'lib/sexpr/matcher/reference.rb', line 9

def initialize(rule_name, grammar)
  @rule_name = rule_name
  @grammar   = grammar
end

Instance Attribute Details

#grammarObject (readonly)

Returns the value of attribute grammar.



7
8
9
# File 'lib/sexpr/matcher/reference.rb', line 7

def grammar
  @grammar
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



6
7
8
# File 'lib/sexpr/matcher/reference.rb', line 6

def rule_name
  @rule_name
end

Instance Method Details

#eat(sexp) ⇒ Object



22
23
24
# File 'lib/sexpr/matcher/reference.rb', line 22

def eat(sexp)
  rule && rule.eat(sexp)
end

#inspectObject



26
27
28
# File 'lib/sexpr/matcher/reference.rb', line 26

def inspect
  "(ref #{rule_name}, #{rule.inspect})"
end

#match?(sexp) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sexpr/matcher/reference.rb', line 18

def match?(sexp)
  rule && rule.match?(sexp)
end

#ruleObject



14
15
16
# File 'lib/sexpr/matcher/reference.rb', line 14

def rule
  @rule ||= @grammar[@rule_name]
end