delorean_lang 2.4.0 → 2.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84e137368e1c85b7005b7662f33e54e7cf6c7f1b0eb7fd2e3ebc8d9ebfbd8a04
4
- data.tar.gz: 1b2039558b54352be0a030a2992aa50fc99c498fe3c1a96c84e36f9b4febb194
3
+ metadata.gz: a2f391feb742261cf7205700f71a6455c3994b88ff33e07ec3acc8b5bba322e7
4
+ data.tar.gz: af2616d688fc0b18844737aaa26dd37a597ed92a8ef338a46fc27c252beab739
5
5
  SHA512:
6
- metadata.gz: 641d20f5de1251faaae77f7e571e6c2d43de03cc314d450b1c6246e00074c4fcb6a59506615d67968cc73b627901eedb7b3ee6375353b4a59e488ff43e4d06b7
7
- data.tar.gz: 85afcad55380bb346f84fae8aa7e8b29601e28fe6a55e1f04d1bd9b968c064d40ab7235e2c19cf9791b3c7dc6b33d9339428e1809e9f51d5e81f1f7fea5cde9a
6
+ metadata.gz: 202515ed652a577f8eb270116397254c0d46e601e4062db196f8c4dd07abd13914e74dce21ee4a086d9e7e404b823f56671573bbafc382f950b32fec9fdfdab8
7
+ data.tar.gz: 2fca9df1461cc20b7e5a4c0e6aa60c9c54d35ec2bbe3b954b539b5b757818cfab5d315bc8bbd48d53aa35a2beb3a8fdb3f914dfced09068299cc104da0088578
@@ -464,7 +464,7 @@ eos
464
464
 
465
465
  return "#{a_name}#{POST}" if expr.empty?
466
466
 
467
- "#{a_name}#{POST} = #{expr}"
467
+ "#{a_name}#{POST} = (#{expr})"
468
468
  end
469
469
 
470
470
  def force_def(context)
@@ -523,10 +523,6 @@ eos
523
523
  element.force_def(context)
524
524
  end
525
525
 
526
- formulas = expressions.elements.select do |elem|
527
- elem.is_a? BlockFormula
528
- end
529
-
530
526
  result_formula = formulas.find do |formula|
531
527
  formula.i.text_value == 'result'
532
528
  end
@@ -548,6 +544,12 @@ eos
548
544
  end
549
545
  end
550
546
 
547
+ def formulas
548
+ expressions.elements.select do |elem|
549
+ elem.is_a? BlockFormula
550
+ end
551
+ end
552
+
551
553
  def rewrite(context, vcode)
552
554
  if !respond_to?(:al) || al.text_value.empty?
553
555
  args_str = ''
@@ -556,6 +558,7 @@ eos
556
558
  args_str = al.rewrite(context)
557
559
  arg_count = al.arg_count
558
560
  end
561
+
559
562
  if vcode.is_a?(ClassText)
560
563
  # FIXME: Do we really need this check here?
561
564
  # ruby class call
@@ -567,6 +570,10 @@ eos
567
570
  element.force_def(context)
568
571
  end
569
572
 
573
+ formulas.each do |element|
574
+ element.force_def(context)
575
+ end
576
+
570
577
  block_args_str = if b_args.elements.any?
571
578
  block_args = b_args.elements.map do |v|
572
579
  v.rewrite(context)
@@ -587,6 +594,10 @@ eos
587
594
  element.force_undef(context)
588
595
  end
589
596
 
597
+ formulas.each do |element|
598
+ element.force_undef(context)
599
+ end
600
+
590
601
  block = "{ #{block_args_str} #{expression_str} }"
591
602
 
592
603
  "_instance_call(#{vcode}, '#{i.text_value}', [#{args_str}], _e) #{block}"
@@ -654,8 +665,8 @@ eos
654
665
  end
655
666
 
656
667
  def rewrite(context)
657
- "(#{v.rewrite(context)}) ? (#{e1.rewrite(context)}) :
658
- (#{e2.rewrite(context)})"
668
+ "((#{v.rewrite(context)}) ? (#{e1.rewrite(context)}) :
669
+ (#{e2.rewrite(context)}))"
659
670
  end
660
671
  end
661
672
 
@@ -678,12 +689,12 @@ eos
678
689
  (#{node.e1.rewrite(context)})"
679
690
  end.join("\n")
680
691
 
681
- "if (#{v.rewrite(context)})
692
+ "(if (#{v.rewrite(context)})
682
693
  (#{e1.rewrite(context)})
683
694
  #{elsifs_string}
684
695
  else
685
696
  (#{e2.rewrite(context)})
686
- end"
697
+ end)"
687
698
  end
688
699
  end
689
700
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delorean
4
- VERSION = '2.4.0'
4
+ VERSION = '2.4.2'
5
5
  end
data/spec/eval_spec.rb CHANGED
@@ -1386,6 +1386,17 @@ eof
1386
1386
  expect(r).to eq [5, 2460, 128, 1230]
1387
1387
  end
1388
1388
 
1389
+ it 'works with the weird if case' do
1390
+ engine.parse defn('A:',
1391
+ ' a = 1',
1392
+ ' b = 1',
1393
+ ' c = nil',
1394
+ ' d = a || if b || c then 999 else 0',
1395
+ )
1396
+ r = engine.evaluate('A', 'd')
1397
+ expect(r).to eq 1
1398
+ end
1399
+
1389
1400
  describe 'blocks' do
1390
1401
  let(:default_node) do
1391
1402
  ['A:',
@@ -1560,6 +1571,42 @@ eof
1560
1571
  expect(r).to eq([[3], 1])
1561
1572
  end
1562
1573
 
1574
+ it 'works with custom formulas in blocks' do
1575
+ engine.parse defn(*default_node,
1576
+ ' a = 1',
1577
+ ' b = 1',
1578
+ ' c = array.select ',
1579
+ ' b =? 1',
1580
+ ' base_result = (b + a) > 2',
1581
+ ' base_result2 = base_result || false',
1582
+ ' result = base_result2',
1583
+ ' result = 10',
1584
+ )
1585
+ r = engine.evaluate('A', 'c')
1586
+ expect(r).to eq([2, 3])
1587
+
1588
+ r = engine.evaluate('A', 'result')
1589
+ expect(r).to eq(10)
1590
+ end
1591
+
1592
+ it 'block parameter can reference another block parameter or outside var' do
1593
+ engine.parse defn(*default_node,
1594
+ ' a = 1',
1595
+ ' ab = 1',
1596
+ ' b = 1',
1597
+ ' c = array.select ',
1598
+ ' b =? 1',
1599
+ ' ab =? b + a - 1',
1600
+ ' result = ab > 2',
1601
+ ' result = 10',
1602
+ )
1603
+ r = engine.evaluate('A', 'c')
1604
+ expect(r).to eq([3])
1605
+
1606
+ r = engine.evaluate('A', ['c', 'ab'])
1607
+ expect(r).to eq([[3], 1])
1608
+ end
1609
+
1563
1610
  it 'works with syntax in blocks' do
1564
1611
  engine.parse defn(*default_node,
1565
1612
  ' b = 1',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delorean_lang
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-27 00:00:00.000000000 Z
11
+ date: 2020-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord