finitio 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +66 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +34 -30
- data/finitio.gemspec +1 -1
- data/lib/finitio.rb +7 -39
- data/lib/finitio/errors.rb +14 -0
- data/lib/finitio/support.rb +4 -1
- data/lib/finitio/support/attribute.rb +13 -7
- data/lib/finitio/support/compilation.rb +55 -0
- data/lib/finitio/support/constraint.rb +46 -0
- data/lib/finitio/support/contract.rb +33 -0
- data/lib/finitio/support/dress_helper.rb +3 -2
- data/lib/finitio/support/heading.rb +57 -17
- data/lib/finitio/support/metadata.rb +20 -0
- data/lib/finitio/support/type_factory.rb +154 -41
- data/lib/finitio/syntax.rb +16 -31
- data/lib/finitio/syntax/expr.rb +56 -0
- data/lib/finitio/syntax/expr/arith_op.rb +22 -0
- data/lib/finitio/syntax/expr/comparison.rb +22 -0
- data/lib/finitio/syntax/expr/fn_call.rb +24 -0
- data/lib/finitio/syntax/expr/identifier.rb +18 -0
- data/lib/finitio/syntax/expr/literal.rb +19 -0
- data/lib/finitio/syntax/expr/logic_dyadic.rb +22 -0
- data/lib/finitio/syntax/expr/logic_not.rb +21 -0
- data/lib/finitio/syntax/expr/oo_call.rb +24 -0
- data/lib/finitio/syntax/expr/parenthesized.rb +20 -0
- data/lib/finitio/syntax/expr/unary_minus_op.rb +21 -0
- data/lib/finitio/syntax/expressions.citrus +129 -0
- data/lib/finitio/syntax/finitio.citrus +10 -208
- data/lib/finitio/syntax/finitio.sexp +5 -1
- data/lib/finitio/syntax/lexer.citrus +91 -0
- data/lib/finitio/syntax/literal.rb +16 -0
- data/lib/finitio/syntax/literal/boolean.rb +22 -0
- data/lib/finitio/syntax/literal/integer.rb +14 -0
- data/lib/finitio/syntax/literal/real.rb +14 -0
- data/lib/finitio/syntax/literal/string.rb +14 -0
- data/lib/finitio/syntax/literals.citrus +44 -0
- data/lib/finitio/syntax/node.rb +53 -0
- data/lib/finitio/syntax/type.rb +28 -0
- data/lib/finitio/syntax/type/ad_type.rb +29 -0
- data/lib/finitio/syntax/{any_type.rb → type/any_type.rb} +1 -1
- data/lib/finitio/syntax/type/attribute.rb +33 -0
- data/lib/finitio/syntax/{builtin_type.rb → type/builtin_type.rb} +3 -1
- data/lib/finitio/syntax/{constraint_def.rb → type/constraint_def.rb} +4 -3
- data/lib/finitio/syntax/type/constraints.rb +17 -0
- data/lib/finitio/syntax/{contract.rb → type/contract.rb} +9 -3
- data/lib/finitio/syntax/{definitions.rb → type/definitions.rb} +1 -0
- data/lib/finitio/syntax/{expression.rb → type/expression.rb} +2 -1
- data/lib/finitio/syntax/{external_pair.rb → type/external_pair.rb} +3 -1
- data/lib/finitio/syntax/type/heading.rb +30 -0
- data/lib/finitio/syntax/{inline_pair.rb → type/inline_pair.rb} +3 -1
- data/lib/finitio/syntax/{lambda_expr.rb → type/lambda_expr.rb} +3 -0
- data/lib/finitio/syntax/type/main_type.rb +18 -0
- data/lib/finitio/syntax/type/metadata.rb +18 -0
- data/lib/finitio/syntax/type/metadata_attr.rb +15 -0
- data/lib/finitio/syntax/{named_constraint.rb → type/named_constraint.rb} +10 -3
- data/lib/finitio/syntax/type/relation_type.rb +24 -0
- data/lib/finitio/syntax/{seq_type.rb → type/seq_type.rb} +3 -0
- data/lib/finitio/syntax/{set_type.rb → type/set_type.rb} +3 -0
- data/lib/finitio/syntax/type/struct_type.rb +17 -0
- data/lib/finitio/syntax/{sub_type.rb → type/sub_type.rb} +3 -0
- data/lib/finitio/syntax/{system.rb → type/system.rb} +5 -4
- data/lib/finitio/syntax/type/tuple_type.rb +24 -0
- data/lib/finitio/syntax/{type_def.rb → type/type_def.rb} +8 -3
- data/lib/finitio/syntax/{type_ref.rb → type/type_ref.rb} +4 -1
- data/lib/finitio/syntax/{union_type.rb → type/union_type.rb} +1 -0
- data/lib/finitio/syntax/{unnamed_constraint.rb → type/unnamed_constraint.rb} +7 -1
- data/lib/finitio/syntax/types.citrus +196 -0
- data/lib/finitio/system.rb +15 -15
- data/lib/finitio/type.rb +38 -6
- data/lib/finitio/type/ad_type.rb +41 -18
- data/lib/finitio/type/alias_type.rb +37 -0
- data/lib/finitio/type/any_type.rb +7 -3
- data/lib/finitio/type/builtin_type.rb +5 -4
- data/lib/finitio/{support → type}/collection_type.rb +3 -4
- data/lib/finitio/type/hash_based_type.rb +91 -0
- data/lib/finitio/type/heading_based_type.rb +28 -0
- data/lib/finitio/type/multi_relation_type.rb +34 -0
- data/lib/finitio/type/multi_tuple_type.rb +29 -0
- data/lib/finitio/type/proxy_type.rb +40 -0
- data/lib/finitio/type/rel_based_type.rb +42 -0
- data/lib/finitio/type/relation_type.rb +6 -47
- data/lib/finitio/type/seq_type.rb +4 -0
- data/lib/finitio/type/set_type.rb +4 -0
- data/lib/finitio/type/struct_type.rb +84 -0
- data/lib/finitio/type/sub_type.rb +25 -22
- data/lib/finitio/type/tuple_type.rb +6 -57
- data/lib/finitio/type/union_type.rb +12 -5
- data/lib/finitio/version.rb +2 -2
- data/spec/{unit/attribute → attribute}/test_equality.rb +8 -5
- data/spec/{unit/attribute → attribute}/test_fetch_on.rb +5 -5
- data/spec/attribute/test_initialize.rb +26 -0
- data/spec/attribute/test_optional.rb +18 -0
- data/spec/attribute/test_required.rb +18 -0
- data/spec/attribute/test_to_name.rb +20 -0
- data/spec/constraint/test_anonymous.rb +20 -0
- data/spec/constraint/test_equality.rb +39 -0
- data/spec/constraint/test_name.rb +20 -0
- data/spec/constraint/test_named.rb +20 -0
- data/spec/constraint/test_triple_equal.rb +13 -0
- data/spec/{unit/qrb/system.q → finitio/system.fio} +0 -0
- data/spec/{unit/qrb → finitio}/test_ast.rb +0 -0
- data/spec/finitio/test_parse.rb +23 -0
- data/spec/{unit/qrb/test_parse.rb → finitio/test_system.rb} +6 -6
- data/spec/heading/test_allow_extra.rb +24 -0
- data/spec/{unit/heading → heading}/test_each.rb +2 -2
- data/spec/heading/test_equality.rb +38 -0
- data/spec/heading/test_hash.rb +38 -0
- data/spec/heading/test_hash_get.rb +17 -0
- data/spec/{unit/heading → heading}/test_initialize.rb +2 -2
- data/spec/heading/test_multi.rb +57 -0
- data/spec/{unit/heading → heading}/test_size.rb +0 -0
- data/spec/heading/test_to_name.rb +58 -0
- data/spec/spec_helper.rb +17 -1
- data/spec/syntax/expr/test_free_variables.rb +46 -0
- data/spec/syntax/expr/test_to_proc_source.rb +43 -0
- data/spec/{unit/syntax → syntax}/nodes/test_ad_type.rb +26 -26
- data/spec/{unit/syntax → syntax}/nodes/test_any_type.rb +2 -2
- data/spec/syntax/nodes/test_attribute.rb +65 -0
- data/spec/{unit/syntax → syntax}/nodes/test_builtin_type.rb +5 -5
- data/spec/{unit/syntax → syntax}/nodes/test_comment.rb +1 -1
- data/spec/{unit/syntax → syntax}/nodes/test_constraint_def.rb +3 -8
- data/spec/{unit/syntax → syntax}/nodes/test_constraints.rb +21 -16
- data/spec/{unit/syntax → syntax}/nodes/test_contract.rb +28 -35
- data/spec/{unit/syntax → syntax}/nodes/test_expression.rb +13 -5
- data/spec/{unit/syntax → syntax}/nodes/test_heading.rb +25 -7
- data/spec/syntax/nodes/test_metadata.rb +28 -0
- data/spec/{unit/syntax → syntax}/nodes/test_named_constraint.rb +8 -8
- data/spec/syntax/nodes/test_relation_type.rb +84 -0
- data/spec/{unit/syntax → syntax}/nodes/test_seq_type.rb +4 -4
- data/spec/{unit/syntax → syntax}/nodes/test_set_type.rb +4 -4
- data/spec/{unit/syntax → syntax}/nodes/test_spacing.rb +1 -1
- data/spec/syntax/nodes/test_struct_type.rb +38 -0
- data/spec/{unit/syntax → syntax}/nodes/test_sub_type.rb +14 -14
- data/spec/{unit/syntax → syntax}/nodes/test_system.rb +3 -3
- data/spec/syntax/nodes/test_tuple_type.rb +94 -0
- data/spec/syntax/nodes/test_type_def.rb +57 -0
- data/spec/{unit/syntax → syntax}/nodes/test_type_ref.rb +3 -3
- data/spec/{unit/syntax → syntax}/nodes/test_union_type.rb +3 -3
- data/spec/{unit/syntax → syntax}/nodes/test_unnamed_constraint.rb +7 -7
- data/spec/syntax/test_compile.rb +41 -0
- data/spec/{unit/syntax → syntax}/test_compile_type.rb +1 -1
- data/spec/{unit/system → system}/test_add_type.rb +6 -6
- data/spec/{unit/system → system}/test_dsl.rb +2 -2
- data/spec/{unit/system → system}/test_dup.rb +4 -4
- data/spec/{unit/system → system}/test_fetch.rb +4 -4
- data/spec/{unit/system → system}/test_get_type.rb +2 -2
- data/spec/{unit/system → system}/test_initialize.rb +0 -0
- data/spec/test_finitio.rb +8 -0
- data/spec/{unit/type → type}/ad_type/test_default_name.rb +1 -2
- data/spec/{unit/type → type}/ad_type/test_dress.rb +19 -9
- data/spec/{unit/type → type}/ad_type/test_include.rb +3 -3
- data/spec/{unit/type → type}/ad_type/test_initialize.rb +15 -8
- data/spec/{unit/type → type}/ad_type/test_name.rb +2 -2
- data/spec/type/alias_type/test_default_name.rb +10 -0
- data/spec/type/alias_type/test_delegation.rb +29 -0
- data/spec/type/alias_type/test_name.rb +10 -0
- data/spec/{unit/type → type}/any_type/test_default_name.rb +1 -1
- data/spec/{unit/type → type}/any_type/test_dress.rb +0 -0
- data/spec/{unit/type → type}/any_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/any_type/test_include.rb +2 -2
- data/spec/{unit/type → type}/any_type/test_initialize.rb +0 -0
- data/spec/{unit/type → type}/any_type/test_name.rb +2 -2
- data/spec/{unit/type → type}/builtin_type/test_default_name.rb +1 -1
- data/spec/{unit/type → type}/builtin_type/test_dress.rb +3 -3
- data/spec/{unit/type → type}/builtin_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/builtin_type/test_include.rb +2 -2
- data/spec/{unit/type → type}/builtin_type/test_initialize.rb +1 -1
- data/spec/{unit/type → type}/builtin_type/test_name.rb +2 -2
- data/spec/type/multi_relation_type/test_default_name.rb +19 -0
- data/spec/type/multi_relation_type/test_dress.rb +206 -0
- data/spec/type/multi_relation_type/test_equality.rb +36 -0
- data/spec/type/multi_relation_type/test_include.rb +89 -0
- data/spec/type/multi_relation_type/test_initialize.rb +29 -0
- data/spec/type/multi_relation_type/test_name.rb +27 -0
- data/spec/type/multi_tuple_type/test_default_name.rb +17 -0
- data/spec/type/multi_tuple_type/test_dress.rb +146 -0
- data/spec/type/multi_tuple_type/test_equality.rb +32 -0
- data/spec/type/multi_tuple_type/test_include.rb +73 -0
- data/spec/type/multi_tuple_type/test_initialize.rb +30 -0
- data/spec/type/multi_tuple_type/test_name.rb +24 -0
- data/spec/type/proxy_type/test_delegation.rb +37 -0
- data/spec/type/proxy_type/test_resolve.rb +29 -0
- data/spec/{unit/type → type}/relation_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/relation_type/test_dress.rb +24 -24
- data/spec/{unit/type → type}/relation_type/test_equality.rb +6 -6
- data/spec/{unit/type → type}/relation_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/relation_type/test_initialize.rb +2 -2
- data/spec/{unit/type → type}/relation_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/seq_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/seq_type/test_dress.rb +5 -5
- data/spec/{unit/type → type}/seq_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/seq_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/seq_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/seq_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/set_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/set_type/test_dress.rb +8 -8
- data/spec/{unit/type → type}/set_type/test_equality.rb +4 -4
- data/spec/{unit/type → type}/set_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/set_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/set_type/test_name.rb +0 -0
- data/spec/type/struct_type/test_default_name.rb +10 -0
- data/spec/type/struct_type/test_dress.rb +105 -0
- data/spec/type/struct_type/test_equality.rb +28 -0
- data/spec/type/struct_type/test_include.rb +40 -0
- data/spec/type/struct_type/test_initialize.rb +22 -0
- data/spec/type/struct_type/test_name.rb +20 -0
- data/spec/{unit/type → type}/sub_type/test_default_name.rb +2 -2
- data/spec/{unit/type → type}/sub_type/test_dress.rb +14 -14
- data/spec/type/sub_type/test_equality.rb +46 -0
- data/spec/{unit/type → type}/sub_type/test_include.rb +6 -6
- data/spec/type/sub_type/test_initialize.rb +13 -0
- data/spec/{unit/type → type}/sub_type/test_name.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/tuple_type/test_dress.rb +18 -18
- data/spec/{unit/type → type}/tuple_type/test_equality.rb +6 -6
- data/spec/{unit/type → type}/tuple_type/test_include.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_initialize.rb +4 -4
- data/spec/{unit/type → type}/tuple_type/test_name.rb +0 -0
- data/spec/{unit/type → type}/union_type/test_default_name.rb +0 -0
- data/spec/{unit/type → type}/union_type/test_dress.rb +7 -6
- data/spec/{unit/type → type}/union_type/test_equality.rb +7 -7
- data/spec/{unit/type → type}/union_type/test_include.rb +3 -3
- data/spec/{unit/type → type}/union_type/test_initialize.rb +3 -3
- data/spec/{unit/type → type}/union_type/test_name.rb +0 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_adt.rb +4 -4
- data/spec/{unit/type_factory → type_factory}/dsl/test_any.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/dsl/test_attribute.rb +16 -2
- data/spec/{unit/type_factory → type_factory}/dsl/test_attributes.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/dsl/test_builtin.rb +3 -3
- data/spec/type_factory/dsl/test_multi_relation.rb +39 -0
- data/spec/type_factory/dsl/test_multi_tuple.rb +37 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_relation.rb +6 -6
- data/spec/{unit/type_factory → type_factory}/dsl/test_seq.rb +4 -4
- data/spec/{unit/type_factory → type_factory}/dsl/test_set.rb +4 -4
- data/spec/type_factory/dsl/test_struct.rb +45 -0
- data/spec/{unit/type_factory → type_factory}/dsl/test_subtype.rb +10 -8
- data/spec/{unit/type_factory → type_factory}/dsl/test_tuple.rb +5 -5
- data/spec/{unit/type_factory → type_factory}/dsl/test_union.rb +6 -6
- data/spec/{unit/type_factory → type_factory}/factory/test_builtin.rb +1 -1
- data/spec/{unit/type_factory → type_factory}/factory/test_seq_type.rb +2 -2
- data/spec/{unit/type_factory → type_factory}/factory/test_set_type.rb +2 -2
- data/spec/type_factory/factory/test_struct_type.rb +18 -0
- data/spec/{unit/type_factory → type_factory}/factory/test_sub_type.rb +7 -7
- data/spec/{unit/type_factory → type_factory}/factory/test_tuple_type.rb +4 -4
- metadata +398 -286
- data/lib/finitio/data_type.rb +0 -29
- data/lib/finitio/syntax/ad_type.rb +0 -32
- data/lib/finitio/syntax/attribute.rb +0 -15
- data/lib/finitio/syntax/constraints.rb +0 -22
- data/lib/finitio/syntax/heading.rb +0 -19
- data/lib/finitio/syntax/relation_type.rb +0 -15
- data/lib/finitio/syntax/support.rb +0 -13
- data/lib/finitio/syntax/tuple_type.rb +0 -15
- data/spec/acceptance/Finitio/test_default.rb +0 -96
- data/spec/acceptance/Finitio/test_parsing.rb +0 -15
- data/spec/acceptance/ad_type/test_in_finitio.rb +0 -82
- data/spec/acceptance/ad_type/test_in_ruby.rb +0 -60
- data/spec/unit/attribute/test_initialize.rb +0 -13
- data/spec/unit/attribute/test_to_name.rb +0 -10
- data/spec/unit/heading/test_equality.rb +0 -28
- data/spec/unit/heading/test_to_name.rb +0 -32
- data/spec/unit/syntax/nodes/test_attribute.rb +0 -38
- data/spec/unit/syntax/nodes/test_relation_type.rb +0 -59
- data/spec/unit/syntax/nodes/test_tuple_type.rb +0 -59
- data/spec/unit/syntax/nodes/test_type_def.rb +0 -33
- data/spec/unit/test_finitio.rb +0 -15
- data/spec/unit/type/sub_type/test_equality.rb +0 -34
- data/spec/unit/type/sub_type/test_initialize.rb +0 -16
checksums.yaml
ADDED
@@ -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
|
data/CHANGELOG.md
CHANGED
@@ -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
data/Gemfile.lock
CHANGED
@@ -1,55 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
finitio (0.
|
5
|
-
citrus (
|
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.
|
10
|
+
awesome_print (1.6.1)
|
11
11
|
builder (3.2.2)
|
12
|
-
citrus (
|
13
|
-
coveralls (0.7.
|
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.
|
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
|
22
|
+
gherkin (~> 2.12)
|
23
23
|
multi_json (>= 1.7.5, < 2.0)
|
24
|
-
multi_test (>= 0.
|
24
|
+
multi_test (>= 0.1.1)
|
25
25
|
diff-lcs (1.2.5)
|
26
|
-
docile (1.1.
|
26
|
+
docile (1.1.5)
|
27
27
|
gherkin (2.12.2)
|
28
28
|
multi_json (~> 1.3)
|
29
|
-
mime-types (2.
|
30
|
-
multi_json (1.
|
31
|
-
multi_test (0.
|
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.
|
33
|
+
rake (10.4.2)
|
34
34
|
rest-client (1.6.7)
|
35
35
|
mime-types (>= 1.16)
|
36
|
-
rspec (
|
37
|
-
rspec-core (~>
|
38
|
-
rspec-expectations (~>
|
39
|
-
rspec-mocks (~>
|
40
|
-
rspec-core (
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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.
|
50
|
-
tins (~>
|
53
|
+
term-ansicolor (1.2.2)
|
54
|
+
tins (~> 0.8)
|
51
55
|
thor (0.18.1)
|
52
|
-
tins (
|
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 (~>
|
68
|
+
rspec (~> 3.0)
|
data/finitio.gemspec
CHANGED
@@ -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", "
|
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
|
data/lib/finitio.rb
CHANGED
@@ -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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
14
|
+
def parse(source)
|
15
|
+
require "finitio/syntax"
|
16
|
+
Syntax.parse(source)
|
37
17
|
end
|
38
18
|
|
39
|
-
def
|
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(
|
31
|
+
DEFAULT_SYSTEM = system(File.read(
|
32
|
+
File.expand_path('../finitio/Finitio/default.fio', __FILE__)
|
33
|
+
))
|
66
34
|
end # module Finitio
|
data/lib/finitio/errors.rb
CHANGED
@@ -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
|
data/lib/finitio/support.rb
CHANGED
@@ -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
|
-
|
44
|
-
|
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
|