finitio 0.4.1 → 0.5.0

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.
Files changed (270) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +66 -0
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +34 -30
  5. data/finitio.gemspec +1 -1
  6. data/lib/finitio.rb +7 -39
  7. data/lib/finitio/errors.rb +14 -0
  8. data/lib/finitio/support.rb +4 -1
  9. data/lib/finitio/support/attribute.rb +13 -7
  10. data/lib/finitio/support/compilation.rb +55 -0
  11. data/lib/finitio/support/constraint.rb +46 -0
  12. data/lib/finitio/support/contract.rb +33 -0
  13. data/lib/finitio/support/dress_helper.rb +3 -2
  14. data/lib/finitio/support/heading.rb +57 -17
  15. data/lib/finitio/support/metadata.rb +20 -0
  16. data/lib/finitio/support/type_factory.rb +154 -41
  17. data/lib/finitio/syntax.rb +16 -31
  18. data/lib/finitio/syntax/expr.rb +56 -0
  19. data/lib/finitio/syntax/expr/arith_op.rb +22 -0
  20. data/lib/finitio/syntax/expr/comparison.rb +22 -0
  21. data/lib/finitio/syntax/expr/fn_call.rb +24 -0
  22. data/lib/finitio/syntax/expr/identifier.rb +18 -0
  23. data/lib/finitio/syntax/expr/literal.rb +19 -0
  24. data/lib/finitio/syntax/expr/logic_dyadic.rb +22 -0
  25. data/lib/finitio/syntax/expr/logic_not.rb +21 -0
  26. data/lib/finitio/syntax/expr/oo_call.rb +24 -0
  27. data/lib/finitio/syntax/expr/parenthesized.rb +20 -0
  28. data/lib/finitio/syntax/expr/unary_minus_op.rb +21 -0
  29. data/lib/finitio/syntax/expressions.citrus +129 -0
  30. data/lib/finitio/syntax/finitio.citrus +10 -208
  31. data/lib/finitio/syntax/finitio.sexp +5 -1
  32. data/lib/finitio/syntax/lexer.citrus +91 -0
  33. data/lib/finitio/syntax/literal.rb +16 -0
  34. data/lib/finitio/syntax/literal/boolean.rb +22 -0
  35. data/lib/finitio/syntax/literal/integer.rb +14 -0
  36. data/lib/finitio/syntax/literal/real.rb +14 -0
  37. data/lib/finitio/syntax/literal/string.rb +14 -0
  38. data/lib/finitio/syntax/literals.citrus +44 -0
  39. data/lib/finitio/syntax/node.rb +53 -0
  40. data/lib/finitio/syntax/type.rb +28 -0
  41. data/lib/finitio/syntax/type/ad_type.rb +29 -0
  42. data/lib/finitio/syntax/{any_type.rb → type/any_type.rb} +1 -1
  43. data/lib/finitio/syntax/type/attribute.rb +33 -0
  44. data/lib/finitio/syntax/{builtin_type.rb → type/builtin_type.rb} +3 -1
  45. data/lib/finitio/syntax/{constraint_def.rb → type/constraint_def.rb} +4 -3
  46. data/lib/finitio/syntax/type/constraints.rb +17 -0
  47. data/lib/finitio/syntax/{contract.rb → type/contract.rb} +9 -3
  48. data/lib/finitio/syntax/{definitions.rb → type/definitions.rb} +1 -0
  49. data/lib/finitio/syntax/{expression.rb → type/expression.rb} +2 -1
  50. data/lib/finitio/syntax/{external_pair.rb → type/external_pair.rb} +3 -1
  51. data/lib/finitio/syntax/type/heading.rb +30 -0
  52. data/lib/finitio/syntax/{inline_pair.rb → type/inline_pair.rb} +3 -1
  53. data/lib/finitio/syntax/{lambda_expr.rb → type/lambda_expr.rb} +3 -0
  54. data/lib/finitio/syntax/type/main_type.rb +18 -0
  55. data/lib/finitio/syntax/type/metadata.rb +18 -0
  56. data/lib/finitio/syntax/type/metadata_attr.rb +15 -0
  57. data/lib/finitio/syntax/{named_constraint.rb → type/named_constraint.rb} +10 -3
  58. data/lib/finitio/syntax/type/relation_type.rb +24 -0
  59. data/lib/finitio/syntax/{seq_type.rb → type/seq_type.rb} +3 -0
  60. data/lib/finitio/syntax/{set_type.rb → type/set_type.rb} +3 -0
  61. data/lib/finitio/syntax/type/struct_type.rb +17 -0
  62. data/lib/finitio/syntax/{sub_type.rb → type/sub_type.rb} +3 -0
  63. data/lib/finitio/syntax/{system.rb → type/system.rb} +5 -4
  64. data/lib/finitio/syntax/type/tuple_type.rb +24 -0
  65. data/lib/finitio/syntax/{type_def.rb → type/type_def.rb} +8 -3
  66. data/lib/finitio/syntax/{type_ref.rb → type/type_ref.rb} +4 -1
  67. data/lib/finitio/syntax/{union_type.rb → type/union_type.rb} +1 -0
  68. data/lib/finitio/syntax/{unnamed_constraint.rb → type/unnamed_constraint.rb} +7 -1
  69. data/lib/finitio/syntax/types.citrus +196 -0
  70. data/lib/finitio/system.rb +15 -15
  71. data/lib/finitio/type.rb +38 -6
  72. data/lib/finitio/type/ad_type.rb +41 -18
  73. data/lib/finitio/type/alias_type.rb +37 -0
  74. data/lib/finitio/type/any_type.rb +7 -3
  75. data/lib/finitio/type/builtin_type.rb +5 -4
  76. data/lib/finitio/{support → type}/collection_type.rb +3 -4
  77. data/lib/finitio/type/hash_based_type.rb +91 -0
  78. data/lib/finitio/type/heading_based_type.rb +28 -0
  79. data/lib/finitio/type/multi_relation_type.rb +34 -0
  80. data/lib/finitio/type/multi_tuple_type.rb +29 -0
  81. data/lib/finitio/type/proxy_type.rb +40 -0
  82. data/lib/finitio/type/rel_based_type.rb +42 -0
  83. data/lib/finitio/type/relation_type.rb +6 -47
  84. data/lib/finitio/type/seq_type.rb +4 -0
  85. data/lib/finitio/type/set_type.rb +4 -0
  86. data/lib/finitio/type/struct_type.rb +84 -0
  87. data/lib/finitio/type/sub_type.rb +25 -22
  88. data/lib/finitio/type/tuple_type.rb +6 -57
  89. data/lib/finitio/type/union_type.rb +12 -5
  90. data/lib/finitio/version.rb +2 -2
  91. data/spec/{unit/attribute → attribute}/test_equality.rb +8 -5
  92. data/spec/{unit/attribute → attribute}/test_fetch_on.rb +5 -5
  93. data/spec/attribute/test_initialize.rb +26 -0
  94. data/spec/attribute/test_optional.rb +18 -0
  95. data/spec/attribute/test_required.rb +18 -0
  96. data/spec/attribute/test_to_name.rb +20 -0
  97. data/spec/constraint/test_anonymous.rb +20 -0
  98. data/spec/constraint/test_equality.rb +39 -0
  99. data/spec/constraint/test_name.rb +20 -0
  100. data/spec/constraint/test_named.rb +20 -0
  101. data/spec/constraint/test_triple_equal.rb +13 -0
  102. data/spec/{unit/qrb/system.q → finitio/system.fio} +0 -0
  103. data/spec/{unit/qrb → finitio}/test_ast.rb +0 -0
  104. data/spec/finitio/test_parse.rb +23 -0
  105. data/spec/{unit/qrb/test_parse.rb → finitio/test_system.rb} +6 -6
  106. data/spec/heading/test_allow_extra.rb +24 -0
  107. data/spec/{unit/heading → heading}/test_each.rb +2 -2
  108. data/spec/heading/test_equality.rb +38 -0
  109. data/spec/heading/test_hash.rb +38 -0
  110. data/spec/heading/test_hash_get.rb +17 -0
  111. data/spec/{unit/heading → heading}/test_initialize.rb +2 -2
  112. data/spec/heading/test_multi.rb +57 -0
  113. data/spec/{unit/heading → heading}/test_size.rb +0 -0
  114. data/spec/heading/test_to_name.rb +58 -0
  115. data/spec/spec_helper.rb +17 -1
  116. data/spec/syntax/expr/test_free_variables.rb +46 -0
  117. data/spec/syntax/expr/test_to_proc_source.rb +43 -0
  118. data/spec/{unit/syntax → syntax}/nodes/test_ad_type.rb +26 -26
  119. data/spec/{unit/syntax → syntax}/nodes/test_any_type.rb +2 -2
  120. data/spec/syntax/nodes/test_attribute.rb +65 -0
  121. data/spec/{unit/syntax → syntax}/nodes/test_builtin_type.rb +5 -5
  122. data/spec/{unit/syntax → syntax}/nodes/test_comment.rb +1 -1
  123. data/spec/{unit/syntax → syntax}/nodes/test_constraint_def.rb +3 -8
  124. data/spec/{unit/syntax → syntax}/nodes/test_constraints.rb +21 -16
  125. data/spec/{unit/syntax → syntax}/nodes/test_contract.rb +28 -35
  126. data/spec/{unit/syntax → syntax}/nodes/test_expression.rb +13 -5
  127. data/spec/{unit/syntax → syntax}/nodes/test_heading.rb +25 -7
  128. data/spec/syntax/nodes/test_metadata.rb +28 -0
  129. data/spec/{unit/syntax → syntax}/nodes/test_named_constraint.rb +8 -8
  130. data/spec/syntax/nodes/test_relation_type.rb +84 -0
  131. data/spec/{unit/syntax → syntax}/nodes/test_seq_type.rb +4 -4
  132. data/spec/{unit/syntax → syntax}/nodes/test_set_type.rb +4 -4
  133. data/spec/{unit/syntax → syntax}/nodes/test_spacing.rb +1 -1
  134. data/spec/syntax/nodes/test_struct_type.rb +38 -0
  135. data/spec/{unit/syntax → syntax}/nodes/test_sub_type.rb +14 -14
  136. data/spec/{unit/syntax → syntax}/nodes/test_system.rb +3 -3
  137. data/spec/syntax/nodes/test_tuple_type.rb +94 -0
  138. data/spec/syntax/nodes/test_type_def.rb +57 -0
  139. data/spec/{unit/syntax → syntax}/nodes/test_type_ref.rb +3 -3
  140. data/spec/{unit/syntax → syntax}/nodes/test_union_type.rb +3 -3
  141. data/spec/{unit/syntax → syntax}/nodes/test_unnamed_constraint.rb +7 -7
  142. data/spec/syntax/test_compile.rb +41 -0
  143. data/spec/{unit/syntax → syntax}/test_compile_type.rb +1 -1
  144. data/spec/{unit/system → system}/test_add_type.rb +6 -6
  145. data/spec/{unit/system → system}/test_dsl.rb +2 -2
  146. data/spec/{unit/system → system}/test_dup.rb +4 -4
  147. data/spec/{unit/system → system}/test_fetch.rb +4 -4
  148. data/spec/{unit/system → system}/test_get_type.rb +2 -2
  149. data/spec/{unit/system → system}/test_initialize.rb +0 -0
  150. data/spec/test_finitio.rb +8 -0
  151. data/spec/{unit/type → type}/ad_type/test_default_name.rb +1 -2
  152. data/spec/{unit/type → type}/ad_type/test_dress.rb +19 -9
  153. data/spec/{unit/type → type}/ad_type/test_include.rb +3 -3
  154. data/spec/{unit/type → type}/ad_type/test_initialize.rb +15 -8
  155. data/spec/{unit/type → type}/ad_type/test_name.rb +2 -2
  156. data/spec/type/alias_type/test_default_name.rb +10 -0
  157. data/spec/type/alias_type/test_delegation.rb +29 -0
  158. data/spec/type/alias_type/test_name.rb +10 -0
  159. data/spec/{unit/type → type}/any_type/test_default_name.rb +1 -1
  160. data/spec/{unit/type → type}/any_type/test_dress.rb +0 -0
  161. data/spec/{unit/type → type}/any_type/test_equality.rb +4 -4
  162. data/spec/{unit/type → type}/any_type/test_include.rb +2 -2
  163. data/spec/{unit/type → type}/any_type/test_initialize.rb +0 -0
  164. data/spec/{unit/type → type}/any_type/test_name.rb +2 -2
  165. data/spec/{unit/type → type}/builtin_type/test_default_name.rb +1 -1
  166. data/spec/{unit/type → type}/builtin_type/test_dress.rb +3 -3
  167. data/spec/{unit/type → type}/builtin_type/test_equality.rb +4 -4
  168. data/spec/{unit/type → type}/builtin_type/test_include.rb +2 -2
  169. data/spec/{unit/type → type}/builtin_type/test_initialize.rb +1 -1
  170. data/spec/{unit/type → type}/builtin_type/test_name.rb +2 -2
  171. data/spec/type/multi_relation_type/test_default_name.rb +19 -0
  172. data/spec/type/multi_relation_type/test_dress.rb +206 -0
  173. data/spec/type/multi_relation_type/test_equality.rb +36 -0
  174. data/spec/type/multi_relation_type/test_include.rb +89 -0
  175. data/spec/type/multi_relation_type/test_initialize.rb +29 -0
  176. data/spec/type/multi_relation_type/test_name.rb +27 -0
  177. data/spec/type/multi_tuple_type/test_default_name.rb +17 -0
  178. data/spec/type/multi_tuple_type/test_dress.rb +146 -0
  179. data/spec/type/multi_tuple_type/test_equality.rb +32 -0
  180. data/spec/type/multi_tuple_type/test_include.rb +73 -0
  181. data/spec/type/multi_tuple_type/test_initialize.rb +30 -0
  182. data/spec/type/multi_tuple_type/test_name.rb +24 -0
  183. data/spec/type/proxy_type/test_delegation.rb +37 -0
  184. data/spec/type/proxy_type/test_resolve.rb +29 -0
  185. data/spec/{unit/type → type}/relation_type/test_default_name.rb +0 -0
  186. data/spec/{unit/type → type}/relation_type/test_dress.rb +24 -24
  187. data/spec/{unit/type → type}/relation_type/test_equality.rb +6 -6
  188. data/spec/{unit/type → type}/relation_type/test_include.rb +4 -4
  189. data/spec/{unit/type → type}/relation_type/test_initialize.rb +2 -2
  190. data/spec/{unit/type → type}/relation_type/test_name.rb +0 -0
  191. data/spec/{unit/type → type}/seq_type/test_default_name.rb +0 -0
  192. data/spec/{unit/type → type}/seq_type/test_dress.rb +5 -5
  193. data/spec/{unit/type → type}/seq_type/test_equality.rb +4 -4
  194. data/spec/{unit/type → type}/seq_type/test_include.rb +4 -4
  195. data/spec/{unit/type → type}/seq_type/test_initialize.rb +3 -3
  196. data/spec/{unit/type → type}/seq_type/test_name.rb +0 -0
  197. data/spec/{unit/type → type}/set_type/test_default_name.rb +0 -0
  198. data/spec/{unit/type → type}/set_type/test_dress.rb +8 -8
  199. data/spec/{unit/type → type}/set_type/test_equality.rb +4 -4
  200. data/spec/{unit/type → type}/set_type/test_include.rb +4 -4
  201. data/spec/{unit/type → type}/set_type/test_initialize.rb +3 -3
  202. data/spec/{unit/type → type}/set_type/test_name.rb +0 -0
  203. data/spec/type/struct_type/test_default_name.rb +10 -0
  204. data/spec/type/struct_type/test_dress.rb +105 -0
  205. data/spec/type/struct_type/test_equality.rb +28 -0
  206. data/spec/type/struct_type/test_include.rb +40 -0
  207. data/spec/type/struct_type/test_initialize.rb +22 -0
  208. data/spec/type/struct_type/test_name.rb +20 -0
  209. data/spec/{unit/type → type}/sub_type/test_default_name.rb +2 -2
  210. data/spec/{unit/type → type}/sub_type/test_dress.rb +14 -14
  211. data/spec/type/sub_type/test_equality.rb +46 -0
  212. data/spec/{unit/type → type}/sub_type/test_include.rb +6 -6
  213. data/spec/type/sub_type/test_initialize.rb +13 -0
  214. data/spec/{unit/type → type}/sub_type/test_name.rb +4 -4
  215. data/spec/{unit/type → type}/tuple_type/test_default_name.rb +0 -0
  216. data/spec/{unit/type → type}/tuple_type/test_dress.rb +18 -18
  217. data/spec/{unit/type → type}/tuple_type/test_equality.rb +6 -6
  218. data/spec/{unit/type → type}/tuple_type/test_include.rb +4 -4
  219. data/spec/{unit/type → type}/tuple_type/test_initialize.rb +4 -4
  220. data/spec/{unit/type → type}/tuple_type/test_name.rb +0 -0
  221. data/spec/{unit/type → type}/union_type/test_default_name.rb +0 -0
  222. data/spec/{unit/type → type}/union_type/test_dress.rb +7 -6
  223. data/spec/{unit/type → type}/union_type/test_equality.rb +7 -7
  224. data/spec/{unit/type → type}/union_type/test_include.rb +3 -3
  225. data/spec/{unit/type → type}/union_type/test_initialize.rb +3 -3
  226. data/spec/{unit/type → type}/union_type/test_name.rb +0 -0
  227. data/spec/{unit/type_factory → type_factory}/dsl/test_adt.rb +4 -4
  228. data/spec/{unit/type_factory → type_factory}/dsl/test_any.rb +1 -1
  229. data/spec/{unit/type_factory → type_factory}/dsl/test_attribute.rb +16 -2
  230. data/spec/{unit/type_factory → type_factory}/dsl/test_attributes.rb +1 -1
  231. data/spec/{unit/type_factory → type_factory}/dsl/test_builtin.rb +3 -3
  232. data/spec/type_factory/dsl/test_multi_relation.rb +39 -0
  233. data/spec/type_factory/dsl/test_multi_tuple.rb +37 -0
  234. data/spec/{unit/type_factory → type_factory}/dsl/test_relation.rb +6 -6
  235. data/spec/{unit/type_factory → type_factory}/dsl/test_seq.rb +4 -4
  236. data/spec/{unit/type_factory → type_factory}/dsl/test_set.rb +4 -4
  237. data/spec/type_factory/dsl/test_struct.rb +45 -0
  238. data/spec/{unit/type_factory → type_factory}/dsl/test_subtype.rb +10 -8
  239. data/spec/{unit/type_factory → type_factory}/dsl/test_tuple.rb +5 -5
  240. data/spec/{unit/type_factory → type_factory}/dsl/test_union.rb +6 -6
  241. data/spec/{unit/type_factory → type_factory}/factory/test_builtin.rb +1 -1
  242. data/spec/{unit/type_factory → type_factory}/factory/test_seq_type.rb +2 -2
  243. data/spec/{unit/type_factory → type_factory}/factory/test_set_type.rb +2 -2
  244. data/spec/type_factory/factory/test_struct_type.rb +18 -0
  245. data/spec/{unit/type_factory → type_factory}/factory/test_sub_type.rb +7 -7
  246. data/spec/{unit/type_factory → type_factory}/factory/test_tuple_type.rb +4 -4
  247. metadata +398 -286
  248. data/lib/finitio/data_type.rb +0 -29
  249. data/lib/finitio/syntax/ad_type.rb +0 -32
  250. data/lib/finitio/syntax/attribute.rb +0 -15
  251. data/lib/finitio/syntax/constraints.rb +0 -22
  252. data/lib/finitio/syntax/heading.rb +0 -19
  253. data/lib/finitio/syntax/relation_type.rb +0 -15
  254. data/lib/finitio/syntax/support.rb +0 -13
  255. data/lib/finitio/syntax/tuple_type.rb +0 -15
  256. data/spec/acceptance/Finitio/test_default.rb +0 -96
  257. data/spec/acceptance/Finitio/test_parsing.rb +0 -15
  258. data/spec/acceptance/ad_type/test_in_finitio.rb +0 -82
  259. data/spec/acceptance/ad_type/test_in_ruby.rb +0 -60
  260. data/spec/unit/attribute/test_initialize.rb +0 -13
  261. data/spec/unit/attribute/test_to_name.rb +0 -10
  262. data/spec/unit/heading/test_equality.rb +0 -28
  263. data/spec/unit/heading/test_to_name.rb +0 -32
  264. data/spec/unit/syntax/nodes/test_attribute.rb +0 -38
  265. data/spec/unit/syntax/nodes/test_relation_type.rb +0 -59
  266. data/spec/unit/syntax/nodes/test_tuple_type.rb +0 -59
  267. data/spec/unit/syntax/nodes/test_type_def.rb +0 -33
  268. data/spec/unit/test_finitio.rb +0 -15
  269. data/spec/unit/type/sub_type/test_equality.rb +0 -34
  270. data/spec/unit/type/sub_type/test_initialize.rb +0 -16
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cae1bbbd04a1136243171e987246538c9b575800
4
+ data.tar.gz: d1de82b9707e8969bad9b51297fd8ebc62f18d27
5
+ SHA512:
6
+ metadata.gz: 1511839793f7c4595e158494d8a879f8edad4331c1e0774836bbaf752ca325f1769d62c7a6c03fd966b8ad09d23b78f4ba67117b94981ac0977ebd162f9c8e92
7
+ data.tar.gz: 519e91f7ba489a200cfd05c462fc0014d836211efcce7b69cbae44c77ca4a3044a36984022153e083d929f7373da5778f593c87f3dd14150d07f259a12739008
@@ -1,3 +1,69 @@
1
+ # 0.5.0 / HEAD
2
+
3
+ * Breaking changes on public API
4
+
5
+ * Finitio.parse now returns the parsing tree, no longer the compiled system,
6
+ use Finitio.system instead.
7
+
8
+ * Dress error messages have been changed from `Invalid value xxx for Type` to
9
+ a more friendly `Invalid Type xxx`. The rationale is that end-users might
10
+ be exposed to those messages in practice. The new messages seem less cryptic.
11
+
12
+ * Major enhancements
13
+
14
+ * Types no longer have to declared before being used. In order words, the
15
+ following will work fine even if Bigint references Posint that is declared
16
+ afterwards:
17
+
18
+ ```
19
+ Bigint = Posint( i | i >= 255 )
20
+ Posint = Integer( i | i >= 0 )
21
+ { length: Bigint }
22
+ ```
23
+
24
+ * Added support for recursive types, e.g.,
25
+
26
+ ```
27
+ Tree = { label: String, children: [Tree] }
28
+ ```
29
+
30
+ * Added support for MultiTuple and MultiRelation types, aka "optional
31
+ vs. required attributes". In the following system, `Person` is a multi
32
+ tuple while `Persons` is a multi relation; the date of birth is optional
33
+ in both cases:
34
+
35
+ ```
36
+ Person = { name : String, dob :? Date }
37
+ Persons = {{ name : String, dob :? Date }}
38
+ ```
39
+
40
+ * Added basic support for namespacing, through dots being now allowed in
41
+ type names. More namespacing support will be added later.
42
+
43
+
44
+ ```
45
+ This.Is.A.NameSpaced.Type = .Integer( i | i >= 0 )
46
+ { length: This.Is.A.NameSpaced.Type }
47
+ ```
48
+
49
+ * Attribute names can now start with an underscore, e.g. '_links'
50
+
51
+ * Error now have an `root_cause` helper.
52
+
53
+ * Dress errors resulting from Union and AdType now set a cause to the first
54
+ error encountered during the various attempts to dress.
55
+
56
+ * Breaking changes on undocumented APIs
57
+
58
+ * Removed factory methods from the Finitio module itself. Use a System
59
+ instance instead.
60
+ * Removed Finitio::DataType
61
+
62
+ * Other changes & Bug fixes
63
+
64
+ * Make Finitio compatible with both Citrus 2.4.x and Citrus 3.x
65
+ * Fixed parsing of constraint expressions having inner parentheses
66
+
1
67
  # 0.4.1 / 2014-03-20
