modl 0.3.17 → 0.3.18
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/grammar_tests/base_tests.json +20 -2
- data/lib/modl/parser/class_processor.rb +23 -1
- data/lib/modl/parser/modl_class.rb +7 -0
- data/lib/modl/parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2026e9660a82339e3d0c54bb6517df0c38a6612ae28fb454423a9f170b451e11
|
4
|
+
data.tar.gz: 54a98f2f08d8a2b3691adc98abb7de41b38812a11bb3cb0a6c3773da99609547
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bafcf9f75a72b96f2a390e0ff62e4647d47991703606aa56ea3460f8d60f5f5ee6f1b2f8553205751c0e0d5bb51f06f1ca8ed6850f9e0f9fccc11bfbac59873
|
7
|
+
data.tar.gz: 83090d9e804d8f4a1be5ab1cb17ca37c9d6a1324986bca748e6ec58100346e08c47fc5abf51d24f552217ddb2efa146d0c3c3dd51a99d3e41c88ef88ba44dd3f
|
data/CHANGELOG.md
CHANGED
@@ -3032,11 +3032,29 @@
|
|
3032
3032
|
},
|
3033
3033
|
{
|
3034
3034
|
"id": "318",
|
3035
|
-
"input": "*class(\n *id=root
|
3036
|
-
"expected_output": "
|
3035
|
+
"input": "*class(\n *id=root; ## (or something along these lines)\n *assign=[[myArray]]\n);\n*class(\n *id=numbers;\n *assign=[[one;two;three]]\n);\n*class(\n *id=letters;\n *assign=[[alpha;bravo;charlie]]\n);\n*class(\n *id=myArray;\n *assign=[[letters;numbers]]\n);\n\n[[a;b;c];[1;2;3]]",
|
3036
|
+
"expected_output": "[\n {\n \"alpha\": \"a\",\n \"bravo\": \"b\",\n \"charlie\": \"c\"\n },\n {\n \"one\": 1,\n \"two\": 2,\n \"three\": 3\n }\n]",
|
3037
3037
|
"tested_features": [
|
3038
3038
|
"class"
|
3039
3039
|
],
|
3040
3040
|
"minimised_modl": "*class(*id=root;*assign=[[myArray]]);*class(*id=numbers;*assign=[[one;two;three]]);*class(*id=letters;*assign=[[a;b;c]]);*class(*id=myArray;*assign=[[letters;numbers]]);[[a;b;c];[1;2;3]]"
|
3041
|
+
},
|
3042
|
+
{
|
3043
|
+
"id": "319",
|
3044
|
+
"input": "*class(\n *id=root;\n *assign=[[people]]\n);\n*class(\n *id=people;\n *assign=[[person*]]\n);\n*class(\n *id=person;\n *assign=[[first;last;age]]\n);\n\n[[John;Smith;20];[Jane;Jones;21]]",
|
3045
|
+
"expected_output": "[\n {\n \"first\": \"John\",\n \"last\": \"Smith\",\n \"age\": 20\n },\n {\n \"first\": \"Jane\",\n \"last\": \"Jones\",\n \"age\": 21\n }\n]",
|
3046
|
+
"tested_features": [
|
3047
|
+
"class"
|
3048
|
+
],
|
3049
|
+
"minimised_modl": "*class(*id=root;*assign=[[people]]);*class(*id=people;*assign=[[person*]]);*class(*id=person;*assign=[[first;last;age]]);[[John;Smith;20];[Jane;Jones;21]]"
|
3050
|
+
},
|
3051
|
+
{
|
3052
|
+
"id": "320",
|
3053
|
+
"input": "*class(\n *id=m;\n *name=message;\n *superclass=map;\n *assign=[\n [direction;date_time;message]\n ];\n method=sms\n);\n\n[\n m=out:2018-03-22 15\\:25:Hi;\n m=in:2018-03-22 15\\:26:Hello, how are you?;\n m=out:2018-03-22 15\\:25:Hi, good thanks;\n m=out:2018-03-22 15\\:26:How about you?;\n m=in:2018-03-22 15\\:26:Yes, fine thanks. What are you up to?;\n m=out:2018-03-22 15\\:25:Just testing out MODL;\n m=in:2018-03-22 15\\:26:Cool!\n]",
|
3054
|
+
"expected_output": "[\n {\n \"message\": {\n \"direction\": \"out\",\n \"date_time\": \"2018-03-22 15:25\",\n \"message\": \"Hi\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"in\",\n \"date_time\": \"2018-03-22 15:26\",\n \"message\": \"Hello, how are you?\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"out\",\n \"date_time\": \"2018-03-22 15:25\",\n \"message\": \"Hi, good thanks\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"out\",\n \"date_time\": \"2018-03-22 15:26\",\n \"message\": \"How about you?\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"in\",\n \"date_time\": \"2018-03-22 15:26\",\n \"message\": \"Yes, fine thanks. What are you up to?\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"out\",\n \"date_time\": \"2018-03-22 15:25\",\n \"message\": \"Just testing out MODL\",\n \"method\": \"sms\"\n }\n },\n {\n \"message\": {\n \"direction\": \"in\",\n \"date_time\": \"2018-03-22 15:26\",\n \"message\": \"Cool!\",\n \"method\": \"sms\"\n }\n }\n]",
|
3055
|
+
"tested_features": [
|
3056
|
+
"class"
|
3057
|
+
],
|
3058
|
+
"minimised_modl": "*class(*id=m;*name=message;*superclass=map;*assign=[[direction;date_time;message]];method=sms);[m=out:2018-03-22 15\\:25:Hi;m=in:2018-03-22 15\\:26:Hello, how are you?;m=out:2018-03-22 15\\:25:Hi, good thanks;m=out:2018-03-22 15\\:26:How about you?;m=in:2018-03-22 1\\:26:Yes, fine thanks. What are you up to?;m=out:2018-03-22 15\\:25:Just testing out MODL;m=in:2018-03-22 15\\:26:Cool!]"
|
3041
3059
|
}
|
3042
3060
|
]
|
@@ -41,8 +41,30 @@ module MODL
|
|
41
41
|
raise StandardError, 'root class has no *assign statement.' if root_class.assign.nil?
|
42
42
|
raise StandardError, 'root class *assign statement should be of the form "*assign=[[class_name]]".' if root_class.assign.length > 1 || root_class.assign[0].length > 1
|
43
43
|
root_class_assign = root_class.assign[0][0]
|
44
|
-
|
44
|
+
|
45
|
+
array_class = global.classs root_class_assign
|
46
|
+
classes = array_class.keylist_of_length obj.length
|
47
|
+
new_obj = []
|
48
|
+
|
49
|
+
# The top level array can be an array of arrays or an array of hashes, so we need to handle both.
|
50
|
+
obj.each_index do |i|
|
51
|
+
item = obj[i]
|
52
|
+
if item.is_a? Array
|
53
|
+
new_obj << {classes[i] => item}
|
54
|
+
elsif item.is_a? Hash
|
55
|
+
new_obj << item
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
obj = new_obj
|
60
|
+
process_recursive global, obj
|
61
|
+
|
62
|
+
result = []
|
63
|
+
obj.each_index do |i|
|
64
|
+
result << obj[i][global.classs(classes[i]).name_or_id]
|
65
|
+
end
|
66
|
+
|
67
|
+
return result
|
46
68
|
end
|
47
69
|
end
|
48
70
|
process_recursive global, obj
|
@@ -45,6 +45,13 @@ module MODL
|
|
45
45
|
@assign.each do |kl|
|
46
46
|
return kl if kl.length == len
|
47
47
|
end
|
48
|
+
|
49
|
+
# *assign can support iteration, e.g. *assign=[[person*]]
|
50
|
+
# so return a list of the right length in this case
|
51
|
+
if @assign.length == 1 && @assign[0].length == 1 && @assign[0][0].end_with?('*')
|
52
|
+
key = Sutil.head @assign[0][0]
|
53
|
+
return Array.new(len, key)
|
54
|
+
end
|
48
55
|
raise InterpreterError,
|
49
56
|
'Interpreter Error: No key list of the correct length in class ' + @id + ' - looking for one of length ' + len.to_s
|
50
57
|
end
|
data/lib/modl/parser/version.rb
CHANGED