shulkerscript-lang/grammar.md

162 lines
2.1 KiB
Markdown
Raw Normal View History

# Grammar of the Shulkerscript language
## Table of contents
### Program
```ebnf
2024-06-09 17:59:56 +02:00
Program: Namespace Declaration*;
```
### Namespace
```ebnf
Namespace: 'namespace' StringLiteral;
```
### Declaration
```ebnf
2024-09-21 22:45:05 +02:00
Declaration: FunctionDeclaration | Import | TagDeclaration;
2024-06-24 21:37:02 +02:00
```
### Import
```ebnf
Import: 'from' StringLiteral 'import' Identifier;
```
2024-09-21 22:45:05 +02:00
### TagDeclaration
```ebnf
TagDeclaration: 'tag' StringLiteral ('of' StringLiteral)? 'replace'? '[' (StringLiteral (',' StringLiteral)*)? ']';
```
### FunctionDeclaration
```ebnf
Function:
2024-06-09 17:59:56 +02:00
Annotation* 'pub'? 'fn' Identifier '(' ParameterList? ')' Block
;
ParameterList:
Identifier (',' Identifier)* ','?
;
```
2024-04-01 20:42:38 +02:00
### Annotation
```ebnf
Annotation: '#[' Identifier ('=' StringLiteral)? ']';
```
### Statement
```ebnf
Statement:
Block
| LiteralCommand
| Conditional
2024-04-05 16:16:12 +02:00
| Grouping
| DocComment
| Semicolon
| Run
;
```
### Block
```ebnf
Block: '{' Statement* '}';
```
### Run
```ebnf
Run:
'run' Expression ';'
;
```
### Conditional
```ebnf
Conditional:
'if' ParenthizedCondition Block ('else' Block)?
;
```
2024-04-06 17:23:20 +02:00
### Condition
```ebnf
2024-04-06 17:23:20 +02:00
Condition:
PrimaryCondition
BinaryCondition
;
```
2024-04-06 17:23:20 +02:00
#### PrimaryCondition
```ebnf
2024-04-06 17:23:20 +02:00
PrimaryCondition:
ConditionalPrefix
| ParenthesizedCondition
| StringLiteral
;
```
#### ConditionalPrefix
```ebnf
ConditionalPrefix:
ConditionalPrefixOperator PrimaryCondition
;
```
#### ConditionalPrefixOperator
``` ebnf
ConditionalPrefixOperator: '!';
```
#### BinaryCondition
``` ebnf
BinaryCondition:
Condition ConditionalBinaryOperator Condition
;
2024-04-05 16:16:12 +02:00
```
2024-04-06 17:23:20 +02:00
#### ConditionalBinaryOperator
``` ebnf
ConditionalBinaryOperator:
'&&'
| '||'
;
```
#### ParenthizedCondition
```ebnf
ParenthizedCondition:
'(' Condition ')'
;
```
2024-04-05 16:16:12 +02:00
### Grouping
``` ebnf
Grouping:
'group' Block
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### Expression
```ebnf
Expression:
Primary
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### Primary
```ebnf
2024-04-05 16:16:12 +02:00
Primary:
FunctionCall
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### FunctionCall
```ebnf
2024-04-05 16:16:12 +02:00
FunctionCall:
Identifier '(' (Expression (',' Expression)*)? ')'
;
2024-04-06 17:23:20 +02:00
```
### LuaCode
```ebnf
LuaCode:
'lua' '(' (Expression (',' Expression)*)? ')' '{' (.*?)* '}'
;
```