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 |
# File 'lib/redshift/syntax.rb', line 212 def initialize block @flows = [] instance_eval(&block) 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
217 218 219 220 221 222 223 224 |
# File 'lib/redshift/syntax.rb', line 217 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
263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/redshift/syntax.rb', line 263 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
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/redshift/syntax.rb', line 244 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] for equation in equations 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
226 227 228 229 230 231 232 233 |
# File 'lib/redshift/syntax.rb', line 226 def euler(*equations) for equation in equations 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
235 236 237 238 239 240 241 242 |
# File 'lib/redshift/syntax.rb', line 235 def rk4(*equations) for equation in equations 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 |