// MAPLE - Multi Agent Protocol Language Engine - Specification

// Top-level constructs
Protocol        ::= Header Definitions Body

// Header section
Header          ::= "protocol" Identifier Version Requirements

Version         ::= "version" Number "." Number "." Number
Requirements    ::= "requires" "{" Capability* "}"
Capability      ::= Identifier ":" Value

// Definitions section
Definitions     ::= "definitions" "{" (TypeDef | MessageDef | RoleDef)* "}"

TypeDef         ::= "type" Identifier "{" Field* "}"
Field           ::= Identifier ":" DataType ["=" DefaultValue]

MessageDef      ::= "message" Identifier "{" 
                    "sender" ":" RoleType
                    "receiver" ":" RoleType
                    "payload" ":" DataType
                    "priority" ":" PriorityLevel
                    ["timeout" ":" Duration]
                    "}"

RoleDef         ::= "role" Identifier "{" 
                    "capabilities" ":" Capability*
                    "states" ":" State*
                    "}"

// Body section
Body            ::= "flow" "{" (Stage | Transaction)* "}"

Stage           ::= "stage" Identifier "{" 
                    "preconditions" ":" Condition*
                    "actions" ":" Action*
                    "postconditions" ":" Condition*
                    "error" ":" ErrorHandler
                    "}"

Transaction     ::= "transaction" Identifier "{"
                    "atomic" ":" Boolean
                    "participants" ":" RoleType*
                    "steps" ":" Step*
                    "compensation" ":" Action*
                    "}"

// Data types and utilities
DataType        ::= "String" | "Number" | "Boolean" | "Map" | "List" | CustomType
PriorityLevel   ::= "HIGH" | "MEDIUM" | "LOW"
State           ::= "INIT" | "ACTIVE" | "WAITING" | "COMPLETED" | "ERROR"
ErrorHandler    ::= "retry" | "fail" | "compensate" | CustomHandler


"""
Copyright (C) 2025 Mahesh Vaijainthymala Krishnamoorthy (Mahesh Vaikri)

This file is part of MAPLE - Multi Agent Protocol Language Engine. 

MAPLE - Multi Agent Protocol Language Engine is free software: you can redistribute it and/or 
modify it under the terms of the GNU Affero General Public License as published by the Free Software 
Foundation, either version 3 of the License, or (at your option) any later version. 
MAPLE - Multi Agent Protocol Language Engine is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have 
received a copy of the GNU Affero General Public License along with MAPLE - Multi Agent Protocol 
Language Engine. If not, see <https://www.gnu.org/licenses/>.
"""