2
68
 
3
69
  * Fixed access to the default system that lead to 'Unknown system
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gemspec
4
4
 
5
5
  group :development do
6
6
  gem "rake", "~> 10.0"
7
- gem "rspec", "~> 2.14"
7
+ gem "rspec", "~> 3.0"
8
8
  gem "cucumber", "~> 1.3"
9
9
  gem "path", "~> 1.3"
10
10
  gem "awesome_print", "~> 1.2"
@@ -1,55 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- finitio (0.4.1)
5
- citrus (~> 2.4)
4
+ finitio (0.5.0)
5
+ citrus (>= 2.4, < 4.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- awesome_print (1.2.0)
10
+ awesome_print (1.6.1)
11
11
  builder (3.2.2)
12
- citrus (2.4.1)
13
- coveralls (0.7.0)
12
+ citrus (3.0.2)
13
+ coveralls (0.7.2)
14
14
  multi_json (~> 1.3)
15
- rest-client
15
+ rest-client (= 1.6.7)
16
16
  simplecov (>= 0.7)
17
- term-ansicolor
18
- thor
19
- cucumber (1.3.8)
17
+ term-ansicolor (= 1.2.2)
18
+ thor (= 0.18.1)
19
+ cucumber (1.3.18)
20
20
  builder (>= 2.1.2)
21
21
  diff-lcs (>= 1.1.3)
22
- gherkin (~> 2.12.1)
22
+ gherkin (~> 2.12)
23
23
  multi_json (>= 1.7.5, < 2.0)
24
- multi_test (>= 0.0.2)
24
+ multi_test (>= 0.1.1)
25
25
  diff-lcs (1.2.5)
26
- docile (1.1.3)
26
+ docile (1.1.5)
27
27
  gherkin (2.12.2)
28
28
  multi_json (~> 1.3)
29
- mime-types (2.1)
30
- multi_json (1.8.4)
31
- multi_test (0.0.2)
29
+ mime-types (2.4.3)
30
+ multi_json (1.10.1)
31
+ multi_test (0.1.1)
32
32
  path (1.3.3)
33
- rake (10.1.1)
33
+ rake (10.4.2)
34
34
  rest-client (1.6.7)
35
35
  mime-types (>= 1.16)
36
- rspec (2.14.1)
37
- rspec-core (~> 2.14.0)
38
- rspec-expectations (~> 2.14.0)
39
- rspec-mocks (~> 2.14.0)
40
- rspec-core (2.14.7)
41
- rspec-expectations (2.14.4)
42
- diff-lcs (>= 1.1.3, < 2.0)
43
- rspec-mocks (2.14.4)
44
- simplecov (0.8.2)
36
+ rspec (3.1.0)
37
+ rspec-core (~> 3.1.0)
38
+ rspec-expectations (~> 3.1.0)
39
+ rspec-mocks (~> 3.1.0)
40
+ rspec-core (3.1.7)
41
+ rspec-support (~> 3.1.0)
42
+ rspec-expectations (3.1.2)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.1.0)
45
+ rspec-mocks (3.1.3)
46
+ rspec-support (~> 3.1.0)
47
+ rspec-support (3.1.2)
48
+ simplecov (0.9.1)
45
49
  docile (~> 1.1.0)
