require 'finitio/syntax/lexer' require 'finitio/syntax/literals' grammar Finitio::Syntax::Types include Finitio::Syntax::Lexer include Finitio::Syntax::Literals rule type_def (metadata? type_name equal type) end rule main_type (metadata? type) end rule type union_type end # union and sub types rule union_type (sub_type (pipe sub_type)*) end rule sub_type (rel_type constraint_def?) end rule constraint_def ('(' spacing var_name pipe constraints spacing ')') end rule constraints (constraint:named_constraint (opt_comma constraint:named_constraint)* opt_comma) | (spacing constraint:unnamed_constraint) end rule named_constraint (metadata? constraint_name colon expression) end rule unnamed_constraint (metadata? expression) end # relational types rule rel_type relation_type | tuple_type | collection_type end rule relation_type ('{{' spacing heading spacing '}}') end rule tuple_type ('{' spacing heading spacing '}') end rule heading (attribute? (opt_comma attribute)* (opt_comma allow_extra:heading_extra)? opt_comma?) end rule heading_extra (dots (':' spacing extra_type:type)?) end rule attribute (metadata? attribute_name spacing multiplicity:(':?' | ':') spacing type) end # collection types rule collection_type set_type | seq_type | struct_type | term_type end rule set_type ('{' type '}') end rule seq_type ('[' type ']') end rule struct_type ('<' type (comma type)* '>') end # terminal forms rule term_type ad_type | builtin_type | any_type | type_ref end # ad type rule ad_type (('.' builtin_type_name)? spacing contract (opt_comma contract)* opt_comma) end rule contract (metadata? '<' contract_name '>' spacing type spacing pair?) end rule pair inline_pair | external_pair end rule inline_pair ('\\' dress:lambda_expr spacing '\\' undress:lambda_expr) end rule external_pair ('.' builtin_type_name) end # any rule any_type '.' end # builtin and refs rule builtin_type ('.' builtin_type_name) end rule type_ref (type_name spacing) end # metadata rule metadata (open_metadata metadata_attr (opt_comma metadata_attr)* opt_comma close_metadata) | (open_metadata description:(!'-/' .)+ close_metadata) end rule metadata_attr (attribute_name colon literal) end # lambda and expressions rule lambda_expr ('(' spacing var_name pipe expression spacing ')') end rule expression expression_part+ end rule expression_part ('(' expression ')') | (![\(,\)\n] .)+ end end