├── .gitattributes
├── .gitignore
├── DEVELOPMENT.md
├── LICENSE
├── README.md
├── build_plugin.sh
├── game.project
├── lua-preprocessor
├── ext.manifest
├── plugins
│ └── share
│ │ └── pluginLuaPreprocessor.jar
├── pluginsrc
│ └── com
│ │ └── defold
│ │ └── extension
│ │ └── pipeline
│ │ ├── LuaPreprocessor.java
│ │ └── antlr
│ │ ├── LuaPreProc.g4
│ │ ├── LuaPreProcBaseListener.java
│ │ ├── LuaPreProcLexer.g4
│ │ ├── LuaPreProcLexer.java
│ │ ├── LuaPreProcListener.java
│ │ └── LuaPreProcParser.java
└── src
│ └── plugin.cpp
└── main
├── default.font
├── empty.lua
├── main.collection
├── main.script
└── test.lua
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Defold Protocol Buffer Text Files (https://github.com/github/linguist/issues/5091)
2 | *.animationset linguist-language=JSON5
3 | *.atlas linguist-language=JSON5
4 | *.camera linguist-language=JSON5
5 | *.collection linguist-language=JSON5
6 | *.collectionfactory linguist-language=JSON5
7 | *.collectionproxy linguist-language=JSON5
8 | *.collisionobject linguist-language=JSON5
9 | *.cubemap linguist-language=JSON5
10 | *.display_profiles linguist-language=JSON5
11 | *.factory linguist-language=JSON5
12 | *.font linguist-language=JSON5
13 | *.gamepads linguist-language=JSON5
14 | *.go linguist-language=JSON5
15 | *.gui linguist-language=JSON5
16 | *.input_binding linguist-language=JSON5
17 | *.label linguist-language=JSON5
18 | *.material linguist-language=JSON5
19 | *.mesh linguist-language=JSON5
20 | *.model linguist-language=JSON5
21 | *.particlefx linguist-language=JSON5
22 | *.render linguist-language=JSON5
23 | *.sound linguist-language=JSON5
24 | *.sprite linguist-language=JSON5
25 | *.spinemodel linguist-language=JSON5
26 | *.spinescene linguist-language=JSON5
27 | *.texture_profiles linguist-language=JSON5
28 | *.tilemap linguist-language=JSON5
29 | *.tilesource linguist-language=JSON5
30 |
31 | # Defold JSON Files
32 | *.buffer linguist-language=JSON
33 |
34 | # Defold GLSL Shaders
35 | *.fp linguist-language=GLSL
36 | *.vp linguist-language=GLSL
37 |
38 | # Defold Lua Files
39 | *.editor_script linguist-language=Lua
40 | *.render_script linguist-language=Lua
41 | *.script linguist-language=Lua
42 | *.gui_script linguist-language=Lua
43 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /.internal
2 | /build
3 | .externalToolBuilders
4 | .DS_Store
5 | Thumbs.db
6 | .lock-wscript
7 | *.pyc
8 | .project
9 | .cproject
10 | builtins
11 | _site
12 | bob.jar
13 | *.interp
14 | *.tokens
15 | *.class
16 |
--------------------------------------------------------------------------------
/DEVELOPMENT.md:
--------------------------------------------------------------------------------
1 | # Notes for the extension development
2 |
3 | This extension uses [ANTLR](https://www.antlr.org).
4 |
5 | All `*.java` files in `lua-preprocessor/pluginsrc/com/dynamo/bob/pipeline/antlr` are generated from the gramma files `*.g4` in the same folder using ANTLR.
6 |
7 | 0. Make sure you have Java installed
8 | 1. Download [https://www.antlr.org/download/antlr-4.9.3-complete.jar](https://www.antlr.org/download/antlr-4.9.3-complete.jar)
9 | 2. Run:
10 |
11 | ```
12 | jar_path="PATH_TO_antlr-4.9.3-complete.jar"
13 |
14 | export CLASSPATH="".:${jar_path}:$CLASSPATH""
15 | alias antlr4='java -Xmx500M -cp "${jar_path}:$CLASSPATH" org.antlr.v4.Tool'
16 | alias grun='java -Xmx500M -cp "${jar_path}:$CLASSPATH" org.antlr.v4.gui.TestRig'
17 | ```
18 |
19 | 3. For `*.java` classes generation use:
20 |
21 | ```
22 | antlr4 LuaPreProc*.g4 -package com.dynamo.bob.pipeline.antlr
23 | ```
24 |
25 | 4. For testing grammar use:
26 |
27 | ```
28 | antlr4 LuaPreProc*.g4 && javac LuaPre*.java && grun LuaPreProc codefile -tree
29 | ```
30 |
31 | * Paste your code
32 | * Press `Enter`
33 | * Press `Cmd+D`
34 |
35 | Use online sandbox to make testing process easier: [http://lab.antlr.org](http://lab.antlr.org)
36 |
37 | ---
38 | Use `build_plugin.sh` for the final build of the plugin `jar` file.
39 |
40 | Have fun! )
41 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Defold
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # extension-lua-preprocessor
2 | A small and simple Lua preprocessor for Defold. This extension hooks into the [Lua builder plugin system in bob](https://github.com/defold/defold/blob/cb60610ba7c4683267a2abd509340507105ef3bb/com.dynamo.cr/com.dynamo.cr.bob/src/com/dynamo/bob/pipeline/LuaBuilder.java#L94).
3 |
4 | ## Requirements
5 |
6 | Defold version 1.4.2 or higher
7 |
8 | ## Installation
9 | To use this library in your Defold project, add the needed version URL to your `game.project` dependencies from [Releases](https://github.com/defold/extension-lua-preprocessor/releases)
10 |
11 |
12 |
13 | ## Example
14 |
15 | ```lua
16 | -- Use one of the following keywords: RELEASE, DEBUG or HEADLESS
17 | --#IF DEBUG
18 | local lives_num = 999
19 | --#ELSE
20 | local lives_num = 3
21 | --#ENDIF
22 | ```
23 | ---
24 | If you have any issues, questions or suggestions please [create an issue](https://github.com/defold/extension-lua-preprocessor/issues)
25 |
--------------------------------------------------------------------------------
/build_plugin.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | rm -f lua-preprocessor/plugins/share/pluginLuaPreprocessor.jar
4 |
5 | java -jar bob.jar --debug --platform=x86_64-macos --verbose --build-artifacts=plugins clean build
6 |
7 | cp build/x86_64-osx/lua-preprocessor/pluginLuaPreprocessor.jar lua-preprocessor/plugins/share
--------------------------------------------------------------------------------
/game.project:
--------------------------------------------------------------------------------
1 | [bootstrap]
2 | main_collection = /main/main.collectionc
3 |
4 | [script]
5 | shared_state = 1
6 |
7 | [display]
8 | width = 960
9 | height = 640
10 |
11 | [android]
12 | input_method = HiddenInputField
13 |
14 | [project]
15 | title = lua-preprocessor
16 |
17 | [library]
18 | include_dirs = lua-preprocessor
19 |
20 | [input]
21 | game_binding = /builtins/input/all.input_bindingc
22 |
23 |
--------------------------------------------------------------------------------
/lua-preprocessor/ext.manifest:
--------------------------------------------------------------------------------
1 | name: LuaPreprocessor
--------------------------------------------------------------------------------
/lua-preprocessor/plugins/share/pluginLuaPreprocessor.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/defold/extension-lua-preprocessor/2c48bbf3ae3350609d243ed58a8eb047240f14d3/lua-preprocessor/plugins/share/pluginLuaPreprocessor.jar
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/LuaPreprocessor.java:
--------------------------------------------------------------------------------
1 | package com.defold.extension.pipeline;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.OutputStream;
7 | import java.util.List;
8 | import java.util.ArrayList;
9 | import java.util.logging.Logger;
10 | import java.nio.file.Files;
11 | import java.nio.file.StandardCopyOption;
12 |
13 | import com.dynamo.bob.Bob;
14 | import com.dynamo.bob.Platform;
15 | import com.dynamo.bob.util.TimeProfiler;
16 |
17 | import org.antlr.v4.runtime.BaseErrorListener;
18 | import org.antlr.v4.runtime.CommonTokenStream;
19 | import org.antlr.v4.runtime.tree.ParseTreeWalker;
20 | import org.antlr.v4.runtime.CharStreams;
21 | import org.antlr.v4.runtime.Token;
22 | import org.antlr.v4.runtime.Recognizer;
23 | import org.antlr.v4.runtime.RecognitionException;
24 |
25 | import com.dynamo.bob.pipeline.antlr.LuaPreProcParser;
26 | import com.dynamo.bob.pipeline.antlr.LuaPreProcLexer;
27 | import com.dynamo.bob.pipeline.antlr.LuaPreProcListener;
28 | import com.dynamo.bob.pipeline.antlr.LuaPreProcBaseListener;
29 |
30 | public class LuaPreprocessor implements ILuaPreprocessor {
31 | private static Logger logger = Logger.getLogger(LuaPreprocessor.class.getName());
32 |
33 | private static StringBuffer parsedBuffer = null;
34 | private static Boolean hasChanges;
35 | private static String errorMessage;
36 | private static int currentBuildVariant;
37 |
38 | // replace the token with an empty string
39 | private static void removeToken(Token token) {
40 | LuaPreprocessor.hasChanges = true;
41 | int from = token.getStartIndex();
42 | logger.fine("removeToken " + token.getText());
43 | int to = from + token.getText().length() - 1;
44 | for(int i = from; i <= to; i++) {
45 | parsedBuffer.replace(i, i + 1, " ");
46 | }
47 | }
48 |
49 | private static void setBuildVariant(String variant) {
50 | switch (variant)
51 | {
52 | case Bob.VARIANT_DEBUG:
53 | currentBuildVariant = LuaPreProcParser.PP_PARAM_DEBUG;
54 | break;
55 | case Bob.VARIANT_RELEASE:
56 | currentBuildVariant = LuaPreProcParser.PP_PARAM_RELEASE;
57 | break;
58 | case Bob.VARIANT_HEADLESS:
59 | currentBuildVariant = LuaPreProcParser.PP_PARAM_HEADLESS;
60 | break;
61 | default:
62 | throw new RuntimeException(String.format("Invalid variant %s", variant));
63 | }
64 | }
65 |
66 | @Override
67 | public String preprocess(String input, String filePath, String buildVariant) throws Exception {
68 | TimeProfiler.start("LuaPreprocessor");
69 | setBuildVariant(buildVariant);
70 | LuaPreprocessor.hasChanges = false;
71 | LuaPreprocessor.errorMessage = null;
72 | parsedBuffer = new StringBuffer(input);
73 | LuaPreProcLexer lexer = new LuaPreProcLexer(CharStreams.fromString(input));
74 | CommonTokenStream tokenStream = new CommonTokenStream(lexer);
75 | LuaPreProcParser parser = new LuaPreProcParser(tokenStream);
76 | parser.addErrorListener(new BaseErrorListener() {
77 | @Override
78 | public void syntaxError(Recognizer, ?> recognizer, Object offendingSymbol, int line,
79 | int charPositionInLine, String msg, RecognitionException e) {
80 | if (LuaPreprocessor.errorMessage == null) {
81 | LuaPreprocessor.errorMessage = String.format("%s:%d %s", filePath, line, msg);
82 | }
83 | }
84 | });
85 |
86 | ParseTreeWalker walker = new ParseTreeWalker();
87 | LuaPreprocessor.LuaPreprocessorListener listener = new LuaPreprocessor.LuaPreprocessorListener();
88 | walker.walk(listener, parser.codefile());
89 |
90 | TimeProfiler.stop();
91 |
92 | if (LuaPreprocessor.errorMessage != null) {
93 | throw new Exception(LuaPreprocessor.errorMessage);
94 | }
95 |
96 | if (LuaPreprocessor.hasChanges) {
97 | logger.fine("LuaPreprocessor: apply " + buildVariant);
98 | return parsedBuffer.toString();
99 | }
100 |
101 | return input;
102 | }
103 |
104 | private class LuaPreprocessorListener extends LuaPreProcBaseListener {
105 |
106 | private boolean isInRemovingMode = false;
107 |
108 | @Override
109 | public void enterIfdef(LuaPreProcParser.IfdefContext ctx) {
110 | int currentToken = ctx.param().getStart().getType();
111 | if (currentToken != currentBuildVariant) {
112 | isInRemovingMode = true;
113 | }
114 | }
115 |
116 | @Override
117 | public void enterElsedef(LuaPreProcParser.ElsedefContext ctx) {
118 | isInRemovingMode = !isInRemovingMode;
119 | }
120 |
121 | @Override
122 | public void enterEndif(LuaPreProcParser.EndifContext ctx) {
123 | isInRemovingMode = false;
124 | }
125 |
126 | @Override
127 | public void enterLine(LuaPreProcParser.LineContext ctx) {
128 | if (isInRemovingMode) {
129 | LuaPreprocessor.removeToken(ctx.TEXT().getSymbol());
130 | }
131 | }
132 |
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProc.g4:
--------------------------------------------------------------------------------
1 | grammar LuaPreProc ;
2 | options {
3 | tokenVocab = LuaPreProcLexer;
4 | }
5 |
6 | codefile: (preproc | line)* EOF ;
7 |
8 | preproc : ifdef | elsedef | endif ;
9 | param : PP_PARAM_RELEASE | PP_PARAM_DEBUG | PP_PARAM_HEADLESS ;
10 | ifdef : PP_IFDEF param PP_EOL ;
11 | elsedef : PP_ELSE PP_EOL ;
12 | endif : PP_ENDIF PP_EOL? ;
13 |
14 | line : TEXT (PP_EOL | EOL | EOF?) ;
15 |
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProcBaseListener.java:
--------------------------------------------------------------------------------
1 | // Generated from LuaPreProc.g4 by ANTLR 4.9.1
2 | package com.dynamo.bob.pipeline.antlr;
3 |
4 | import org.antlr.v4.runtime.ParserRuleContext;
5 | import org.antlr.v4.runtime.tree.ErrorNode;
6 | import org.antlr.v4.runtime.tree.TerminalNode;
7 |
8 | /**
9 | * This class provides an empty implementation of {@link LuaPreProcListener},
10 | * which can be extended to create a listener which only needs to handle a subset
11 | * of the available methods.
12 | */
13 | public class LuaPreProcBaseListener implements LuaPreProcListener {
14 | /**
15 | * {@inheritDoc}
16 | *
17 | *
The default implementation does nothing.
18 | */
19 | @Override public void enterCodefile(LuaPreProcParser.CodefileContext ctx) { }
20 | /**
21 | * {@inheritDoc}
22 | *
23 | * The default implementation does nothing.
24 | */
25 | @Override public void exitCodefile(LuaPreProcParser.CodefileContext ctx) { }
26 | /**
27 | * {@inheritDoc}
28 | *
29 | * The default implementation does nothing.
30 | */
31 | @Override public void enterPreproc(LuaPreProcParser.PreprocContext ctx) { }
32 | /**
33 | * {@inheritDoc}
34 | *
35 | * The default implementation does nothing.
36 | */
37 | @Override public void exitPreproc(LuaPreProcParser.PreprocContext ctx) { }
38 | /**
39 | * {@inheritDoc}
40 | *
41 | * The default implementation does nothing.
42 | */
43 | @Override public void enterParam(LuaPreProcParser.ParamContext ctx) { }
44 | /**
45 | * {@inheritDoc}
46 | *
47 | * The default implementation does nothing.
48 | */
49 | @Override public void exitParam(LuaPreProcParser.ParamContext ctx) { }
50 | /**
51 | * {@inheritDoc}
52 | *
53 | * The default implementation does nothing.
54 | */
55 | @Override public void enterIfdef(LuaPreProcParser.IfdefContext ctx) { }
56 | /**
57 | * {@inheritDoc}
58 | *
59 | * The default implementation does nothing.
60 | */
61 | @Override public void exitIfdef(LuaPreProcParser.IfdefContext ctx) { }
62 | /**
63 | * {@inheritDoc}
64 | *
65 | * The default implementation does nothing.
66 | */
67 | @Override public void enterElsedef(LuaPreProcParser.ElsedefContext ctx) { }
68 | /**
69 | * {@inheritDoc}
70 | *
71 | * The default implementation does nothing.
72 | */
73 | @Override public void exitElsedef(LuaPreProcParser.ElsedefContext ctx) { }
74 | /**
75 | * {@inheritDoc}
76 | *
77 | * The default implementation does nothing.
78 | */
79 | @Override public void enterEndif(LuaPreProcParser.EndifContext ctx) { }
80 | /**
81 | * {@inheritDoc}
82 | *
83 | * The default implementation does nothing.
84 | */
85 | @Override public void exitEndif(LuaPreProcParser.EndifContext ctx) { }
86 | /**
87 | * {@inheritDoc}
88 | *
89 | * The default implementation does nothing.
90 | */
91 | @Override public void enterLine(LuaPreProcParser.LineContext ctx) { }
92 | /**
93 | * {@inheritDoc}
94 | *
95 | * The default implementation does nothing.
96 | */
97 | @Override public void exitLine(LuaPreProcParser.LineContext ctx) { }
98 |
99 | /**
100 | * {@inheritDoc}
101 | *
102 | * The default implementation does nothing.
103 | */
104 | @Override public void enterEveryRule(ParserRuleContext ctx) { }
105 | /**
106 | * {@inheritDoc}
107 | *
108 | * The default implementation does nothing.
109 | */
110 | @Override public void exitEveryRule(ParserRuleContext ctx) { }
111 | /**
112 | * {@inheritDoc}
113 | *
114 | * The default implementation does nothing.
115 | */
116 | @Override public void visitTerminal(TerminalNode node) { }
117 | /**
118 | * {@inheritDoc}
119 | *
120 | * The default implementation does nothing.
121 | */
122 | @Override public void visitErrorNode(ErrorNode node) { }
123 | }
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProcLexer.g4:
--------------------------------------------------------------------------------
1 | lexer grammar LuaPreProcLexer ;
2 |
3 | EMPTY_LINE : '\r'? '\n' -> skip ;
4 | MODE_PP : PP_WS? '--#' -> channel(HIDDEN), pushMode(PreProc) ;
5 | MODE_LINE : [\r\n]* -> channel(HIDDEN),pushMode(LineMode) ;
6 |
7 | mode PreProc ;
8 |
9 | PP_IFDEF : 'IF' ;
10 | PP_ELSE : 'ELSE' ;
11 | PP_ENDIF : 'ENDIF' ;
12 |
13 | PP_PARAM_RELEASE : 'RELEASE' ;
14 | PP_PARAM_DEBUG : 'DEBUG' ;
15 | PP_PARAM_HEADLESS : 'HEADLESS' ;
16 |
17 | PP_TEXT : [a-zA-Z0-9_-]+ ;
18 | PP_EOL : '\r'? '\n' -> popMode ;
19 | PP_WS : [ \t]+ -> channel(HIDDEN) ;
20 |
21 | mode LineMode ;
22 |
23 | TEXT : ~[\r\n]+ ;
24 | EOL : '\r'? '\n' -> popMode ;
25 |
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProcLexer.java:
--------------------------------------------------------------------------------
1 | // Generated from LuaPreProcLexer.g4 by ANTLR 4.9.1
2 | package com.dynamo.bob.pipeline.antlr;
3 | import org.antlr.v4.runtime.Lexer;
4 | import org.antlr.v4.runtime.CharStream;
5 | import org.antlr.v4.runtime.Token;
6 | import org.antlr.v4.runtime.TokenStream;
7 | import org.antlr.v4.runtime.*;
8 | import org.antlr.v4.runtime.atn.*;
9 | import org.antlr.v4.runtime.dfa.DFA;
10 | import org.antlr.v4.runtime.misc.*;
11 |
12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
13 | public class LuaPreProcLexer extends Lexer {
14 | static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); }
15 |
16 | protected static final DFA[] _decisionToDFA;
17 | protected static final PredictionContextCache _sharedContextCache =
18 | new PredictionContextCache();
19 | public static final int
20 | EMPTY_LINE=1, MODE_PP=2, MODE_LINE=3, PP_IFDEF=4, PP_ELSE=5, PP_ENDIF=6,
21 | PP_PARAM_RELEASE=7, PP_PARAM_DEBUG=8, PP_PARAM_HEADLESS=9, PP_TEXT=10,
22 | PP_EOL=11, PP_WS=12, TEXT=13, EOL=14;
23 | public static final int
24 | PreProc=1, LineMode=2;
25 | public static String[] channelNames = {
26 | "DEFAULT_TOKEN_CHANNEL", "HIDDEN"
27 | };
28 |
29 | public static String[] modeNames = {
30 | "DEFAULT_MODE", "PreProc", "LineMode"
31 | };
32 |
33 | private static String[] makeRuleNames() {
34 | return new String[] {
35 | "EMPTY_LINE", "MODE_PP", "MODE_LINE", "PP_IFDEF", "PP_ELSE", "PP_ENDIF",
36 | "PP_PARAM_RELEASE", "PP_PARAM_DEBUG", "PP_PARAM_HEADLESS", "PP_TEXT",
37 | "PP_EOL", "PP_WS", "TEXT", "EOL"
38 | };
39 | }
40 | public static final String[] ruleNames = makeRuleNames();
41 |
42 | private static String[] makeLiteralNames() {
43 | return new String[] {
44 | null, null, null, null, "'IF'", "'ELSE'", "'ENDIF'", "'RELEASE'", "'DEBUG'",
45 | "'HEADLESS'"
46 | };
47 | }
48 | private static final String[] _LITERAL_NAMES = makeLiteralNames();
49 | private static String[] makeSymbolicNames() {
50 | return new String[] {
51 | null, "EMPTY_LINE", "MODE_PP", "MODE_LINE", "PP_IFDEF", "PP_ELSE", "PP_ENDIF",
52 | "PP_PARAM_RELEASE", "PP_PARAM_DEBUG", "PP_PARAM_HEADLESS", "PP_TEXT",
53 | "PP_EOL", "PP_WS", "TEXT", "EOL"
54 | };
55 | }
56 | private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
57 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
58 |
59 | /**
60 | * @deprecated Use {@link #VOCABULARY} instead.
61 | */
62 | @Deprecated
63 | public static final String[] tokenNames;
64 | static {
65 | tokenNames = new String[_SYMBOLIC_NAMES.length];
66 | for (int i = 0; i < tokenNames.length; i++) {
67 | tokenNames[i] = VOCABULARY.getLiteralName(i);
68 | if (tokenNames[i] == null) {
69 | tokenNames[i] = VOCABULARY.getSymbolicName(i);
70 | }
71 |
72 | if (tokenNames[i] == null) {
73 | tokenNames[i] = "";
74 | }
75 | }
76 | }
77 |
78 | @Override
79 | @Deprecated
80 | public String[] getTokenNames() {
81 | return tokenNames;
82 | }
83 |
84 | @Override
85 |
86 | public Vocabulary getVocabulary() {
87 | return VOCABULARY;
88 | }
89 |
90 |
91 | public LuaPreProcLexer(CharStream input) {
92 | super(input);
93 | _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
94 | }
95 |
96 | @Override
97 | public String getGrammarFileName() { return "LuaPreProcLexer.g4"; }
98 |
99 | @Override
100 | public String[] getRuleNames() { return ruleNames; }
101 |
102 | @Override
103 | public String getSerializedATN() { return _serializedATN; }
104 |
105 | @Override
106 | public String[] getChannelNames() { return channelNames; }
107 |
108 | @Override
109 | public String[] getModeNames() { return modeNames; }
110 |
111 | @Override
112 | public ATN getATN() { return _ATN; }
113 |
114 | public static final String _serializedATN =
115 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\2\20\177\b\1\b\1\b"+
116 | "\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"+
117 | "\t\n\4\13\t\13\4\f\t\f\4\r\t\r\4\16\t\16\4\17\t\17\3\2\5\2#\n\2\3\2\3"+
118 | "\2\3\2\3\2\3\3\5\3*\n\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\4\7\4\64\n\4\f\4"+
119 | "\16\4\67\13\4\3\4\3\4\3\4\3\5\3\5\3\5\3\6\3\6\3\6\3\6\3\6\3\7\3\7\3\7"+
120 | "\3\7\3\7\3\7\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\b\3\t\3\t\3\t\3\t\3\t\3\t\3"+
121 | "\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\n\3\13\6\13b\n\13\r\13\16\13c\3\f\5\f"+
122 | "g\n\f\3\f\3\f\3\f\3\f\3\r\6\rn\n\r\r\r\16\ro\3\r\3\r\3\16\6\16u\n\16\r"+
123 | "\16\16\16v\3\17\5\17z\n\17\3\17\3\17\3\17\3\17\2\2\20\5\3\7\4\t\5\13\6"+
124 | "\r\7\17\b\21\t\23\n\25\13\27\f\31\r\33\16\35\17\37\20\5\2\3\4\5\4\2\f"+
125 | "\f\17\17\7\2//\62;C\\aac|\4\2\13\13\"\"\2\u0084\2\5\3\2\2\2\2\7\3\2\2"+
126 | "\2\2\t\3\2\2\2\3\13\3\2\2\2\3\r\3\2\2\2\3\17\3\2\2\2\3\21\3\2\2\2\3\23"+
127 | "\3\2\2\2\3\25\3\2\2\2\3\27\3\2\2\2\3\31\3\2\2\2\3\33\3\2\2\2\4\35\3\2"+
128 | "\2\2\4\37\3\2\2\2\5\"\3\2\2\2\7)\3\2\2\2\t\65\3\2\2\2\13;\3\2\2\2\r>\3"+
129 | "\2\2\2\17C\3\2\2\2\21I\3\2\2\2\23Q\3\2\2\2\25W\3\2\2\2\27a\3\2\2\2\31"+
130 | "f\3\2\2\2\33m\3\2\2\2\35t\3\2\2\2\37y\3\2\2\2!#\7\17\2\2\"!\3\2\2\2\""+
131 | "#\3\2\2\2#$\3\2\2\2$%\7\f\2\2%&\3\2\2\2&\'\b\2\2\2\'\6\3\2\2\2(*\5\33"+
132 | "\r\2)(\3\2\2\2)*\3\2\2\2*+\3\2\2\2+,\7/\2\2,-\7/\2\2-.\7%\2\2./\3\2\2"+
133 | "\2/\60\b\3\3\2\60\61\b\3\4\2\61\b\3\2\2\2\62\64\t\2\2\2\63\62\3\2\2\2"+
134 | "\64\67\3\2\2\2\65\63\3\2\2\2\65\66\3\2\2\2\668\3\2\2\2\67\65\3\2\2\28"+
135 | "9\b\4\3\29:\b\4\5\2:\n\3\2\2\2;<\7K\2\2<=\7H\2\2=\f\3\2\2\2>?\7G\2\2?"+
136 | "@\7N\2\2@A\7U\2\2AB\7G\2\2B\16\3\2\2\2CD\7G\2\2DE\7P\2\2EF\7F\2\2FG\7"+
137 | "K\2\2GH\7H\2\2H\20\3\2\2\2IJ\7T\2\2JK\7G\2\2KL\7N\2\2LM\7G\2\2MN\7C\2"+
138 | "\2NO\7U\2\2OP\7G\2\2P\22\3\2\2\2QR\7F\2\2RS\7G\2\2ST\7D\2\2TU\7W\2\2U"+
139 | "V\7I\2\2V\24\3\2\2\2WX\7J\2\2XY\7G\2\2YZ\7C\2\2Z[\7F\2\2[\\\7N\2\2\\]"+
140 | "\7G\2\2]^\7U\2\2^_\7U\2\2_\26\3\2\2\2`b\t\3\2\2a`\3\2\2\2bc\3\2\2\2ca"+
141 | "\3\2\2\2cd\3\2\2\2d\30\3\2\2\2eg\7\17\2\2fe\3\2\2\2fg\3\2\2\2gh\3\2\2"+
142 | "\2hi\7\f\2\2ij\3\2\2\2jk\b\f\6\2k\32\3\2\2\2ln\t\4\2\2ml\3\2\2\2no\3\2"+
143 | "\2\2om\3\2\2\2op\3\2\2\2pq\3\2\2\2qr\b\r\3\2r\34\3\2\2\2su\n\2\2\2ts\3"+
144 | "\2\2\2uv\3\2\2\2vt\3\2\2\2vw\3\2\2\2w\36\3\2\2\2xz\7\17\2\2yx\3\2\2\2"+
145 | "yz\3\2\2\2z{\3\2\2\2{|\7\f\2\2|}\3\2\2\2}~\b\17\6\2~ \3\2\2\2\r\2\3\4"+
146 | "\")\65cfovy\7\b\2\2\2\3\2\7\3\2\7\4\2\6\2\2";
147 | public static final ATN _ATN =
148 | new ATNDeserializer().deserialize(_serializedATN.toCharArray());
149 | static {
150 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
151 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
152 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
153 | }
154 | }
155 | }
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProcListener.java:
--------------------------------------------------------------------------------
1 | // Generated from LuaPreProc.g4 by ANTLR 4.9.1
2 | package com.dynamo.bob.pipeline.antlr;
3 | import org.antlr.v4.runtime.tree.ParseTreeListener;
4 |
5 | /**
6 | * This interface defines a complete listener for a parse tree produced by
7 | * {@link LuaPreProcParser}.
8 | */
9 | public interface LuaPreProcListener extends ParseTreeListener {
10 | /**
11 | * Enter a parse tree produced by {@link LuaPreProcParser#codefile}.
12 | * @param ctx the parse tree
13 | */
14 | void enterCodefile(LuaPreProcParser.CodefileContext ctx);
15 | /**
16 | * Exit a parse tree produced by {@link LuaPreProcParser#codefile}.
17 | * @param ctx the parse tree
18 | */
19 | void exitCodefile(LuaPreProcParser.CodefileContext ctx);
20 | /**
21 | * Enter a parse tree produced by {@link LuaPreProcParser#preproc}.
22 | * @param ctx the parse tree
23 | */
24 | void enterPreproc(LuaPreProcParser.PreprocContext ctx);
25 | /**
26 | * Exit a parse tree produced by {@link LuaPreProcParser#preproc}.
27 | * @param ctx the parse tree
28 | */
29 | void exitPreproc(LuaPreProcParser.PreprocContext ctx);
30 | /**
31 | * Enter a parse tree produced by {@link LuaPreProcParser#param}.
32 | * @param ctx the parse tree
33 | */
34 | void enterParam(LuaPreProcParser.ParamContext ctx);
35 | /**
36 | * Exit a parse tree produced by {@link LuaPreProcParser#param}.
37 | * @param ctx the parse tree
38 | */
39 | void exitParam(LuaPreProcParser.ParamContext ctx);
40 | /**
41 | * Enter a parse tree produced by {@link LuaPreProcParser#ifdef}.
42 | * @param ctx the parse tree
43 | */
44 | void enterIfdef(LuaPreProcParser.IfdefContext ctx);
45 | /**
46 | * Exit a parse tree produced by {@link LuaPreProcParser#ifdef}.
47 | * @param ctx the parse tree
48 | */
49 | void exitIfdef(LuaPreProcParser.IfdefContext ctx);
50 | /**
51 | * Enter a parse tree produced by {@link LuaPreProcParser#elsedef}.
52 | * @param ctx the parse tree
53 | */
54 | void enterElsedef(LuaPreProcParser.ElsedefContext ctx);
55 | /**
56 | * Exit a parse tree produced by {@link LuaPreProcParser#elsedef}.
57 | * @param ctx the parse tree
58 | */
59 | void exitElsedef(LuaPreProcParser.ElsedefContext ctx);
60 | /**
61 | * Enter a parse tree produced by {@link LuaPreProcParser#endif}.
62 | * @param ctx the parse tree
63 | */
64 | void enterEndif(LuaPreProcParser.EndifContext ctx);
65 | /**
66 | * Exit a parse tree produced by {@link LuaPreProcParser#endif}.
67 | * @param ctx the parse tree
68 | */
69 | void exitEndif(LuaPreProcParser.EndifContext ctx);
70 | /**
71 | * Enter a parse tree produced by {@link LuaPreProcParser#line}.
72 | * @param ctx the parse tree
73 | */
74 | void enterLine(LuaPreProcParser.LineContext ctx);
75 | /**
76 | * Exit a parse tree produced by {@link LuaPreProcParser#line}.
77 | * @param ctx the parse tree
78 | */
79 | void exitLine(LuaPreProcParser.LineContext ctx);
80 | }
--------------------------------------------------------------------------------
/lua-preprocessor/pluginsrc/com/defold/extension/pipeline/antlr/LuaPreProcParser.java:
--------------------------------------------------------------------------------
1 | // Generated from LuaPreProc.g4 by ANTLR 4.9.1
2 | package com.dynamo.bob.pipeline.antlr;
3 | import org.antlr.v4.runtime.atn.*;
4 | import org.antlr.v4.runtime.dfa.DFA;
5 | import org.antlr.v4.runtime.*;
6 | import org.antlr.v4.runtime.misc.*;
7 | import org.antlr.v4.runtime.tree.*;
8 | import java.util.List;
9 | import java.util.Iterator;
10 | import java.util.ArrayList;
11 |
12 | @SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
13 | public class LuaPreProcParser extends Parser {
14 | static { RuntimeMetaData.checkVersion("4.9.1", RuntimeMetaData.VERSION); }
15 |
16 | protected static final DFA[] _decisionToDFA;
17 | protected static final PredictionContextCache _sharedContextCache =
18 | new PredictionContextCache();
19 | public static final int
20 | EMPTY_LINE=1, MODE_PP=2, MODE_LINE=3, PP_IFDEF=4, PP_ELSE=5, PP_ENDIF=6,
21 | PP_PARAM_RELEASE=7, PP_PARAM_DEBUG=8, PP_PARAM_HEADLESS=9, PP_TEXT=10,
22 | PP_EOL=11, PP_WS=12, TEXT=13, EOL=14;
23 | public static final int
24 | RULE_codefile = 0, RULE_preproc = 1, RULE_param = 2, RULE_ifdef = 3, RULE_elsedef = 4,
25 | RULE_endif = 5, RULE_line = 6;
26 | private static String[] makeRuleNames() {
27 | return new String[] {
28 | "codefile", "preproc", "param", "ifdef", "elsedef", "endif", "line"
29 | };
30 | }
31 | public static final String[] ruleNames = makeRuleNames();
32 |
33 | private static String[] makeLiteralNames() {
34 | return new String[] {
35 | null, null, null, null, "'IF'", "'ELSE'", "'ENDIF'", "'RELEASE'", "'DEBUG'",
36 | "'HEADLESS'"
37 | };
38 | }
39 | private static final String[] _LITERAL_NAMES = makeLiteralNames();
40 | private static String[] makeSymbolicNames() {
41 | return new String[] {
42 | null, "EMPTY_LINE", "MODE_PP", "MODE_LINE", "PP_IFDEF", "PP_ELSE", "PP_ENDIF",
43 | "PP_PARAM_RELEASE", "PP_PARAM_DEBUG", "PP_PARAM_HEADLESS", "PP_TEXT",
44 | "PP_EOL", "PP_WS", "TEXT", "EOL"
45 | };
46 | }
47 | private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames();
48 | public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES);
49 |
50 | /**
51 | * @deprecated Use {@link #VOCABULARY} instead.
52 | */
53 | @Deprecated
54 | public static final String[] tokenNames;
55 | static {
56 | tokenNames = new String[_SYMBOLIC_NAMES.length];
57 | for (int i = 0; i < tokenNames.length; i++) {
58 | tokenNames[i] = VOCABULARY.getLiteralName(i);
59 | if (tokenNames[i] == null) {
60 | tokenNames[i] = VOCABULARY.getSymbolicName(i);
61 | }
62 |
63 | if (tokenNames[i] == null) {
64 | tokenNames[i] = "";
65 | }
66 | }
67 | }
68 |
69 | @Override
70 | @Deprecated
71 | public String[] getTokenNames() {
72 | return tokenNames;
73 | }
74 |
75 | @Override
76 |
77 | public Vocabulary getVocabulary() {
78 | return VOCABULARY;
79 | }
80 |
81 | @Override
82 | public String getGrammarFileName() { return "LuaPreProc.g4"; }
83 |
84 | @Override
85 | public String[] getRuleNames() { return ruleNames; }
86 |
87 | @Override
88 | public String getSerializedATN() { return _serializedATN; }
89 |
90 | @Override
91 | public ATN getATN() { return _ATN; }
92 |
93 | public LuaPreProcParser(TokenStream input) {
94 | super(input);
95 | _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
96 | }
97 |
98 | public static class CodefileContext extends ParserRuleContext {
99 | public TerminalNode EOF() { return getToken(LuaPreProcParser.EOF, 0); }
100 | public List preproc() {
101 | return getRuleContexts(PreprocContext.class);
102 | }
103 | public PreprocContext preproc(int i) {
104 | return getRuleContext(PreprocContext.class,i);
105 | }
106 | public List line() {
107 | return getRuleContexts(LineContext.class);
108 | }
109 | public LineContext line(int i) {
110 | return getRuleContext(LineContext.class,i);
111 | }
112 | public CodefileContext(ParserRuleContext parent, int invokingState) {
113 | super(parent, invokingState);
114 | }
115 | @Override public int getRuleIndex() { return RULE_codefile; }
116 | @Override
117 | public void enterRule(ParseTreeListener listener) {
118 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterCodefile(this);
119 | }
120 | @Override
121 | public void exitRule(ParseTreeListener listener) {
122 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitCodefile(this);
123 | }
124 | }
125 |
126 | public final CodefileContext codefile() throws RecognitionException {
127 | CodefileContext _localctx = new CodefileContext(_ctx, getState());
128 | enterRule(_localctx, 0, RULE_codefile);
129 | int _la;
130 | try {
131 | enterOuterAlt(_localctx, 1);
132 | {
133 | setState(18);
134 | _errHandler.sync(this);
135 | _la = _input.LA(1);
136 | while ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PP_IFDEF) | (1L << PP_ELSE) | (1L << PP_ENDIF) | (1L << TEXT))) != 0)) {
137 | {
138 | setState(16);
139 | _errHandler.sync(this);
140 | switch (_input.LA(1)) {
141 | case PP_IFDEF:
142 | case PP_ELSE:
143 | case PP_ENDIF:
144 | {
145 | setState(14);
146 | preproc();
147 | }
148 | break;
149 | case TEXT:
150 | {
151 | setState(15);
152 | line();
153 | }
154 | break;
155 | default:
156 | throw new NoViableAltException(this);
157 | }
158 | }
159 | setState(20);
160 | _errHandler.sync(this);
161 | _la = _input.LA(1);
162 | }
163 | setState(21);
164 | match(EOF);
165 | }
166 | }
167 | catch (RecognitionException re) {
168 | _localctx.exception = re;
169 | _errHandler.reportError(this, re);
170 | _errHandler.recover(this, re);
171 | }
172 | finally {
173 | exitRule();
174 | }
175 | return _localctx;
176 | }
177 |
178 | public static class PreprocContext extends ParserRuleContext {
179 | public IfdefContext ifdef() {
180 | return getRuleContext(IfdefContext.class,0);
181 | }
182 | public ElsedefContext elsedef() {
183 | return getRuleContext(ElsedefContext.class,0);
184 | }
185 | public EndifContext endif() {
186 | return getRuleContext(EndifContext.class,0);
187 | }
188 | public PreprocContext(ParserRuleContext parent, int invokingState) {
189 | super(parent, invokingState);
190 | }
191 | @Override public int getRuleIndex() { return RULE_preproc; }
192 | @Override
193 | public void enterRule(ParseTreeListener listener) {
194 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterPreproc(this);
195 | }
196 | @Override
197 | public void exitRule(ParseTreeListener listener) {
198 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitPreproc(this);
199 | }
200 | }
201 |
202 | public final PreprocContext preproc() throws RecognitionException {
203 | PreprocContext _localctx = new PreprocContext(_ctx, getState());
204 | enterRule(_localctx, 2, RULE_preproc);
205 | try {
206 | setState(26);
207 | _errHandler.sync(this);
208 | switch (_input.LA(1)) {
209 | case PP_IFDEF:
210 | enterOuterAlt(_localctx, 1);
211 | {
212 | setState(23);
213 | ifdef();
214 | }
215 | break;
216 | case PP_ELSE:
217 | enterOuterAlt(_localctx, 2);
218 | {
219 | setState(24);
220 | elsedef();
221 | }
222 | break;
223 | case PP_ENDIF:
224 | enterOuterAlt(_localctx, 3);
225 | {
226 | setState(25);
227 | endif();
228 | }
229 | break;
230 | default:
231 | throw new NoViableAltException(this);
232 | }
233 | }
234 | catch (RecognitionException re) {
235 | _localctx.exception = re;
236 | _errHandler.reportError(this, re);
237 | _errHandler.recover(this, re);
238 | }
239 | finally {
240 | exitRule();
241 | }
242 | return _localctx;
243 | }
244 |
245 | public static class ParamContext extends ParserRuleContext {
246 | public TerminalNode PP_PARAM_RELEASE() { return getToken(LuaPreProcParser.PP_PARAM_RELEASE, 0); }
247 | public TerminalNode PP_PARAM_DEBUG() { return getToken(LuaPreProcParser.PP_PARAM_DEBUG, 0); }
248 | public TerminalNode PP_PARAM_HEADLESS() { return getToken(LuaPreProcParser.PP_PARAM_HEADLESS, 0); }
249 | public ParamContext(ParserRuleContext parent, int invokingState) {
250 | super(parent, invokingState);
251 | }
252 | @Override public int getRuleIndex() { return RULE_param; }
253 | @Override
254 | public void enterRule(ParseTreeListener listener) {
255 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterParam(this);
256 | }
257 | @Override
258 | public void exitRule(ParseTreeListener listener) {
259 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitParam(this);
260 | }
261 | }
262 |
263 | public final ParamContext param() throws RecognitionException {
264 | ParamContext _localctx = new ParamContext(_ctx, getState());
265 | enterRule(_localctx, 4, RULE_param);
266 | int _la;
267 | try {
268 | enterOuterAlt(_localctx, 1);
269 | {
270 | setState(28);
271 | _la = _input.LA(1);
272 | if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << PP_PARAM_RELEASE) | (1L << PP_PARAM_DEBUG) | (1L << PP_PARAM_HEADLESS))) != 0)) ) {
273 | _errHandler.recoverInline(this);
274 | }
275 | else {
276 | if ( _input.LA(1)==Token.EOF ) matchedEOF = true;
277 | _errHandler.reportMatch(this);
278 | consume();
279 | }
280 | }
281 | }
282 | catch (RecognitionException re) {
283 | _localctx.exception = re;
284 | _errHandler.reportError(this, re);
285 | _errHandler.recover(this, re);
286 | }
287 | finally {
288 | exitRule();
289 | }
290 | return _localctx;
291 | }
292 |
293 | public static class IfdefContext extends ParserRuleContext {
294 | public TerminalNode PP_IFDEF() { return getToken(LuaPreProcParser.PP_IFDEF, 0); }
295 | public ParamContext param() {
296 | return getRuleContext(ParamContext.class,0);
297 | }
298 | public TerminalNode PP_EOL() { return getToken(LuaPreProcParser.PP_EOL, 0); }
299 | public IfdefContext(ParserRuleContext parent, int invokingState) {
300 | super(parent, invokingState);
301 | }
302 | @Override public int getRuleIndex() { return RULE_ifdef; }
303 | @Override
304 | public void enterRule(ParseTreeListener listener) {
305 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterIfdef(this);
306 | }
307 | @Override
308 | public void exitRule(ParseTreeListener listener) {
309 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitIfdef(this);
310 | }
311 | }
312 |
313 | public final IfdefContext ifdef() throws RecognitionException {
314 | IfdefContext _localctx = new IfdefContext(_ctx, getState());
315 | enterRule(_localctx, 6, RULE_ifdef);
316 | try {
317 | enterOuterAlt(_localctx, 1);
318 | {
319 | setState(30);
320 | match(PP_IFDEF);
321 | setState(31);
322 | param();
323 | setState(32);
324 | match(PP_EOL);
325 | }
326 | }
327 | catch (RecognitionException re) {
328 | _localctx.exception = re;
329 | _errHandler.reportError(this, re);
330 | _errHandler.recover(this, re);
331 | }
332 | finally {
333 | exitRule();
334 | }
335 | return _localctx;
336 | }
337 |
338 | public static class ElsedefContext extends ParserRuleContext {
339 | public TerminalNode PP_ELSE() { return getToken(LuaPreProcParser.PP_ELSE, 0); }
340 | public TerminalNode PP_EOL() { return getToken(LuaPreProcParser.PP_EOL, 0); }
341 | public ElsedefContext(ParserRuleContext parent, int invokingState) {
342 | super(parent, invokingState);
343 | }
344 | @Override public int getRuleIndex() { return RULE_elsedef; }
345 | @Override
346 | public void enterRule(ParseTreeListener listener) {
347 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterElsedef(this);
348 | }
349 | @Override
350 | public void exitRule(ParseTreeListener listener) {
351 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitElsedef(this);
352 | }
353 | }
354 |
355 | public final ElsedefContext elsedef() throws RecognitionException {
356 | ElsedefContext _localctx = new ElsedefContext(_ctx, getState());
357 | enterRule(_localctx, 8, RULE_elsedef);
358 | try {
359 | enterOuterAlt(_localctx, 1);
360 | {
361 | setState(34);
362 | match(PP_ELSE);
363 | setState(35);
364 | match(PP_EOL);
365 | }
366 | }
367 | catch (RecognitionException re) {
368 | _localctx.exception = re;
369 | _errHandler.reportError(this, re);
370 | _errHandler.recover(this, re);
371 | }
372 | finally {
373 | exitRule();
374 | }
375 | return _localctx;
376 | }
377 |
378 | public static class EndifContext extends ParserRuleContext {
379 | public TerminalNode PP_ENDIF() { return getToken(LuaPreProcParser.PP_ENDIF, 0); }
380 | public TerminalNode PP_EOL() { return getToken(LuaPreProcParser.PP_EOL, 0); }
381 | public EndifContext(ParserRuleContext parent, int invokingState) {
382 | super(parent, invokingState);
383 | }
384 | @Override public int getRuleIndex() { return RULE_endif; }
385 | @Override
386 | public void enterRule(ParseTreeListener listener) {
387 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterEndif(this);
388 | }
389 | @Override
390 | public void exitRule(ParseTreeListener listener) {
391 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitEndif(this);
392 | }
393 | }
394 |
395 | public final EndifContext endif() throws RecognitionException {
396 | EndifContext _localctx = new EndifContext(_ctx, getState());
397 | enterRule(_localctx, 10, RULE_endif);
398 | int _la;
399 | try {
400 | enterOuterAlt(_localctx, 1);
401 | {
402 | setState(37);
403 | match(PP_ENDIF);
404 | setState(39);
405 | _errHandler.sync(this);
406 | _la = _input.LA(1);
407 | if (_la==PP_EOL) {
408 | {
409 | setState(38);
410 | match(PP_EOL);
411 | }
412 | }
413 |
414 | }
415 | }
416 | catch (RecognitionException re) {
417 | _localctx.exception = re;
418 | _errHandler.reportError(this, re);
419 | _errHandler.recover(this, re);
420 | }
421 | finally {
422 | exitRule();
423 | }
424 | return _localctx;
425 | }
426 |
427 | public static class LineContext extends ParserRuleContext {
428 | public TerminalNode TEXT() { return getToken(LuaPreProcParser.TEXT, 0); }
429 | public TerminalNode PP_EOL() { return getToken(LuaPreProcParser.PP_EOL, 0); }
430 | public TerminalNode EOL() { return getToken(LuaPreProcParser.EOL, 0); }
431 | public TerminalNode EOF() { return getToken(LuaPreProcParser.EOF, 0); }
432 | public LineContext(ParserRuleContext parent, int invokingState) {
433 | super(parent, invokingState);
434 | }
435 | @Override public int getRuleIndex() { return RULE_line; }
436 | @Override
437 | public void enterRule(ParseTreeListener listener) {
438 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).enterLine(this);
439 | }
440 | @Override
441 | public void exitRule(ParseTreeListener listener) {
442 | if ( listener instanceof LuaPreProcListener ) ((LuaPreProcListener)listener).exitLine(this);
443 | }
444 | }
445 |
446 | public final LineContext line() throws RecognitionException {
447 | LineContext _localctx = new LineContext(_ctx, getState());
448 | enterRule(_localctx, 12, RULE_line);
449 | try {
450 | enterOuterAlt(_localctx, 1);
451 | {
452 | setState(41);
453 | match(TEXT);
454 | setState(47);
455 | _errHandler.sync(this);
456 | switch (_input.LA(1)) {
457 | case PP_EOL:
458 | {
459 | setState(42);
460 | match(PP_EOL);
461 | }
462 | break;
463 | case EOL:
464 | {
465 | setState(43);
466 | match(EOL);
467 | }
468 | break;
469 | case EOF:
470 | case PP_IFDEF:
471 | case PP_ELSE:
472 | case PP_ENDIF:
473 | case TEXT:
474 | {
475 | setState(45);
476 | _errHandler.sync(this);
477 | switch ( getInterpreter().adaptivePredict(_input,4,_ctx) ) {
478 | case 1:
479 | {
480 | setState(44);
481 | match(EOF);
482 | }
483 | break;
484 | }
485 | }
486 | break;
487 | default:
488 | throw new NoViableAltException(this);
489 | }
490 | }
491 | }
492 | catch (RecognitionException re) {
493 | _localctx.exception = re;
494 | _errHandler.reportError(this, re);
495 | _errHandler.recover(this, re);
496 | }
497 | finally {
498 | exitRule();
499 | }
500 | return _localctx;
501 | }
502 |
503 | public static final String _serializedATN =
504 | "\3\u608b\ua72a\u8133\ub9ed\u417c\u3be7\u7786\u5964\3\20\64\4\2\t\2\4\3"+
505 | "\t\3\4\4\t\4\4\5\t\5\4\6\t\6\4\7\t\7\4\b\t\b\3\2\3\2\7\2\23\n\2\f\2\16"+
506 | "\2\26\13\2\3\2\3\2\3\3\3\3\3\3\5\3\35\n\3\3\4\3\4\3\5\3\5\3\5\3\5\3\6"+
507 | "\3\6\3\6\3\7\3\7\5\7*\n\7\3\b\3\b\3\b\3\b\5\b\60\n\b\5\b\62\n\b\3\b\2"+
508 | "\2\t\2\4\6\b\n\f\16\2\3\3\2\t\13\2\64\2\24\3\2\2\2\4\34\3\2\2\2\6\36\3"+
509 | "\2\2\2\b \3\2\2\2\n$\3\2\2\2\f\'\3\2\2\2\16+\3\2\2\2\20\23\5\4\3\2\21"+
510 | "\23\5\16\b\2\22\20\3\2\2\2\22\21\3\2\2\2\23\26\3\2\2\2\24\22\3\2\2\2\24"+
511 | "\25\3\2\2\2\25\27\3\2\2\2\26\24\3\2\2\2\27\30\7\2\2\3\30\3\3\2\2\2\31"+
512 | "\35\5\b\5\2\32\35\5\n\6\2\33\35\5\f\7\2\34\31\3\2\2\2\34\32\3\2\2\2\34"+
513 | "\33\3\2\2\2\35\5\3\2\2\2\36\37\t\2\2\2\37\7\3\2\2\2 !\7\6\2\2!\"\5\6\4"+
514 | "\2\"#\7\r\2\2#\t\3\2\2\2$%\7\7\2\2%&\7\r\2\2&\13\3\2\2\2\')\7\b\2\2(*"+
515 | "\7\r\2\2)(\3\2\2\2)*\3\2\2\2*\r\3\2\2\2+\61\7\17\2\2,\62\7\r\2\2-\62\7"+
516 | "\20\2\2.\60\7\2\2\3/.\3\2\2\2/\60\3\2\2\2\60\62\3\2\2\2\61,\3\2\2\2\61"+
517 | "-\3\2\2\2\61/\3\2\2\2\62\17\3\2\2\2\b\22\24\34)/\61";
518 | public static final ATN _ATN =
519 | new ATNDeserializer().deserialize(_serializedATN.toCharArray());
520 | static {
521 | _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
522 | for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
523 | _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
524 | }
525 | }
526 | }
--------------------------------------------------------------------------------
/lua-preprocessor/src/plugin.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | DM_DECLARE_EXTENSION(LuaPreprocessor, "LuaPreprocessor", 0, 0, 0, 0, 0, 0);
4 |
--------------------------------------------------------------------------------
/main/default.font:
--------------------------------------------------------------------------------
1 | font: "/builtins/fonts/vera_mo_bd.ttf"
2 | material: "/builtins/fonts/font-df.material"
3 | size: 14
4 | antialias: 1
5 | alpha: 1.0
6 | shadow_alpha: 0.0
7 | shadow_blur: 0
8 | output_format: TYPE_DISTANCE_FIELD
9 |
--------------------------------------------------------------------------------
/main/empty.lua:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/defold/extension-lua-preprocessor/2c48bbf3ae3350609d243ed58a8eb047240f14d3/main/empty.lua
--------------------------------------------------------------------------------
/main/main.collection:
--------------------------------------------------------------------------------
1 | name: "default"
2 | scale_along_z: 0
3 | embedded_instances {
4 | id: "go"
5 | data: "components {\n"
6 | " id: \"main\"\n"
7 | " component: \"/main/main.script\"\n"
8 | " position {\n"
9 | " x: 0.0\n"
10 | " y: 0.0\n"
11 | " z: 0.0\n"
12 | " }\n"
13 | " rotation {\n"
14 | " x: 0.0\n"
15 | " y: 0.0\n"
16 | " z: 0.0\n"
17 | " w: 1.0\n"
18 | " }\n"
19 | " property_decls {\n"
20 | " }\n"
21 | "}\n"
22 | "embedded_components {\n"
23 | " id: \"label\"\n"
24 | " type: \"label\"\n"
25 | " data: \"size {\\n"
26 | " x: 128.0\\n"
27 | " y: 32.0\\n"
28 | " z: 0.0\\n"
29 | " w: 0.0\\n"
30 | "}\\n"
31 | "color {\\n"
32 | " x: 1.0\\n"
33 | " y: 1.0\\n"
34 | " z: 1.0\\n"
35 | " w: 1.0\\n"
36 | "}\\n"
37 | "outline {\\n"
38 | " x: 0.0\\n"
39 | " y: 0.0\\n"
40 | " z: 0.0\\n"
41 | " w: 1.0\\n"
42 | "}\\n"
43 | "shadow {\\n"
44 | " x: 0.0\\n"
45 | " y: 0.0\\n"
46 | " z: 0.0\\n"
47 | " w: 1.0\\n"
48 | "}\\n"
49 | "leading: 1.0\\n"
50 | "tracking: 0.0\\n"
51 | "pivot: PIVOT_CENTER\\n"
52 | "blend_mode: BLEND_MODE_ALPHA\\n"
53 | "line_break: false\\n"
54 | "text: \\\"Label\\\"\\n"
55 | "font: \\\"/main/default.font\\\"\\n"
56 | "material: \\\"/builtins/fonts/label-df.material\\\"\\n"
57 | "\"\n"
58 | " position {\n"
59 | " x: 0.0\n"
60 | " y: 0.0\n"
61 | " z: 0.0\n"
62 | " }\n"
63 | " rotation {\n"
64 | " x: 0.0\n"
65 | " y: 0.0\n"
66 | " z: 0.0\n"
67 | " w: 1.0\n"
68 | " }\n"
69 | "}\n"
70 | ""
71 | position {
72 | x: 131.0
73 | y: 97.0
74 | z: 0.0
75 | }
76 | rotation {
77 | x: 0.0
78 | y: 0.0
79 | z: 0.0
80 | w: 1.0
81 | }
82 | scale3 {
83 | x: 1.0
84 | y: 1.0
85 | z: 1.0
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/main/main.script:
--------------------------------------------------------------------------------
1 | local test = require("main.test")
2 |
3 | function init(self)
4 | --#IF DEBUG
5 | label.set_text("#label", "Debug")
6 | --#ELSE
7 | label.set_text("#label", "Release")
8 | --#ENDIF
9 | test.greet("Bob")
10 |
11 | --#IF HEADLESS
12 | print("HEADLESS ")
13 | label.set_text("#label", "HEADLESS")
14 | --#ENDIF
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/main/test.lua:
--------------------------------------------------------------------------------
1 | local M = {
2 | }
3 |
4 | function M.greet(name)
5 | --#IF RELEASE
6 | -- use io.stdout as that will still write to stdout in release mode
7 | io.stdout:write("Hello " .. name .. "\n")
8 | --#ELSE
9 | print("More debug info: " .. name)
10 | --#ENDIF
11 |
12 | end
13 |
14 | return M
--------------------------------------------------------------------------------