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.
- 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
data/lib/finitio/data_type.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module DataType
|
3
|
-
|
4
|
-
def dress(value, handler = DressHelper.new)
|
5
|
-
ad_type.dress(value, handler)
|
6
|
-
end
|
7
|
-
|
8
|
-
def contract(name, infotype)
|
9
|
-
dresser = method(name)
|
10
|
-
undresser = instance_method(:"to_#{name}")
|
11
|
-
ad_contracts[name] = [
|
12
|
-
Finitio.type(infotype),
|
13
|
-
dresser,
|
14
|
-
->(d){ undresser.bind(d).call }
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def ad_type
|
21
|
-
@ad_type ||= Finitio.adt(self, ad_contracts)
|
22
|
-
end
|
23
|
-
|
24
|
-
def ad_contracts
|
25
|
-
@ad_contracts ||= {}
|
26
|
-
end
|
27
|
-
|
28
|
-
end # module DataType
|
29
|
-
end # module Finitio
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module AdType
|
4
|
-
include Support
|
5
|
-
|
6
|
-
def compile(factory)
|
7
|
-
name = builtin_type_name
|
8
|
-
clazz = name ? resolve_ruby_const(name.to_s) : nil
|
9
|
-
factory.adt(clazz, compile_contracts(factory, clazz))
|
10
|
-
end
|
11
|
-
|
12
|
-
def compile_contracts(factory, clazz)
|
13
|
-
contracts = {}
|
14
|
-
captures[:contract].each do |node|
|
15
|
-
contract = node.compile(factory, clazz)
|
16
|
-
contracts.merge!(contract) do |k,_,_|
|
17
|
-
raise Error, "Duplicate contract name `#{k}`"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
contracts
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_ast
|
24
|
-
[
|
25
|
-
:ad_type,
|
26
|
-
builtin_type_name ? builtin_type_name.to_s : nil
|
27
|
-
] + captures[:contract].map(&:to_ast)
|
28
|
-
end
|
29
|
-
|
30
|
-
end # module AdType
|
31
|
-
end # module Syntax
|
32
|
-
end # module Finitio
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module Attribute
|
4
|
-
|
5
|
-
def compile(factory)
|
6
|
-
factory.attribute(attribute_name.to_sym, type.compile(factory))
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_ast
|
10
|
-
[:attribute, attribute_name.to_s, type.to_ast]
|
11
|
-
end
|
12
|
-
|
13
|
-
end # module BuiltinType
|
14
|
-
end # module Syntax
|
15
|
-
end # module Finitio
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module Constraints
|
4
|
-
|
5
|
-
def compile(var_name)
|
6
|
-
constraints = {}
|
7
|
-
captures[:named_constraint].each do |node|
|
8
|
-
compiled = node.compile(var_name)
|
9
|
-
constraints.merge!(compiled) do |k,_,_|
|
10
|
-
raise Error, "Duplicate constraint name `#{k}`"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
constraints
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_ast(var_name)
|
17
|
-
captures[:named_constraint].map{|c| c.to_ast(var_name) }
|
18
|
-
end
|
19
|
-
|
20
|
-
end # module Constraints
|
21
|
-
end # module Syntax
|
22
|
-
end # module Finitio
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module Heading
|
4
|
-
|
5
|
-
def attributes(factory)
|
6
|
-
captures[:attribute].map{|x| x.compile(factory) }
|
7
|
-
end
|
8
|
-
|
9
|
-
def compile(factory)
|
10
|
-
Finitio::Heading.new(attributes(factory))
|
11
|
-
end
|
12
|
-
|
13
|
-
def to_ast
|
14
|
-
captures[:attribute].map(&:to_ast).unshift(:heading)
|
15
|
-
end
|
16
|
-
|
17
|
-
end # module Heading
|
18
|
-
end # module Syntax
|
19
|
-
end # module Finitio
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module RelationType
|
4
|
-
|
5
|
-
def compile(factory)
|
6
|
-
factory.relation(heading.compile(factory))
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_ast
|
10
|
-
[:relation_type, heading.to_ast]
|
11
|
-
end
|
12
|
-
|
13
|
-
end # module RelationType
|
14
|
-
end # module Syntax
|
15
|
-
end # module Finitio
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module Finitio
|
2
|
-
module Syntax
|
3
|
-
module TupleType
|
4
|
-
|
5
|
-
def compile(factory)
|
6
|
-
factory.tuple(heading.compile(factory))
|
7
|
-
end
|
8
|
-
|
9
|
-
def to_ast
|
10
|
-
[:tuple_type, heading.to_ast]
|
11
|
-
end
|
12
|
-
|
13
|
-
end # module TupleType
|
14
|
-
end # module Syntax
|
15
|
-
end # module Finitio
|
@@ -1,96 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Finitio
|
3
|
-
describe "Finitio/default" do
|
4
|
-
|
5
|
-
let(:system){ Finitio.system('Finitio/default') }
|
6
|
-
|
7
|
-
describe 'Boolean' do
|
8
|
-
let(:type){ system['Boolean'] }
|
9
|
-
|
10
|
-
it 'recognizes true' do
|
11
|
-
type.dress(true).should eq(true)
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'recognizes false' do
|
15
|
-
type.dress(false).should eq(false)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'raises on something else' do
|
19
|
-
->{ type.dress("foo") }.should raise_error(TypeError)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'Date' do
|
24
|
-
let(:type){ system['Date'] }
|
25
|
-
|
26
|
-
let(:expected){ Date.new(2014, 11, 9) }
|
27
|
-
|
28
|
-
it 'recognizes dates' do
|
29
|
-
type.dress(expected).should be(expected)
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'recognizes iso8601 dates' do
|
33
|
-
type.dress('2014-11-09').should eq(expected)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'recognizes the output of iso8601' do
|
37
|
-
type.dress(expected.iso8601).should eq(expected)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'raises on something else' do
|
41
|
-
->{
|
42
|
-
type.dress('foo')
|
43
|
-
}.should raise_error("Invalid value `foo` for Date")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'Time' do
|
48
|
-
let(:type){ system['Time'] }
|
49
|
-
|
50
|
-
let(:expected){ Time.new(2014,3,1,12,9,31) }
|
51
|
-
|
52
|
-
it 'recognizes times' do
|
53
|
-
type.dress(expected).should be(expected)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'recognizes iso8601 times' do
|
57
|
-
type.dress('2014-03-01T12:09:31').should eq(expected)
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'recognizes the output of iso8601' do
|
61
|
-
type.dress(expected.iso8601).should eq(expected)
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'raises on something else' do
|
65
|
-
->{
|
66
|
-
type.dress('foo')
|
67
|
-
}.should raise_error("Invalid value `foo` for Time")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
describe 'DateTime' do
|
72
|
-
let(:type){ system['DateTime'] }
|
73
|
-
|
74
|
-
let(:expected){ DateTime.new(2014,3,1,12,9,31) }
|
75
|
-
|
76
|
-
it 'recognizes times' do
|
77
|
-
type.dress(expected).should be(expected)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'recognizes iso8601 times' do
|
81
|
-
type.dress('2014-03-01T12:09:31').should eq(expected)
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'recognizes the output of iso8601' do
|
85
|
-
type.dress(expected.iso8601).should eq(expected)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'raises on something else' do
|
89
|
-
->{
|
90
|
-
type.dress('foo')
|
91
|
-
}.should raise_error("Invalid value `foo` for DateTime")
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
describe "Finitio definition files" do
|
3
|
-
|
4
|
-
Finitio.definition_files('Finitio').each do |file|
|
5
|
-
file = Path(file)
|
6
|
-
|
7
|
-
describe "Finitio/#{file.basename.rm_ext}" do
|
8
|
-
|
9
|
-
it 'should parse' do
|
10
|
-
Finitio.parse(file.read).should be_a(Finitio::System)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Finitio
|
3
|
-
describe "Using Finitio's abstract data types in Ruby/Finitio" do
|
4
|
-
|
5
|
-
class MyColorClass
|
6
|
-
extend Finitio::DataType
|
7
|
-
|
8
|
-
def initialize(r, g, b)
|
9
|
-
@r, @g, @b = r, g, b
|
10
|
-
end
|
11
|
-
attr_reader :r, :g, :b
|
12
|
-
|
13
|
-
def to_rgb
|
14
|
-
{ r: @r, g: @g, b: @b }
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.rgb(tuple)
|
18
|
-
new(tuple[:r], tuple[:g], tuple[:b])
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:system) do
|
23
|
-
Finitio.parse <<-EOF
|
24
|
-
Byte = .Fixnum( i | i>=0 and i<= 255 )
|
25
|
-
Color = .Finitio::MyColorClass <rgb> {r: Byte, g: Byte, b: Byte}
|
26
|
-
Gender = <mf> .String( s | s=='M' or s=='F' )
|
27
|
-
EOF
|
28
|
-
end
|
29
|
-
|
30
|
-
let(:color){
|
31
|
-
system["Color"]
|
32
|
-
}
|
33
|
-
|
34
|
-
describe 'the Color.dress method' do
|
35
|
-
subject{ color.dress(arg) }
|
36
|
-
|
37
|
-
context 'when valid' do
|
38
|
-
let(:arg){ {"r" => 12, "g" => 17, "b" => 71} }
|
39
|
-
|
40
|
-
it{ should be_a(MyColorClass) }
|
41
|
-
|
42
|
-
it 'should be the expected one' do
|
43
|
-
subject.r.should eq(12)
|
44
|
-
subject.g.should eq(17)
|
45
|
-
subject.b.should eq(71)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context 'when invalid' do
|
50
|
-
let(:arg){ {"r" => -12, "g" => 17, "b" => 71} }
|
51
|
-
|
52
|
-
it 'should raise an error' do
|
53
|
-
->{
|
54
|
-
subject
|
55
|
-
}.should raise_error(TypeError)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
describe 'the Gender.dress method' do
|
62
|
-
subject{ system['Gender'].dress(arg) }
|
63
|
-
|
64
|
-
context 'when valid' do
|
65
|
-
let(:arg){ 'M' }
|
66
|
-
|
67
|
-
it{ should eq('M') }
|
68
|
-
end
|
69
|
-
|
70
|
-
context 'when valid' do
|
71
|
-
let(:arg){ 'Monsieur' }
|
72
|
-
|
73
|
-
it 'should raise an error' do
|
74
|
-
->{
|
75
|
-
subject
|
76
|
-
}.should raise_error(TypeError, "Invalid value `Monsieur` for Gender")
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Finitio
|
3
|
-
describe "Using Finitio's abstract data types in Ruby" do
|
4
|
-
|
5
|
-
let(:color) do
|
6
|
-
Class.new{
|
7
|
-
extend Finitio::DataType
|
8
|
-
|
9
|
-
def initialize(r, g, b)
|
10
|
-
@r, @g, @b = r, g, b
|
11
|
-
end
|
12
|
-
attr_reader :r, :g, :b
|
13
|
-
|
14
|
-
def to_rgb
|
15
|
-
{ r: @r, g: @g, b: @b }
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.rgb(tuple)
|
19
|
-
new(tuple[:r], tuple[:g], tuple[:b])
|
20
|
-
end
|
21
|
-
|
22
|
-
contract :rgb, {r: 0..255, g: 0..255, b: 0..255}
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
describe 'The factored class' do
|
27
|
-
subject{ color }
|
28
|
-
|
29
|
-
it{ should be_a(Class) }
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'the dress method, when valid' do
|
33
|
-
|
34
|
-
subject{
|
35
|
-
color.dress(r: 12, g: 13, b: 28)
|
36
|
-
}
|
37
|
-
|
38
|
-
it{ should be_a(color) }
|
39
|
-
|
40
|
-
it 'should set the instance variables correctly' do
|
41
|
-
subject.r.should eq(12)
|
42
|
-
subject.g.should eq(13)
|
43
|
-
subject.b.should eq(28)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe 'the up method, when already a color' do
|
48
|
-
let(:value){
|
49
|
-
color.new(12, 13, 28)
|
50
|
-
}
|
51
|
-
|
52
|
-
subject{
|
53
|
-
color.dress(value)
|
54
|
-
}
|
55
|
-
|
56
|
-
it{ should be(value) }
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
module Finitio
|
3
|
-
describe Attribute, "initialize" do
|
4
|
-
|
5
|
-
subject{ Attribute.new(:red, intType) }
|
6
|
-
|
7
|
-
it 'should correctly set the instance variables' do
|
8
|
-
subject.name.should eq(:red)
|
9
|
-
subject.type.should eq(intType)
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
end
|