grammar Qrb::Syntax::Parser rule system (spacing definitions spacing type? spacing eof) end rule definitions (type_def (spacing type_def)*)? end ###################################################################### Types rule type_def (type_name spacing '=' spacing type) end rule type union_type end # union and sub types rule union_type (sub_type ('|' sub_type)+) | sub_type end rule sub_type (rel_type constraint_def) | rel_type end rule constraint_def ('(' spacing var_name spacing '|' spacing constraints spacing ')') end rule constraints (named_constraint (spacing ',' spacing named_constraint)*) | unnamed_constraint end rule named_constraint (constraint_name ':' spacing expression) end rule unnamed_constraint (spacing 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 (',' spacing attribute)*) | spacing end rule attribute (attribute_name spacing ':' spacing type) end # collection types rule collection_type set_type | seq_type | term_type end rule set_type ('{' type '}') end rule seq_type ('[' type ']') end # terminal forms rule term_type ad_type | builtin_type | type_ref end # ad type rule ad_type (('.' builtin_type_name)? spacing contract (spacing ',' spacing contract)*) end rule contract ('<' contract_name '>' spacing type (spacing ('\\' up:lambda_expr) spacing ('\\' down:lambda_expr))?) end # builtin and refs rule builtin_type ('.' builtin_type_name) end rule type_ref (type_name spacing) end # lambda and expressions rule lambda_expr ('(' spacing var_name spacing '|' spacing expression spacing ')') end rule expression ( ('(' spacing expression spacing ')') | (![\(,\)] .)+ expression? ) end # lexer rule var_name /[a-z]+/ end rule contract_name /[a-z][a-z0-9]*/ end rule constraint_name /[a-z][a-z_]*/ end rule attribute_name /[a-z][a-zA-Z0-9_]*/ end rule type_name /[A-Z][a-zA-Z]+/ end rule builtin_type_name /[a-zA-Z0-9:]/+ end rule spacing (spaces | comment)* end rule comment '#' (![\n] .)* [\n]? end rule spaces /[ \t\n]+/ end rule eof !. end end