Class: Racc::Rule
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/racc/grammar.rb |
Class Method Summary
- .new(target, syms, act) ⇒ Rule constructor
Instance Attribute Summary
- #accept? ⇒ Boolean readonly
- #action readonly
- #empty? ⇒ Boolean readonly
- #hash rw
- #hash=(n) rw
- #ident rw
- #null=(n) writeonly
- #precedence rw
- #precedence=(sym) rw
- #ptrs readonly
- #specified_prec rw
- #symbols readonly
- #target rw
- #useless=(u) writeonly
Instance Method Summary
Constructor Details
.new(target, syms, act) ⇒ Rule
Instance Attribute Details
#accept? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/racc/grammar.rb', line 707
def accept? if tok = @symbols[-1] tok.anchor? else false end end
#action (readonly)
[ GitHub ]# File 'lib/racc/grammar.rb', line 625
attr_reader :action
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'lib/racc/grammar.rb', line 699
def empty? @symbols.empty? end
#hash (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 643
attr_reader :hash
#hash=(n) (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 646
def hash=(n) @hash = n ptrs = [] @symbols.each_with_index do |sym, idx| ptrs.push LocationPointer.new(self, idx, sym) end ptrs.push LocationPointer.new(self, @symbols.size, nil) @ptrs = ptrs end
#ident (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 641
attr_accessor :ident
#null=(n) (writeonly)
[ GitHub ]# File 'lib/racc/grammar.rb', line 678
def null=(n) @null = n end
#precedence (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 656
def precedence @specified_prec || @precedence end
#precedence=(sym) (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 660
def precedence=(sym) @precedence ||= sym end
#ptrs (readonly)
[ GitHub ]# File 'lib/racc/grammar.rb', line 644
attr_reader :ptrs
#specified_prec (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 675
attr_accessor :specified_prec
#symbols (readonly)
[ GitHub ]# File 'lib/racc/grammar.rb', line 624
attr_reader :symbols
#target (rw)
[ GitHub ]# File 'lib/racc/grammar.rb', line 623
attr_accessor :target
#useless=(u) (writeonly)
[ GitHub ]# File 'lib/racc/grammar.rb', line 681
def useless=(u) @useless = u end
Instance Method Details
#==(other)
[ GitHub ]# File 'lib/racc/grammar.rb', line 687
def ==(other) other.kind_of?(Rule) and @ident == other.ident end
#[](idx)
[ GitHub ]# File 'lib/racc/grammar.rb', line 691
def [](idx) @symbols[idx] end
#each(&block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 715
def each(&block) @symbols.each(&block) end
#each_rule {|_self| ... }
# File 'lib/racc/grammar.rb', line 636
def each_rule(&block) yield self @alternatives.each(&block) end
#inspect
[ GitHub ]# File 'lib/racc/grammar.rb', line 683
def inspect "#<Racc::Rule id=#{@ident} (#{@target})>" end
#nullable? ⇒ Boolean
# File 'lib/racc/grammar.rb', line 677
def nullable?() @null end
#prec(sym, &block)
[ GitHub ]# File 'lib/racc/grammar.rb', line 664
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
#replace(src, dest)
[ GitHub ]# File 'lib/racc/grammar.rb', line 719
def replace(src, dest) @target = dest @symbols = @symbols.map {|s| s == src ? dest : s } end
#rule
[ GitHub ]# File 'lib/racc/grammar.rb', line 632
def rule self end
#size
[ GitHub ]# File 'lib/racc/grammar.rb', line 695
def size @symbols.size end
#to_s
[ GitHub ]# File 'lib/racc/grammar.rb', line 703
def to_s "#<rule#{@ident}>" end
#useless? ⇒ Boolean
(writeonly)
# File 'lib/racc/grammar.rb', line 680
def useless?() @useless end
#|(x)
[ GitHub ]# File 'lib/racc/grammar.rb', line 627
def |(x) @alternatives.push x.rule self end