Class: RedShift::FlowSyntax::FlowParser
- Defined in:
- lib/redshift/syntax.rb
Instance Attribute Summary collapse
-
#flows ⇒ Object
readonly
Returns the value of attribute flows.
Instance Method Summary collapse
- #algebraic(*equations) ⇒ Object (also: #alg)
- #delay(*equations) ⇒ Object
- #derive(*equations) ⇒ Object
- #euler(*equations) ⇒ Object
-
#initialize(block) ⇒ FlowParser
constructor
A new instance of FlowParser.
- #rk4(*equations) ⇒ Object (also: #diff, #differential)
Constructor Details
#initialize(block) ⇒ FlowParser
Returns a new instance of FlowParser.
212 213 214 215 216 217 218 219 |
# File 'lib/redshift/syntax.rb', line 212 def initialize block @flows = [] val = instance_eval(&block) if val.kind_of? String and val =~ /=/ warn "Equation appears to be missing a specifier (alg, diff, etc.):" + val end end |
Instance Attribute Details
#flows ⇒ Object (readonly)
Returns the value of attribute flows.
210 211 212 |
# File 'lib/redshift/syntax.rb', line 210 def flows @flows end |
Instance Method Details
#algebraic(*equations) ⇒ Object Also known as: alg
221 222 223 224 225 226 227 228 |
# File 'lib/redshift/syntax.rb', line 221 def algebraic(*equations) equations.each do |equation| unless equation =~ /^\s*(\w+)\s*=\s*(.+)/m raise SyntaxError, "parse error in\n\t#{equation}." end @flows << AlgebraicFlow.new($1.intern, $2.strip) end end |
#delay(*equations) ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/redshift/syntax.rb', line 267 def delay(*equations) opts = equations.pop unless opts and opts.kind_of? Hash and opts[:by] raise SyntaxError, "Missing delay term: :delay => <delay>" end delay_by = opts[:by] equations.each do |equation| unless equation =~ /^\s*(\w+)\s*=\s*(.+)/m raise SyntaxError, "parse error in\n\t#{equation}." end @flows << DelayFlow.new($1.intern, $2.strip, delay_by) end end |
#derive(*equations) ⇒ Object
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/redshift/syntax.rb', line 248 def derive(*equations) opts = equations.pop unless opts and opts.kind_of? Hash and (opts[:feedback] == true or opts[:feedback] == false) raise SyntaxError, "Missing option: :feedback => <true|false>\n" + "Use 'true' when the output of this flow feeds back into another\n" + "derivative flow (even after a delay). Also, set <var>_init_rhs.\n" ## should false be the default? ## rename 'feedback'? end feedback = opts[:feedback] equations.each do |equation| unless equation =~ /^\s*(\w+)\s*=\s*(.+)'\s*\z/m raise SyntaxError, "parse error in\n\t#{equation}." end @flows << DerivativeFlow.new($1.intern, $2.strip, feedback) end end |
#euler(*equations) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/redshift/syntax.rb', line 230 def euler(*equations) equations.each do |equation| unless equation =~ /^\s*(\w+)\s*'\s*=\s*(.+)/m raise SyntaxError, "parse error in\n\t#{equation}." end @flows << EulerDifferentialFlow.new($1.intern, $2.strip) end end |
#rk4(*equations) ⇒ Object Also known as: diff, differential
239 240 241 242 243 244 245 246 |
# File 'lib/redshift/syntax.rb', line 239 def rk4(*equations) equations.each do |equation| unless equation =~ /^\s*(\w+)\s*'\s*=\s*(.+)/m raise SyntaxError, "parse error in\n\t#{equation}." end @flows << RK4DifferentialFlow.new($1.intern, $2.strip) end end |