trxl 0.1.8 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/trxl/trxl_grammar.rb +354 -5
- data/lib/trxl/trxl_grammar.treetop +36 -1
- data/spec/trxl/builtins_spec.rb +57 -29
- data/trxl.gemspec +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.9
|
data/lib/trxl/trxl_grammar.rb
CHANGED
@@ -4857,16 +4857,26 @@ module Trxl
|
|
4857
4857
|
if r16
|
4858
4858
|
r0 = r16
|
4859
4859
|
else
|
4860
|
-
r17 =
|
4860
|
+
r17 = _nt_compact_function
|
4861
4861
|
if r17
|
4862
4862
|
r0 = r17
|
4863
4863
|
else
|
4864
|
-
r18 =
|
4864
|
+
r18 = _nt_is_empty_function
|
4865
4865
|
if r18
|
4866
4866
|
r0 = r18
|
4867
4867
|
else
|
4868
|
-
|
4869
|
-
|
4868
|
+
r19 = _nt_matching_ids_function
|
4869
|
+
if r19
|
4870
|
+
r0 = r19
|
4871
|
+
else
|
4872
|
+
r20 = _nt_values_of_type_function
|
4873
|
+
if r20
|
4874
|
+
r0 = r20
|
4875
|
+
else
|
4876
|
+
@index = i0
|
4877
|
+
r0 = nil
|
4878
|
+
end
|
4879
|
+
end
|
4870
4880
|
end
|
4871
4881
|
end
|
4872
4882
|
end
|
@@ -4923,7 +4933,8 @@ module Trxl
|
|
4923
4933
|
help << " HELP,ENV,SIZE,SPLIT,ROUND,MIN,MAX\n"
|
4924
4934
|
help << " SUM, MULT, AVG, PRINT, PRINT_LINE\n"
|
4925
4935
|
help << " TO_INT, TO_FLOAT, TO_ARRAY, AVG_SUM\n"
|
4926
|
-
help << " MATCHING_IDS, VALUES_OF_TYPE\n"
|
4936
|
+
help << " MATCHING_IDS, VALUES_OF_TYPE, COMPACT\n"
|
4937
|
+
help << " IS_EMPTY\n"
|
4927
4938
|
help << "-----------------------------------------\n"
|
4928
4939
|
help << "7) Standard library functions:\n"
|
4929
4940
|
help << " foreach_in, inject, map, select\n"
|
@@ -6694,6 +6705,344 @@ module Trxl
|
|
6694
6705
|
r0
|
6695
6706
|
end
|
6696
6707
|
|
6708
|
+
module CompactFunction0
|
6709
|
+
def space1
|
6710
|
+
elements[1]
|
6711
|
+
end
|
6712
|
+
|
6713
|
+
def space2
|
6714
|
+
elements[3]
|
6715
|
+
end
|
6716
|
+
|
6717
|
+
def expression
|
6718
|
+
elements[4]
|
6719
|
+
end
|
6720
|
+
|
6721
|
+
def space3
|
6722
|
+
elements[5]
|
6723
|
+
end
|
6724
|
+
|
6725
|
+
end
|
6726
|
+
|
6727
|
+
module CompactFunction1
|
6728
|
+
def eval(env = Environment.new)
|
6729
|
+
arr = expression.eval(env)
|
6730
|
+
arr.compact
|
6731
|
+
end
|
6732
|
+
end
|
6733
|
+
|
6734
|
+
module CompactFunction2
|
6735
|
+
def space1
|
6736
|
+
elements[1]
|
6737
|
+
end
|
6738
|
+
|
6739
|
+
def space2
|
6740
|
+
elements[3]
|
6741
|
+
end
|
6742
|
+
|
6743
|
+
end
|
6744
|
+
|
6745
|
+
module CompactFunction3
|
6746
|
+
def eval(env = Environment.new)
|
6747
|
+
[]
|
6748
|
+
end
|
6749
|
+
end
|
6750
|
+
|
6751
|
+
def _nt_compact_function
|
6752
|
+
start_index = index
|
6753
|
+
if node_cache[:compact_function].has_key?(index)
|
6754
|
+
cached = node_cache[:compact_function][index]
|
6755
|
+
if cached
|
6756
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
6757
|
+
@index = cached.interval.end
|
6758
|
+
end
|
6759
|
+
return cached
|
6760
|
+
end
|
6761
|
+
|
6762
|
+
i0 = index
|
6763
|
+
i1, s1 = index, []
|
6764
|
+
if has_terminal?('COMPACT', false, index)
|
6765
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
6766
|
+
@index += 7
|
6767
|
+
else
|
6768
|
+
terminal_parse_failure('COMPACT')
|
6769
|
+
r2 = nil
|
6770
|
+
end
|
6771
|
+
s1 << r2
|
6772
|
+
if r2
|
6773
|
+
r3 = _nt_space
|
6774
|
+
s1 << r3
|
6775
|
+
if r3
|
6776
|
+
if has_terminal?('(', false, index)
|
6777
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6778
|
+
@index += 1
|
6779
|
+
else
|
6780
|
+
terminal_parse_failure('(')
|
6781
|
+
r4 = nil
|
6782
|
+
end
|
6783
|
+
s1 << r4
|
6784
|
+
if r4
|
6785
|
+
r5 = _nt_space
|
6786
|
+
s1 << r5
|
6787
|
+
if r5
|
6788
|
+
r6 = _nt_expression
|
6789
|
+
s1 << r6
|
6790
|
+
if r6
|
6791
|
+
r7 = _nt_space
|
6792
|
+
s1 << r7
|
6793
|
+
if r7
|
6794
|
+
if has_terminal?(')', false, index)
|
6795
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6796
|
+
@index += 1
|
6797
|
+
else
|
6798
|
+
terminal_parse_failure(')')
|
6799
|
+
r8 = nil
|
6800
|
+
end
|
6801
|
+
s1 << r8
|
6802
|
+
end
|
6803
|
+
end
|
6804
|
+
end
|
6805
|
+
end
|
6806
|
+
end
|
6807
|
+
end
|
6808
|
+
if s1.last
|
6809
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
6810
|
+
r1.extend(CompactFunction0)
|
6811
|
+
r1.extend(CompactFunction1)
|
6812
|
+
else
|
6813
|
+
@index = i1
|
6814
|
+
r1 = nil
|
6815
|
+
end
|
6816
|
+
if r1
|
6817
|
+
r0 = r1
|
6818
|
+
else
|
6819
|
+
i9, s9 = index, []
|
6820
|
+
if has_terminal?('COMPACT', false, index)
|
6821
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
6822
|
+
@index += 7
|
6823
|
+
else
|
6824
|
+
terminal_parse_failure('COMPACT')
|
6825
|
+
r10 = nil
|
6826
|
+
end
|
6827
|
+
s9 << r10
|
6828
|
+
if r10
|
6829
|
+
r11 = _nt_space
|
6830
|
+
s9 << r11
|
6831
|
+
if r11
|
6832
|
+
if has_terminal?('(', false, index)
|
6833
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6834
|
+
@index += 1
|
6835
|
+
else
|
6836
|
+
terminal_parse_failure('(')
|
6837
|
+
r12 = nil
|
6838
|
+
end
|
6839
|
+
s9 << r12
|
6840
|
+
if r12
|
6841
|
+
r13 = _nt_space
|
6842
|
+
s9 << r13
|
6843
|
+
if r13
|
6844
|
+
if has_terminal?(')', false, index)
|
6845
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6846
|
+
@index += 1
|
6847
|
+
else
|
6848
|
+
terminal_parse_failure(')')
|
6849
|
+
r14 = nil
|
6850
|
+
end
|
6851
|
+
s9 << r14
|
6852
|
+
end
|
6853
|
+
end
|
6854
|
+
end
|
6855
|
+
end
|
6856
|
+
if s9.last
|
6857
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
6858
|
+
r9.extend(CompactFunction2)
|
6859
|
+
r9.extend(CompactFunction3)
|
6860
|
+
else
|
6861
|
+
@index = i9
|
6862
|
+
r9 = nil
|
6863
|
+
end
|
6864
|
+
if r9
|
6865
|
+
r0 = r9
|
6866
|
+
else
|
6867
|
+
@index = i0
|
6868
|
+
r0 = nil
|
6869
|
+
end
|
6870
|
+
end
|
6871
|
+
|
6872
|
+
node_cache[:compact_function][start_index] = r0
|
6873
|
+
|
6874
|
+
r0
|
6875
|
+
end
|
6876
|
+
|
6877
|
+
module IsEmptyFunction0
|
6878
|
+
def space1
|
6879
|
+
elements[1]
|
6880
|
+
end
|
6881
|
+
|
6882
|
+
def space2
|
6883
|
+
elements[3]
|
6884
|
+
end
|
6885
|
+
|
6886
|
+
def expression
|
6887
|
+
elements[4]
|
6888
|
+
end
|
6889
|
+
|
6890
|
+
def space3
|
6891
|
+
elements[5]
|
6892
|
+
end
|
6893
|
+
|
6894
|
+
end
|
6895
|
+
|
6896
|
+
module IsEmptyFunction1
|
6897
|
+
def eval(env = Environment.new)
|
6898
|
+
arr = expression.eval(env)
|
6899
|
+
arr.empty?
|
6900
|
+
end
|
6901
|
+
end
|
6902
|
+
|
6903
|
+
module IsEmptyFunction2
|
6904
|
+
def space1
|
6905
|
+
elements[1]
|
6906
|
+
end
|
6907
|
+
|
6908
|
+
def space2
|
6909
|
+
elements[3]
|
6910
|
+
end
|
6911
|
+
|
6912
|
+
end
|
6913
|
+
|
6914
|
+
module IsEmptyFunction3
|
6915
|
+
def eval(env = Environment.new)
|
6916
|
+
true
|
6917
|
+
end
|
6918
|
+
end
|
6919
|
+
|
6920
|
+
def _nt_is_empty_function
|
6921
|
+
start_index = index
|
6922
|
+
if node_cache[:is_empty_function].has_key?(index)
|
6923
|
+
cached = node_cache[:is_empty_function][index]
|
6924
|
+
if cached
|
6925
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
6926
|
+
@index = cached.interval.end
|
6927
|
+
end
|
6928
|
+
return cached
|
6929
|
+
end
|
6930
|
+
|
6931
|
+
i0 = index
|
6932
|
+
i1, s1 = index, []
|
6933
|
+
if has_terminal?('IS_EMPTY', false, index)
|
6934
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
6935
|
+
@index += 8
|
6936
|
+
else
|
6937
|
+
terminal_parse_failure('IS_EMPTY')
|
6938
|
+
r2 = nil
|
6939
|
+
end
|
6940
|
+
s1 << r2
|
6941
|
+
if r2
|
6942
|
+
r3 = _nt_space
|
6943
|
+
s1 << r3
|
6944
|
+
if r3
|
6945
|
+
if has_terminal?('(', false, index)
|
6946
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6947
|
+
@index += 1
|
6948
|
+
else
|
6949
|
+
terminal_parse_failure('(')
|
6950
|
+
r4 = nil
|
6951
|
+
end
|
6952
|
+
s1 << r4
|
6953
|
+
if r4
|
6954
|
+
r5 = _nt_space
|
6955
|
+
s1 << r5
|
6956
|
+
if r5
|
6957
|
+
r6 = _nt_expression
|
6958
|
+
s1 << r6
|
6959
|
+
if r6
|
6960
|
+
r7 = _nt_space
|
6961
|
+
s1 << r7
|
6962
|
+
if r7
|
6963
|
+
if has_terminal?(')', false, index)
|
6964
|
+
r8 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
6965
|
+
@index += 1
|
6966
|
+
else
|
6967
|
+
terminal_parse_failure(')')
|
6968
|
+
r8 = nil
|
6969
|
+
end
|
6970
|
+
s1 << r8
|
6971
|
+
end
|
6972
|
+
end
|
6973
|
+
end
|
6974
|
+
end
|
6975
|
+
end
|
6976
|
+
end
|
6977
|
+
if s1.last
|
6978
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
6979
|
+
r1.extend(IsEmptyFunction0)
|
6980
|
+
r1.extend(IsEmptyFunction1)
|
6981
|
+
else
|
6982
|
+
@index = i1
|
6983
|
+
r1 = nil
|
6984
|
+
end
|
6985
|
+
if r1
|
6986
|
+
r0 = r1
|
6987
|
+
else
|
6988
|
+
i9, s9 = index, []
|
6989
|
+
if has_terminal?('IS_EMPTY', false, index)
|
6990
|
+
r10 = instantiate_node(SyntaxNode,input, index...(index + 8))
|
6991
|
+
@index += 8
|
6992
|
+
else
|
6993
|
+
terminal_parse_failure('IS_EMPTY')
|
6994
|
+
r10 = nil
|
6995
|
+
end
|
6996
|
+
s9 << r10
|
6997
|
+
if r10
|
6998
|
+
r11 = _nt_space
|
6999
|
+
s9 << r11
|
7000
|
+
if r11
|
7001
|
+
if has_terminal?('(', false, index)
|
7002
|
+
r12 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
7003
|
+
@index += 1
|
7004
|
+
else
|
7005
|
+
terminal_parse_failure('(')
|
7006
|
+
r12 = nil
|
7007
|
+
end
|
7008
|
+
s9 << r12
|
7009
|
+
if r12
|
7010
|
+
r13 = _nt_space
|
7011
|
+
s9 << r13
|
7012
|
+
if r13
|
7013
|
+
if has_terminal?(')', false, index)
|
7014
|
+
r14 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
7015
|
+
@index += 1
|
7016
|
+
else
|
7017
|
+
terminal_parse_failure(')')
|
7018
|
+
r14 = nil
|
7019
|
+
end
|
7020
|
+
s9 << r14
|
7021
|
+
end
|
7022
|
+
end
|
7023
|
+
end
|
7024
|
+
end
|
7025
|
+
if s9.last
|
7026
|
+
r9 = instantiate_node(SyntaxNode,input, i9...index, s9)
|
7027
|
+
r9.extend(IsEmptyFunction2)
|
7028
|
+
r9.extend(IsEmptyFunction3)
|
7029
|
+
else
|
7030
|
+
@index = i9
|
7031
|
+
r9 = nil
|
7032
|
+
end
|
7033
|
+
if r9
|
7034
|
+
r0 = r9
|
7035
|
+
else
|
7036
|
+
@index = i0
|
7037
|
+
r0 = nil
|
7038
|
+
end
|
7039
|
+
end
|
7040
|
+
|
7041
|
+
node_cache[:is_empty_function][start_index] = r0
|
7042
|
+
|
7043
|
+
r0
|
7044
|
+
end
|
7045
|
+
|
6697
7046
|
module AvgFunction0
|
6698
7047
|
def space1
|
6699
7048
|
elements[0]
|
@@ -825,6 +825,10 @@ grammar Trxl
|
|
825
825
|
/
|
826
826
|
avg_function
|
827
827
|
/
|
828
|
+
compact_function
|
829
|
+
/
|
830
|
+
is_empty_function
|
831
|
+
/
|
828
832
|
matching_ids_function
|
829
833
|
/
|
830
834
|
values_of_type_function
|
@@ -863,7 +867,8 @@ grammar Trxl
|
|
863
867
|
help << " HELP,ENV,SIZE,SPLIT,ROUND,MIN,MAX\n"
|
864
868
|
help << " SUM, MULT, AVG, PRINT, PRINT_LINE\n"
|
865
869
|
help << " TO_INT, TO_FLOAT, TO_ARRAY, AVG_SUM\n"
|
866
|
-
help << " MATCHING_IDS, VALUES_OF_TYPE\n"
|
870
|
+
help << " MATCHING_IDS, VALUES_OF_TYPE, COMPACT\n"
|
871
|
+
help << " IS_EMPTY\n"
|
867
872
|
help << "-----------------------------------------\n"
|
868
873
|
help << "7) Standard library functions:\n"
|
869
874
|
help << " foreach_in, inject, map, select\n"
|
@@ -1173,6 +1178,36 @@ grammar Trxl
|
|
1173
1178
|
}
|
1174
1179
|
end
|
1175
1180
|
|
1181
|
+
rule compact_function
|
1182
|
+
'COMPACT' space '(' space expression space ')' {
|
1183
|
+
def eval(env = Environment.new)
|
1184
|
+
arr = expression.eval(env)
|
1185
|
+
arr.compact
|
1186
|
+
end
|
1187
|
+
}
|
1188
|
+
/
|
1189
|
+
'COMPACT' space '(' space ')' {
|
1190
|
+
def eval(env = Environment.new)
|
1191
|
+
[]
|
1192
|
+
end
|
1193
|
+
}
|
1194
|
+
end
|
1195
|
+
|
1196
|
+
rule is_empty_function
|
1197
|
+
'IS_EMPTY' space '(' space expression space ')' {
|
1198
|
+
def eval(env = Environment.new)
|
1199
|
+
arr = expression.eval(env)
|
1200
|
+
arr.empty?
|
1201
|
+
end
|
1202
|
+
}
|
1203
|
+
/
|
1204
|
+
'IS_EMPTY' space '(' space ')' {
|
1205
|
+
def eval(env = Environment.new)
|
1206
|
+
true
|
1207
|
+
end
|
1208
|
+
}
|
1209
|
+
end
|
1210
|
+
|
1176
1211
|
rule avg_function
|
1177
1212
|
'AVG' space '(' space expression more_expressions:( space ',' space expression)* space ')' {
|
1178
1213
|
def eval(env = Environment.new)
|
data/spec/trxl/builtins_spec.rb
CHANGED
@@ -3,16 +3,16 @@ require 'spec_helper'
|
|
3
3
|
describe "The language" do
|
4
4
|
|
5
5
|
include Trxl::SpecHelper
|
6
|
-
|
6
|
+
|
7
7
|
before(:each) do
|
8
8
|
@parser = Trxl::Calculator.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
it "should allow to access the current environment by calling ENV" do
|
12
12
|
env = eval("ENV", {})
|
13
13
|
env.should be_kind_of(Trxl::Environment)
|
14
14
|
env.should be_empty
|
15
|
-
|
15
|
+
|
16
16
|
env = eval("ENV", { :a => 1, :b => 2 })
|
17
17
|
env.should be_kind_of(Trxl::Environment)
|
18
18
|
env.should have_key(:a)
|
@@ -36,24 +36,24 @@ describe "The language" do
|
|
36
36
|
eval("ENV['a'..'c']", { :a => 1, :b => 2, :c => 3 }).should include(2)
|
37
37
|
eval("ENV['a'..'c']", { :a => 1, :b => 2, :c => 3 }).should include(3)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should be able to PRINT and PRINT_LINE to STDOUT" do
|
41
41
|
eval("PRINT('- This is output from PRINT. ')").should be_nil
|
42
42
|
eval("PRINT_LINE('And this is output from PRINT_LINE')").should be_nil
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should be able to split strings by calling SPLIT(some_string, split_char)" do
|
46
46
|
eval("SPLIT('foo/bar', '/')").should == [ 'foo', 'bar' ]
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
it "should be able to convert values into integers by calling TO_INT(alpha_numeric_string)" do
|
50
50
|
eval("TO_INT('1')").should == 1
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should be able to convert values into floats by calling TO_FLOAT(alpha_numeric_string)" do
|
54
54
|
eval("TO_FLOAT('1.12')").should == 1.12
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "should be able to convert values into arrays by calling TO_ARRAY(some_value)" do
|
58
58
|
eval("TO_ARRAY(1)").should == [ 1 ]
|
59
59
|
eval("TO_ARRAY('1')").should == [ '1' ]
|
@@ -100,14 +100,14 @@ describe "The language" do
|
|
100
100
|
eval(program).should == 12
|
101
101
|
program = "SUM(x)"
|
102
102
|
eval(program, { :x => [ 1, 2, 3 ] }).should == 6
|
103
|
-
|
103
|
+
|
104
104
|
program = "SUM([2,2,2],[4,4,4],[3,3,3])"
|
105
105
|
eval(program).should == 27
|
106
|
-
|
106
|
+
|
107
107
|
program = "SUM([ [2,2,2], [4,4,4], [3,3,3] ])"
|
108
108
|
eval(program).should == 27
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
it "should be able to calculate MULT for an arbitrary number of argument expressions" do
|
112
112
|
program = "MULT()"
|
113
113
|
eval(program).should == 0
|
@@ -126,20 +126,48 @@ describe "The language" do
|
|
126
126
|
program = "MULT(x)"
|
127
127
|
eval(program, { :x => [ 1, 2, 3 ] }).should == 6
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
|
+
it "should provide COMPACT in order to remove NULL values from arrays" do
|
131
|
+
program = "COMPACT([1])"
|
132
|
+
eval(program).should == [1]
|
133
|
+
program = "COMPACT([1, NULL])"
|
134
|
+
eval(program).should == [1]
|
135
|
+
program = "COMPACT([NULL])"
|
136
|
+
eval(program).should == []
|
137
|
+
program = "COMPACT([NULL, NULL])"
|
138
|
+
eval(program).should == []
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should provide IS_EMPTY in order to test if an array contains elements" do
|
142
|
+
program = "IS_EMPTY([])"
|
143
|
+
eval(program).should == true
|
144
|
+
program = "IS_EMPTY([1])"
|
145
|
+
eval(program).should == false
|
146
|
+
program = "IS_EMPTY([NULL])"
|
147
|
+
eval(program).should == false
|
148
|
+
end
|
149
|
+
|
130
150
|
it "should be able to calculate AVG for an arbitrary number of argument expressions" do
|
131
151
|
program = "AVG()"
|
132
152
|
eval(program).should == 0
|
133
153
|
program = "AVG(NULL)"
|
134
154
|
eval(program).should be_nil
|
155
|
+
program = "AVG(FALSE, NULL)"
|
156
|
+
eval(program).should be_nil
|
157
|
+
program = "AVG(NULL, NULL)"
|
158
|
+
eval(program).should be_nil
|
159
|
+
program = "AVG(FALSE, NULL, NULL)"
|
160
|
+
eval(program).should be_nil
|
161
|
+
program = "AVG([NULL, NULL])"
|
162
|
+
eval(program).should == 0
|
163
|
+
program = "AVG(FALSE, [NULL, NULL])"
|
164
|
+
eval(program).should == 0
|
135
165
|
program = "AVG(0)"
|
136
166
|
eval(program).should == 0
|
137
167
|
program = "AVG(1)"
|
138
168
|
eval(program).should == 1
|
139
169
|
program = "AVG(3,3,3)"
|
140
170
|
eval(program).should == 3
|
141
|
-
program = "AVG(3,3,3)"
|
142
|
-
eval(program).should == 3
|
143
171
|
program = "AVG(3,5,0)"
|
144
172
|
eval(program).should be_close(2.66666666666, 0.01)
|
145
173
|
program = "AVG(FALSE, 3,5,0)"
|
@@ -154,19 +182,19 @@ describe "The language" do
|
|
154
182
|
eval(program).should == 4
|
155
183
|
program = "AVG(fun(){4}(),fun(x){x}(4),fun(x,y){x+y}(2,2))"
|
156
184
|
eval(program).should == 4
|
157
|
-
|
185
|
+
|
158
186
|
program = "AVG([1,2,3],[4,4,4],[6,6,6])"
|
159
187
|
eval(program).should == 4
|
160
188
|
program = "AVG([2,2],[4,4,4],[6,6])"
|
161
189
|
eval(program).should == 4
|
162
190
|
end
|
163
|
-
|
191
|
+
|
164
192
|
it "should be able to calculate AVG_SUM for an arbitrary number of argument expressions" do
|
165
193
|
program = "AVG_SUM([1,2,3],[4,4,4],[6,6,6])"
|
166
194
|
eval(program).should == 12
|
167
195
|
program = "AVG_SUM([2,2],[4,4,4],[6,6])"
|
168
196
|
eval(program).should == 12
|
169
|
-
|
197
|
+
|
170
198
|
env = {
|
171
199
|
:ap => [138542.0, 136795.0, 134256.0], # 136531
|
172
200
|
:aq => [124580.0, 21458.0, 34560.0], # 60199.3333333333
|
@@ -176,10 +204,10 @@ describe "The language" do
|
|
176
204
|
:au => [250.0, 250.0, 250.0] # 250
|
177
205
|
# ------------------
|
178
206
|
# 206859
|
179
|
-
|
207
|
+
|
180
208
|
}
|
181
209
|
eval("AVG_SUM(ENV['ap'..'au'])", env).should == 206859
|
182
|
-
|
210
|
+
|
183
211
|
env = {
|
184
212
|
:ap => [138542.0, 136795.0, 134256.0], # 136531
|
185
213
|
:aq => [124580.0, 21458.0, 34560.0], # 60199.3333333333
|
@@ -189,10 +217,10 @@ describe "The language" do
|
|
189
217
|
:au => [0, 0, 0] # 0
|
190
218
|
# ------------------
|
191
219
|
# 206609
|
192
|
-
|
220
|
+
|
193
221
|
}
|
194
222
|
eval("AVG_SUM(ENV['ap'..'au'])", env).should == 206609
|
195
|
-
|
223
|
+
|
196
224
|
end
|
197
225
|
|
198
226
|
it "should be able to calculate MIN for an arbitrary number of argument expressions" do
|
@@ -224,7 +252,7 @@ describe "The language" do
|
|
224
252
|
program = "MAX(fun(){4}(),fun(x){x}(4),fun(x,y){x+y}(2,2))"
|
225
253
|
eval(program).should == 4
|
226
254
|
end
|
227
|
-
|
255
|
+
|
228
256
|
it "should be able to map all hash ids that match a given value by calling MATCHING_IDS" do
|
229
257
|
env = { :foo => { :a => "bar", :b => "bar", :c => "baz" } }
|
230
258
|
eval("MATCHING_IDS('bar', foo)", env).should include(:a)
|
@@ -232,9 +260,9 @@ describe "The language" do
|
|
232
260
|
eval("MATCHING_IDS('baz', foo)", env).should == [ :c ]
|
233
261
|
eval("MATCHING_IDS('bam', foo)", env).should == []
|
234
262
|
end
|
235
|
-
|
263
|
+
|
236
264
|
it "should define a VALUES_OF_TYPE function" do
|
237
|
-
env = {
|
265
|
+
env = {
|
238
266
|
:all_types => { :a => "bar", :b => "bar", :c => "baz" },
|
239
267
|
:all_values => { :a => 100, :b => 200, :c => 300 }
|
240
268
|
}
|
@@ -243,7 +271,7 @@ describe "The language" do
|
|
243
271
|
eval("VALUES_OF_TYPE('baz', all_types, all_values)", env).should == [ 300 ]
|
244
272
|
eval("VALUES_OF_TYPE('bam', all_types, all_values)", env).should == []
|
245
273
|
|
246
|
-
env = {
|
274
|
+
env = {
|
247
275
|
:all_types => { :a => "bar", :b => "bar", :c => "baz" },
|
248
276
|
:all_values => { :a => [100,200,300], :b => [400,500,600], :c => [700,800,900] }
|
249
277
|
}
|
@@ -252,17 +280,17 @@ describe "The language" do
|
|
252
280
|
eval("VALUES_OF_TYPE('baz', all_types, all_values)", env).should == [ [700,800,900] ]
|
253
281
|
eval("VALUES_OF_TYPE('bam', all_types, all_values)", env).should == []
|
254
282
|
|
255
|
-
env = {
|
283
|
+
env = {
|
256
284
|
:all_types => { :a => "bar", :b => "bar", :c => "baz" },
|
257
285
|
:all_values => []
|
258
286
|
}
|
259
287
|
lambda { eval("VALUES_OF_TYPE('bar', all_types, all_values)", env) }.should raise_error(Trxl::InvalidArgumentException)
|
260
|
-
|
261
|
-
env = {
|
288
|
+
|
289
|
+
env = {
|
262
290
|
:all_types => [],
|
263
291
|
:all_values => { :a => [100,200,300], :b => [400,500,600], :c => [700,800,900] }
|
264
292
|
}
|
265
293
|
lambda { eval("VALUES_OF_TYPE('bar', all_types, all_values)", env) }.should raise_error(Trxl::InvalidArgumentException)
|
266
294
|
end
|
267
|
-
|
295
|
+
|
268
296
|
end
|
data/trxl.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{trxl}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.9"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Martin Gamsjaeger (snusnu)}, %q{Michael Aufreiter}]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trxl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 9
|
10
|
+
version: 0.1.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Martin Gamsjaeger (snusnu)
|