// Derived from grammar/gnomon.ebnf; run tools/emit_peg.py --write.
// Syntax-only PEG. AST, ordered-choice, and fixture conformance remain open.

gnomon_file = __ (top_level_decl __)*
_ = (" " / "\t" / BLOCK_COMMENT)*
__ = (" " / "\t" / NEWLINE / BLOCK_COMMENT / DOC_COMMENT / LINE_COMMENT)*
UNICODE_CHAR = .

IDENT = ([a-zA-Z_] ([a-zA-Z0-9_])*)
QUALIFIED = (IDENT (("." IDENT))*)
NAME = ([a-z] ([a-z0-9])* (("-" ([a-z0-9])+))*)
FQN = (NAME (("." NAME))*)
STRING = ('"' ((!'"' UNICODE_CHAR))* '"')
NUMBER = (([0-9])+ (("." ([0-9])+))?)
BOOL = (("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))
NEWLINE = ("\r\n" / "\n")
BLOCK_COMMENT = ("/*" ((!"*/" UNICODE_CHAR))* "*/")
LINE_COMMENT = ("//" ((!NEWLINE UNICODE_CHAR))* NEWLINE)
DOC_COMMENT = ("///" ((!NEWLINE UNICODE_CHAR))* NEWLINE)
WHITESPACE = ((" " / "\t" / NEWLINE))*
top_level_decl = (bare_top_level_decl / decorated_decl)
bare_top_level_decl = (config_set_decl / project_decl / import_decl / extend_decl / module_decl / config_decl / apply_stmt / types_decl / test_decl / entity_decl / facet_decl / relation_decl / action_decl / mutation_decl / actuator_decl / procedure_decl / event_decl / task_decl / compute_decl / client_decl / saga_decl / workflow_decl / claim_decl / flow_decl / policy_decl / invariant_decl / aspect_decl / compose_decl / query_decl / view_decl / app_decl / agent_decl / model_decl / enum_decl / annotation_facet_decl / annotation_aspect_decl)
type_expr = (base_type (__ (("required" ![A-Za-z0-9_-]) / ("optional" ![A-Za-z0-9_-])))?)
base_type = ((("Claim" ![A-Za-z0-9_-]) __ "<" __ type_expr __ ">") / (("List" ![A-Za-z0-9_-]) __ "<" __ type_expr __ ">") / inline_enum / union_type)
union_type = (atomic_type (__ ("|" __ atomic_type))*)
atomic_type = QUALIFIED
inline_enum = (("enum" ![A-Za-z0-9_-]) __ "{" __ IDENT (__ ("," __ IDENT))* __ "}")
types_decl = (("type" ![A-Za-z0-9_-]) __ IDENT __ "{" __ type_body __ "}")
type_body = (__ type_prop)*
type_prop = (annotation_block / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("label" ![A-Za-z0-9_-]) __ ":" __ STRING))
facet_decl = ((__ decl_modifier)* __ ("facet" ![A-Za-z0-9_-]) __ IDENT __ "{" __ facet_body __ "}")
facet_body = (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING (__ (("requires" ![A-Za-z0-9_-]) __ ident_set))? (__ (("rules" ![A-Za-z0-9_-]) __ rule_block))?)
entity_decl = ((__ decl_modifier)* __ ("entity" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ entity_prop)* __ "}")
entity_prop = (annotation_block / (("includes" ![A-Za-z0-9_-]) __ ident_set _ NEWLINE) / (("examples" ![A-Za-z0-9_-]) __ string_seq _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("fields" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("flow" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("is" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / field_decl)
relation_decl = ((__ decl_modifier)* __ ("relation" ![A-Za-z0-9_-]) __ IDENT __ "{" __ relation_body __ "}")
relation_body = (("from" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ ("to" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ ("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING (__ (("cardinality" ![A-Za-z0-9_-]) __ ":" __ ((("zero-or-one" ![A-Za-z0-9_-]) / ("many" ![A-Za-z0-9_-]) / ("one" ![A-Za-z0-9_-])))))? (__ (("qualifiers" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}"))? (__ (("constraints" ![A-Za-z0-9_-]) __ rule_block))?)
flow_decl = ((__ decl_modifier)* __ ("flow" ![A-Za-z0-9_-]) __ IDENT __ ("for" ![A-Za-z0-9_-]) __ QUALIFIED __ "{" __ flow_body __ "}")
flow_body = (("states" ![A-Za-z0-9_-]) __ ident_set (__ (("transitions" ![A-Za-z0-9_-]) __ "{" (__ transition_rule)* __ "}"))? (__ (("rules" ![A-Za-z0-9_-]) __ rule_block))?)
transition_rule = (IDENT __ "->" __ IDENT __ ("by" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE)
policy_decl = ((__ decl_modifier)* __ ("policy" ![A-Za-z0-9_-]) __ IDENT __ "{" __ policy_body __ "}")
policy_body = (__ policy_prop)*
policy_prop = ((("enforcement" ![A-Za-z0-9_-]) __ ":" __ ((("hard" ![A-Za-z0-9_-]) / ("soft" ![A-Za-z0-9_-])))) / annotation_block / (("applies" ![A-Za-z0-9_-]) __ ("to" ![A-Za-z0-9_-]) __ ident_set) / (("rules" ![A-Za-z0-9_-]) __ rule_block))
agent_decl = ((__ decl_modifier)* __ ("agent" ![A-Za-z0-9_-]) __ IDENT __ "{" __ agent_body __ "}")
agent_body = (__ agent_prop)*
agent_prop = ((("prohibitions" ![A-Za-z0-9_-]) __ rule_block) / (("requirements" ![A-Za-z0-9_-]) __ rule_block) / (("permissions" ![A-Za-z0-9_-]) __ rule_block) / annotation_block / (("readScope" ![A-Za-z0-9_-]) __ read_scope_block) / (("purpose" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("outputs" ![A-Za-z0-9_-]) __ "{" (__ output_stmt)* __ "}") / (("inputs" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("model" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE))
output_stmt = (("produces" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ ("in" ![A-Za-z0-9_-]) __ IDENT _ NEWLINE)
read_scope_block = (("readScope" ![A-Za-z0-9_-]) __ "{" (__ read_scope_entry)* __ "}")
read_scope_entry = (QUALIFIED (__ (("fields" ![A-Za-z0-9_-]) __ "[" (__ IDENT)* __ "]"))? _ NEWLINE)
test_decl = (("test" ![A-Za-z0-9_-]) __ STRING __ "{" __ test_body __ "}")
test_body = (("given" ![A-Za-z0-9_-]) __ "{" (__ given_stmt)* __ "}" __ ("when" ![A-Za-z0-9_-]) __ "{" (__ when_stmt)* __ "}" __ ("expect" ![A-Za-z0-9_-]) __ "{" (__ expect_stmt)* __ "}")
given_stmt = (IDENT __ ":" __ QUALIFIED (__ (("in" ![A-Za-z0-9_-]) __ IDENT))? _ NEWLINE)
when_stmt = ((IDENT __ ("attempts" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (IDENT __ ("attempts" ![A-Za-z0-9_-]) __ ("transition" ![A-Za-z0-9_-]) __ IDENT __ "->" __ IDENT _ NEWLINE))
expect_stmt = ((("reason" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (((("allowed" ![A-Za-z0-9_-]) / ("denied" ![A-Za-z0-9_-]))) _ NEWLINE))
action_decl = ((__ decl_modifier)* __ ("action" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ action_prop)* __ "}")
action_prop = (annotation_block / (("mutations" ![A-Za-z0-9_-]) __ "{" (__ mutation_ref)* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("execute" ![A-Za-z0-9_-]) __ "{" (__ execute_binding)* __ "}") / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("after" ![A-Za-z0-9_-]) __ "{" (__ emits_stmt)* __ "}"))
execute_binding = (IDENT __ "=" __ IDENT __ "." __ IDENT __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}")
mutation_ref = (IDENT __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}")
emits_stmt = (("emits" ![A-Za-z0-9_-]) __ IDENT (__ (("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}"))? _ NEWLINE)
mutation_decl = ((__ decl_modifier)* __ ("mutation" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ mutation_prop)* __ "}")
mutation_prop = ((("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("returns" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE) / (("effects" ![A-Za-z0-9_-]) __ "{" (__ effect_stmt)* __ "}") / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}"))
effect_stmt = ((("transitions" ![A-Za-z0-9_-]) __ QUALIFIED (__ ("(" __ IDENT __ ")"))? __ "->" __ IDENT (__ (("if" ![A-Za-z0-9_-]) __ expr))? _ NEWLINE) / (("replaces" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("creates" ![A-Za-z0-9_-]) __ QUALIFIED (__ (("in" ![A-Za-z0-9_-]) __ IDENT))? _ NEWLINE) / (("creates" ![A-Za-z0-9_-]) __ QUALIFIED __ ("for" ![A-Za-z0-9_-]) __ ("each" ![A-Za-z0-9_-]) __ IDENT _ NEWLINE) / (("mutates" ![A-Za-z0-9_-]) __ QUALIFIED (__ ("." __ QUALIFIED))? _ NEWLINE) / (("deletes" ![A-Za-z0-9_-]) __ QUALIFIED (__ ("(" __ IDENT __ ")"))? (__ (("if" ![A-Za-z0-9_-]) __ expr))? _ NEWLINE) / (("deletes" ![A-Za-z0-9_-]) __ ("all" ![A-Za-z0-9_-]) __ QUALIFIED __ ("where" ![A-Za-z0-9_-]) __ field_assign _ NEWLINE) / (("creates" ![A-Za-z0-9_-]) __ QUALIFIED __ ("linking" ![A-Za-z0-9_-]) __ QUALIFIED __ ("to" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("deletes" ![A-Za-z0-9_-]) __ QUALIFIED __ ("between" ![A-Za-z0-9_-]) __ QUALIFIED __ ("and" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("if" ![A-Za-z0-9_-]) __ expr __ "{" (__ effect_stmt)* __ "}"))
actuator_decl = ((__ decl_modifier)* __ ("actuator" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ actuator_prop)* __ "}")
actuator_prop = ((("onFailure" ![A-Za-z0-9_-]) __ "{" (__ failure_stmt)* __ "}") / (("notifies" ![A-Za-z0-9_-]) __ ":" __ ("push" ![A-Za-z0-9_-]) _ NEWLINE) / (("template" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("channel" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("message" ![A-Za-z0-9_-]) __ "=" __ expr _ NEWLINE) / (("sends" ![A-Za-z0-9_-]) __ ":" __ ((("email" ![A-Za-z0-9_-]) / ("sms" ![A-Za-z0-9_-]))) _ NEWLINE) / (("calls" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED _ NEWLINE) / (("posts" ![A-Za-z0-9_-]) __ ":" __ ("webhook" ![A-Za-z0-9_-]) _ NEWLINE) / (("retry" ![A-Za-z0-9_-]) __ "{" __ retry_prop (__ retry_prop)* __ "}") / (("url" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("on" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE) / (("to" ![A-Za-z0-9_-]) __ "=" __ expr _ NEWLINE))
retry_prop = ((("attempts" ![A-Za-z0-9_-]) __ ":" __ NUMBER _ NEWLINE) / (("backoff" ![A-Za-z0-9_-]) __ ":" __ ((("exponential" ![A-Za-z0-9_-]) / ("linear" ![A-Za-z0-9_-]) / ("fixed" ![A-Za-z0-9_-]))) _ NEWLINE) / (("on" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE))
failure_stmt = (emits_stmt / (("log" ![A-Za-z0-9_-]) __ expr _ NEWLINE))
procedure_decl = ((__ decl_modifier)* __ ("procedure" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ procedure_prop)* __ "}")
procedure_prop = ((("preconditions" ![A-Za-z0-9_-]) __ "{" (__ (precond_stmt _ NEWLINE))* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("returns" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE) / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("runs" ![A-Za-z0-9_-]) __ ":" __ IDENT __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}"))
precond_stmt = ((("session" ![A-Za-z0-9_-]) __ ("has" ![A-Za-z0-9_-]) __ QUALIFIED (__ (("on" ![A-Za-z0-9_-]) __ QUALIFIED (__ ("(" __ IDENT __ ")"))? (__ ("." __ QUALIFIED))?))? _ NEWLINE) / (expr _ NEWLINE))
event_decl = ((__ decl_modifier)* __ ("event" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ event_prop)* __ "}")
event_prop = ((("subscribedBy" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE) / (("emittedBy" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("fields" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}"))
task_decl = ((__ decl_modifier)* __ ("task" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ task_prop)* __ "}")
task_prop = ((("triggeredBy" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("effects" ![A-Za-z0-9_-]) __ "{" (__ effect_stmt)* __ "}") / (("onError" ![A-Za-z0-9_-]) __ "{" (__ effect_stmt)* __ "}") / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("retry" ![A-Za-z0-9_-]) __ "{" __ retry_prop (__ retry_prop)* __ "}") / (("after" ![A-Za-z0-9_-]) __ "{" (__ emits_stmt)* __ "}"))
compute_decl = ((__ decl_modifier)* __ ("compute" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ compute_prop)* __ "}")
compute_prop = ((("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("returns" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE) / (("script" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ (!"}" UNICODE_CHAR))* __ "}") / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("expr" ![A-Za-z0-9_-]) __ "=" __ expr _ NEWLINE))
extend_decl = (("extend" ![A-Za-z0-9_-]) __ IDENT __ ("includes" ![A-Za-z0-9_-]) __ ident_set)
client_decl = ((__ decl_modifier)* __ ("client" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ client_prop)* __ "}")
client_prop = ((("operations" ![A-Za-z0-9_-]) __ "{" (__ client_op_decl)* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("baseUrl" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("auth" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE))
client_op_decl = (IDENT __ "{" (__ op_prop)* __ "}")
op_prop = ((("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("returns" ![A-Za-z0-9_-]) __ ":" __ ((("void" ![A-Za-z0-9_-]) / ("{" (__ field_decl)* __ "}") / type_expr)) _ NEWLINE) / (("method" ![A-Za-z0-9_-]) __ ":" __ ((("DELETE" ![A-Za-z0-9_-]) / ("PATCH" ![A-Za-z0-9_-]) / ("POST" ![A-Za-z0-9_-]) / ("GET" ![A-Za-z0-9_-]) / ("PUT" ![A-Za-z0-9_-]))) _ NEWLINE) / (("errors" ![A-Za-z0-9_-]) __ "{" (__ error_class_entry)* __ "}") / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("path" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE))
error_class_entry = (((("timeout" ![A-Za-z0-9_-]) / NUMBER / (NUMBER __ ("xx" ![A-Za-z0-9_-])))) __ ":" __ ((("transient" ![A-Za-z0-9_-]) / ("terminal" ![A-Za-z0-9_-]) / ("ignore" ![A-Za-z0-9_-]))) _ NEWLINE)
workflow_decl = ((__ decl_modifier)* __ ("workflow" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ workflow_prop)* __ "}")
workflow_prop = ((("compensations" ![A-Za-z0-9_-]) __ "{" (__ compensation_decl)* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("state" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE) / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("steps" ![A-Za-z0-9_-]) __ "{" (__ workflow_step)* __ "}"))
workflow_step = (("step" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ step_prop)* __ "}")
step_prop = ((("requires" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("calls" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}") / (("retry" ![A-Za-z0-9_-]) __ "{" __ retry_prop (__ retry_prop)* __ "}") / (("on" ![A-Za-z0-9_-]) __ ("success" ![A-Za-z0-9_-]) __ "{" (__ step_handler_stmt)* __ "}") / (("on" ![A-Za-z0-9_-]) __ ("failure" ![A-Za-z0-9_-]) (__ ("(" __ ("terminal" ![A-Za-z0-9_-]) __ ")"))? __ "{" (__ step_handler_stmt)* __ "}"))
step_handler_stmt = ((("transitions" ![A-Za-z0-9_-]) __ "->" __ IDENT _ NEWLINE) / (("compensate" ![A-Za-z0-9_-]) __ ident_set _ NEWLINE) / (("mutation" ![A-Za-z0-9_-]) __ IDENT __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}" _ NEWLINE) / emits_stmt)
compensation_decl = (("compensate" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ step_prop)* __ "}")
saga_decl = ((__ decl_modifier)* __ ("saga" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ saga_prop)* __ "}")
saga_prop = ((("compensations" ![A-Za-z0-9_-]) __ "{" (__ saga_step)* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("state" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE) / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}") / (("steps" ![A-Za-z0-9_-]) __ "{" (__ saga_step)* __ "}") / (IDENT __ ":" __ expr _ NEWLINE))
saga_step = ((("compensate" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ saga_step_prop)* __ "}") / (("step" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ saga_step_prop)* __ "}"))
saga_step_prop = ((("requires" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("calls" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ ("using" ![A-Za-z0-9_-]) __ "{" (__ (field_assign _ NEWLINE))* __ "}") / (("retry" ![A-Za-z0-9_-]) __ "{" __ retry_prop (__ retry_prop)* __ "}") / (("on" ![A-Za-z0-9_-]) __ ("success" ![A-Za-z0-9_-]) __ "{" (__ step_handler_stmt)* __ "}") / (("on" ![A-Za-z0-9_-]) __ ("failure" ![A-Za-z0-9_-]) (__ ("(" __ ("terminal" ![A-Za-z0-9_-]) __ ")"))? __ "{" (__ step_handler_stmt)* __ "}"))
claim_decl = ((__ decl_modifier)* __ ("claim" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ claim_prop)* __ "}")
claim_prop = ((("requiredEvidence" ![A-Za-z0-9_-]) __ ident_set _ NEWLINE) / (("allowedStatus" ![A-Za-z0-9_-]) __ ident_set _ NEWLINE) / annotation_block / (("policies" ![A-Za-z0-9_-]) __ "{" (__ claim_policy_stmt)* __ "}") / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("wraps" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE))
claim_policy_stmt = (IDENT __ ":" __ NUMBER _ NEWLINE)
import_decl = (("import" ![A-Za-z0-9_-]) __ STRING)
invariant_decl = ((__ decl_modifier)* __ ("invariant" ![A-Za-z0-9_-]) __ IDENT __ "(" __ param_list __ ")" __ "{" __ expr __ "}")
aspect_decl = ((__ decl_modifier)* __ ("aspect" ![A-Za-z0-9_-]) __ IDENT __ ("on" ![A-Za-z0-9_-]) __ aspect_target __ "{" (__ aspect_stmt)* __ "}")
aspect_target = ((("field" ![A-Za-z0-9_-]) __ "(" __ qualified_list __ ")") / (("any" ![A-Za-z0-9_-]) __ ("write" ![A-Za-z0-9_-]) __ "(" __ QUALIFIED __ ")") / QUALIFIED)
aspect_stmt = ((("contribution" ![A-Za-z0-9_-]) __ ":" __ "{" (__ contribution_clause)* __ "}") / (("require" ![A-Za-z0-9_-]) __ expr _ NEWLINE) / (("emit" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ field_assign)* __ "}" _ NEWLINE) / (("log" ![A-Za-z0-9_-]) __ expr _ NEWLINE))
contribution_clause = (("properties" ![A-Za-z0-9_-]) __ ":" __ "{" (__ field_decl)* __ "}")
compose_decl = ((__ decl_modifier)* __ ("compose" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ compose_stmt)* __ "}")
compose_stmt = ((("include" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("resolve" ![A-Za-z0-9_-]) __ ("conflicts" ![A-Za-z0-9_-]) __ ("by" ![A-Za-z0-9_-]) __ ("precedence" ![A-Za-z0-9_-]) __ ":" __ precedence_list _ NEWLINE))
precedence_list = (QUALIFIED (__ (">" __ QUALIFIED))*)
apply_stmt = (("apply" ![A-Za-z0-9_-]) __ QUALIFIED __ ("to" ![A-Za-z0-9_-]) __ QUALIFIED)
query_decl = ((__ decl_modifier)* __ ("query" ![A-Za-z0-9_-]) __ IDENT __ ((("(" (__ param_list)? __ ")" __ "->" __ type_expr) / ("{" (__ query_prop)* __ "}"))))
query_prop = (annotation_block / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("returns" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE) / (("input" ![A-Za-z0-9_-]) __ "{" (__ field_decl)* __ "}"))
view_decl = ((__ decl_modifier)* __ ("view" ![A-Za-z0-9_-]) __ IDENT (__ (("for" ![A-Za-z0-9_-]) __ QUALIFIED))? __ "{" (__ view_prop)* __ "}")
view_prop = (annotation_block / (("explain" ![A-Za-z0-9_-]) __ "{" (__ explain_stmt)* __ "}") / (("actions" ![A-Za-z0-9_-]) __ "{" (__ view_action_stmt)* __ "}") / (("layout" ![A-Za-z0-9_-]) __ "{" (__ layout_section)* __ "}") / (("route" ![A-Za-z0-9_-]) __ "{" (__ route_prop)* __ "}") / (("data" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED _ NEWLINE) / (("show" ![A-Za-z0-9_-]) __ "[" (__ (QUALIFIED (__ ",")?))* __ "]" _ NEWLINE))
route_prop = ((("fallback" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("path" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("when" ![A-Za-z0-9_-]) __ ":" __ expr _ NEWLINE))
explain_stmt = (IDENT __ ("as" ![A-Za-z0-9_-]) __ STRING _ NEWLINE)
view_action_stmt = (IDENT __ ("can" ![A-Za-z0-9_-]) __ ("mark" ![A-Za-z0-9_-]) __ IDENT _ NEWLINE)
layout_section = ((("extensionPoints" ![A-Za-z0-9_-]) __ "[" (__ IDENT)* __ "]" _ NEWLINE) / (("sublayout" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("section" ![A-Za-z0-9_-]) __ STRING __ "{" (__ layout_item)* __ "}") / (("region" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ ((("sublayout" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / layout_item))* __ "}") / view_layout_hint)
layout_item = ((("button" ![A-Za-z0-9_-]) __ STRING __ ("triggers" ![A-Za-z0-9_-]) __ QUALIFIED _ NEWLINE) / (("button" ![A-Za-z0-9_-]) __ STRING __ ("navigates" ![A-Za-z0-9_-]) __ ("to" ![A-Za-z0-9_-]) __ QUALIFIED __ "(" __ field_assign_list __ ")" _ NEWLINE) / (("field" ![A-Za-z0-9_-]) __ IDENT (__ ("{" __ ("claimWidget" ![A-Za-z0-9_-]) __ ":" __ QUALIFIED __ "}"))? __ ("label" ![A-Za-z0-9_-]) __ STRING _ NEWLINE))
view_layout_hint = ((("sectionOrder" ![A-Za-z0-9_-]) __ ":" __ "[" __ IDENT (__ ("," __ IDENT))* __ "]" _ NEWLINE) / (("columns" ![A-Za-z0-9_-]) __ ":" __ NUMBER _ NEWLINE))
app_decl = ((__ decl_modifier)* __ ("app" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ app_prop)* __ "}")
app_prop = ((("audience" ![A-Za-z0-9_-]) __ ":" __ ident_set _ NEWLINE) / app_includes / (("version" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE))
app_includes = (("includes" ![A-Za-z0-9_-]) __ ((("policies" ![A-Za-z0-9_-]) / ("models" ![A-Za-z0-9_-]) / ("agents" ![A-Za-z0-9_-]) / ("flows" ![A-Za-z0-9_-]) / ("views" ![A-Za-z0-9_-]))) __ ident_set _ NEWLINE)
model_decl = ((__ decl_modifier)* __ ("model" ![A-Za-z0-9_-]) __ IDENT __ "{" __ model_body __ "}")
model_body = (__ model_prop)*
model_prop = (annotation_block / (("parameters" ![A-Za-z0-9_-]) __ "{" (__ model_param)* __ "}") / (("provider" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("version" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("digest" ![A-Za-z0-9_-]) __ ":" __ STRING) / (("roles" ![A-Za-z0-9_-]) __ ident_set) / (("name" ![A-Za-z0-9_-]) __ ":" __ STRING))
model_param = (IDENT __ ":" __ ((STRING / NUMBER)) _ NEWLINE)
enum_decl = ((__ decl_modifier)* __ ("enum" ![A-Za-z0-9_-]) __ IDENT __ "{" __ enum_body __ "}")
enum_body = (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING __ ("values" ![A-Za-z0-9_-]) __ ident_set)
config_decl = (("config" ![A-Za-z0-9_-]) __ IDENT __ "{" (__ config_prop)* __ "}")
config_prop = ((("description" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("sensitive" ![A-Za-z0-9_-]) __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))) _ NEWLINE) / (("perTenant" ![A-Za-z0-9_-]) __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))) _ NEWLINE) / (("required" ![A-Za-z0-9_-]) __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))) _ NEWLINE) / (("exported" ![A-Za-z0-9_-]) __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))) _ NEWLINE) / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("default" ![A-Za-z0-9_-]) __ ":" __ config_literal _ NEWLINE) / (("type" ![A-Za-z0-9_-]) __ ":" __ type_expr _ NEWLINE) / (("flag" ![A-Za-z0-9_-]) __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]))) _ NEWLINE))
config_set_decl = (("config-set" ![A-Za-z0-9_-]) __ QUALIFIED __ "=" __ config_literal _ NEWLINE)
config_literal = (("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]) / STRING / ("-" __ NUMBER) / config_list / config_map / NUMBER)
config_list = ("[" (__ (config_literal (__ ("," __ config_literal))*))? __ "]")
config_map = ("{" (__ (STRING __ ":" __ config_literal (__ ("," __ STRING __ ":" __ config_literal))*))? __ "}")
module_decl = (("module" ![A-Za-z0-9_-]) __ FQN __ "{" __ module_body __ "}")
module_body = (("version" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE __ ("type" ![A-Za-z0-9_-]) __ ":" __ module_type _ NEWLINE (__ module_imports_block)? (__ module_objects_block)? (__ module_ops_block)? (__ module_agents_block)?)
module_type = (("backend-only" ![A-Za-z0-9_-]) / ("ui-only" ![A-Za-z0-9_-]) / ("hybrid" ![A-Za-z0-9_-]))
module_imports_block = (("imports" ![A-Za-z0-9_-]) __ "{" (__ module_import_entry)* __ "}")
module_import_entry = (FQN __ ":" __ STRING _ NEWLINE)
module_objects_block = (("objects" ![A-Za-z0-9_-]) __ "[" _ NEWLINE (__ (STRING _ NEWLINE))* __ "]")
module_agents_block = (("agents" ![A-Za-z0-9_-]) __ "[" _ NEWLINE (__ (STRING _ NEWLINE))* __ "]")
module_ops_block = (("operations" ![A-Za-z0-9_-]) __ "[" _ NEWLINE (__ (module_op_entry _ NEWLINE))* __ "]")
module_op_entry = (STRING / ("{" __ ("path" ![A-Za-z0-9_-]) __ ":" __ STRING (__ ("," __ ("rollbackCheckpoint" ![A-Za-z0-9_-]) __ ":" __ BOOL))? (__ ("," __ ("rollbackDependsOn" ![A-Za-z0-9_-]) __ ":" __ string_seq))? __ "}"))
project_decl = (("project" ![A-Za-z0-9_-]) __ STRING __ "{" __ project_body __ "}")
project_body = (("version" ![A-Za-z0-9_-]) __ ":" __ STRING (__ (("imports" ![A-Za-z0-9_-]) __ ":" __ string_seq))? (__ (("modules" ![A-Za-z0-9_-]) __ ":" __ string_seq))? (__ compiler_block)?)
compiler_block = (("compiler" ![A-Za-z0-9_-]) __ "{" __ compiler_prop (__ compiler_prop)* __ "}")
compiler_prop = ((("promptTemplate" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / (("ruleCompiler" ![A-Za-z0-9_-]) __ ":" __ IDENT _ NEWLINE))
query_shorthand = ((__ decl_modifier)* __ ("query" ![A-Za-z0-9_-]) __ IDENT __ "(" (__ param_list)? __ ")" __ "->" __ type_expr)
decl_modifier = (visibility_modifier / epistemic_modifier)
visibility_modifier = (("internal" ![A-Za-z0-9_-]) / ("public" ![A-Za-z0-9_-]))
epistemic_modifier = (("experimental" ![A-Za-z0-9_-]) / ("deprecated" ![A-Za-z0-9_-]) / ("abstract" ![A-Za-z0-9_-]) / ("sealed" ![A-Za-z0-9_-]) / ("draft" ![A-Za-z0-9_-]))
rule_block = ("{" (__ rule_stmt)* __ "}")
rule_stmt = (runtime_prompt / compiled_rule / expr_rule / doc_note)
compiled_rule = (("rule" ![A-Za-z0-9_-]) __ STRING (__ (("with" ![A-Za-z0-9_-]) __ IDENT))? _ NEWLINE)
expr_rule = (("expr" ![A-Za-z0-9_-]) __ "{" __ expr __ "}" _ NEWLINE)
runtime_prompt = (("prompt" ![A-Za-z0-9_-]) __ STRING (__ (("with" ![A-Za-z0-9_-]) __ IDENT))? _ NEWLINE)
doc_note = (("note" ![A-Za-z0-9_-]) __ STRING _ NEWLINE)
nat_lang_stmt = ((__ ((!(("{" / "}" / NEWLINE)) UNICODE_CHAR)))+ _ NEWLINE)
nat_lang_block = ("{" (__ nat_lang_stmt)* __ "}")
ident_set = ("[" __ ident_list __ "]")
string_seq = ("[" (__ (STRING (__ ",")?))* __ "]")
qualified_set = ("[" __ qualified_list __ "]")
field_decl = (IDENT __ ":" __ type_expr _ NEWLINE)
param_list = (param_decl (__ ("," __ param_decl))*)
param_decl = (IDENT __ ":" __ type_expr)
ident_list = (IDENT (__ ("," __ IDENT))*)
qualified_list = (QUALIFIED (__ ("," __ QUALIFIED))*)
field_assign = (IDENT __ ":" __ expr)
field_assign_list = (field_assign (__ ("," __ field_assign))*)
expr = (unary_expr (__ (binary_op __ unary_expr))*)
unary_expr = (("!" __ unary_expr) / postfix_expr)
postfix_expr = (primary_expr (__ ("." __ IDENT (__ ("(" (__ arg_list)? __ ")"))?))*)
primary_expr = ((("irsLimits" ![A-Za-z0-9_-]) __ "(" __ expr __ "," __ expr __ ")") / (("context" ![A-Za-z0-9_-]) __ "." __ IDENT (__ ("." __ IDENT))*) / (("exists" ![A-Za-z0-9_-]) __ "(" __ expr __ "," __ IDENT __ "->" __ expr __ ")") / ("false" ![A-Za-z0-9_-]) / (("count" ![A-Za-z0-9_-]) __ "(" __ expr __ ")") / (("today" ![A-Za-z0-9_-]) __ "(" __ ")") / ("true" ![A-Za-z0-9_-]) / ("null" ![A-Za-z0-9_-]) / (("sum" ![A-Za-z0-9_-]) __ "(" __ expr __ ")") / (("all" ![A-Za-z0-9_-]) __ "(" __ expr __ "," __ IDENT __ "->" __ expr __ ")") / (("age" ![A-Za-z0-9_-]) __ "(" __ expr __ ")") / (("now" ![A-Za-z0-9_-]) __ "(" __ ")") / STRING / ("(" __ expr __ ")") / QUALIFIED / NUMBER)
binary_op = ("==" / "!=" / "<=" / ">=" / "&&" / "||" / "->" / "<" / ">" / "+" / "-" / "*" / "/")
arg_list = (expr (__ ("," __ expr))*)
annotation_facet_decl = ((__ visibility_modifier)? __ ("annotation" ![A-Za-z0-9_-]) __ ("facet" ![A-Za-z0-9_-]) __ IDENT __ "{" __ annotation_facet_body __ "}")
annotation_facet_body = (__ annotation_facet_prop)*
annotation_facet_prop = (conflicts_with_constraint / annotation_block / requires_constraint / (("meaning" ![A-Za-z0-9_-]) __ ":" __ STRING _ NEWLINE) / targets_constraint / annotation_field_decl)
annotation_field_decl = (IDENT __ ":" __ annotation_type (__ ("=" __ annotation_value))? _ NEWLINE)
annotation_type = (("Boolean" ![A-Za-z0-9_-]) / ("String" ![A-Za-z0-9_-]) / ("Number" ![A-Za-z0-9_-]) / IDENT)
annotation_value = (("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]) / STRING / NUMBER / IDENT)
targets_constraint = (("targets" ![A-Za-z0-9_-]) __ "[" __ kind_name (__ ("," __ kind_name))* __ "]")
conflicts_with_constraint = (("conflicts-with" ![A-Za-z0-9_-]) __ ident_set)
requires_constraint = (("requires" ![A-Za-z0-9_-]) __ ident_set)
kind_name = (("integration" ![A-Za-z0-9_-]) / ("procedure" ![A-Za-z0-9_-]) / ("relation" ![A-Za-z0-9_-]) / ("mutation" ![A-Za-z0-9_-]) / ("workflow" ![A-Za-z0-9_-]) / ("variant" ![A-Za-z0-9_-]) / ("compute" ![A-Za-z0-9_-]) / ("entity" ![A-Za-z0-9_-]) / ("action" ![A-Za-z0-9_-]) / ("policy" ![A-Za-z0-9_-]) / ("facet" ![A-Za-z0-9_-]) / ("query" ![A-Za-z0-9_-]) / ("agent" ![A-Za-z0-9_-]) / ("serve" ![A-Za-z0-9_-]) / ("event" ![A-Za-z0-9_-]) / ("task" ![A-Za-z0-9_-]) / ("saga" ![A-Za-z0-9_-]) / ("api" ![A-Za-z0-9_-]))
annotation_aspect_decl = ((__ visibility_modifier)? __ ("annotation" ![A-Za-z0-9_-]) __ ("aspect" ![A-Za-z0-9_-]) __ IDENT __ ("on" ![A-Za-z0-9_-]) __ annotation_target __ "{" __ annotation_block __ "}")
annotation_target = ((("entity" ![A-Za-z0-9_-]) __ ("where" ![A-Za-z0-9_-]) __ annotation_predicate) / (("action" ![A-Za-z0-9_-]) __ ("where" ![A-Za-z0-9_-]) __ annotation_predicate) / (("facet" ![A-Za-z0-9_-]) __ ("where" ![A-Za-z0-9_-]) __ annotation_predicate) / QUALIFIED)
annotation_predicate = (annotation_predicate_atom (__ (("and" ![A-Za-z0-9_-]) __ annotation_predicate_atom))*)
annotation_predicate_atom = ((("includes" ![A-Za-z0-9_-]) __ IDENT) / (("fields" ![A-Za-z0-9_-]) __ ("contains" ![A-Za-z0-9_-]) __ type_expr))
annotation_block = (("annotations" ![A-Za-z0-9_-]) __ "{" (__ inline_annotation)* __ "}")
inline_annotation = (IDENT __ ":" __ ((("false" ![A-Za-z0-9_-]) / ("true" ![A-Za-z0-9_-]) / STRING / NUMBER / IDENT)) _ NEWLINE)
decorated_decl = (decorator _ NEWLINE (__ (decorator _ NEWLINE))* __ bare_top_level_decl)
decorator = (("@" __ IDENT) / ("@" __ ident_set))
