Module: RedParse::Stackable::Meta

Included in:
Node, Token
Defined in:
lib/redparse/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#boolean_identity_paramsObject



138
139
140
141
142
143
144
145
146
# File 'lib/redparse/node.rb', line 138

def boolean_identity_params
  return @boolean_identity_params if defined?(@boolean_identity_params) and @boolean_identity_params
  @boolean_identity_params=
  if superclass.respond_to? :boolean_identity_params
    superclass.boolean_identity_params.dup
  else
    {}
  end
end

#identity_paramsObject



129
130
131
132
133
134
135
136
137
# File 'lib/redparse/node.rb', line 129

def identity_params
  return @identity_params if defined?(@identity_params) and @identity_params
  @identity_params=
  if superclass.respond_to? :identity_params
    superclass.identity_params.dup
  else
    {}
  end
end

Instance Method Details

#build_exemplarsObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/redparse/node.rb', line 95

def build_exemplars
  exemplars=[[self]]

  (boolean_identity_params.merge identity_params).each{|name,variations|
    todo=[]
    variations=variations.dup
    variations.each{|var|
      exemplars.each{|exm|
        res=exm.dup

        #res.send name+"=", var
        #res.send :define_method, name do var end
        Symbol|String|Integer|true|false|nil===var or fail #so inspect works as a quoting
        #eval "def res.#{name}; #{var.inspect} end"
        res.push name, var

        todo<<res #unless exemplars.include? res
      }
    }
    exemplars=todo
  }
  #by now, may be some exemplars with identical identities...
  #those duplicate identities should be culled
#          identities_seen={}
#          exemplars.delete_if{|ex|
#            idn=ex.identity_name
#            chuck_it=identities_seen[idn]
#            identities_seen[idn]=true
#            chuck_it
#          }

  return exemplars
end

#enumerate_exemplarsObject

old_exemplars=self.exemplars||=

exemplars=[]
variations.each{|var| old_exemplars.each{|exm| 
  exemplars<< res=exm.dup

  #res.send name+"=", var
  #res.send :define_method, name do var end
  Symbol|String|Integer|true|false|nil===var or fail #so inspect works as a quoting 
  eval "def res.#{name}; #{var.inspect} end"
}}
old_exemplars.replace exemplars


92
93
94
# File 'lib/redparse/node.rb', line 92

def enumerate_exemplars
  @exemplars||= build_exemplars
end

#identity_param(name, *variations) ⇒ Object

declare name to be part of the identity of current class variations are the allowed values for name in this class keep variations simple: booleans, integers, symbols and strings only



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/redparse/node.rb', line 66

def identity_param name, *variations
  name=name.to_s
  list=
  if (variations-[true,false,nil]).empty?
    #const_get("BOOLEAN_IDENTITY_PARAMS") rescue const_set("BOOLEAN_IDENTITY_PARAMS",{})
      self.boolean_identity_params
  else
    #const_get("IDENTITY_PARAMS") rescue const_set("IDENTITY_PARAMS",{})
      self.identity_params
  end
  list[name]=variations
  return #old way to generate examplars below
=begin
  old_exemplars=self.exemplars||=[allocate]
  exemplars=[]
  variations.each{|var| old_exemplars.each{|exm| 
    exemplars<< res=exm.dup

    #res.send name+"=", var
    #res.send :define_method, name do var end
    Symbol|String|Integer|true|false|nil===var or fail #so inspect works as a quoting 
    eval "def res.#{name}; #{var.inspect} end"
  }}
  old_exemplars.replace exemplars
=end
end