Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ ignore/
remappedSrc
remappedSrc/
/libs
.antlr
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java-library'
id 'net.neoforged.moddev.legacyforge' version "2.0.107"
id "me.modmuss50.mod-publish-plugin" version "0.8.4"
id 'antlr'
}

//archivesBaseName = "${mod_archive_name}-${minecraft_version}"
Expand All @@ -20,11 +21,19 @@ base {
archivesName = "${mod_archive_name}-${minecraft_version}"
}

sourceSets.main.java {
srcDir 'build/generated-src/antlr'
}

sourceSets.main.resources{
srcDir 'src/generated/resources'
exclude '.cache/**'
}

generateGrammarSource {
arguments += ["-visitor", "-package", "com.robertx22.mine_and_slash.antlr"]
}

legacyForge {
version = "${minecraft_version}-${forge_version}"

Expand Down Expand Up @@ -159,6 +168,8 @@ dependencies {
modImplementation("com.robertx22:the_harvest:${project.the_harvest_version}")
modImplementation("com.robertx22:dungeon_realm:${project.dungeon_realm_version}")
//modImplementation("maven.modrinth:library-of-exile:${project.exile_library_version}")

antlr "org.antlr:antlr4:4.5" // use ANTLR version 4
}


Expand Down
88 changes: 88 additions & 0 deletions src/main/antlr/com/robertx22/mine_and_slash/antlr/Spell.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
grammar Spell;

/*
* Parser
*/

spell: statement+;

statement: propertyStatement | attachedStatement;

// json property values
propertyBlock: '{' propertyStatement* '}' | propertyStatement;
propertyStatement: assignment | subobject;

assignment: propertyName '=' propertyValue ';';
propertyName: Identifier;
propertyValue: literal | literalArrayValue | objectArrayValue;
literalArrayValue: '[' (literal (',' literal)* ','?)? ']';
objectArrayValue: '[' (arrayElement (',' arrayElement)* ','?)? ']';
arrayElement: '{' propertyStatement* '}';

subobject: subobjectName propertyBlock;
subobjectName: Identifier;

// spell attached action blocks
attachedStatement: eventHandler | entity;
eventHandler: eventName scriptBlock;
eventName: OnCast | OnTick | OnCastEnd;
entity: 'entity' entityName scriptBlock;
entityName: Identifier;

// spell action syntax
scriptBlock: '{' scriptStatement* '}' | scriptStatement;
scriptStatement: ifBlock | selectBlock | actions;
ifBlock: 'if' '(' conditionExpr ')' scriptBlock elseBlock?;
elseBlock: 'else' scriptBlock;
selectBlock: 'select' '(' selectorList ')' scriptBlock;
actions: mapHolder+ (';' | perEntityHit); // spell action list
perEntityHit: 'per_entity_hit' scriptBlock;

selectorList: selector ('||' selector)*;
selector: mapHolder; // spell targets entry

enPredPrefix: 'en' '.';
condition: enPredPrefix? mapHolder; // single condition
conditionParen: '(' conditionExpr ')' | condition;
conditionNot: Not conditionParen | conditionParen;
conditionAnd: conditionNot ('&&' conditionNot)*;
conditionExpr: conditionAnd;

// corresponds to MapHolder with type and map
mapHolder: mapHolderType '(' mapHolderArguments? ')';
mapHolderType: Identifier;
mapHolderArguments: argumentPositional (',' argumentPositional)* (',' argumentKeyValue)*
| argumentKeyValue (',' argumentKeyValue)*;
argumentPositional: literal;
argumentKeyValue: argumentKey '=' argumentValue;
argumentKey: Identifier;
argumentValue: literal;

literal: String | Double | Int | bool;
bool: True | False;

/*
* Lexer
*/

Not: '!';

OnCast: 'on_cast';
OnTick: 'on_tick';
OnCastEnd: 'on_cast_end';

True: 'true';
False: 'false';

Double: Number? '.' Number;
Int: Number;
fragment Number: '0'..'9'+;

String: '"' ~[\r\n"]* '"';

Identifier: ('a'..'z' | 'A'..'Z' | '0'..'9' | [_$])+;

Comment: '//' ~[\r\n]* [\r]? [\n] -> skip;
BlockComment: '/*' .*? '*/' -> skip;

WS: [ \t\r\n]+ -> skip;
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class StatMod implements ISerializable<StatMod> {

public static StatMod EMPTY = new StatMod();

private StatMod() {
public StatMod() {

}

Expand Down
Loading