modl 0.3.17 → 0.3.18

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: dc3336e90f65102b9266f9968a7a81a8def817b081a8ccfa007b0819c49b109a
4
- data.tar.gz: 0f2bbad0bcc9f1cff56965f9c7a68118917ac398bc0807fb3929237bce4ab76c
3
+ metadata.gz: 2026e9660a82339e3d0c54bb6517df0c38a6612ae28fb454423a9f170b451e11
4
+ data.tar.gz: 54a98f2f08d8a2b3691adc98abb7de41b38812a11bb3cb0a6c3773da99609547
5
5
  SHA512:
6
- metadata.gz: cb919907839936e3251fda5e404ca7f3bb9778f8885e156cfc159a138e204cfa5ac09186ce239477d8038e68a6a400e3f567f9978929c77970b06720375d9d09
7
- data.tar.gz: 214d394b2044722be42171e802c710901a670120ebfc3d1f810ac82ccb1a85f145d4e8e086bce7419b86f1f8c2c9b72fb7ca3abf66dad0fab5502546b23e9e6d
6
+ metadata.gz: 3bafcf9f75a72b96f2a390e0ff62e4647d47991703606aa56ea3460f8d60f5f5ee6f1b2f8553205751c0e0d5bb51f06f1ca8ed6850f9e0f9fccc11bfbac59873
7
+ data.tar.gz: 83090d9e804d8f4a1be5ab1cb17ca37c9d6a1324986bca748e6ec58100346e08c47fc5abf51d24f552217ddb2efa146d0c3c3dd51a99d3e41c88ef88ba44dd3f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.3.18
2
+ ===
3
+ - Fix problems with `*assign`.
4
+
1
5
  0.3.17
2
6
  ===
3
7
  - Remove support for `*array`.
@@ -3032,11 +3032,29 @@
3032
3032
  },
3033
3033
  {
3034
3034
  "id": "318",
3035
- "input": "*class(\n *id=root;\n *assign=[[myArray]]\n);\n*class(\n *id=numbers;\n *assign=[[one;two;three]]\n);\n*class(\n *id=letters;\n *assign=[[a;b;c]]\n);\n*class(\n *id=myArray;\n *assign=[[letters;numbers]]\n);\n\n[[a;b;c];[1;2;3]]\n",
3036
- "expected_output": "{\n \"myArray\": [\n {\n \"a\": \"a\",\n \"b\": \"b\",\n \"c\": \"c\"\n },\n {\n \"one\": 1,\n \"two\": 2,\n \"three\": 3\n }\n ]\n}",
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
- new_obj = {root_class_assign => obj}
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
@@ -24,6 +24,6 @@
24
24
 
25
25
  module MODL
26
26
  module Parser
27
- VERSION = "0.3.17"
27
+ VERSION = "0.3.18"
28
28
  end
29
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.17
4
+ version: 0.3.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Walmsley