46
- multi_json
50
+ multi_json (~> 1.0)
47
51
  simplecov-html (~> 0.8.0)
48
52
  simplecov-html (0.8.0)
49
- term-ansicolor (1.3.0)
50
- tins (~> 1.0)
53
+ term-ansicolor (1.2.2)
54
+ tins (~> 0.8)
51
55
  thor (0.18.1)
52
- tins (1.0.0)
56
+ tins (0.13.2)
53
57
 
54
58
  PLATFORMS
55
59
  ruby
@@ -61,4 +65,4 @@ DEPENDENCIES
61
65
  finitio!
62
66
  path (~> 1.3)
63
67
  rake (~> 10.0)
64
- rspec (~> 2.14)
68
+ rspec (~> 3.0)
@@ -116,7 +116,7 @@ Gem::Specification.new do |s|
116
116
  # "~> 2.2" (shortcut for ">= 2.2.0", "< 3.0")
117
117
  # "~> 2.2.0" (shortcut for ">= 2.2.0", "< 2.3.0")
118
118
  #
119
- s.add_dependency("citrus", "~> 2.4")
119
+ s.add_dependency("citrus", ">= 2.4", "< 4.0")
120
120
 
121
121
  #
122
122
  # One call to add_dependency('gem_name', 'gem version requirement') for each
