Class: Racc::Sym

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

Overview

Stands terminal and nonterminal symbols.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, dummyp) ⇒ Sym

Returns a new instance of Sym.



972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'lib/racc/grammar.rb', line 972

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

Instance Attribute Details

#assocObject

Returns the value of attribute assoc.



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

def assoc
  @assoc
end

#expandObject (readonly)

Returns the value of attribute expand.



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

def expand
  @expand
end

#headsObject (readonly)

cache



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

def heads
  @heads
end

#identObject (readonly) Also known as: hash

Returns the value of attribute ident.



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

def ident
  @ident
end

#locateObject (readonly)

Returns the value of attribute locate.



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

def locate
  @locate
end

#precedenceObject

Returns the value of attribute precedence.



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

def precedence
  @precedence
end

#serialized=(value) ⇒ Object (writeonly)

Sets the attribute serialized

Parameters:

  • value

    the value to set the attribute serialized to.



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

def serialized=(value)
  @serialized = value
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.once_writer(nm) ⇒ Object



1011
1012
1013
1014
1015
1016
1017
1018
1019
# File 'lib/racc/grammar.rb', line 1011

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 Method Details

#dummy?Boolean

Returns:

  • (Boolean)


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

def dummy?
  @dummyp
end

#nonterminal?Boolean

Returns:

  • (Boolean)


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

def nonterminal?
  @nterm
end

#null=(n) ⇒ Object



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

def null=(n)
  @null = n
end

#nullable?Boolean

Returns:

  • (Boolean)


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

def nullable?
  @null
end

#ruleObject



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

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

#self_null?Boolean

Returns:

  • (Boolean)


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

def self_null?
  @snull
end

#serializeObject



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

def serialize
  @serialized
end

#should_terminalObject



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

def should_terminal
  @should_terminal = true
end

#should_terminal?Boolean

Returns:

  • (Boolean)


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

def should_terminal?
  @should_terminal
end

#string_symbol?Boolean

Returns:

  • (Boolean)


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

def string_symbol?
  @string
end

#term=(t) ⇒ Object



1041
1042
1043
1044
1045
# File 'lib/racc/grammar.rb', line 1041

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

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal?
  @term
end

#to_sObject Also known as: inspect



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

def to_s
  @to_s.dup
end

#useless=(f) ⇒ Object



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

def useless=(f)
  @useless = f
end

#useless?Boolean

Returns:

  • (Boolean)


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

def useless?
  @useless
end

#|(x) ⇒ Object



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

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