diff --git a/.github/workflows/maven-build-jar.yml b/.github/workflows/maven-build-jar.yml new file mode 100644 index 0000000..b1da36d --- /dev/null +++ b/.github/workflows/maven-build-jar.yml @@ -0,0 +1,41 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + - push + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build with Maven + run: mvn -B package + + - name: Upload built jar as CI artifact + uses: actions/upload-artifact@v3 + with: + name: jar + path: target/*.jar + + - name: From tags, create GH release and attach built jar + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: target/*.jar diff --git a/README.md b/README.md new file mode 100644 index 0000000..1eb02a6 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# stellaris tech tree parser +[![Java CI with Maven](https://github.com/azrdev/stellaris-technology-parser/actions/workflows/maven-build-jar.yml/badge.svg)](https://github.com/azrdev/stellaris-technology-parser/actions/workflows/maven-build-jar.yml) + +Usage: +1. install a JDK and maven +2. build the project using `mvn package` resulting in `target/stellaris-1.0.0-SNAPSHOT.jar`, or use the .jar built by GitHub Actions +3. open a shell, change to a directory in which `files/` contains your Stellaris installation (e.g. `ln -Ts files ~/.steam/steam/steamapps/common/Stellaris`) +4. Run `java -jar /path/to/your/target/stellaris-1.0.0-SNAPSHOT.jar` +5. Collect the generated `*.json` files and `index.html` and publish to a webserver, e.g. add to https://github.com/turanar/stellaris-tech-tree/ diff --git a/files/common/.gitkeep b/files/common/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/files/localisation/.gitkeep b/files/localisation/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/pom.xml b/pom.xml index 4849d88..156ce81 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,26 @@ + + org.antlr + antlr4-maven-plugin + 4.7.1 + + + + antlr4 + + + true + + -package + net.turanar.stellaris.antlr + + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -55,6 +75,27 @@ 1.8 - + + org.springframework.boot + spring-boot-maven-plugin + 2.1.4.RELEASE + + ${start-class} + + + + + - \ No newline at end of file + + + org.springframework.boot + spring-boot-starter-parent + 2.4.0 + + + + + net.turanar.stellaris.App + + diff --git a/Stellaris.g4 b/src/main/antlr4/Stellaris.g4 similarity index 72% rename from Stellaris.g4 rename to src/main/antlr4/Stellaris.g4 index be07172..23febab 100644 --- a/Stellaris.g4 +++ b/src/main/antlr4/Stellaris.g4 @@ -5,11 +5,12 @@ file ; map - : '{' (pair)* '}' + : '{' (pair | 'optimize_memory' )* '}' ; pair : BAREWORD SPECIFIER value + | NUMBER SPECIFIER value ; var @@ -20,6 +21,10 @@ array : '{' value+ '}' ; +valueSpec + : BAREWORD ':' BAREWORD (( '|' BAREWORD )* '|')? + ; + value : NUMBER | BOOLEAN @@ -27,6 +32,7 @@ value | STRING | VARIABLE | BAREWORD + | valueSpec | map | array ; @@ -43,7 +49,7 @@ VARIABLE ; SPECIFIER - : '=' | '<>' | '>' | '<' | '<=' | '>=' ; + : '=' | '!=' | '<>' | '>' | '<' | '<=' | '>=' ; NUMBER : '-'?[0-9]+'%' @@ -55,7 +61,7 @@ DATE : [0-9]+'.'[0-9]+'.'[0-9]+; BAREWORD - : [A-Za-z][@A-Za-z_0-9.%-]* + : [A-Za-z][@A-Za-z_0-9.%/-]* ; STRING @@ -68,4 +74,4 @@ WS LINE_COMMENT : '#'~[\r\n]* -> channel(HIDDEN) - ; \ No newline at end of file + ; diff --git a/src/main/java/net/turanar/stellaris/Config.java b/src/main/java/net/turanar/stellaris/Config.java index b5e50dd..05fa874 100644 --- a/src/main/java/net/turanar/stellaris/Config.java +++ b/src/main/java/net/turanar/stellaris/Config.java @@ -10,7 +10,9 @@ import org.yaml.snakeyaml.Yaml; import java.io.IOException; +import java.lang.RuntimeException; import java.util.HashMap; +import java.util.Collections; import java.util.Map; import static net.turanar.stellaris.Global.*; @@ -24,11 +26,21 @@ public Map variables() throws IOException { HashMap retval = new HashMap<>(); parse("files/common/scripted_variables", "txt", p -> { - factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText())); + try { + factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText())); + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + p.toString(), e); + } }); parse("files/common/technology", "txt", p -> { - factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText())); + try { + factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText())); + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + p.toString(), e); + } }); return retval; @@ -39,12 +51,20 @@ public Map localisation() throws IOException { Map retval = new HashMap<>(); parse("files/localisation/english", "yml", path -> { - Yaml yaml = new Yaml(); - Iterable data = yaml.loadAll(new StellarisYamlReader(path)); - Map> map = (Map>)data.iterator().next(); - map.get("l_english").forEach((k, v) -> { - retval.put(k.toString().toLowerCase(), v.toString()); - }); + try { + Yaml yaml = new Yaml(); + Iterable data = yaml.loadAll(new StellarisYamlReader(path)); + Map> map = (Map>)data.iterator().next(); + Map english_l10n = map.getOrDefault("l_english", Collections.emptyMap()); + if (english_l10n != null) { + english_l10n.forEach((k, v) -> { + retval.put(k.toString().toLowerCase(), v.toString()); + }); + }; + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + path.toString(), e); + } }); return retval; @@ -55,7 +75,12 @@ public Map scriptedTriggers() throws IOExce Map retval = new HashMap<>(); parse("files/common/scripted_triggers", "txt", path -> { - factory.getParser(path).file().pair().forEach(pair -> retval.put(pair.key(), pair)); + try { + factory.getParser(path).file().pair().forEach(pair -> retval.put(key(pair), pair)); + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + path.toString(), e); + } }); return retval; diff --git a/src/main/java/net/turanar/stellaris/Global.java b/src/main/java/net/turanar/stellaris/Global.java index b65c5d2..914471c 100644 --- a/src/main/java/net/turanar/stellaris/Global.java +++ b/src/main/java/net/turanar/stellaris/Global.java @@ -31,6 +31,7 @@ public void init(Map GLOBAL_VARIABLES, Map GLOBAL_ } public static String i18n(String key) { + if(key == null) return null; String retval = GLOBAL_STRINGS.get(key.toLowerCase()); if(retval == null) return key; if(retval.contains("$")) { @@ -74,6 +75,10 @@ public static String gs(StellarisParser.ValueContext value) { return null; } + public static String key(StellarisParser.PairContext pair) { + return pair.BAREWORD().getText(); + } + public static String variable(String key) { return GLOBAL_VARIABLES.get(key); } diff --git a/src/main/java/net/turanar/stellaris/antlr/Stellaris.tokens b/src/main/java/net/turanar/stellaris/antlr/Stellaris.tokens deleted file mode 100644 index efb21d6..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/Stellaris.tokens +++ /dev/null @@ -1,13 +0,0 @@ -T__0=1 -T__1=2 -BOOLEAN=3 -VARIABLE=4 -SPECIFIER=5 -NUMBER=6 -DATE=7 -BAREWORD=8 -STRING=9 -WS=10 -LINE_COMMENT=11 -'{'=1 -'}'=2 diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisBaseListener.java b/src/main/java/net/turanar/stellaris/antlr/StellarisBaseListener.java deleted file mode 100644 index 8f6eb26..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisBaseListener.java +++ /dev/null @@ -1,111 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; - -import org.antlr.v4.runtime.ParserRuleContext; -import org.antlr.v4.runtime.tree.ErrorNode; -import org.antlr.v4.runtime.tree.TerminalNode; - -/** - * This class provides an empty implementation of {@link StellarisListener}, - * which can be extended to create a listener which only needs to handle a subset - * of the available methods. - */ -public class StellarisBaseListener implements StellarisListener { - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterFile(StellarisParser.FileContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitFile(StellarisParser.FileContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterMap(StellarisParser.MapContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitMap(StellarisParser.MapContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterPair(StellarisParser.PairContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitPair(StellarisParser.PairContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterVar(StellarisParser.VarContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitVar(StellarisParser.VarContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterArray(StellarisParser.ArrayContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitArray(StellarisParser.ArrayContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterValue(StellarisParser.ValueContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitValue(StellarisParser.ValueContext ctx) { } - - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void enterEveryRule(ParserRuleContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void exitEveryRule(ParserRuleContext ctx) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void visitTerminal(TerminalNode node) { } - /** - * {@inheritDoc} - * - *

The default implementation does nothing.

- */ - @Override public void visitErrorNode(ErrorNode node) { } -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisBaseVisitor.java b/src/main/java/net/turanar/stellaris/antlr/StellarisBaseVisitor.java deleted file mode 100644 index 7e0c952..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisBaseVisitor.java +++ /dev/null @@ -1,56 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; -import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor; - -/** - * This class provides an empty implementation of {@link StellarisVisitor}, - * which can be extended to create a visitor which only needs to handle a subset - * of the available methods. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public class StellarisBaseVisitor extends AbstractParseTreeVisitor implements StellarisVisitor { - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitFile(StellarisParser.FileContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitMap(StellarisParser.MapContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitPair(StellarisParser.PairContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitVar(StellarisParser.VarContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitArray(StellarisParser.ArrayContext ctx) { return visitChildren(ctx); } - /** - * {@inheritDoc} - * - *

The default implementation returns the result of calling - * {@link #visitChildren} on {@code ctx}.

- */ - @Override public T visitValue(StellarisParser.ValueContext ctx) { return visitChildren(ctx); } -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.java b/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.java deleted file mode 100644 index d6830e6..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.java +++ /dev/null @@ -1,149 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; - -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.LexerATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; -import org.antlr.v4.runtime.dfa.DFA; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class StellarisLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - T__0=1, T__1=2, BOOLEAN=3, VARIABLE=4, SPECIFIER=5, NUMBER=6, DATE=7, - BAREWORD=8, STRING=9, WS=10, LINE_COMMENT=11; - public static String[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static String[] modeNames = { - "DEFAULT_MODE" - }; - - public static final String[] ruleNames = { - "T__0", "T__1", "BOOLEAN", "VARIABLE", "SPECIFIER", "NUMBER", "DATE", - "BAREWORD", "STRING", "WS", "LINE_COMMENT" - }; - - private static final String[] _LITERAL_NAMES = { - null, "'{'", "'}'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, null, null, "BOOLEAN", "VARIABLE", "SPECIFIER", "NUMBER", "DATE", - "BAREWORD", "STRING", "WS", "LINE_COMMENT" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - - public StellarisLexer(CharStream input) { - super(input); - _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @Override - public String getGrammarFileName() { return "Stellaris.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public String[] getChannelNames() { return channelNames; } - - @Override - public String[] getModeNames() { return modeNames; } - - @Override - public ATN getATN() { return _ATN; } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\r\u0091\b\1\4\2\t"+ - "\2\4\3\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\4\t\t\t\4\n\t\n\4\13"+ - "\t\13\4\f\t\f\3\2\3\2\3\3\3\3\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4\3\4"+ - "\3\4\3\4\3\4\3\4\5\4,\n\4\3\5\3\5\3\5\7\5\61\n\5\f\5\16\5\64\13\5\3\6"+ - "\3\6\3\6\3\6\3\6\3\6\3\6\3\6\5\6>\n\6\3\7\5\7A\n\7\3\7\6\7D\n\7\r\7\16"+ - "\7E\3\7\3\7\5\7J\n\7\3\7\6\7M\n\7\r\7\16\7N\3\7\3\7\6\7S\n\7\r\7\16\7"+ - "T\3\7\5\7X\n\7\3\7\6\7[\n\7\r\7\16\7\\\5\7_\n\7\3\b\6\bb\n\b\r\b\16\b"+ - "c\3\b\3\b\6\bh\n\b\r\b\16\bi\3\b\3\b\6\bn\n\b\r\b\16\bo\3\t\3\t\7\tt\n"+ - "\t\f\t\16\tw\13\t\3\n\3\n\7\n{\n\n\f\n\16\n~\13\n\3\n\3\n\3\13\6\13\u0083"+ - "\n\13\r\13\16\13\u0084\3\13\3\13\3\f\3\f\7\f\u008b\n\f\f\f\16\f\u008e"+ - "\13\f\3\f\3\f\2\2\r\3\3\5\4\7\5\t\6\13\7\r\b\17\t\21\n\23\13\25\f\27\r"+ - "\3\2\n\4\2C\\c|\b\2\'\'/\60\62;C\\aac|\4\2>>@@\3\2\62;\b\2\'\'/\60\62"+ - ";B\\aac|\3\2$$\5\2\13\f\17\17\"\"\4\2\f\f\17\17\2\u00a8\2\3\3\2\2\2\2"+ - "\5\3\2\2\2\2\7\3\2\2\2\2\t\3\2\2\2\2\13\3\2\2\2\2\r\3\2\2\2\2\17\3\2\2"+ - "\2\2\21\3\2\2\2\2\23\3\2\2\2\2\25\3\2\2\2\2\27\3\2\2\2\3\31\3\2\2\2\5"+ - "\33\3\2\2\2\7+\3\2\2\2\t-\3\2\2\2\13=\3\2\2\2\r^\3\2\2\2\17a\3\2\2\2\21"+ - "q\3\2\2\2\23x\3\2\2\2\25\u0082\3\2\2\2\27\u0088\3\2\2\2\31\32\7}\2\2\32"+ - "\4\3\2\2\2\33\34\7\177\2\2\34\6\3\2\2\2\35\36\7{\2\2\36\37\7g\2\2\37,"+ - "\7u\2\2 !\7p\2\2!,\7q\2\2\"#\7v\2\2#$\7t\2\2$%\7w\2\2%,\7g\2\2&\'\7h\2"+ - "\2\'(\7c\2\2()\7n\2\2)*\7u\2\2*,\7g\2\2+\35\3\2\2\2+ \3\2\2\2+\"\3\2\2"+ - "\2+&\3\2\2\2,\b\3\2\2\2-.\7B\2\2.\62\t\2\2\2/\61\t\3\2\2\60/\3\2\2\2\61"+ - "\64\3\2\2\2\62\60\3\2\2\2\62\63\3\2\2\2\63\n\3\2\2\2\64\62\3\2\2\2\65"+ - ">\7?\2\2\66\67\7>\2\2\67>\7@\2\28>\t\4\2\29:\7>\2\2:>\7?\2\2;<\7@\2\2"+ - "<>\7?\2\2=\65\3\2\2\2=\66\3\2\2\2=8\3\2\2\2=9\3\2\2\2=;\3\2\2\2>\f\3\2"+ - "\2\2?A\7/\2\2@?\3\2\2\2@A\3\2\2\2AC\3\2\2\2BD\t\5\2\2CB\3\2\2\2DE\3\2"+ - "\2\2EC\3\2\2\2EF\3\2\2\2FG\3\2\2\2G_\7\'\2\2HJ\7/\2\2IH\3\2\2\2IJ\3\2"+ - "\2\2JL\3\2\2\2KM\t\5\2\2LK\3\2\2\2MN\3\2\2\2NL\3\2\2\2NO\3\2\2\2OP\3\2"+ - "\2\2PR\7\60\2\2QS\t\5\2\2RQ\3\2\2\2ST\3\2\2\2TR\3\2\2\2TU\3\2\2\2U_\3"+ - "\2\2\2VX\7/\2\2WV\3\2\2\2WX\3\2\2\2XZ\3\2\2\2Y[\t\5\2\2ZY\3\2\2\2[\\\3"+ - "\2\2\2\\Z\3\2\2\2\\]\3\2\2\2]_\3\2\2\2^@\3\2\2\2^I\3\2\2\2^W\3\2\2\2_"+ - "\16\3\2\2\2`b\t\5\2\2a`\3\2\2\2bc\3\2\2\2ca\3\2\2\2cd\3\2\2\2de\3\2\2"+ - "\2eg\7\60\2\2fh\t\5\2\2gf\3\2\2\2hi\3\2\2\2ig\3\2\2\2ij\3\2\2\2jk\3\2"+ - "\2\2km\7\60\2\2ln\t\5\2\2ml\3\2\2\2no\3\2\2\2om\3\2\2\2op\3\2\2\2p\20"+ - "\3\2\2\2qu\t\2\2\2rt\t\6\2\2sr\3\2\2\2tw\3\2\2\2us\3\2\2\2uv\3\2\2\2v"+ - "\22\3\2\2\2wu\3\2\2\2x|\7$\2\2y{\n\7\2\2zy\3\2\2\2{~\3\2\2\2|z\3\2\2\2"+ - "|}\3\2\2\2}\177\3\2\2\2~|\3\2\2\2\177\u0080\7$\2\2\u0080\24\3\2\2\2\u0081"+ - "\u0083\t\b\2\2\u0082\u0081\3\2\2\2\u0083\u0084\3\2\2\2\u0084\u0082\3\2"+ - "\2\2\u0084\u0085\3\2\2\2\u0085\u0086\3\2\2\2\u0086\u0087\b\13\2\2\u0087"+ - "\26\3\2\2\2\u0088\u008c\7%\2\2\u0089\u008b\n\t\2\2\u008a\u0089\3\2\2\2"+ - "\u008b\u008e\3\2\2\2\u008c\u008a\3\2\2\2\u008c\u008d\3\2\2\2\u008d\u008f"+ - "\3\2\2\2\u008e\u008c\3\2\2\2\u008f\u0090\b\f\3\2\u0090\30\3\2\2\2\25\2"+ - "+\62=@EINTW\\^ciou|\u0084\u008c\4\b\2\2\2\3\2"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.tokens b/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.tokens deleted file mode 100644 index efb21d6..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisLexer.tokens +++ /dev/null @@ -1,13 +0,0 @@ -T__0=1 -T__1=2 -BOOLEAN=3 -VARIABLE=4 -SPECIFIER=5 -NUMBER=6 -DATE=7 -BAREWORD=8 -STRING=9 -WS=10 -LINE_COMMENT=11 -'{'=1 -'}'=2 diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisListener.java b/src/main/java/net/turanar/stellaris/antlr/StellarisListener.java deleted file mode 100644 index 5ae1717..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisListener.java +++ /dev/null @@ -1,70 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; -import org.antlr.v4.runtime.tree.ParseTreeListener; - -/** - * This interface defines a complete listener for a parse tree produced by - * {@link StellarisParser}. - */ -public interface StellarisListener extends ParseTreeListener { - /** - * Enter a parse tree produced by {@link StellarisParser#file}. - * @param ctx the parse tree - */ - void enterFile(StellarisParser.FileContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#file}. - * @param ctx the parse tree - */ - void exitFile(StellarisParser.FileContext ctx); - /** - * Enter a parse tree produced by {@link StellarisParser#map}. - * @param ctx the parse tree - */ - void enterMap(StellarisParser.MapContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#map}. - * @param ctx the parse tree - */ - void exitMap(StellarisParser.MapContext ctx); - /** - * Enter a parse tree produced by {@link StellarisParser#pair}. - * @param ctx the parse tree - */ - void enterPair(StellarisParser.PairContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#pair}. - * @param ctx the parse tree - */ - void exitPair(StellarisParser.PairContext ctx); - /** - * Enter a parse tree produced by {@link StellarisParser#var}. - * @param ctx the parse tree - */ - void enterVar(StellarisParser.VarContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#var}. - * @param ctx the parse tree - */ - void exitVar(StellarisParser.VarContext ctx); - /** - * Enter a parse tree produced by {@link StellarisParser#array}. - * @param ctx the parse tree - */ - void enterArray(StellarisParser.ArrayContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#array}. - * @param ctx the parse tree - */ - void exitArray(StellarisParser.ArrayContext ctx); - /** - * Enter a parse tree produced by {@link StellarisParser#value}. - * @param ctx the parse tree - */ - void enterValue(StellarisParser.ValueContext ctx); - /** - * Exit a parse tree produced by {@link StellarisParser#value}. - * @param ctx the parse tree - */ - void exitValue(StellarisParser.ValueContext ctx); -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisParser.java b/src/main/java/net/turanar/stellaris/antlr/StellarisParser.java deleted file mode 100644 index be05447..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisParser.java +++ /dev/null @@ -1,529 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; - -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.ATN; -import org.antlr.v4.runtime.atn.ATNDeserializer; -import org.antlr.v4.runtime.atn.ParserATNSimulator; -import org.antlr.v4.runtime.atn.PredictionContextCache; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.tree.ParseTreeListener; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; -import org.antlr.v4.runtime.tree.TerminalNode; - -import java.util.List; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"}) -public class StellarisParser extends Parser { - static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - T__0=1, T__1=2, BOOLEAN=3, VARIABLE=4, SPECIFIER=5, NUMBER=6, DATE=7, - BAREWORD=8, STRING=9, WS=10, LINE_COMMENT=11; - public static final int - RULE_file = 0, RULE_map = 1, RULE_pair = 2, RULE_var = 3, RULE_array = 4, - RULE_value = 5; - public static final String[] ruleNames = { - "file", "map", "pair", "var", "array", "value" - }; - - private static final String[] _LITERAL_NAMES = { - null, "'{'", "'}'" - }; - private static final String[] _SYMBOLIC_NAMES = { - null, null, null, "BOOLEAN", "VARIABLE", "SPECIFIER", "NUMBER", "DATE", - "BAREWORD", "STRING", "WS", "LINE_COMMENT" - }; - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - @Override - public String getGrammarFileName() { return "Stellaris.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public ATN getATN() { return _ATN; } - - public StellarisParser(TokenStream input) { - super(input); - _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - public static class FileContext extends ParserRuleContext { - public List pair() { - return getRuleContexts(PairContext.class); - } - public PairContext pair(int i) { - return getRuleContext(PairContext.class,i); - } - public List var() { - return getRuleContexts(VarContext.class); - } - public VarContext var(int i) { - return getRuleContext(VarContext.class,i); - } - public FileContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_file; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterFile(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitFile(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitFile(this); - else return visitor.visitChildren(this); - } - } - - public final FileContext file() throws RecognitionException { - FileContext _localctx = new FileContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_file); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(16); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==VARIABLE || _la==BAREWORD) { - { - setState(14); - _errHandler.sync(this); - switch (_input.LA(1)) { - case BAREWORD: - { - setState(12); - pair(); - } - break; - case VARIABLE: - { - setState(13); - var(); - } - break; - default: - throw new NoViableAltException(this); - } - } - setState(18); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class MapContext extends ParserRuleContext { - public List pair() { - return getRuleContexts(PairContext.class); - } - public PairContext pair(int i) { - return getRuleContext(PairContext.class,i); - } - public MapContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_map; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterMap(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitMap(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitMap(this); - else return visitor.visitChildren(this); - } - } - - public final MapContext map() throws RecognitionException { - MapContext _localctx = new MapContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_map); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(19); - match(T__0); - setState(23); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==BAREWORD) { - { - { - setState(20); - pair(); - } - } - setState(25); - _errHandler.sync(this); - _la = _input.LA(1); - } - setState(26); - match(T__1); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class PairContext extends ParserRuleContext { - public String key() { return BAREWORD().getText(); } - public TerminalNode BAREWORD() { return getToken(StellarisParser.BAREWORD, 0); } - public TerminalNode SPECIFIER() { return getToken(StellarisParser.SPECIFIER, 0); } - public ValueContext value() { - return getRuleContext(ValueContext.class,0); - } - public PairContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_pair; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterPair(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitPair(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitPair(this); - else return visitor.visitChildren(this); - } - } - - public final PairContext pair() throws RecognitionException { - PairContext _localctx = new PairContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_pair); - try { - enterOuterAlt(_localctx, 1); - { - setState(28); - match(BAREWORD); - setState(29); - match(SPECIFIER); - setState(30); - value(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class VarContext extends ParserRuleContext { - public TerminalNode VARIABLE() { return getToken(StellarisParser.VARIABLE, 0); } - public TerminalNode SPECIFIER() { return getToken(StellarisParser.SPECIFIER, 0); } - public TerminalNode NUMBER() { return getToken(StellarisParser.NUMBER, 0); } - public VarContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_var; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterVar(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitVar(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitVar(this); - else return visitor.visitChildren(this); - } - } - - public final VarContext var() throws RecognitionException { - VarContext _localctx = new VarContext(_ctx, getState()); - enterRule(_localctx, 6, RULE_var); - try { - enterOuterAlt(_localctx, 1); - { - setState(32); - match(VARIABLE); - setState(33); - match(SPECIFIER); - setState(34); - match(NUMBER); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ArrayContext extends ParserRuleContext { - public List value() { - return getRuleContexts(ValueContext.class); - } - public ValueContext value(int i) { - return getRuleContext(ValueContext.class,i); - } - public ArrayContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_array; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterArray(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitArray(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitArray(this); - else return visitor.visitChildren(this); - } - } - - public final ArrayContext array() throws RecognitionException { - ArrayContext _localctx = new ArrayContext(_ctx, getState()); - enterRule(_localctx, 8, RULE_array); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(36); - match(T__0); - setState(38); - _errHandler.sync(this); - _la = _input.LA(1); - do { - { - { - setState(37); - value(); - } - } - setState(40); - _errHandler.sync(this); - _la = _input.LA(1); - } while ( (((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__0) | (1L << BOOLEAN) | (1L << VARIABLE) | (1L << NUMBER) | (1L << DATE) | (1L << BAREWORD) | (1L << STRING))) != 0) ); - setState(42); - match(T__1); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static class ValueContext extends ParserRuleContext { - public TerminalNode NUMBER() { return getToken(StellarisParser.NUMBER, 0); } - public TerminalNode BOOLEAN() { return getToken(StellarisParser.BOOLEAN, 0); } - public TerminalNode DATE() { return getToken(StellarisParser.DATE, 0); } - public TerminalNode STRING() { return getToken(StellarisParser.STRING, 0); } - public TerminalNode VARIABLE() { return getToken(StellarisParser.VARIABLE, 0); } - public TerminalNode BAREWORD() { return getToken(StellarisParser.BAREWORD, 0); } - public MapContext map() { - return getRuleContext(MapContext.class,0); - } - public ArrayContext array() { - return getRuleContext(ArrayContext.class,0); - } - public ValueContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_value; } - @Override - public void enterRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).enterValue(this); - } - @Override - public void exitRule(ParseTreeListener listener) { - if ( listener instanceof StellarisListener ) ((StellarisListener)listener).exitValue(this); - } - @Override - public T accept(ParseTreeVisitor visitor) { - if ( visitor instanceof StellarisVisitor ) return ((StellarisVisitor)visitor).visitValue(this); - else return visitor.visitChildren(this); - } - } - - public final ValueContext value() throws RecognitionException { - ValueContext _localctx = new ValueContext(_ctx, getState()); - enterRule(_localctx, 10, RULE_value); - try { - setState(52); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) { - case 1: - enterOuterAlt(_localctx, 1); - { - setState(44); - match(NUMBER); - } - break; - case 2: - enterOuterAlt(_localctx, 2); - { - setState(45); - match(BOOLEAN); - } - break; - case 3: - enterOuterAlt(_localctx, 3); - { - setState(46); - match(DATE); - } - break; - case 4: - enterOuterAlt(_localctx, 4); - { - setState(47); - match(STRING); - } - break; - case 5: - enterOuterAlt(_localctx, 5); - { - setState(48); - match(VARIABLE); - } - break; - case 6: - enterOuterAlt(_localctx, 6); - { - setState(49); - match(BAREWORD); - } - break; - case 7: - enterOuterAlt(_localctx, 7); - { - setState(50); - map(); - } - break; - case 8: - enterOuterAlt(_localctx, 8); - { - setState(51); - array(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static final String _serializedATN = - "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\r9\4\2\t\2\4\3\t"+ - "\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\3\2\3\2\7\2\21\n\2\f\2\16\2\24\13\2"+ - "\3\3\3\3\7\3\30\n\3\f\3\16\3\33\13\3\3\3\3\3\3\4\3\4\3\4\3\4\3\5\3\5\3"+ - "\5\3\5\3\6\3\6\6\6)\n\6\r\6\16\6*\3\6\3\6\3\7\3\7\3\7\3\7\3\7\3\7\3\7"+ - "\3\7\5\7\67\n\7\3\7\2\2\b\2\4\6\b\n\f\2\2\2=\2\22\3\2\2\2\4\25\3\2\2\2"+ - "\6\36\3\2\2\2\b\"\3\2\2\2\n&\3\2\2\2\f\66\3\2\2\2\16\21\5\6\4\2\17\21"+ - "\5\b\5\2\20\16\3\2\2\2\20\17\3\2\2\2\21\24\3\2\2\2\22\20\3\2\2\2\22\23"+ - "\3\2\2\2\23\3\3\2\2\2\24\22\3\2\2\2\25\31\7\3\2\2\26\30\5\6\4\2\27\26"+ - "\3\2\2\2\30\33\3\2\2\2\31\27\3\2\2\2\31\32\3\2\2\2\32\34\3\2\2\2\33\31"+ - "\3\2\2\2\34\35\7\4\2\2\35\5\3\2\2\2\36\37\7\n\2\2\37 \7\7\2\2 !\5\f\7"+ - "\2!\7\3\2\2\2\"#\7\6\2\2#$\7\7\2\2$%\7\b\2\2%\t\3\2\2\2&(\7\3\2\2\')\5"+ - "\f\7\2(\'\3\2\2\2)*\3\2\2\2*(\3\2\2\2*+\3\2\2\2+,\3\2\2\2,-\7\4\2\2-\13"+ - "\3\2\2\2.\67\7\b\2\2/\67\7\5\2\2\60\67\7\t\2\2\61\67\7\13\2\2\62\67\7"+ - "\6\2\2\63\67\7\n\2\2\64\67\5\4\3\2\65\67\5\n\6\2\66.\3\2\2\2\66/\3\2\2"+ - "\2\66\60\3\2\2\2\66\61\3\2\2\2\66\62\3\2\2\2\66\63\3\2\2\2\66\64\3\2\2"+ - "\2\66\65\3\2\2\2\67\r\3\2\2\2\7\20\22\31*\66"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisParserFactory.java b/src/main/java/net/turanar/stellaris/antlr/StellarisParserFactory.java index 390fd69..8a230d9 100644 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisParserFactory.java +++ b/src/main/java/net/turanar/stellaris/antlr/StellarisParserFactory.java @@ -8,6 +8,7 @@ public class StellarisParserFactory { public StellarisParser getParser(Path path) { StellarisParser retval = new StellarisParser(new StellarisTokenStream(path)); + retval.addErrorListener(ThrowingErrorListener.INSTANCE); return retval; } } diff --git a/src/main/java/net/turanar/stellaris/antlr/StellarisVisitor.java b/src/main/java/net/turanar/stellaris/antlr/StellarisVisitor.java deleted file mode 100644 index f6487fc..0000000 --- a/src/main/java/net/turanar/stellaris/antlr/StellarisVisitor.java +++ /dev/null @@ -1,49 +0,0 @@ -// Generated from D:/workspaces/stellaris\Stellaris.g4 by ANTLR 4.7 -package net.turanar.stellaris.antlr; -import org.antlr.v4.runtime.tree.ParseTreeVisitor; - -/** - * This interface defines a complete generic visitor for a parse tree produced - * by {@link StellarisParser}. - * - * @param The return type of the visit operation. Use {@link Void} for - * operations with no return type. - */ -public interface StellarisVisitor extends ParseTreeVisitor { - /** - * Visit a parse tree produced by {@link StellarisParser#file}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitFile(StellarisParser.FileContext ctx); - /** - * Visit a parse tree produced by {@link StellarisParser#map}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitMap(StellarisParser.MapContext ctx); - /** - * Visit a parse tree produced by {@link StellarisParser#pair}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitPair(StellarisParser.PairContext ctx); - /** - * Visit a parse tree produced by {@link StellarisParser#var}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitVar(StellarisParser.VarContext ctx); - /** - * Visit a parse tree produced by {@link StellarisParser#array}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitArray(StellarisParser.ArrayContext ctx); - /** - * Visit a parse tree produced by {@link StellarisParser#value}. - * @param ctx the parse tree - * @return the visitor result - */ - T visitValue(StellarisParser.ValueContext ctx); -} \ No newline at end of file diff --git a/src/main/java/net/turanar/stellaris/antlr/ThrowingErrorListener.java b/src/main/java/net/turanar/stellaris/antlr/ThrowingErrorListener.java index ffc7342..7d8bd06 100644 --- a/src/main/java/net/turanar/stellaris/antlr/ThrowingErrorListener.java +++ b/src/main/java/net/turanar/stellaris/antlr/ThrowingErrorListener.java @@ -12,6 +12,6 @@ public class ThrowingErrorListener extends BaseErrorListener { @Override public void syntaxError(Recognizer recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) throws ParseCancellationException { - throw new ParseCancellationException("line " + line + ":" + charPositionInLine + " " + msg); + throw new ParseCancellationException("file " + recognizer.getInputStream().getSourceName() + " line " + line + ":" + charPositionInLine + " " + msg); } -} \ No newline at end of file +} diff --git a/src/main/java/net/turanar/stellaris/domain/Category.java b/src/main/java/net/turanar/stellaris/domain/Category.java index 7b2802a..732cd33 100644 --- a/src/main/java/net/turanar/stellaris/domain/Category.java +++ b/src/main/java/net/turanar/stellaris/domain/Category.java @@ -6,7 +6,7 @@ public enum Category { // physics Particles, @SerializedName("Field Manipulation") Field_Manipulation, Computing, // society - Biology, @SerializedName("Military Theory") Military_Theory, @SerializedName("New Worlds") New_Worlds, Statecraft, Psionics, + Biology, @SerializedName("Military Theory") Military_Theory, @SerializedName("New Worlds") New_Worlds, Statecraft, Psionics, Archaeostudies, // engineering Industry, Materials, Propulsion, Voidcraft; diff --git a/src/main/java/net/turanar/stellaris/domain/Modifier.java b/src/main/java/net/turanar/stellaris/domain/Modifier.java index 87809b1..f596f53 100644 --- a/src/main/java/net/turanar/stellaris/domain/Modifier.java +++ b/src/main/java/net/turanar/stellaris/domain/Modifier.java @@ -16,6 +16,6 @@ public class Modifier { @Override public String toString() { - return type != null && pair != null ? type.parse(pair) : (pair != null ? pair.getText() : ""); + return type != null && pair != null ? type.parse(pair) : (pair != null ? pair.getText() : "??"); } -} \ No newline at end of file +} diff --git a/src/main/java/net/turanar/stellaris/domain/ModifierType.java b/src/main/java/net/turanar/stellaris/domain/ModifierType.java index 56fcb9f..b24b3b6 100644 --- a/src/main/java/net/turanar/stellaris/domain/ModifierType.java +++ b/src/main/java/net/turanar/stellaris/domain/ModifierType.java @@ -31,6 +31,46 @@ public enum ModifierType { owns_any_bypass((p) -> f("Controls a system with a %s", i18n("bypass_" + gs(p).toLowerCase()))), has_seen_any_bypass((p) -> f("Has encountered a %s", i18n("bypass_" + gs(p).toLowerCase()))), + // FIXME: proper parsing of the following + count_archaeological_site((p)->{ + String type = ""; + String count = ""; + for(PairContext prop : p.value().map().pair()) { + if(key(prop).equals("type")) { + type = i18n(gs(prop)); + } else if (key(prop).equals("value")) { + count = op(prop) + " " + gs(prop); + } + } + return "Number of " + type + " is " + count; + }), + exists("Exists"), + federation("Is Federation"), + has_federation("Has %s federation"), + has_first_contact_dlc("Has DLC First Contact"), + has_nemesis("Has Nemesis"), + has_origin("Has %s federation"), + has_paragon_dlc("Has DLC galactic paragons"), + has_trait_in_council("Has trait %s in council"), + is_eager_explorer_empire("Is eager explorer empire"), + is_same_value("IS SAME VALUE"), + is_specialist_subject_type("Is specialist subject"), + mid_game_years_passed("In Mid-game"), + num_buildings("Has %s buildings"), + count_owned_pop("Owns %s pops"), + harvested_leviathan_dna("Has harvested leviathan DNA"), + has_lithoids("Has Lithoids"), + has_overlord_dlc("Has DLC Overlord"), + has_plantoids("Has Plantoids"), + has_relic("Has Relic"), + has_space_monster_dlc("Has DLC Space Monsters"), + is_catalytic_empire("Is Catalytic Empire"), + is_galactic_community_member("Is member of the galactic community"), + is_homicidal("Is homicidal"), + is_lithoid_empire("Is lithoid empire"), + // until here + + is_xenophile(DefaultParser.SCRIPTED), is_pacifist(DefaultParser.SCRIPTED), is_materialist(DefaultParser.SCRIPTED), @@ -103,9 +143,9 @@ public enum ModifierType { String type = ""; String count = ""; for(PairContext prop : p.value().map().pair()) { - if(prop.key().equals("type")) { + if(key(prop).equals("type")) { type = gs(prop); - } else if (prop.key().equals("amount")) { + } else if (key(prop).equals("amount")) { count = op(prop) + " " + gs(prop); } } @@ -116,9 +156,9 @@ public enum ModifierType { String retval = "Number of %s is %s %s"; String size = null, operator = null, count = null; for(PairContext prop : p.value().map().pair()) { - if(prop.key().equals("starbase_size")) { + if(key(prop).equals("starbase_size")) { size = i18n(gs(prop)); - } else if (prop.key().equals("count")) { + } else if (key(prop).equals("count")) { operator = op(prop); count = gs(prop); } @@ -130,9 +170,9 @@ public enum ModifierType { String type = ""; String count = ""; for(PairContext prop : p.value().map().pair()) { - if(prop.key().equals("type")) { + if(key(prop).equals("type")) { type = i18n(gs(prop)); - } else if (prop.key().equals("value")) { + } else if (key(prop).equals("value")) { count = op(prop) + " " + gs(prop); } } @@ -143,12 +183,12 @@ public enum ModifierType { String limits = ""; String count = ""; for(PairContext prop : p.value().map().pair()) { - if(prop.key().equals("limit")) { + if(key(prop).equals("limit")) { for(PairContext l : prop.value().map().pair()) { Modifier m = visitCondition(l); limits += "\n" + LS + m.toString(); } - } else if(prop.key().equals("count")) { + } else if(key(prop).equals("count")) { count = op(prop) + " " + gs(prop); } } @@ -202,7 +242,7 @@ private static enum DefaultParser { return retval; }), SCRIPTED((format, p) -> { - PairContext q = GLOBAL_TRIGGERS.get(p.key()); + PairContext q = GLOBAL_TRIGGERS.get(key(p)); boolean value = gs(p).equals("yes"); List conditions = new ArrayList<>(); @@ -270,7 +310,7 @@ public static ModifierType value(String name) { public static Modifier visitCondition(PairContext pair) { Modifier retval = new Modifier(); - retval.type = ModifierType.value(pair.key()); + retval.type = ModifierType.value(key(pair)); retval.pair = pair; return retval; } diff --git a/src/main/java/net/turanar/stellaris/parser/VanillaConfigParser.java b/src/main/java/net/turanar/stellaris/parser/VanillaConfigParser.java index dc23208..8b8f551 100644 --- a/src/main/java/net/turanar/stellaris/parser/VanillaConfigParser.java +++ b/src/main/java/net/turanar/stellaris/parser/VanillaConfigParser.java @@ -30,10 +30,15 @@ public class VanillaConfigParser extends AbstractConfigParser { public void parseTechnolgies(String folder) throws IOException { parse(folder + "/common/technology","txt", f -> { - factory.getParser(f).file().pair().forEach(p -> { - Technology t = techVisitor.visitPair(p); - technologies.put(t.key, t); - }); + try { + factory.getParser(f).file().pair().forEach(p -> { + Technology t = techVisitor.visitPair(p); + technologies.put(t.key, t); + }); + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + f.toString(), e); + } }); } @@ -41,9 +46,14 @@ public void parseGamesObjets(String folder) throws IOException { Arrays.stream(GameObject.values()).forEach(type -> { try { parse(folder + "/" + type.folder, "txt", path -> { - if (path.getFileName().toString().startsWith("README")) return; - if (!path.getFileName().toString().endsWith(type.filter)) return; - unlockVisitor.visitFile(type, factory.getParser(path).file()); + try { + if (path.getFileName().toString().contains("README")) return; + if (!path.getFileName().toString().endsWith(type.filter)) return; + unlockVisitor.visitFile(type, factory.getParser(path).file()); + } + catch (RuntimeException e) { + throw new RuntimeException("Error parsing file " + path.toString(), e); + } }); } catch (IOException e) {e.printStackTrace();} }); diff --git a/src/main/java/net/turanar/stellaris/visitor/ModifierVisitor.java b/src/main/java/net/turanar/stellaris/visitor/ModifierVisitor.java index 166c1ad..ae65bea 100644 --- a/src/main/java/net/turanar/stellaris/visitor/ModifierVisitor.java +++ b/src/main/java/net/turanar/stellaris/visitor/ModifierVisitor.java @@ -11,6 +11,7 @@ import java.util.List; import static net.turanar.stellaris.Global.gs; +import static net.turanar.stellaris.Global.key; @Component public class ModifierVisitor { @@ -21,7 +22,7 @@ public ArrayList visitPotential(StellarisParser.PairContext ctx) { ctx.value().map().pair().forEach(p -> { try { Modifier m = new Modifier(); - m.type = ModifierType.valueOf(p.key()); + m.type = ModifierType.valueOf(key(p)); m.pair = p; retval.add(m); } catch (IllegalArgumentException e) { @@ -34,7 +35,7 @@ public ArrayList visitPotential(StellarisParser.PairContext ctx) { public List visitPair(Technology tech, StellarisParser.PairContext ctx) { List retval = new ArrayList(); ctx.value().map().pair().forEach(p -> { - switch(p.key()) { + switch(key(p)) { case "factor": tech.base_factor = Float.valueOf(gs(p)); break; case "modifier": WeightModifier m = visitModifier(p); @@ -50,11 +51,15 @@ public WeightModifier visitModifier(StellarisParser.PairContext ctx) { WeightModifier retval = new WeightModifier(); ctx.value().map().pair().forEach(p -> { try { - switch(p.key()) { - case "factor": retval.factor = Float.valueOf(gs(p)); break; + switch(key(p)) { + case "factor": + String _gs = gs(p); + if (_gs != null) + retval.factor = Float.valueOf(_gs); + break; case "add": retval.add = Integer.valueOf(gs(p)); break; default: - retval.type = ModifierType.valueOf(p.key()); + retval.type = ModifierType.valueOf(key(p)); retval.pair = p; } } catch (IllegalArgumentException e) { diff --git a/src/main/java/net/turanar/stellaris/visitor/TechnologyVisitor.java b/src/main/java/net/turanar/stellaris/visitor/TechnologyVisitor.java index 5bea946..64d2407 100644 --- a/src/main/java/net/turanar/stellaris/visitor/TechnologyVisitor.java +++ b/src/main/java/net/turanar/stellaris/visitor/TechnologyVisitor.java @@ -20,16 +20,16 @@ public class TechnologyVisitor { private void visitFeatureUnlocks(Technology retval, StellarisParser.ValueContext val) { if(val.map() == null) return; for(StellarisParser.PairContext mod : val.map().pair()) { - if(mod.key().equals("BIOLOGICAL_species_trait_points_add")) continue; - if(mod.key().equals("show_only_custom_tooltip")) continue; - if(mod.key().equals("description") || mod.key().equals("custom_tooltip")) { + if(key(mod).equals("BIOLOGICAL_species_trait_points_add")) continue; + if(key(mod).equals("show_only_custom_tooltip")) continue; + if(key(mod).equals("description") || key(mod).equals("custom_tooltip")) { String key = mod.value().BAREWORD().getText(); String effect = i18n(key); if(key.equals(effect)) effect = i18n("mod_" + key.toLowerCase()); effect = effect.replace("$POINTS|0=+$","+1"); retval.feature_unlocks.add(effect); - } else if (!mod.key().startsWith("description")){ - String key = mod.key().toLowerCase(); + } else if (!key(mod).startsWith("description")){ + String key = key(mod).toLowerCase(); if(key.equals("science_ship_survey_speed")) key = "mod_ship_science_survey_speed"; if(key.equals("ship_anomaly_generation_chance_mult")) key = "mod_ship_anomaly_generation_chance"; @@ -66,12 +66,12 @@ private void visitFeatureUnlocks(Technology retval, StellarisParser.ValueContext public Technology visitPair(StellarisParser.PairContext ctx) { Technology retval = new Technology(); - retval.key = ctx.key(); + retval.key = key(ctx); retval.name = i18n(retval.key); retval.description = i18n(retval.key + "_desc"); for(StellarisParser.PairContext pair : ctx.value().map().pair()) { - switch (pair.key()) { + switch (key(pair)) { case "cost": retval.cost = Integer.valueOf(gs(pair)); break; case "tier": diff --git a/src/main/java/net/turanar/stellaris/visitor/UnlockVisitor.java b/src/main/java/net/turanar/stellaris/visitor/UnlockVisitor.java index eacd539..0fc6a32 100644 --- a/src/main/java/net/turanar/stellaris/visitor/UnlockVisitor.java +++ b/src/main/java/net/turanar/stellaris/visitor/UnlockVisitor.java @@ -27,38 +27,38 @@ public String clean(String prop) { } public Technology visitPair(GameObject type, StellarisParser.PairContext pair) { - String key = pair.key(); + String tkey = key(pair); if(type == GameObject.STARBASE) { - //System.out.println(key); + //System.out.println(tkey); } Technology tech = null; if(pair.value().map() == null) return null; for(StellarisParser.PairContext props : pair.value().map().pair()) { - if(props.key().equals("prerequisites")) { + if(key(props).equals("prerequisites")) { if(props.value().array() == null) continue; for(StellarisParser.ValueContext ctx : props.value().array().value()) { tech = technologies.get(gs(ctx)); } - } else if (props.key().equals("key") || props.key().equals("name")) { - key = gs(props.value()); - } else if (props.key().equals("show_in_tech")) { + } else if (key(props).equals("key") || key(props).equals("name")) { + tkey = gs(props.value()); + } else if (key(props).equals("show_in_tech")) { tech = technologies.get(gs(props.value())); - } else if (props.key().equals("option") && type == GameObject.POLICY) { - key = null; + } else if (key(props).equals("option") && type == GameObject.POLICY) { + tkey = null; tech = visitPair(type, props); } } - if(key == null) return tech; + if(tkey == null) return tech; - if(i18n(key).equals(key)) { - key = i18n(type.locale_prefix + key); + if(i18n(tkey).equals(tkey)) { + tkey = i18n(type.locale_prefix + tkey); } else { - key = i18n(key); + tkey = i18n(tkey); } - if(tech != null) tech.feature_unlocks.add(clean("" + type.label + ": " + key)); + if(tech != null) tech.feature_unlocks.add(clean("" + type.label + ": " + tkey)); return tech; } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index af299d6..a02fb4f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,2 @@ spring.gson.pretty-printing=true -spring.main.banner-mode=off \ No newline at end of file +spring.main.banner-mode=off