@@ -3,40 +3,20 @@ require 'time'
3
3
 
4
4
  module Finitio
5
5
 
6
- DSL_METHODS = [
7
- :attribute,
8
- :heading,
9
- :constraints,
10
- :any,
11
- :builtin,
12
- :adt,
13
- :subtype,
14
- :union,
15
- :seq,
16
- :set,
17
- :tuple,
18
- :relation,
19
- :type
20
- ]
21
-
22
6
  require_relative "finitio/version"
23
7
  require_relative "finitio/errors"
24
8
  require_relative "finitio/support"
25
9
  require_relative 'finitio/type'
26
- require_relative 'finitio/data_type'
27
10
  require_relative 'finitio/system'
28
11
 
29
- DEFAULT_FACTORY = TypeFactory.new
30
-
31
12
  IDENTITY = ->(object){ object }
32
13
 
33
- DSL_METHODS.each do |meth|
34
- define_method(meth) do |*args, &bl|
35
- DEFAULT_FACTORY.public_send(meth, *args, &bl)
36
- end
14
+ def parse(source)
15
+ require "finitio/syntax"
16
+ Syntax.parse(source)
37
17
  end
38
18
 
39
- def parse(source)
19
+ def system(source)
40
20
  require "finitio/syntax"
41
21
  Syntax.compile(source)
