123456789_123456789_123456789_123456789_123456789_

Class: Racc::Sym

Relationships & Source Files
Inherits: Object
Defined in: lib/racc/grammar.rb

Overview

Stands terminal and nonterminal symbols.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(value, dummyp) ⇒ Sym

[ GitHub ]

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

def initialize(value, dummyp)
  @ident = nil
  @value = value
  @dummyp = dummyp

  @term  = nil
  @nterm = nil
  @should_terminal = false
  @precedence = nil
  case value
  when Symbol
    @to_s = value.to_s
    @serialized = value.inspect
    @string = false
  when String
    @to_s = value.inspect
    @serialized = value.dump
    @string = true
  when false
    @to_s = '$end'
    @serialized = 'false'
    @string = false
  when ErrorSymbolValue
    @to_s = 'error'
    @serialized = 'Object.new'
    @string = false
  else
    raise ArgumentError, "unknown symbol value: #{value.class}"
  end

  @heads    = []
  @locate   = []
  @snull    = nil
  @null     = nil
  @expand   = nil
  @useless  = nil
end

Class Method Details

.once_writer(nm)

[ GitHub ]

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

def once_writer(nm)
  nm = nm.id2name
  module_eval(<<-EOS)
    def #{nm}=(v)
      raise 'racc: fatal: @#{nm} != nil' unless @#{nm}.nil?
      @#{nm} = v
    end
  EOS
end

Instance Attribute Details

#assoc (rw)

[ GitHub ]

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

attr_accessor :assoc

#dummy?Boolean (readonly)

[ GitHub ]

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

def dummy?
  @dummyp
end

#expand (readonly)

[ GitHub ]

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

attr_reader :expand

#hash (readonly)

Alias for #ident.

[ GitHub ]

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

alias hash ident

#heads (readonly)

cache

[ GitHub ]

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

attr_reader :heads

#ident (readonly) Also known as: #hash

[ GitHub ]

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

attr_reader :ident

#locate (readonly)

[ GitHub ]

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

attr_reader :locate

#nonterminal?Boolean (readonly)

[ GitHub ]

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

def nonterminal?
  @nterm
end

#null=(n) (writeonly)

[ GitHub ]

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

def null=(n)
  @null = n
end

#nullable?Boolean (readonly)

[ GitHub ]

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

def nullable?
  @null
end

#precedence (rw)

[ GitHub ]

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

attr_accessor :precedence

#self_null?Boolean (readonly)

[ GitHub ]

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

def self_null?
  @snull
end

#serialized=(value) (writeonly)

[ GitHub ]

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

attr_writer :serialized

#should_terminal (readonly)

[ GitHub ]

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

def should_terminal
  @should_terminal = true
end

#should_terminal?Boolean (readonly)

[ GitHub ]

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

def should_terminal?
  @should_terminal
end

#string_symbol?Boolean (readonly)

[ GitHub ]

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

def string_symbol?
  @string
end

#term=(t) (writeonly)

[ GitHub ]

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

def term=(t)
  raise 'racc: fatal: term= called twice' unless @term.nil?
  @term = t
  @nterm = !t
end

#terminal?Boolean (readonly)

[ GitHub ]

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

def terminal?
  @term
end

#useless=(f) (rw)

[ GitHub ]

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

def useless=(f)
  @useless = f
end

#useless?Boolean (rw)

[ GitHub ]

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

def useless?
  @useless
end

#value (readonly)

[ GitHub ]

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

attr_reader :value

Instance Method Details

#inspect

Alias for #to_s.

[ GitHub ]

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

alias inspect to_s

#rule

[ GitHub ]

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

def rule
  Rule.new(nil, [self], UserAction.empty)
end

#serialize

[ GitHub ]

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

def serialize
  @serialized
end

#to_s Also known as: #inspect

[ GitHub ]

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

def to_s
  @to_s.dup
end

#|(x)

[ GitHub ]

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

def |(x)
  rule() | x.rule
end