shulkerscript-lang/grammar.md

1.2 KiB

Grammar of the shulkerscript language

Table of contents

Program

Program: Declaration*;

Declaration

Declaration: FunctionDeclaration;

FunctionDeclaration

Function:
    Annotation* 'fn' Identifier '(' ParameterList? ')' Block
    ;
ParameterList:
    Identifier (',' Identifier)* ','?  
    ;

Annotation

Annotation: '#[' Identifier ('=' StringLiteral)? ']';

Statement

Statement:
    Block
    | LiteralCommand
    | Conditional
    | Grouping
    | DocComment
    | Semicolon
    | Run
    ;

Block

Block: '{' Statement* '}';

Run

Run:
    'run' Expression ';'
    ;

Conditional

Conditional:
    'if' ParenthizedCondition Block ('else' Block)?
    ;

ParenthizedCondition

ParenthizedCondition:
    '(' Condition ')'
    ;

Condition

Condition:
    StringLiteral

Grouping

Grouping:
    'group' Block
;

Expression

Expression:
    Primary

Primary

Primary:
    FunctionCall

FunctionCall

FunctionCall:
    Identifier '(' (Expression (',' Expression)*)? ')'
    ;