(* Bowen 1.4 additions *) parameter = identifier, [ ":", type_name ], [ "=", expr ] ; function_head = "to", identifier, "(", [ parameters ], ")", [ "->", type_name ] ; type_name = "text" | "number" | "int" | "bool" | "list" | "map" | "function" | "any" | identifier ; (* a record or enum *) enum_def = [ "export" ], "enum", identifier, "(", identifier, { ",", identifier }, ")" ; safe_access = postfix, "?.", field, [ "(", [ arguments ], ")" ] ; spread = "...", expr ; (* in list, map and call arguments *) range = sum, ( ".." | "..<" ), sum ; (* ..< excludes the end *) record_def = [ "export" ], "record", identifier, "(", fields, ")", [ newline, INDENT, { function_def }, DEDENT ] ; fields = field, { ",", field } ; (* defaulted fields come last *) field = identifier, [ ":", type_name ], [ "=", expr ] ; parameters = parameter, { ",", parameter }, [ ",", "...", identifier ] ; method_call = postfix, ".", field, "(", [ arguments ], ")" ; try_stmt = "try", suite, [ "catch", identifier, suite ], [ "finally", suite ] ; (* at least one of catch or finally *) pass_stmt = "pass" ; choice = query, "if", binary_expr, "else", expr ; (* a if cond else b *) comparison = sum, { ( "<" | "<=" | ">" | ">=" ), sum } ; (* chains: 1 < x < 10 *) membership = sum, [ "not" ], "in", sum ; lambda_block = "fn", "(", [ parameters ], ")", suite ; (* at the end of a line *) text = '"' chars '"' | "'" chars "'" | '"""' lines '"""' ; template = [ "$" ], text ; (* {expr} or {expr:format} inside *) format = [ align ], [ sign ], [ "#" ], [ "0" ], [ width ], [ "," | "_" ], [ ".", precision ], [ type_letter ] ; (* Python format spec *) (* Bowen 1.3 additions. See grammar.ebnf for the inherited expression, declaration, query, pattern, test and search productions. INDENT and DEDENT denote changes of leading spaces on nonblank lines. Lines inside explicit delimiters form one logical line. *) suite = [ ":" ], newline, INDENT, statements, DEDENT | block ; statement = assignment | say_values | ask_value | function_def | repeated | "if", expr, suite, { "else", "if", expr, suite }, [ "else", suite ] | "for", names, "in", expr, suite | "while", expr, suite | "try", suite, "catch", identifier, suite | "test", string, suite | import | inherited_statement ; assignment = target, assign_op, expr | names, "=", expr, { ",", expr } ; target = identifier, { ".", field | "[", expr, "]" } ; assign_op = "=" | "+=" | "-=" | "*=" | "/=" | "%=" ; names = identifier, { ",", identifier } ; function_def = [ "export" ], [ "memo" ], "to", identifier, "(", [ parameters ], ")", ( "=", expr | "=>", expr | suite ) ; repeated = "repeat", expr, [ "times" ], [ "as", identifier ], suite ; say_values = "say", display_expr, { ",", display_expr } ; ask_value = "ask", identifier, [ ":", type_name ], [ template_text ], [ "from", expr | "between", bound, "and", bound ], [ "default", expr ] ; import = "use", identifier, [ "as", identifier ] | "use", string, "as", identifier | "use", "python", ( dotted_name | string ), [ "as", identifier ] ; dotted_name = identifier, { ".", identifier } ; query = binary_expr, { stage | [ newline ], "|>", stage } ; selector = ".", field | "[", expr, "]" | "[", [ expr ], ":", [ expr ], "]" ; search = "solve", [ "first" | "best" ], search_body ; search_body = [ ":" ], newline, INDENT, search_clauses, DEDENT | "{", search_clauses, "}" ; search_clause = "choose", identifier, "from", expr | "require", expr | identifier, "=", expr ; (* A search has zero or more search clauses, followed by objectives for solve best and exactly one yield. A display_expr that starts with a string treats that first string as a template. Only plain names may be unpacked. The separate operator table in Bowen.md covers ** and //. *)