42
22
  end
@@ -46,21 +26,9 @@ module Finitio
46
26
  Syntax.ast(source)
47
27
  end
48
28
 
49
- def system(identifier)
50
- f = File.expand_path("../finitio/#{identifier}.fio", __FILE__)
51
- if File.exists?(f)
52
- parse(File.read(f))
53
- else
54
- raise Error, "Unknown system #{identifier}"
55
- end
56
- end
57
-
58
- def definition_files(of)
59
- dir = File.expand_path("../finitio/#{of}", __FILE__)
60
- Dir.glob("#{dir}/*.fio")
61
- end
62
-
63
29
  extend self
64
30
 
65
- DEFAULT_SYSTEM = system('Finitio/default')
31
+ DEFAULT_SYSTEM = system(File.read(
32
+ File.expand_path('../finitio/Finitio/default.fio', __FILE__)
33
+ ))
66
34
  end # module Finitio
@@ -8,6 +8,20 @@ module Finitio
8
8
  end
9
9
  attr_reader :cause
10
10
 
11
+ def root_cause(sandbox = true)
12
+ # 1) no deeper cause, it's me
13
+ return self if cause.nil?
14
+
15
+ # 2) not a Finitio cause and sandbox
16
+ return self if sandbox and not cause.is_a?(Error)
17
+
18
+ # 3) cause may not go deeper
19
+ return cause unless cause.respond_to?(:root_cause)
20
+
21
+ # 4) delegate
22
+ cause.root_cause
23
+ end
24
+
11
25
  end # class Error
