Complete grammar (appendix)
The complete Bynk grammar, generated from the tree-sitter-bynk grammar. For the annotated, per-construct reference see Syntax & grammar.
Notation. "x" a literal token · /x/ a regular expression · ( … )? optional · ( … )* zero or more · ( … )+ one or more · a | b choice · ε empty. Rule names are the readable display names (a leading _ denotes an internal helper rule; trivial wrappers are collapsed). doc_block is an external token — a --- … --- documentation block.
source_file ::= (commons_decl | context_decl | adapter_decl | integration_decl | test_decl)+ | item_fragment+ | expr_fragmentitem_fragment ::= context_body_item | handler | store_field | key_declexpr_fragment ::= statement+ expression? | expressioncommons_decl ::= "commons" qualified_name ("{" commons_body_item* "}" | commons_body_item*)context_decl ::= "context" qualified_name ("{" context_body_item* "}" | context_body_item*)adapter_decl ::= "adapter" qualified_name ("{" adapter_body_item* "}" | adapter_body_item*)test_decl ::= "test" qualified_name ("{" test_body_item* "}" | test_body_item*)integration_decl ::= "test" "integration" string_literal ("{" wires_decl integration_body_item* "}" | wires_decl integration_body_item*)wires_decl ::= "wires" qualified_name ("," qualified_name)*integration_body_item ::= uses_decl | test_casequalified_name ::= identifier ("." identifier)*commons_body_item ::= uses_decl | type_decl | fn_decl | capability_decl | provider_decl | service_decl | agent_decl | actor_declcontext_body_item ::= uses_decl | consumes_decl | exports_decl | type_decl | fn_decl | capability_decl | provider_decl | service_decl | agent_decl | actor_decladapter_body_item ::= binding_decl | uses_decl | consumes_decl | exports_decl | type_decl | fn_decl | capability_decl | provider_decl | service_decl | agent_decl | actor_decltest_body_item ::= uses_decl | consumes_decl | mocks_decl | test_caseuses_decl ::= "uses" qualified_nameconsumes_decl ::= "consumes" qualified_name ("as" identifier | "{" (identifier ("," identifier)*)? ","? "}")?binding_decl ::= "binding" string_literal ("requires" "{" (binding_requirement ("," binding_requirement)*)? ","? "}")?binding_requirement ::= string_literal ":" string_literalexports_decl ::= "exports" ("opaque" | "transparent" | "capability") "{" (identifier ("," identifier)*)? ","? "}"type_decl ::= "type" identifier "=" type_bodytype_body ::= opaque_type | refined_type | record_type | sum_type | enum_typeopaque_type ::= "opaque" base_type ("where" refinement)?refined_type ::= base_type ("where" refinement)?record_type ::= "{" (record_field ("," record_field)*)? ","? "}"record_field ::= identifier ":" type_ref ("where" refinement)? ("=" expression)?sum_type ::= sum_variant+sum_variant ::= "|" constant_name ("(" (variant_payload_field ("," variant_payload_field)*)? ","? ")")?variant_payload_field ::= identifier ":" type_refenum_type ::= "enum" "{" (constant_name ("," constant_name)*)? ","? "}"refinement ::= refinement_pred ("and" refinement_pred)*refinement_pred ::= pred_call | predicate_namepred_call ::= predicate_name "(" (pred_arg ("," pred_arg)*)? ")"predicate_name ::= "Matches" | "InRange" | "MinLength" | "MaxLength" | "Length" | "NonNegative" | "Positive" | "NonEmpty"pred_arg ::= number_literal | float_literal | string_literalbase_type ::= "Int" | "String" | "Bool" | "Float" | "Duration" | "Instant"type_ref ::= function_type_ref | base_type | unit_type | validation_error_type | generic_type_ref | identifierfunction_type_ref ::= (base_type | unit_type | validation_error_type | generic_type_ref | identifier | "(" type_ref ("," type_ref)* ","? ")") "->" type_refunit_type ::= "(" ")"validation_error_type ::= "ValidationError"generic_type_ref ::= ("Result" | "Option" | "Effect" | "HttpResult" | "List" | "Map" | "Stream" | "Query" | "Connection") "[" type_ref ("," type_ref)* "]"fn_decl ::= "fn" (method_name | identifier) ("[" identifier ("," identifier)* "]")? "(" params? ")" "->" type_ref blockmethod_name ::= identifier "." identifierparams ::= (self_param | param) ("," param)* ","?self_param ::= "self"param ::= identifier ":" type_refcapability_decl ::= "capability" identifier "{" capability_op* "}"capability_op ::= "fn" identifier "(" (param ("," param)*)? ","? ")" "->" type_refprovider_decl ::= "provides" identifier "=" identifier given_clause? ("{" provider_op* "}")?provider_op ::= "fn" identifier "(" (param ("," param)*)? ","? ")" "->" type_ref blockservice_decl ::= "service" identifier service_protocol? "{" handler* "}"service_protocol ::= "from" ("http" | "cron" | "queue" "(" string_literal ")" | "WebSocket" "(" "in" ":" type_ref "," "out" ":" type_ref ","? ")")agent_decl ::= "agent" identifier "{" key_decl store_field* invariant_decl* handler* "}"invariant_decl ::= "invariant" identifier ":" expressionkey_decl ::= "key" identifier ":" type_refstore_field ::= "store" identifier ":" store_kind store_annotation* ("=" expression)?store_kind ::= identifier ("[" type_ref ("," type_ref)* "]")?store_annotation ::= "@" identifier ("(" (annotation_arg ("," annotation_arg)*)? ","? ")")?annotation_arg ::= (identifier ":")? expressionhandler ::= call_handler | http_handler | cron_handler | queue_handler | ws_open_handler | ws_close_handlercall_handler ::= "on" "call" identifier? by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockhttp_handler ::= "on" http_method "(" string_literal ")" by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockhttp_method ::= "GET" | "POST" | "PUT" | "PATCH" | "DELETE"cron_handler ::= "on" "schedule" "(" string_literal ")" by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockqueue_handler ::= "on" "message" by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockws_open_handler ::= "on" "open" by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockws_close_handler ::= "on" "close" by_clause? "(" (param ("," param)*)? ","? ")" "->" type_ref given_clause? blockgiven_clause ::= "given" qualified_name ("," qualified_name)*actor_decl ::= "actor" identifier ("{" "auth" "=" scheme scheme_config? ("," "identity" "=" type_ref)? "}" | "=" identifier "where" refinement)scheme ::= "None" | "Internal" | "Bearer" | "Signature"scheme_config ::= "(" scheme_arg ("," scheme_arg)* ")"scheme_arg ::= identifier "=" (string_literal | number_literal)by_clause ::= "by" (identifier ":")? identifier ("|" identifier)*mocks_decl ::= "mocks" identifier "=" identifier "{" provider_op* "}"test_case ::= "test" string_literal blockblock ::= "{" statement* expression? "}"statement ::= let_stmt | effect_let_stmt | effect_send_stmt | assign_stmt | assert_exprlet_stmt ::= "let" binding_name (":" type_ref)? "=" expressioneffect_let_stmt ::= "let" binding_name (":" type_ref)? "<-" expressioneffect_send_stmt ::= "~>" expressionassign_stmt ::= identifier ":=" expressionbinding_name ::= identifier | "_"expression ::= if_expr | match_expr | is_expr | assert_expr | binary_expr | unary_expr | primaryassert_expr ::= "assert" expressionif_expr ::= "if" expression block "else" (if_expr | block)match_expr ::= "match" expression "{" match_arm* "}"match_arm ::= pattern "=>" expression ","?pattern ::= wildcard_pattern | variant_patternwildcard_pattern ::= "_"variant_pattern ::= (identifier ".")? identifier ("(" (pattern_binding ("," pattern_binding)*)? ","? ")")?pattern_binding ::= named_binding | positional_bindingnamed_binding ::= identifier ":" (identifier | "_")positional_binding ::= identifier | "_"is_expr ::= expression "is" patternbinary_expr ::= expression "implies" expression | expression "||" expression | expression "&&" expression | expression ("==" | "!=") expression | expression ("<" | "<=" | ">" | ">=") expression | expression ("+" | "-") expression | expression ("*" | "/") expressionunary_expr ::= ("!" | "-") expressionprimary ::= lambda_expr | paren_expr | method_call | field_access | call | record_construction | record_spread | question_expr | ok_expr | err_expr | some_expr | none_expr | effect_pure_expr | mock_expr | list_literal | block | number_literal | float_literal | string_literal | boolean_literal | unit_literal | self_expr | identifierlambda_expr ::= "(" (lambda_param ("," lambda_param)*)? ")" "=>" (expression | block)lambda_param ::= identifier (":" type_ref)?paren_expr ::= "(" expression ")"method_call ::= primary "." identifier ("[" type_ref ("," type_ref)* "]")? "(" (expression ("," expression)*)? ","? ")"field_access ::= primary "." identifiercall ::= identifier ("[" type_ref ("," type_ref)* "]")? "(" (expression ("," expression)*)? ","? ")"list_literal ::= "[" (expression ("," expression)* ","?)? "]"record_construction ::= identifier "{" (field_init ("," field_init)*)? ","? "}"field_init ::= identifier ":" expression | identifierrecord_spread ::= identifier "{" "..." expression ("," field_init)* ","? "}" | "{" "..." expression ("," field_init)* ","? "}"question_expr ::= expression "?"ok_expr ::= "Ok" "(" expression ")"err_expr ::= "Err" "(" expression ")"some_expr ::= "Some" "(" expression ")"none_expr ::= "None"effect_pure_expr ::= "Effect" "." "pure" "(" expression ")"mock_expr ::= "Mock" "[" type_ref "]" mock_arg?mock_arg ::= "(" expression ("," expression)* ","? ")" | "{" (field_init ("," field_init)*)? ","? "}"self_expr ::= "self"identifier ::= /[A-Za-z][A-Za-z0-9_]*/constant_name ::= /[A-Z][A-Za-z0-9_]*/number_literal ::= /[0-9]+/float_literal ::= /[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?|[0-9]+[eE][+-]?[0-9]+/string_literal ::= """ (/[^"\\\n]/ | /\\[nt"\\]/ | string_interpolation)* """string_interpolation ::= "\(" expression ")"boolean_literal ::= "true" | "false"unit_literal ::= "(" ")"line_comment ::= "--" /[^\n]*/Tokens & trivia
Section titled “Tokens & trivia”- Word token:
identifier - Ignored between tokens:
/\s+/,line_comment,doc_block - External tokens:
doc_block