101 lines
3.3 KiB
Plaintext
101 lines
3.3 KiB
Plaintext
PARSER_BEGIN(BlockConfigParser)
|
|
package mods.betterfoliage.config.match.parser;
|
|
|
|
import java.util.List;
|
|
import java.util.LinkedList;
|
|
import mods.betterfoliage.config.match.*;
|
|
|
|
public class BlockConfigParser {
|
|
public String configFile;
|
|
|
|
ConfigSource getSource(Token t) {
|
|
return new ConfigSource(configFile, t.beginLine, t.beginColumn);
|
|
}
|
|
}
|
|
|
|
PARSER_END(BlockConfigParser)
|
|
|
|
// Whitespace definition
|
|
SKIP : { " " | "\n" | "\t" | "\r" }
|
|
|
|
// Single-line comment
|
|
SPECIAL_TOKEN : { <lineComment: "//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")> }
|
|
|
|
// Lexical state for string literal in quotes
|
|
SPECIAL_TOKEN : { < quoteStart : "\"" > : withinQuotes }
|
|
<withinQuotes> SPECIAL_TOKEN : { < quoteEnd : "\"" > : DEFAULT }
|
|
<withinQuotes> TOKEN : { < stringLiteral : (["a"-"z"] | ["0"-"9"] | "/" | "." | "_" | "-" | ":" )* > }
|
|
|
|
// Symbol tokens
|
|
TOKEN : {
|
|
< parenStart : "(" > |
|
|
< parenEnd : ")" > |
|
|
< dot : "." > |
|
|
< comma : "," > |
|
|
< exclamation : "!" >
|
|
}
|
|
|
|
List<Node.MatchAll> matchFile() : {
|
|
Token t; Node n; List<Node.MatchAll> rules = new LinkedList<Node.MatchAll>();
|
|
} {
|
|
(
|
|
t = "match"
|
|
{ List<Node> nodes = new LinkedList<Node>(); }
|
|
(n = match() { nodes.add(n); })*
|
|
"end"
|
|
{ rules.add(new Node.MatchAll(getSource(t), nodes)); }
|
|
)*
|
|
{ return rules; }
|
|
}
|
|
|
|
Node match() : {
|
|
Token t; Token t2; MatchMethod mm; List<Node.Value> values; Node.Value v; Node n;
|
|
} {
|
|
<exclamation> n = match() { return new Node.Negate(n); }
|
|
|
|
|
t = "block.class." mm = matchMethod() <parenStart> values = matchValueList() <parenEnd>
|
|
{ return new Node.MatchValueList(Node.MatchSource.BLOCK_CLASS, mm, getSource(t), values); }
|
|
|
|
|
t = "block.name." mm = matchMethod() <parenStart> values = matchValueList() <parenEnd>
|
|
{ return new Node.MatchValueList(Node.MatchSource.BLOCK_NAME, mm, getSource(t), values); }
|
|
|
|
|
t = "model." mm = matchMethod() <parenStart> values = matchValueList() <parenEnd>
|
|
{ return new Node.MatchValueList(Node.MatchSource.MODEL_LOCATION, mm, getSource(t), values); }
|
|
|
|
|
t = "isParam" <parenStart> t2 = <stringLiteral> <comma> values = matchValueList() <parenEnd>
|
|
{ return new Node.MatchParam(t2.image, values, getSource(t)); }
|
|
|
|
|
t = "setParam" <parenStart> t2 = <stringLiteral> <comma> v = matchValue() <parenEnd>
|
|
{ return new Node.SetParam(t2.image, v, getSource(t)); }
|
|
}
|
|
|
|
MatchMethod matchMethod() : {} {
|
|
"matches" { return MatchMethod.EXACT_MATCH; } |
|
|
"extends" { return MatchMethod.EXTENDS; } |
|
|
"contains" { return MatchMethod.CONTAINS; }
|
|
}
|
|
|
|
List<Node.Value> matchValueList() : {
|
|
List<Node.Value> values = new LinkedList<Node.Value>();
|
|
Node.Value v;
|
|
} {
|
|
v = matchValue() { values.add(v); }
|
|
(<comma> v = matchValue() { values.add(v); } )*
|
|
{ return values; }
|
|
}
|
|
|
|
Node.Value matchValue() : {
|
|
Token t;
|
|
} {
|
|
t = <stringLiteral>
|
|
{ return new Node.Value.Literal(getSource(t), t.image); }
|
|
|
|
|
"classOf" <parenStart> t = <stringLiteral> <parenEnd>
|
|
{ return new Node.Value.ClassOf(getSource(t), t.image); }
|
|
|
|
|
"model.texture" <parenStart> t = <stringLiteral> <parenEnd>
|
|
{ return new Node.Value.Texture(getSource(t), t.image); }
|
|
|
|
|
"model.tint" <parenStart> t = <stringLiteral> <parenEnd>
|
|
{ return new Node.Value.Tint(getSource(t), t.image); }
|
|
} |