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
@@ -0,0 +1,17 @@
|
|
1
|
+
module Finitio
|
2
|
+
module Syntax
|
3
|
+
module StructType
|
4
|
+
include Node
|
5
|
+
|
6
|
+
def compile(factory)
|
7
|
+
component_types = captures[:type].map{|x| x.compile(factory) }
|
8
|
+
factory.struct(component_types)
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_ast
|
12
|
+
captures[:type].map(&:to_ast).unshift(:struct_type)
|
13
|
+
end
|
14
|
+
|
15
|
+
end # module StructType
|
16
|
+
end # module Syntax
|
17
|
+
end # module Finitio
|
@@ -1,18 +1,19 @@
|
|
1
1
|
module Finitio
|
2
2
|
module Syntax
|
3
3
|
module System
|
4
|
+
include Node
|
5
|
+
|
6
|
+
capture :definitions, :main_type
|
4
7
|
|
5
8
|
def compile(system)
|
6
9
|
definitions.compile(system)
|
7
|
-
if
|
8
|
-
system.main = type.compile(system)
|
9
|
-
end
|
10
|
+
main_type.compile(system) if main_type
|
10
11
|
system
|
11
12
|
end
|
12
13
|
|
13
14
|
def to_ast
|
14
15
|
ast = [ :system ] + definitions.to_ast
|
15
|
-
ast <<
|
16
|
+
ast << main_type.to_ast if main_type
|
16
17
|
ast
|
17
18
|
end
|
18
19
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Finitio
|
2
|
+
module Syntax
|
3
|
+
module TupleType
|
4
|
+
include Node
|
5
|
+
|
6
|
+
capture :heading
|
7
|
+
|
8
|
+
def compile(factory)
|
9
|
+
factory.send(kind, heading.compile(factory))
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_ast
|
13
|
+
[ :"#{kind}_type", heading.to_ast ]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def kind
|
19
|
+
heading.multi? ? :multi_tuple : :tuple
|
20
|
+
end
|
21
|
+
|
22
|
+
end # module TupleType
|
23
|
+
end # module Syntax
|
24
|
+
end # module Finitio
|
@@ -1,16 +1,21 @@
|
|
1
1
|
module Finitio
|
2
2
|
module Syntax
|
3
3
|
module TypeDef
|
4
|
+
include Node
|
5
|
+
|
6
|
+
capture :type
|
7
|
+
capture :type_name
|
4
8
|
|
5
9
|
def compile(system)
|
6
10
|
t = type.compile(system)
|
7
|
-
|
8
|
-
|
11
|
+
n = type_name && type_name.to_str
|
12
|
+
m = metadata
|
13
|
+
system.add_type(t, n, m)
|
9
14
|
t
|
10
15
|
end
|
11
16
|
|
12
17
|
def to_ast
|
13
|
-
[:type_def, type_name
|
18
|
+
[:type_def, type_name, type.to_ast]
|
14
19
|
end
|
15
20
|
|
16
21
|
end # module TypeDef
|
@@ -1,9 +1,15 @@
|
|
1
1
|
module Finitio
|
2
2
|
module Syntax
|
3
3
|
module UnnamedConstraint
|
4
|
+
include Node
|
5
|
+
|
6
|
+
capture :expression
|
4
7
|
|
5
8
|
def compile(var_name)
|
6
|
-
|
9
|
+
p = expression.compile(var_name)
|
10
|
+
n = nil
|
11
|
+
m = metadata
|
12
|
+
Constraint.new(p, n, m)
|
7
13
|
end
|
8
14
|
|
9
15
|
def to_ast(var_name)
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'finitio/syntax/lexer'
|
2
|
+
require 'finitio/syntax/literals'
|
3
|
+
|
4
|
+
grammar Finitio::Syntax::Types
|
5
|
+
include Finitio::Syntax::Lexer
|
6
|
+
include Finitio::Syntax::Literals
|
7
|
+
|
8
|
+
rule type_def
|
9
|
+
(metadata? type_name equal type)
|
10
|
+
<Finitio::Syntax::TypeDef>
|
11
|
+
end
|
12
|
+
|
13
|
+
rule main_type
|
14
|
+
(metadata? type)
|
15
|
+
<Finitio::Syntax::MainType>
|
16
|
+
end
|
17
|
+
|
18
|
+
rule type
|
19
|
+
union_type
|
20
|
+
end
|
21
|
+
|
22
|
+
# union and sub types
|
23
|
+
|
24
|
+
rule union_type
|
25
|
+
(sub_type (pipe sub_type)+)
|
26
|
+
<Finitio::Syntax::UnionType>
|
27
|
+
| sub_type
|
28
|
+
end
|
29
|
+
|
30
|
+
rule sub_type
|
31
|
+
(rel_type constraint_def)
|
32
|
+
<Finitio::Syntax::SubType>
|
33
|
+
| rel_type
|
34
|
+
end
|
35
|
+
|
36
|
+
rule constraint_def
|
37
|
+
('(' spacing var_name pipe constraints spacing ')')
|
38
|
+
<Finitio::Syntax::ConstraintDef>
|
39
|
+
end
|
40
|
+
|
41
|
+
rule constraints
|
42
|
+
(constraint:named_constraint (opt_comma constraint:named_constraint)* opt_comma)
|
43
|
+
<Finitio::Syntax::Constraints>
|
44
|
+
| (spacing constraint:unnamed_constraint)
|
45
|
+
<Finitio::Syntax::Constraints>
|
46
|
+
end
|
47
|
+
|
48
|
+
rule named_constraint
|
49
|
+
(metadata? constraint_name colon expression)
|
50
|
+
<Finitio::Syntax::NamedConstraint>
|
51
|
+
end
|
52
|
+
|
53
|
+
rule unnamed_constraint
|
54
|
+
(metadata? expression)
|
55
|
+
<Finitio::Syntax::UnnamedConstraint>
|
56
|
+
end
|
57
|
+
|
58
|
+
# relational types
|
59
|
+
|
60
|
+
rule rel_type
|
61
|
+
relation_type
|
62
|
+
| tuple_type
|
63
|
+
| collection_type
|
64
|
+
end
|
65
|
+
|
66
|
+
rule relation_type
|
67
|
+
('{{' spacing heading spacing '}}')
|
68
|
+
<Finitio::Syntax::RelationType>
|
69
|
+
end
|
70
|
+
|
71
|
+
rule tuple_type
|
72
|
+
('{' spacing heading spacing '}')
|
73
|
+
<Finitio::Syntax::TupleType>
|
74
|
+
end
|
75
|
+
|
76
|
+
rule heading
|
77
|
+
(attribute? (opt_comma attribute)* (opt_comma allow_extra:dots)? opt_comma?)
|
78
|
+
<Finitio::Syntax::Heading>
|
79
|
+
end
|
80
|
+
|
81
|
+
rule attribute
|
82
|
+
(metadata? attribute_name spacing multiplicity:(':?' | ':') spacing type)
|
83
|
+
<Finitio::Syntax::Attribute>
|
84
|
+
end
|
85
|
+
|
86
|
+
# collection types
|
87
|
+
|
88
|
+
rule collection_type
|
89
|
+
set_type
|
90
|
+
| seq_type
|
91
|
+
| struct_type
|
92
|
+
| term_type
|
93
|
+
end
|
94
|
+
|
95
|
+
rule set_type
|
96
|
+
('{' type '}')
|
97
|
+
<Finitio::Syntax::SetType>
|
98
|
+
end
|
99
|
+
|
100
|
+
rule seq_type
|
101
|
+
('[' type ']')
|
102
|
+
<Finitio::Syntax::SeqType>
|
103
|
+
end
|
104
|
+
|
105
|
+
rule struct_type
|
106
|
+
('<' type (comma type)* '>')
|
107
|
+
<Finitio::Syntax::StructType>
|
108
|
+
end
|
109
|
+
|
110
|
+
# terminal forms
|
111
|
+
|
112
|
+
rule term_type
|
113
|
+
ad_type
|
114
|
+
| builtin_type
|
115
|
+
| any_type
|
116
|
+
| type_ref
|
117
|
+
end
|
118
|
+
|
119
|
+
# ad type
|
120
|
+
|
121
|
+
rule ad_type
|
122
|
+
(('.' builtin_type_name)? spacing contract (opt_comma contract)* opt_comma)
|
123
|
+
<Finitio::Syntax::AdType>
|
124
|
+
end
|
125
|
+
|
126
|
+
rule contract
|
127
|
+
(metadata? '<' contract_name '>' spacing type spacing pair?)
|
128
|
+
<Finitio::Syntax::Contract>
|
129
|
+
end
|
130
|
+
|
131
|
+
rule pair
|
132
|
+
inline_pair
|
133
|
+
| external_pair
|
134
|
+
end
|
135
|
+
|
136
|
+
rule inline_pair
|
137
|
+
('\\' dress:lambda_expr spacing '\\' undress:lambda_expr)
|
138
|
+
<Finitio::Syntax::InlinePair>
|
139
|
+
end
|
140
|
+
|
141
|
+
rule external_pair
|
142
|
+
('.' builtin_type_name)
|
143
|
+
<Finitio::Syntax::ExternalPair>
|
144
|
+
end
|
145
|
+
|
146
|
+
# any
|
147
|
+
|
148
|
+
rule any_type
|
149
|
+
'.'
|
150
|
+
<Finitio::Syntax::AnyType>
|
151
|
+
end
|
152
|
+
|
153
|
+
# builtin and refs
|
154
|
+
|
155
|
+
rule builtin_type
|
156
|
+
('.' builtin_type_name)
|
157
|
+
<Finitio::Syntax::BuiltinType>
|
158
|
+
end
|
159
|
+
|
160
|
+
rule type_ref
|
161
|
+
(type_name spacing)
|
162
|
+
<Finitio::Syntax::TypeRef>
|
163
|
+
end
|
164
|
+
|
165
|
+
# metadata
|
166
|
+
|
167
|
+
rule metadata
|
168
|
+
(open_metadata metadata_attr (opt_comma metadata_attr)* opt_comma close_metadata)
|
169
|
+
<Finitio::Syntax::Metadata>
|
170
|
+
| (open_metadata description:(!'-/' .)+ close_metadata)
|
171
|
+
<Finitio::Syntax::Metadata>
|
172
|
+
end
|
173
|
+
|
174
|
+
rule metadata_attr
|
175
|
+
(attribute_name colon literal)
|
176
|
+
<Finitio::Syntax::MetadataAttr>
|
177
|
+
end
|
178
|
+
|
179
|
+
# lambda and expressions
|
180
|
+
|
181
|
+
rule lambda_expr
|
182
|
+
('(' spacing var_name pipe expression spacing ')')
|
183
|
+
<Finitio::Syntax::LambdaExpr>
|
184
|
+
end
|
185
|
+
|
186
|
+
rule expression
|
187
|
+
expression_part+
|
188
|
+
<Finitio::Syntax::Expression>
|
189
|
+
end
|
190
|
+
|
191
|
+
rule expression_part
|
192
|
+
('(' expression ')')
|
193
|
+
| (![\(,\)\n] .)+
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
data/lib/finitio/system.rb
CHANGED
@@ -4,22 +4,12 @@ module Finitio
|
|
4
4
|
#
|
5
5
|
class System
|
6
6
|
|
7
|
-
def initialize(types = {}
|
7
|
+
def initialize(types = {})
|
8
8
|
@types = types
|
9
|
-
@main = main
|
10
9
|
end
|
11
|
-
attr_accessor :main
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
factory.public_send(dsl_method, *args, &bl)
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def add_type(type)
|
20
|
-
unless type.is_a?(Type)
|
21
|
-
raise ArgumentError, "Finitio::Type expected, got `#{type}`"
|
22
|
-
end
|
11
|
+
def add_type(type, name = nil, metadata = nil)
|
12
|
+
type = factory.type(type, name, metadata)
|
23
13
|
|
24
14
|
if @types.has_key?(type.name)
|
25
15
|
raise Error, "Duplicate type name `#{type.name}`"
|
@@ -29,10 +19,14 @@ module Finitio
|
|
29
19
|
end
|
30
20
|
|
31
21
|
def get_type(name)
|
32
|
-
@types[name]
|
22
|
+
@types[name] || @types[name.to_s]
|
33
23
|
end
|
34
24
|
alias :[] :get_type
|
35
25
|
|
26
|
+
def main
|
27
|
+
self['Main']
|
28
|
+
end
|
29
|
+
|
36
30
|
def fetch(name, &bl)
|
37
31
|
@types.fetch(name, &bl)
|
38
32
|
end
|
@@ -41,6 +35,12 @@ module Finitio
|
|
41
35
|
@factory ||= TypeFactory.new
|
42
36
|
end
|
43
37
|
|
38
|
+
TypeFactory::DSL_METHODS.each do |dsl_method|
|
39
|
+
define_method(dsl_method){|*args, &bl|
|
40
|
+
factory.public_send(dsl_method, *args, &bl)
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
44
|
def dress(*args, &bl)
|
45
45
|
raise Error, "No main type." unless main
|
46
46
|
main.dress(*args, &bl)
|
@@ -56,7 +56,7 @@ module Finitio
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def dup
|
59
|
-
System.new(@types.dup
|
59
|
+
System.new(@types.dup)
|
60
60
|
end
|
61
61
|
|
62
62
|
end # class System
|
data/lib/finitio/type.rb
CHANGED
@@ -3,12 +3,29 @@ module Finitio
|
|
3
3
|
# Abstract class for Finitio type (generators).
|
4
4
|
#
|
5
5
|
class Type
|
6
|
+
include Metadata
|
6
7
|
|
7
|
-
def initialize(name)
|
8
|
+
def initialize(name, metadata)
|
8
9
|
unless name.nil? or name.is_a?(String)
|
9
10
|
raise ArgumentError, "String expected for type name, got `#{name}`"
|
10
11
|
end
|
11
|
-
|
12
|
+
unless metadata.nil? or metadata.is_a?(Hash)
|
13
|
+
raise ArgumentError, "Hash expected for metadata, got `#{metadata}`"
|
14
|
+
end
|
15
|
+
@name = name
|
16
|
+
@metadata = metadata
|
17
|
+
end
|
18
|
+
|
19
|
+
def anonymous?
|
20
|
+
@name.nil?
|
21
|
+
end
|
22
|
+
|
23
|
+
def named?
|
24
|
+
!anonymous?
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_name
|
28
|
+
raise NotImplementedError, "Missing #{self.class.name}#default_name"
|
12
29
|
end
|
13
30
|
|
14
31
|
def name
|
@@ -20,10 +37,6 @@ module Finitio
|
|
20
37
|
@name = n
|
21
38
|
end
|
22
39
|
|
23
|
-
def to_s
|
24
|
-
name.to_s
|
25
|
-
end
|
26
|
-
|
27
40
|
# Check if `value` belongs to this type. Returns true if it's the case,
|
28
41
|
# false otherwise.
|
29
42
|
#
|
@@ -41,6 +54,16 @@ module Finitio
|
|
41
54
|
raise NotImplementedError, "Missing #{self.class.name}#dress"
|
42
55
|
end
|
43
56
|
|
57
|
+
def to_s
|
58
|
+
name.to_s
|
59
|
+
end
|
60
|
+
|
61
|
+
def ==(other)
|
62
|
+
super || [ProxyType, AliasType].any?{|t|
|
63
|
+
other.is_a?(t) && other == self
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
44
67
|
protected
|
45
68
|
|
46
69
|
def set_equal?(s1, s2)
|
@@ -53,12 +76,21 @@ module Finitio
|
|
53
76
|
|
54
77
|
end # class Type
|
55
78
|
end # module Finitio
|
79
|
+
require_relative 'type/collection_type'
|
80
|
+
require_relative 'type/heading_based_type'
|
81
|
+
require_relative 'type/hash_based_type'
|
82
|
+
require_relative 'type/rel_based_type'
|
83
|
+
require_relative 'type/proxy_type'
|
84
|
+
require_relative 'type/alias_type'
|
56
85
|
require_relative 'type/any_type'
|
57
86
|
require_relative 'type/builtin_type'
|
58
87
|
require_relative 'type/union_type'
|
59
88
|
require_relative 'type/sub_type'
|
60
89
|
require_relative 'type/seq_type'
|
61
90
|
require_relative 'type/set_type'
|
91
|
+
require_relative 'type/struct_type'
|
62
92
|
require_relative 'type/tuple_type'
|
93
|
+
require_relative 'type/multi_tuple_type'
|
63
94
|
require_relative 'type/relation_type'
|
95
|
+
require_relative 'type/multi_relation_type'
|
64
96
|
require_relative 'type/ad_type'
|