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.



971
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
# File 'lib/racc/grammar.rb', line 971

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.



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

def assoc
  @assoc
end

#expandObject (readonly)

Returns the value of attribute expand.



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

def expand
  @expand
end

#headsObject (readonly)

cache



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

def heads
  @heads
end

#identObject (readonly) Also known as: hash

Returns the value of attribute ident.



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

def ident
  @ident
end

#locateObject (readonly)

Returns the value of attribute locate.



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

def locate
  @locate
end

#precedenceObject

Returns the value of attribute precedence.



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

def precedence
  @precedence
end

#serialized=(value) ⇒ Object (writeonly)

Sets the attribute serialized

Parameters:

  • value

    the value to set the attribute serialized to.



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

def serialized=(value)
  @serialized = value
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.once_writer(nm) ⇒ Object



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

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)


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

def dummy?
  @dummyp
end

#nonterminal?Boolean

Returns:

  • (Boolean)


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

def nonterminal?
  @nterm
end

#null=(n) ⇒ Object



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

def null=(n)
  @null = n
end

#nullable?Boolean

Returns:

  • (Boolean)


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

def nullable?
  @null
end

#ruleObject



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

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

#self_null?Boolean

Returns:

  • (Boolean)


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

def self_null?
  @snull
end

#serializeObject



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

def serialize
  @serialized
end

#should_terminalObject



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

def should_terminal
  @should_terminal = true
end

#should_terminal?Boolean

Returns:

  • (Boolean)


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

def should_terminal?
  @should_terminal
end

#string_symbol?Boolean

Returns:

  • (Boolean)


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

def string_symbol?
  @string
end

#term=(t) ⇒ Object



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

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

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal?
  @term
end

#to_sObject Also known as: inspect



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

def to_s
  @to_s.dup
end

#useless=(f) ⇒ Object



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

def useless=(f)
  @useless = f
end

#useless?Boolean

Returns:

  • (Boolean)


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

def useless?
  @useless
end

#|(x) ⇒ Object



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

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