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.



1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
# File 'lib/racc/grammar.rb', line 1051

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
  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.



1141
1142
1143
# File 'lib/racc/grammar.rb', line 1141

def assoc
  @assoc
end

#expandObject (readonly)

Returns the value of attribute expand.



1178
1179
1180
# File 'lib/racc/grammar.rb', line 1178

def expand
  @expand
end

#headsObject (readonly)

cache



1161
1162
1163
# File 'lib/racc/grammar.rb', line 1161

def heads
  @heads
end

#identObject (readonly) Also known as: hash

Returns the value of attribute ident.



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

def ident
  @ident
end

#locateObject (readonly)

Returns the value of attribute locate.



1162
1163
1164
# File 'lib/racc/grammar.rb', line 1162

def locate
  @locate
end

#precedenceObject

Returns the value of attribute precedence.



1140
1141
1142
# File 'lib/racc/grammar.rb', line 1140

def precedence
  @precedence
end

#serialized=(value) ⇒ Object (writeonly)

Sets the attribute serialized

Parameters:

  • value

    the value to set the attribute serialized to.



1138
1139
1140
# File 'lib/racc/grammar.rb', line 1138

def serialized=(value)
  @serialized = value
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.once_writer(nm) ⇒ Object



1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'lib/racc/grammar.rb', line 1086

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)


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

def dummy?
  @dummyp
end

#nonterminal?Boolean

Returns:

  • (Boolean)


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

def nonterminal?
  @nterm
end

#null=(n) ⇒ Object



1174
1175
1176
# File 'lib/racc/grammar.rb', line 1174

def null=(n)
  @null = n
end

#nullable?Boolean

Returns:

  • (Boolean)


1170
1171
1172
# File 'lib/racc/grammar.rb', line 1170

def nullable?
  @null
end

#ruleObject



1153
1154
1155
# File 'lib/racc/grammar.rb', line 1153

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

#self_null?Boolean

Returns:

  • (Boolean)


1164
1165
1166
# File 'lib/racc/grammar.rb', line 1164

def self_null?
  @snull
end

#serializeObject



1134
1135
1136
# File 'lib/racc/grammar.rb', line 1134

def serialize
  @serialized
end

#should_terminalObject



1122
1123
1124
# File 'lib/racc/grammar.rb', line 1122

def should_terminal
  @should_terminal = true
end

#should_terminal?Boolean

Returns:

  • (Boolean)


1126
1127
1128
# File 'lib/racc/grammar.rb', line 1126

def should_terminal?
  @should_terminal
end

#string_symbol?Boolean

Returns:

  • (Boolean)


1130
1131
1132
# File 'lib/racc/grammar.rb', line 1130

def string_symbol?
  @string
end

#term=(t) ⇒ Object



1116
1117
1118
1119
1120
# File 'lib/racc/grammar.rb', line 1116

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

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal?
  @term
end

#to_sObject Also known as: inspect



1143
1144
1145
# File 'lib/racc/grammar.rb', line 1143

def to_s
  @to_s.dup
end

#useless=(f) ⇒ Object



1185
1186
1187
# File 'lib/racc/grammar.rb', line 1185

def useless=(f)
  @useless = f
end

#useless?Boolean

Returns:

  • (Boolean)


1181
1182
1183
# File 'lib/racc/grammar.rb', line 1181

def useless?
  @useless
end

#|(x) ⇒ Object



1149
1150
1151
# File 'lib/racc/grammar.rb', line 1149

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