12
26
 
13
27
  class TypeError < Error
@@ -1,5 +1,8 @@
1
+ require_relative 'support/metadata'
1
2
  require_relative 'support/attribute'
3
+ require_relative 'support/constraint'
4
+ require_relative 'support/contract'
2
5
  require_relative 'support/heading'
3
6
  require_relative 'support/dress_helper'
4
- require_relative 'support/collection_type'
5
7
  require_relative 'support/type_factory'
8
+ require_relative 'support/compilation'
@@ -6,8 +6,9 @@ module Finitio
6
6
  # type is a Finitio type.
7
7
  #
8
8
  class Attribute
9
+ include Metadata
9
10
 
10
- def initialize(name, type)
11
+ def initialize(name, type, required = true, metadata = nil)
11
12
  unless name.is_a?(Symbol)
12
13
  raise ArgumentError, "Symbol expected for attribute name, got `#{name}`"
13
14
  end
@@ -16,9 +17,14 @@ module Finitio
16
17
  raise ArgumentError, "Type expected for attribute domain, got `#{type}`"
17
18
  end
18
19
 
19
- @name, @type = name, type
20
+ @name, @type, @required, @metadata = name, type, required, metadata
21
+ end
22
+ attr_reader :name, :type, :required
23
+ alias :required? :required
24
+
25
+ def optional?
26
+ !required?
20
27
  end
