Class: Racc::Rule

Inherits:
Object show all
Defined in:
lib/racc/grammar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, syms, act) ⇒ Rule

Returns a new instance of Rule.



606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/racc/grammar.rb', line 606

def initialize(target, syms, act)
  @target = target
  @symbols = syms
  @action = act
  @alternatives = []

  @ident = nil
  @hash = nil
  @ptrs = nil
  @precedence = nil
  @specified_prec = nil
  @null = nil
  @useless = nil
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



623
624
625
# File 'lib/racc/grammar.rb', line 623

def action
  @action
end

#hashObject

Returns the value of attribute hash.



641
642
643
# File 'lib/racc/grammar.rb', line 641

def hash
  @hash
end

#identObject

Returns the value of attribute ident.



639
640
641
# File 'lib/racc/grammar.rb', line 639

def ident
  @ident
end

#ptrsObject (readonly)

Returns the value of attribute ptrs.



642
643
644
# File 'lib/racc/grammar.rb', line 642

def ptrs
  @ptrs
end

#specified_precObject

Returns the value of attribute specified_prec.



673
674
675
# File 'lib/racc/grammar.rb', line 673

def specified_prec
  @specified_prec
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



622
623
624
# File 'lib/racc/grammar.rb', line 622

def symbols
  @symbols
end

#targetObject

Returns the value of attribute target.



621
622
623
# File 'lib/racc/grammar.rb', line 621

def target
  @target
end

Instance Method Details

#==(other) ⇒ Object



685
686
687
# File 'lib/racc/grammar.rb', line 685

def ==(other)
  other.kind_of?(Rule) and @ident == other.ident
end

#[](idx) ⇒ Object



689
690
691
# File 'lib/racc/grammar.rb', line 689

def [](idx)
  @symbols[idx]
end

#accept?Boolean

Returns:

  • (Boolean)


705
706
707
708
709
710
711
# File 'lib/racc/grammar.rb', line 705

def accept?
  if tok = @symbols[-1]
    tok.anchor?
  else
    false
  end
end

#each(&block) ⇒ Object



713
714
715
# File 'lib/racc/grammar.rb', line 713

def each(&block)
  @symbols.each(&block)
end

#each_rule {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Racc::Rule)

    the object that the method was called on



634
635
636
637
# File 'lib/racc/grammar.rb', line 634

def each_rule(&block)
  yield self
  @alternatives.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


697
698
699
# File 'lib/racc/grammar.rb', line 697

def empty?
  @symbols.empty?
end

#inspectObject



681
682
683
# File 'lib/racc/grammar.rb', line 681

def inspect
  "#<Racc::Rule id=#{@ident} (#{@target})>"
end

#null=(n) ⇒ Object



676
# File 'lib/racc/grammar.rb', line 676

def null=(n)    @null = n end

#nullable?Boolean

Returns:

  • (Boolean)


675
# File 'lib/racc/grammar.rb', line 675

def nullable?() @null end

#prec(sym, &block) ⇒ Object



662
663
664
665
666
667
668
669
670
671
# File 'lib/racc/grammar.rb', line 662

def prec(sym, &block)
  @specified_prec = sym
  if block
    unless @action.empty?
      raise CompileError, 'both of rule action block and prec block given'
    end
    @action = UserAction.proc(block)
  end
  self
end

#precedenceObject



654
655
656
# File 'lib/racc/grammar.rb', line 654

def precedence
  @specified_prec || @precedence
end

#precedence=(sym) ⇒ Object



658
659
660
# File 'lib/racc/grammar.rb', line 658

def precedence=(sym)
  @precedence ||= sym
end

#replace(src, dest) ⇒ Object



717
718
719
720
# File 'lib/racc/grammar.rb', line 717

def replace(src, dest)
  @target = dest
  @symbols = @symbols.map {|s| s == src ? dest : s }
end

#ruleObject



630
631
632
# File 'lib/racc/grammar.rb', line 630

def rule
  self
end

#sizeObject



693
694
695
# File 'lib/racc/grammar.rb', line 693

def size
  @symbols.size
end

#to_sObject



701
702
703
# File 'lib/racc/grammar.rb', line 701

def to_s
  "#<rule#{@ident}>"
end

#useless=(u) ⇒ Object



679
# File 'lib/racc/grammar.rb', line 679

def useless=(u) @useless = u end

#useless?Boolean

Returns:

  • (Boolean)


678
# File 'lib/racc/grammar.rb', line 678

def useless?()  @useless end

#|(x) ⇒ Object



625
626
627
628
# File 'lib/racc/grammar.rb', line 625

def |(x)
  @alternatives.push x.rule
  self
end