Class: Fabulator::Grammar::Expr::RuleRef

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator/grammar/expr/rule_ref.rb

Instance Method Summary collapse

Constructor Details

#initialize(qname) ⇒ RuleRef

Returns a new instance of RuleRef.



3
4
5
6
7
8
9
10
11
# File 'lib/fabulator/grammar/expr/rule_ref.rb', line 3

def initialize(qname)
  bits = qname.split(/:/,2)
  if bits.size > 1
    @ns_prefix = bits[0]
    @name = bits[1]
  else
    @name = qname
  end
end

Instance Method Details

#nameObject



13
14
15
# File 'lib/fabulator/grammar/expr/rule_ref.rb', line 13

def name
  @name
end

#parse(cursor) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/fabulator/grammar/expr/rule_ref.rb', line 17

def parse(cursor)
  rule = cursor.find_rule(@name)
  raise Fabulator::Grammar::RejectParse if rule.nil?
  # we have @name as the path prefix for this part?
  ret = cursor.attempt { |c| rule.parse(c) }

  raise Fabulator::Grammar::RejectParse if ret.nil?

  cursor.set_result(ret)
end