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 : { } // Lexical state for string literal in quotes SPECIAL_TOKEN : { < quoteStart : "\"" > : withinQuotes } SPECIAL_TOKEN : { < quoteEnd : "\"" > : DEFAULT } TOKEN : { < stringLiteral : (["a"-"z"] | ["0"-"9"] | "/" | "." | "_" | "-" | ":" )* > } // Symbol tokens TOKEN : { < parenStart : "(" > | < parenEnd : ")" > | < dot : "." > | < comma : "," > | < exclamation : "!" > } List matchFile() : { Token t; Node n; List rules = new LinkedList(); } { ( t = "match" { List nodes = new LinkedList(); } (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 values; Node.Value v; Node n; } { n = match() { return new Node.Negate(n); } | t = "block.class." mm = matchMethod() values = matchValueList() { return new Node.MatchValueList(Node.MatchSource.BLOCK_CLASS, mm, getSource(t), values); } | t = "block.name." mm = matchMethod() values = matchValueList() { return new Node.MatchValueList(Node.MatchSource.BLOCK_NAME, mm, getSource(t), values); } | t = "model." mm = matchMethod() values = matchValueList() { return new Node.MatchValueList(Node.MatchSource.MODEL_LOCATION, mm, getSource(t), values); } | t = "isParam" t2 = values = matchValueList() { return new Node.MatchParam(t2.image, values, getSource(t)); } | t = "setParam" t2 = v = matchValue() { 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 matchValueList() : { List values = new LinkedList(); Node.Value v; } { v = matchValue() { values.add(v); } ( v = matchValue() { values.add(v); } )* { return values; } } Node.Value matchValue() : { Token t; } { t = { return new Node.Value.Literal(getSource(t), t.image); } | "classOf" t = { return new Node.Value.ClassOf(getSource(t), t.image); } | "model.texture" t = { return new Node.Value.Texture(getSource(t), t.image); } | "model.tint" t = { return new Node.Value.Tint(getSource(t), t.image); } }