21
- attr_reader :name, :type
22
28
 
23
29
  # Fetch the attribute on `arg`, which is expected to be a Hash object.
24
30
  #
@@ -36,17 +42,17 @@ module Finitio
36
42
  end
37
43
 
38
44
  def to_name
39
- "#{name}: #{type}"
45
+ required ? "#{name}: #{type}" : "#{name} :? #{type}"
40
46
  end
41
47
 
42
48
  def ==(other)
43
- return nil unless other.is_a?(Attribute)
44
- name==other.name and type==other.type
49
+ other.is_a?(Attribute) && name==other.name && \
50
+ type==other.type && required==other.required
45
51
  end
46
52
  alias :eql? :==
47
53
 
48
54
  def hash
49
- name.hash ^ type.hash
55
+ name.hash ^ type.hash ^ required.hash
50
56
  end
51
57
 
52
58
  end # class Attribute
@@ -0,0 +1,55 @@
1
+ module Finitio
2
+ class Compilation
3
+
4
+ def initialize(system = System.new, factory = TypeFactory.new)
5
+ @system = system
6
+ @factory = factory
7
+ @proxies = []
8
+ end
9
+ attr_reader :system, :factory, :proxies
10
+
11
+ def self.coerce(arg)
12
+ case arg
13
+ when NilClass then new
14
+ when System then new(arg, arg.factory)
15
+ when TypeFactory then new(System.new, arg)
16
+ else
17
+ raise ArgumentError, "Unable to coerce `#{arg}`"
18
+ end
19
+ end
20
+
21
+ def resolve_proxies!
22
+ proxies.each do |p|
23
+ p.resolve(system)
24
+ end
25
+ self
26
+ end
27
+
28
+ # Delegation to Factory
29
+
30
+ TypeFactory::DSL_METHODS.each do |dsl_method|
31
+ define_method(dsl_method){|*args, &bl|
32
+ factory.public_send(dsl_method, *args, &bl)
33
+ }
34
+ end
35
+
36
+ def proxy(*args, &bl)
37
+ proxy = factory.proxy(*args, &bl)
38
+ proxies << proxy
39
+ proxy
40
+ end
41
+
42
+ # Delegation to System
43
+
44
+ [
45
+ :add_type,
46
+ :fetch,
47
+ :main,
48
+ ].each do |meth|
49
+ define_method(meth) do |*args, &bl|
50
+ system.public_send(meth, *args, &bl)
51
+ end
52
+ end
53
+
54
+ end # class Compilation
55
+ end # module Finitio
@@ -0,0 +1,46 @@
1
+ module Finitio
2
+ class Constraint
3
+ include Metadata
4
+
5
+ def initialize(native, name = nil, metadata = nil)
6
+ unless native.respond_to?(:===)
7
+ raise ArgumentError, "Constraint must respond to :==="
8
+ end
9
+ unless name.nil? or name.is_a?(Symbol)
10
+ raise ArgumentError, "Constraint name must be a Symbol"
11
+ end
12
+ @native = native
13
+ @name = name
14
+ @metadata = metadata
15
+ end
16
+
17
+ attr_reader :native
18
+ protected :native
19
+
20
+ def anonymous?
21
+ @name.nil?
22
+ end
23
+
24
+ def named?
25
+ !anonymous?
26
+ end
27
+
28
+ def name
29
+ @name || :default
30
+ end
31
+
32
+ def ===(*args, &bl)
33
+ native.===(*args, &bl)
34
+ end
35
+
36
+ def ==(other)
37
+ super || (other.is_a?(Constraint) && native==other.native)
38
+ end
39
+ alias :eql? :==
40
+
41
+ def hash
42
+ self.class.hash ^ native.hash
43
+ end
44
+
45
+ end # class Constraint
46
+ end # module Finitio