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
@@ -1,7 +1,16 @@
|
|
1
|
+
require 'finitio/syntax/lexer'
|
2
|
+
require 'finitio/syntax/literals'
|
3
|
+
require 'finitio/syntax/types'
|
4
|
+
require 'finitio/syntax/expressions'
|
5
|
+
|
1
6
|
grammar Finitio::Syntax::Parser
|
7
|
+
include Finitio::Syntax::Lexer
|
8
|
+
include Finitio::Syntax::Literals
|
9
|
+
include Finitio::Syntax::Expressions
|
10
|
+
include Finitio::Syntax::Types
|
2
11
|
|
3
12
|
rule system
|
4
|
-
(spacing definitions spacing
|
13
|
+
(spacing definitions spacing main_type? spacing eof)
|
5
14
|
<Finitio::Syntax::System>
|
6
15
|
end
|
7
16
|
|
@@ -10,211 +19,4 @@ grammar Finitio::Syntax::Parser
|
|
10
19
|
<Finitio::Syntax::Definitions>
|
11
20
|
end
|
12
21
|
|
13
|
-
###################################################################### Types
|
14
|
-
rule type_def
|
15
|
-
(type_name spacing '=' spacing type)
|
16
|
-
<Finitio::Syntax::TypeDef>
|
17
|
-
end
|
18
|
-
|
19
|
-
rule type
|
20
|
-
union_type
|
21
|
-
end
|
22
|
-
|
23
|
-
# union and sub types
|
24
|
-
|
25
|
-
rule union_type
|
26
|
-
(sub_type ('|' sub_type)+)
|
27
|
-
<Finitio::Syntax::UnionType>
|
28
|
-
| sub_type
|
29
|
-
end
|
30
|
-
|
31
|
-
rule sub_type
|
32
|
-
(rel_type constraint_def)
|
33
|
-
<Finitio::Syntax::SubType>
|
34
|
-
| rel_type
|
35
|
-
end
|
36
|
-
|
37
|
-
rule constraint_def
|
38
|
-
('(' spacing var_name spacing '|' spacing constraints spacing ')')
|
39
|
-
<Finitio::Syntax::ConstraintDef>
|
40
|
-
end
|
41
|
-
|
42
|
-
rule constraints
|
43
|
-
(named_constraint (spacing ',' spacing named_constraint)*)
|
44
|
-
<Finitio::Syntax::Constraints>
|
45
|
-
| unnamed_constraint
|
46
|
-
end
|
47
|
-
|
48
|
-
rule named_constraint
|
49
|
-
(constraint_name ':' spacing expression)
|
50
|
-
<Finitio::Syntax::NamedConstraint>
|
51
|
-
end
|
52
|
-
|
53
|
-
rule unnamed_constraint
|
54
|
-
(spacing 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 (',' spacing attribute)*)
|
78
|
-
<Finitio::Syntax::Heading>
|
79
|
-
| spacing
|
80
|
-
<Finitio::Syntax::Heading>
|
81
|
-
end
|
82
|
-
|
83
|
-
rule attribute
|
84
|
-
(attribute_name spacing ':' spacing type)
|
85
|
-
<Finitio::Syntax::Attribute>
|
86
|
-
end
|
87
|
-
|
88
|
-
# collection types
|
89
|
-
|
90
|
-
rule collection_type
|
91
|
-
set_type
|
92
|
-
| seq_type
|
93
|
-
| term_type
|
94
|
-
end
|
95
|
-
|
96
|
-
rule set_type
|
97
|
-
('{' type '}')
|
98
|
-
<Finitio::Syntax::SetType>
|
99
|
-
end
|
100
|
-
|
101
|
-
rule seq_type
|
102
|
-
('[' type ']')
|
103
|
-
<Finitio::Syntax::SeqType>
|
104
|
-
end
|
105
|
-
|
106
|
-
# terminal forms
|
107
|
-
|
108
|
-
rule term_type
|
109
|
-
ad_type
|
110
|
-
| builtin_type
|
111
|
-
| any_type
|
112
|
-
| type_ref
|
113
|
-
end
|
114
|
-
|
115
|
-
# ad type
|
116
|
-
|
117
|
-
rule ad_type
|
118
|
-
(('.' builtin_type_name)? spacing contract (spacing ',' spacing contract)*)
|
119
|
-
<Finitio::Syntax::AdType>
|
120
|
-
end
|
121
|
-
|
122
|
-
rule contract
|
123
|
-
('<' contract_name '>' spacing type spacing pair?)
|
124
|
-
<Finitio::Syntax::Contract>
|
125
|
-
end
|
126
|
-
|
127
|
-
rule pair
|
128
|
-
inline_pair
|
129
|
-
| external_pair
|
130
|
-
end
|
131
|
-
|
132
|
-
rule inline_pair
|
133
|
-
('\\' dress:lambda_expr spacing '\\' undress:lambda_expr)
|
134
|
-
<Finitio::Syntax::InlinePair>
|
135
|
-
end
|
136
|
-
|
137
|
-
rule external_pair
|
138
|
-
('.' builtin_type_name)
|
139
|
-
<Finitio::Syntax::ExternalPair>
|
140
|
-
end
|
141
|
-
|
142
|
-
# any
|
143
|
-
|
144
|
-
rule any_type
|
145
|
-
'.'
|
146
|
-
<Finitio::Syntax::AnyType>
|
147
|
-
end
|
148
|
-
|
149
|
-
# builtin and refs
|
150
|
-
|
151
|
-
rule builtin_type
|
152
|
-
('.' builtin_type_name)
|
153
|
-
<Finitio::Syntax::BuiltinType>
|
154
|
-
end
|
155
|
-
|
156
|
-
rule type_ref
|
157
|
-
(type_name spacing)
|
158
|
-
<Finitio::Syntax::TypeRef>
|
159
|
-
end
|
160
|
-
|
161
|
-
# lambda and expressions
|
162
|
-
|
163
|
-
rule lambda_expr
|
164
|
-
('(' spacing var_name spacing '|' spacing expression spacing ')')
|
165
|
-
<Finitio::Syntax::LambdaExpr>
|
166
|
-
end
|
167
|
-
|
168
|
-
rule expression
|
169
|
-
(
|
170
|
-
('(' spacing expression spacing ')')
|
171
|
-
| (![\(,\)] .)+ expression?
|
172
|
-
)
|
173
|
-
<Finitio::Syntax::Expression>
|
174
|
-
end
|
175
|
-
|
176
|
-
# LEXER (names)
|
177
|
-
|
178
|
-
rule var_name
|
179
|
-
/[a-z]+/
|
180
|
-
end
|
181
|
-
|
182
|
-
rule contract_name
|
183
|
-
/[a-z][a-z0-9]*/
|
184
|
-
end
|
185
|
-
|
186
|
-
rule constraint_name
|
187
|
-
/[a-z][a-zA-Z_]*/
|
188
|
-
end
|
189
|
-
|
190
|
-
rule attribute_name
|
191
|
-
/[a-z][a-zA-Z0-9_]*/
|
192
|
-
end
|
193
|
-
|
194
|
-
rule type_name
|
195
|
-
/[A-Z][a-zA-Z]+/
|
196
|
-
end
|
197
|
-
|
198
|
-
rule builtin_type_name
|
199
|
-
/[a-zA-Z0-9:]+/
|
200
|
-
end
|
201
|
-
|
202
|
-
# LEXER (spacing & comments)
|
203
|
-
|
204
|
-
rule spacing
|
205
|
-
(spaces | comment)*
|
206
|
-
end
|
207
|
-
|
208
|
-
rule comment
|
209
|
-
'#' (![\n] .)* [\n]?
|
210
|
-
end
|
211
|
-
|
212
|
-
rule spaces
|
213
|
-
/[ \t\n]+/
|
214
|
-
end
|
215
|
-
|
216
|
-
rule eof
|
217
|
-
!.
|
218
|
-
end
|
219
|
-
|
220
22
|
end
|
@@ -15,6 +15,7 @@ type:
|
|
15
15
|
- union_type
|
16
16
|
- set_type
|
17
17
|
- seq_type
|
18
|
+
- struct_type
|
18
19
|
- tuple_type
|
19
20
|
- relation_type
|
20
21
|
- ad_type
|
@@ -38,6 +39,9 @@ set_type:
|
|
38
39
|
seq_type:
|
39
40
|
- [ type ]
|
40
41
|
|
42
|
+
struct_type:
|
43
|
+
- [ type+ ]
|
44
|
+
|
41
45
|
tuple_type:
|
42
46
|
- [ heading ]
|
43
47
|
|
@@ -56,7 +60,7 @@ heading:
|
|
56
60
|
[ attribute+ ]
|
57
61
|
|
58
62
|
attribute:
|
59
|
-
[ attribute_name, type ]
|
63
|
+
[ attribute_name, type, Boolean ]
|
60
64
|
|
61
65
|
### constraints
|
62
66
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
grammar Finitio::Syntax::Lexer
|
2
|
+
|
3
|
+
# LEXER (keywords)
|
4
|
+
|
5
|
+
rule keyword
|
6
|
+
'and' | 'or' | 'not' | 'true' | 'false'
|
7
|
+
end
|
8
|
+
|
9
|
+
# LEXER (names)
|
10
|
+
|
11
|
+
rule var_name
|
12
|
+
/[a-z]+/
|
13
|
+
end
|
14
|
+
|
15
|
+
rule contract_name
|
16
|
+
/[a-z][a-z0-9]*/
|
17
|
+
end
|
18
|
+
|
19
|
+
rule constraint_name
|
20
|
+
/[a-z][a-zA-Z_]*/
|
21
|
+
end
|
22
|
+
|
23
|
+
rule attribute_name
|
24
|
+
/[a-z_][a-zA-Z0-9_]*/
|
25
|
+
end
|
26
|
+
|
27
|
+
rule type_name
|
28
|
+
/[A-Z][a-zA-Z]+(\.[A-Z][a-zA-Z]+)*/
|
29
|
+
end
|
30
|
+
|
31
|
+
rule builtin_type_name
|
32
|
+
/[a-zA-Z0-9:]+/
|
33
|
+
end
|
34
|
+
|
35
|
+
# LEXER symbols
|
36
|
+
|
37
|
+
rule equal
|
38
|
+
spacing '=' spacing
|
39
|
+
end
|
40
|
+
|
41
|
+
rule dots
|
42
|
+
spacing '...' spacing
|
43
|
+
end
|
44
|
+
|
45
|
+
rule opt_comma
|
46
|
+
spacing ',' spacing | spacing
|
47
|
+
end
|
48
|
+
|
49
|
+
rule comma
|
50
|
+
spacing ',' spacing
|
51
|
+
end
|
52
|
+
|
53
|
+
rule pipe
|
54
|
+
spacing '|' spacing
|
55
|
+
end
|
56
|
+
|
57
|
+
rule colon
|
58
|
+
spacing ':' spacing
|
59
|
+
end
|
60
|
+
|
61
|
+
rule open_metadata
|
62
|
+
spacing '/-' spacing
|
63
|
+
end
|
64
|
+
|
65
|
+
rule close_metadata
|
66
|
+
spacing '-/' spacing
|
67
|
+
end
|
68
|
+
|
69
|
+
# LEXER (spacing & comments)
|
70
|
+
|
71
|
+
rule spacing
|
72
|
+
(spaces | comment)*
|
73
|
+
end
|
74
|
+
|
75
|
+
rule comment
|
76
|
+
'#' (![\n] .)* [\n]?
|
77
|
+
end
|
78
|
+
|
79
|
+
rule spaces
|
80
|
+
space+
|
81
|
+
end
|
82
|
+
|
83
|
+
rule space
|
84
|
+
[ \t\n]
|
85
|
+
end
|
86
|
+
|
87
|
+
rule eof
|
88
|
+
!.
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Finitio
|
2
|
+
module Syntax
|
3
|
+
module Literal
|
4
|
+
include Node
|
5
|
+
|
6
|
+
def to_ruby
|
7
|
+
to_str.strip
|
8
|
+
end
|
9
|
+
|
10
|
+
end # module Literal
|
11
|
+
end # module Syntax
|
12
|
+
end # module Finitio
|
13
|
+
require_relative 'literal/boolean'
|
14
|
+
require_relative 'literal/integer'
|
15
|
+
require_relative 'literal/real'
|
16
|
+
require_relative 'literal/string'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Finitio
|
2
|
+
module Syntax
|
3
|
+
module Literal
|
4
|
+
module Boolean
|
5
|
+
include Literal
|
6
|
+
|
7
|
+
TRUE = "true".freeze
|
8
|
+
FALSE = "false".freeze
|
9
|
+
|
10
|
+
def value
|
11
|
+
case to_str.strip
|
12
|
+
when TRUE then true
|
13
|
+
when FALSE then false
|
14
|
+
else
|
15
|
+
raise "Unexpected boolean literal `#{to_str}`"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end # module Boolean
|
20
|
+
end # module Literal
|
21
|
+
end # module Syntax
|
22
|
+
end # module Finitio
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'finitio/syntax/lexer'
|
2
|
+
|
3
|
+
grammar Finitio::Syntax::Literals
|
4
|
+
include Finitio::Syntax::Lexer
|
5
|
+
|
6
|
+
rule literal
|
7
|
+
seq_literal
|
8
|
+
| scalar_literal
|
9
|
+
end
|
10
|
+
|
11
|
+
rule seq_literal
|
12
|
+
('{' spacing literal? (comma literal)* spacing '}') {
|
13
|
+
captures[:literal].map(&:value)
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
rule scalar_literal
|
18
|
+
boolean_literal
|
19
|
+
| real_literal
|
20
|
+
| integer_literal
|
21
|
+
| string_literal
|
22
|
+
end
|
23
|
+
|
24
|
+
rule boolean_literal
|
25
|
+
("true" | "false")
|
26
|
+
<Finitio::Syntax::Literal::Boolean>
|
27
|
+
end
|
28
|
+
|
29
|
+
rule integer_literal
|
30
|
+
([0] | [1-9] [0-9]*)
|
31
|
+
<Finitio::Syntax::Literal::Integer>
|
32
|
+
end
|
33
|
+
|
34
|
+
rule real_literal
|
35
|
+
(integer_literal? '.' [0-9]*)
|
36
|
+
<Finitio::Syntax::Literal::Real>
|
37
|
+
end
|
38
|
+
|
39
|
+
rule string_literal
|
40
|
+
(["] str:([\\]["] | !["] .)* ["])
|
41
|
+
<Finitio::Syntax::Literal::String>
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|