Files
quixos-protocol/grammar/QuixosCapability.g4
T

404 lines
7.3 KiB
ANTLR

grammar QuixosCapability;
document
: workspaceDecl EOF
;
workspaceDecl
: WORKSPACE identifier ID stringLiteral REVISION stringLiteral COMMIT stringLiteral
LBRACE workspaceItem* RBRACE
;
workspaceItem
: atomDecl
| interfaceDecl
| packageDecl
| sharedAttachmentDecl
| conformanceDecl
| constructorBindingDecl
;
atomDecl
: ATOM identifier ID stringLiteral (DOC stringLiteral)? SEMI
;
interfaceDecl
: INTERFACE identifier ID stringLiteral REVISION stringLiteral sourceBlock
LBRACE interfaceMember* RBRACE
;
sourceBlock
: SOURCE LBRACE
REPOSITORY stringLiteral SEMI
COMMIT stringLiteral SEMI
RBRACE
;
interfaceMember
: valueMember
| relationshipMember
| operationMember
;
operationMember
: OPERATION identifier ID stringLiteral COLON valueType ARROW valueType
LBRACE CALL ID stringLiteral SEMI RBRACE
;
valueMember
: VALUE identifier ID stringLiteral COLON valueType
LBRACE valueMemberOperation* RBRACE
;
valueMemberOperation
: GET ID stringLiteral SEMI
| SET ID stringLiteral SEMI
| WATCH START ID stringLiteral STOP ID stringLiteral SEMI
;
relationshipMember
: RELATION identifier ID stringLiteral COLON cardinality targetConstraint ORDERED?
LBRACE relationshipOperation* RBRACE
;
relationshipOperation
: RESOLVE ID stringLiteral SEMI
| CONNECT ID stringLiteral SEMI
| DISCONNECT ID stringLiteral SEMI
| WATCH START ID stringLiteral STOP ID stringLiteral SEMI
;
targetConstraint
: ATOM identifier
| INTERFACE identifier
;
packageDecl
: PACKAGE identifier ID stringLiteral REVISION stringLiteral sourceBlock
LBRACE packageExport* RBRACE
;
packageExport
: packageOperationExport
| packageFunctionExport
| packageConstructorExport
;
packageOperationExport
: OPERATION identifier ID stringLiteral COLON valueType ARROW valueType
MODE operationMode eventClause? RECEIVER receiverRequirement dependencyBlock? SEMI
;
packageFunctionExport
: FUNCTION identifier ID stringLiteral COLON valueType ARROW valueType
dependencyBlock? SEMI
;
packageConstructorExport
: CONSTRUCTOR identifier ID stringLiteral CONSTRUCTS identifier COLON valueType
dependencyBlock? SEMI
;
eventClause
: EMITS valueType
;
operationMode
: CALL
| WATCH_START
| WATCH_STOP
| SUBSCRIBE
| UNSUBSCRIBE
;
receiverRequirement
: ANY
| ATOM identifier
| INTERFACES LBRACK identifierList? RBRACK
;
identifierList
: identifier (COMMA identifier)*
;
dependencyBlock
: REQUIRES LBRACE dependencyPort* RBRACE
;
dependencyPort
: STATE identifier ID stringLiteral COLON valueType primitiveList SEMI
| EDGE identifier ID stringLiteral COLON cardinality targetConstraint primitiveList SEMI
| INTERFACE identifier ID stringLiteral COLON identifier SEMI
| CONSTRUCTOR identifier ID stringLiteral COLON identifier SEMI
;
primitiveList
: LBRACK primitive (COMMA primitive)* RBRACK
;
primitive
: READ
| WRITE
| RESOLVE
| CONNECT
| DISCONNECT
| WATCH_START
| WATCH_STOP
;
sharedAttachmentDecl
: SHARED attachmentDecl
;
attachmentDecl
: stateDecl
| edgeDecl
;
stateDecl
: STATE identifier ID stringLiteral ON identifier COLON valueType
POLICY storagePolicy (DEFAULT jsonLiteral)? SEMI
;
storagePolicy
: OPTIMISTIC_REGISTER
| CRDT LPAREN valueType RPAREN
;
edgeDecl
: EDGE identifier ID stringLiteral LBRACE edgeEndpoint edgeEndpoint RBRACE
;
edgeEndpoint
: targetConstraint PROJECTION identifier ID stringLiteral cardinality ORDERED? SEMI
;
conformanceDecl
: CONFORM identifier AS identifier LBRACE conformanceItem* RBRACE
;
conformanceItem
: PRIVATE attachmentDecl
| operationBindingDecl
;
operationBindingDecl
: BIND memberOperationRef TO operationProvider SEMI
;
memberOperationRef
: identifier DOT operationName
;
operationName
: identifier
| CALL
| GET
| SET
| RESOLVE
| CONNECT
| DISCONNECT
| WATCH_START
| WATCH_STOP
| SUBSCRIBE
| UNSUBSCRIBE
;
operationProvider
: STATE identifier DOT statePrimitive
| EDGE identifier DOT identifier DOT edgePrimitive
| PACKAGE identifier DOT identifier dependencyBindingBlock?
;
statePrimitive
: READ
| WRITE
| WATCH_START
| WATCH_STOP
;
edgePrimitive
: RESOLVE
| CONNECT
| DISCONNECT
| WATCH_START
| WATCH_STOP
;
dependencyBindingBlock
: WITH LBRACE dependencyBinding* RBRACE
;
dependencyBinding
: identifier TO STATE identifier SEMI
| identifier TO EDGE identifier DOT identifier SEMI
| identifier TO INTERFACE identifier SEMI
| identifier TO CONSTRUCTOR identifier SEMI
;
constructorBindingDecl
: CONSTRUCTOR identifier TO identifier DOT identifier dependencyBindingBlock? SEMI
;
valueType
: scalarType
| UNIT
| WATCH_HANDLE
| MESSAGE stringLiteral
| ATOM_REF LT identifier GT
| INTERFACE_REF LT identifier GT
| OPTIONAL LT valueType GT
| LIST LT valueType GT
;
scalarType
: BOOL
| BYTES
| DOUBLE
| INT32
| INT64
| STRING
| UINT32
| UINT64
;
cardinality
: OPTIONAL_ONE
| EXACTLY_ONE
| MANY
| MANY_UNIQUE
;
jsonLiteral
: stringLiteral
| INTEGER
| JSON_NUMBER
| TRUE
| FALSE
| NULL
| jsonObject
| jsonArray
;
jsonObject
: LBRACE (jsonMember (COMMA jsonMember)*)? RBRACE
;
jsonMember
: stringLiteral COLON jsonLiteral
;
jsonArray
: LBRACK (jsonLiteral (COMMA jsonLiteral)*)? RBRACK
;
identifier
: IDENTIFIER
| SOURCE
;
stringLiteral
: STRING_LITERAL
;
WORKSPACE: 'workspace';
ATOM: 'atom';
INTERFACE: 'interface';
INTERFACES: 'interfaces';
PACKAGE: 'package';
VALUE: 'value';
RELATION: 'relation';
OPERATION: 'operation';
FUNCTION: 'function';
CONSTRUCTOR: 'constructor';
CONSTRUCTS: 'constructs';
CONFORM: 'conform';
AS: 'as';
BIND: 'bind';
TO: 'to';
PRIVATE: 'private';
SHARED: 'shared';
STATE: 'state';
EDGE: 'edge';
PROJECTION: 'projection';
WITH: 'with';
ON: 'on';
POLICY: 'policy';
DEFAULT: 'default';
SOURCE: 'source';
REPOSITORY: 'repository';
COMMIT: 'commit';
REVISION: 'revision';
ID: 'id';
DOC: 'doc';
MODE: 'mode';
EMITS: 'emits';
RECEIVER: 'receiver';
REQUIRES: 'requires';
ANY: 'any';
GET: 'get';
SET: 'set';
WATCH: 'watch';
START: 'start';
STOP: 'stop';
READ: 'read';
WRITE: 'write';
RESOLVE: 'resolve';
CONNECT: 'connect';
DISCONNECT: 'disconnect';
CALL: 'call';
WATCH_START: 'watch-start';
WATCH_STOP: 'watch-stop';
SUBSCRIBE: 'subscribe';
UNSUBSCRIBE: 'unsubscribe';
OPTIMISTIC_REGISTER: 'optimistic-register';
CRDT: 'crdt';
OPTIONAL_ONE: 'optional-one';
EXACTLY_ONE: 'exactly-one';
MANY_UNIQUE: 'many-unique';
MANY: 'many';
ORDERED: 'ordered';
UNIT: 'unit';
WATCH_HANDLE: 'watch-handle';
MESSAGE: 'message';
ATOM_REF: 'atom-ref';
INTERFACE_REF: 'interface-ref';
OPTIONAL: 'optional';
LIST: 'list';
BOOL: 'bool';
BYTES: 'bytes';
DOUBLE: 'double';
INT32: 'int32';
INT64: 'int64';
STRING: 'string';
UINT32: 'uint32';
UINT64: 'uint64';
TRUE: 'true';
FALSE: 'false';
NULL: 'null';
ARROW: '->';
COLON: ':';
SEMI: ';';
COMMA: ',';
DOT: '.';
LBRACE: '{';
RBRACE: '}';
LBRACK: '[';
RBRACK: ']';
LPAREN: '(';
RPAREN: ')';
LT: '<';
GT: '>';
INTEGER: '-'? [0-9]+;
JSON_NUMBER: '-'? ('0' | [1-9] [0-9]*) ('.' [0-9]+)? ([eE] [+-]? [0-9]+)?;
IDENTIFIER: [A-Za-z_] [A-Za-z0-9_]*;
STRING_LITERAL: '"' (ESC | ~["\\\r\n])* '"';
fragment ESC: '\\' (["\\/bfnrt] | 'u' HEX HEX HEX HEX);
fragment HEX: [0-9a-fA-F];
LINE_COMMENT: '//' ~[\r\n]* -> skip;
BLOCK_COMMENT: '/*' .*? '*/' -> skip;
WS: [ \t\r\n]+ -> skip;