Class: SexpGrammar::Reference

Inherits:
Object
  • Object
show all
Includes:
Element
Defined in:
lib/sexp_grammar/reference.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Element

#===

Constructor Details

#initialize(rule_name, grammar) ⇒ Reference

Returns a new instance of Reference.



8
9
10
11
# File 'lib/sexp_grammar/reference.rb', line 8

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

Instance Attribute Details

#grammarObject (readonly)

Returns the value of attribute grammar.



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

def grammar
  @grammar
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



5
6
7
# File 'lib/sexp_grammar/reference.rb', line 5

def rule_name
  @rule_name
end

Instance Method Details

#eat(sexp) ⇒ Object



21
22
23
# File 'lib/sexp_grammar/reference.rb', line 21

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

#inspectObject



25
26
27
# File 'lib/sexp_grammar/reference.rb', line 25

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

#match?(sexp) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/sexp_grammar/reference.rb', line 17

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

#ruleObject



13
14
15
# File 'lib/sexp_grammar/reference.rb', line 13

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