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.



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



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

def assoc
  @assoc
end

#expandObject (readonly)

Returns the value of attribute expand.



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

def expand
  @expand
end

#headsObject (readonly)

cache



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

def heads
  @heads
end

#identObject (readonly) Also known as: hash

Returns the value of attribute ident.



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

def ident
  @ident
end

#locateObject (readonly)

Returns the value of attribute locate.



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

def locate
  @locate
end

#precedenceObject

Returns the value of attribute precedence.



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

def precedence
  @precedence
end

#serialized=(value) ⇒ Object (writeonly)

Sets the attribute serialized

Parameters:

  • value

    the value to set the attribute serialized to.



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

def serialized=(value)
  @serialized = value
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.once_writer(nm) ⇒ Object



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

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)


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

def dummy?
  @dummyp
end

#nonterminal?Boolean

Returns:

  • (Boolean)


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

def nonterminal?
  @nterm
end

#null=(n) ⇒ Object



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

def null=(n)
  @null = n
end

#nullable?Boolean

Returns:

  • (Boolean)


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

def nullable?
  @null
end

#ruleObject



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

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

#self_null?Boolean

Returns:

  • (Boolean)


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

def self_null?
  @snull
end

#serializeObject



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

def serialize
  @serialized
end

#should_terminalObject



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

def should_terminal
  @should_terminal = true
end

#should_terminal?Boolean

Returns:

  • (Boolean)


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

def should_terminal?
  @should_terminal
end

#string_symbol?Boolean

Returns:

  • (Boolean)


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

def string_symbol?
  @string
end

#term=(t) ⇒ Object



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

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

#terminal?Boolean

Returns:

  • (Boolean)


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

def terminal?
  @term
end

#to_sObject Also known as: inspect



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

def to_s
  @to_s.dup
end

#useless=(f) ⇒ Object



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

def useless=(f)
  @useless = f
end

#useless?Boolean

Returns:

  • (Boolean)


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

def useless?
  @useless
end

#|(x) ⇒ Object



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

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