mirror of
https://github.com/hanzo-fi/numscript.git
synced 2026-10-30 20:54:52 +00:00
* feat: feature flag syntax * feat: change syntax * feat: reject invalid features * feat: add static check of unknown features * feat: more defensive args handling * fix: fix typo
76 lines
2.7 KiB
ANTLR
76 lines
2.7 KiB
ANTLR
grammar Numscript;
|
|
|
|
options {
|
|
tokenVocab = 'Lexer';
|
|
}
|
|
|
|
monetaryLit:
|
|
LBRACKET (asset = valueExpr) (amt = valueExpr) RBRACKET;
|
|
|
|
accountLiteralPart:
|
|
ACCOUNT_TEXT # accountTextPart
|
|
| VARIABLE_NAME_ACC # accountVarPart;
|
|
|
|
valueExpr:
|
|
VARIABLE_NAME # variableExpr
|
|
| ASSET # assetLiteral
|
|
| STRING # stringLiteral
|
|
| ACCOUNT_START accountLiteralPart (COLON accountLiteralPart)* # accountLiteral
|
|
| NUMBER # numberLiteral
|
|
| PERCENTAGE_PORTION_LITERAL # percentagePortionLiteral
|
|
| monetaryLit # monetaryLiteral
|
|
| op=MINUS valueExpr # prefixExpr
|
|
| left = valueExpr op = DIV right = valueExpr # infixExpr
|
|
| left = valueExpr op = (PLUS | MINUS) right = valueExpr # infixExpr
|
|
| LPARENS valueExpr RPARENS # parenthesizedExpr
|
|
| functionCall # application;
|
|
|
|
functionCallArgs: valueExpr ( COMMA valueExpr)*;
|
|
functionCall:
|
|
fnName = (OVERDRAFT | IDENTIFIER) LPARENS functionCallArgs? RPARENS;
|
|
|
|
varOrigin: EQ valueExpr;
|
|
varDeclaration:
|
|
type_ = IDENTIFIER name = VARIABLE_NAME varOrigin?;
|
|
varsDeclaration: VARS LBRACE varDeclaration* RBRACE;
|
|
|
|
featureDecl: HASH_BANG LBRACKET FEATURE LPARENS (flag+=STRING (COMMA flag+=STRING)*)? RPARENS RBRACKET;
|
|
program: featureDecl? varsDeclaration? statement* EOF;
|
|
|
|
sentAllLit: LBRACKET (asset = valueExpr) STAR RBRACKET;
|
|
|
|
allotment:
|
|
valueExpr # portionedAllotment
|
|
| REMAINING # remainingAllotment;
|
|
|
|
colorConstraint: RESTRICT valueExpr;
|
|
|
|
source
|
|
: address = valueExpr colorConstraint? ALLOWING UNBOUNDED OVERDRAFT # srcAccountUnboundedOverdraft
|
|
| address = valueExpr colorConstraint? ALLOWING OVERDRAFT UP TO maxOvedraft = valueExpr #srcAccountBoundedOverdraft
|
|
| address = valueExpr WITH SCALING THROUGH swap=valueExpr # srcAccountWithScaling
|
|
| valueExpr colorConstraint? # srcAccount
|
|
| LBRACE allotmentClauseSrc+ RBRACE # srcAllotment
|
|
| LBRACE source* RBRACE # srcInorder
|
|
| ONEOF LBRACE source+ RBRACE # srcOneof
|
|
| MAX cap = valueExpr FROM source # srcCapped;
|
|
allotmentClauseSrc: allotment FROM source;
|
|
|
|
keptOrDestination:
|
|
TO destination # destinationTo
|
|
| KEPT # destinationKept;
|
|
destinationInOrderClause: MAX valueExpr keptOrDestination;
|
|
|
|
destination:
|
|
valueExpr # destAccount
|
|
| LBRACE allotmentClauseDest+ RBRACE # destAllotment
|
|
| LBRACE destinationInOrderClause* REMAINING keptOrDestination RBRACE # destInorder
|
|
| ONEOF LBRACE destinationInOrderClause* REMAINING keptOrDestination RBRACE # destOneof;
|
|
allotmentClauseDest: allotment keptOrDestination;
|
|
|
|
sentValue: valueExpr # sentLiteral | sentAllLit # sentAll;
|
|
|
|
statement:
|
|
SEND sentValue LPARENS SOURCE EQ source DESTINATION EQ destination RPARENS # sendStatement
|
|
| SAVE sentValue FROM valueExpr # saveStatement
|
|
| functionCall # fnCallStatement; |