diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1d96d10
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,17 @@
+language: java
+
+jdk: oraclejdk8
+
+dist: trusty
+
+branches: master
+
+cache:
+ directories:
+ - $HOME/.m2
+
+before_script:
+ - mvn -q clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
+
+script:
+- mvn clean test
diff --git a/README.md b/README.md
index d550e7f..5461670 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,6 @@ This library helps in analyzing Nginx web server configuration files, looking up
#### Features
- Convert config file to AST tree using ANTLR4 parsing capabilities
-- The same is available for JavaCC too (deprecated)
- Rebuild config files and dump them back to *.conf
- Nested blocks support
- If statements support
@@ -17,7 +16,7 @@ Add the following dependency to your POM:
com.github.odiszapc
nginxparser
- 0.9.3
+ 0.9.6
```
diff --git a/compile.javacc.cmd b/compile.javacc.cmd
deleted file mode 100644
index f3dc6f2..0000000
--- a/compile.javacc.cmd
+++ /dev/null
@@ -1,2 +0,0 @@
-@echo off
-javacc -OUTPUT_DIRECTORY=src\main\java\com\github\odiszapc\nginxparser\parser src\main\resources\grammar\grammar.jj
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index e02bdec..49ee8f0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,13 +71,13 @@
org.antlr
antlr4-runtime
- 4.5.3
+ 4.7
junit
junit
- 4.11
+ 4.12
test
@@ -87,7 +87,7 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.5.1
+ 3.6.1
1.6
1.6
diff --git a/src/main/java/com/github/odiszapc/nginxparser/NgxBlock.java b/src/main/java/com/github/odiszapc/nginxparser/NgxBlock.java
index 6a5fc07..df36b68 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/NgxBlock.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/NgxBlock.java
@@ -46,6 +46,7 @@ public Iterator iterator() {
return getEntries().iterator();
}
+ @SuppressWarnings("incomplete-switch")
public void remove(NgxEntry itemToRemove) {
if (null == itemToRemove)
throw new NullPointerException("Item can not be null");
@@ -78,6 +79,7 @@ public void removeAll(Iterable itemsToRemove) {
}
}
+ @SuppressWarnings("unchecked")
public T find(Class clazz, String... params) {
List all = findAll(clazz, new ArrayList(), params);
if (all.isEmpty())
@@ -104,6 +106,7 @@ public List findAll(Class clazz, String... par
return findAll(clazz, new ArrayList(), params);
}
+ @SuppressWarnings("incomplete-switch")
public List findAll(Class clazz, List result, String... params) {
List res = new ArrayList();
diff --git a/src/main/java/com/github/odiszapc/nginxparser/NgxConfig.java b/src/main/java/com/github/odiszapc/nginxparser/NgxConfig.java
index d70e378..14118f2 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/NgxConfig.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/NgxConfig.java
@@ -19,9 +19,9 @@
import com.github.odiszapc.nginxparser.antlr.NginxLexer;
import com.github.odiszapc.nginxparser.antlr.NginxListenerImpl;
import com.github.odiszapc.nginxparser.antlr.NginxParser;
-import com.github.odiszapc.nginxparser.javacc.NginxConfigParser;
-import com.github.odiszapc.nginxparser.javacc.ParseException;
-import org.antlr.v4.runtime.ANTLRInputStream;
+
+import org.antlr.v4.runtime.CharStream;
+import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
@@ -57,21 +57,8 @@ public static NgxConfig read(InputStream in) throws IOException {
return readAntlr(in);
}
- /**
- * Read config from existing stream
- * @param input stream to read from
- * @return Config object
- * @throws IOException
- * @throws ParseException
- */
- public static NgxConfig readJavaCC(InputStream input) throws IOException, ParseException {
- NginxConfigParser parser = new NginxConfigParser(input);
- return parser.parse();
- }
-
-
public static NgxConfig readAntlr(InputStream in) throws IOException {
- ANTLRInputStream input = new ANTLRInputStream(in);
+ CharStream input = CharStreams.fromStream(in);
NginxLexer lexer = new NginxLexer(input);
CommonTokenStream tokens = new CommonTokenStream(lexer);
NginxParser parser = new NginxParser(tokens);
diff --git a/src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java b/src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java
index 7688f13..4842333 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java
@@ -26,12 +26,10 @@
public class NgxDumper {
private NgxConfig config;
- private final static int PAD_SIZE = 2;
private final static String PAD_SYMBOL = " ";
private final static String LBRACE = "{";
private final static String RBRACE = "}";
private final static String LF = "\n";
- private final static String CRLF = "\r\n";
public NgxDumper(NgxConfig config) {
this.config = config;
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseListener.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseListener.java
index 6fa80ac..916d3a8 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseListener.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseListener.java
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3
package com.github.odiszapc.nginxparser.antlr;
- import com.github.odiszapc.nginxparser.*;
import org.antlr.v4.runtime.ParserRuleContext;
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseVisitor.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseVisitor.java
index 0af9ad7..8a88914 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseVisitor.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxBaseVisitor.java
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3
package com.github.odiszapc.nginxparser.antlr;
- import com.github.odiszapc.nginxparser.*;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxLexer.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxLexer.java
index dc49462..3f5e95c 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxLexer.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxLexer.java
@@ -13,7 +13,7 @@
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class NginxLexer extends Lexer {
- static { RuntimeMetaData.checkVersion("4.5.3", RuntimeMetaData.VERSION); }
+ static { RuntimeMetaData.checkVersion("4.7", RuntimeMetaData.VERSION); }
protected static final DFA[] _decisionToDFA;
protected static final PredictionContextCache _sharedContextCache =
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListener.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListener.java
index 4613194..34ce5e9 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListener.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListener.java
@@ -1,9 +1,7 @@
// Generated from Nginx.g4 by ANTLR 4.5.3
package com.github.odiszapc.nginxparser.antlr;
- import com.github.odiszapc.nginxparser.*;
-
-import org.antlr.v4.runtime.tree.ParseTreeListener;
+ import org.antlr.v4.runtime.tree.ParseTreeListener;
/**
* This interface defines a complete listener for a parse tree produced by
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListenerImpl.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListenerImpl.java
index b23e945..9b3de34 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListenerImpl.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxListenerImpl.java
@@ -1,11 +1,7 @@
package com.github.odiszapc.nginxparser.antlr;
import com.github.odiszapc.nginxparser.NgxConfig;
-import org.antlr.v4.runtime.misc.NotNull;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.runtime.tree.TerminalNode;
-import java.util.List;
public class NginxListenerImpl extends NginxBaseListener {
@@ -17,7 +13,7 @@ public NgxConfig getResult() {
}
@Override
- public void enterConfig(@NotNull NginxParser.ConfigContext ctx) {
+ public void enterConfig(NginxParser.ConfigContext ctx) {
result = ctx.ret;
}
}
diff --git a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxVisitor.java b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxVisitor.java
index d7e3666..43728de 100644
--- a/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxVisitor.java
+++ b/src/main/java/com/github/odiszapc/nginxparser/antlr/NginxVisitor.java
@@ -1,7 +1,6 @@
// Generated from Nginx.g4 by ANTLR 4.5.3
package com.github.odiszapc.nginxparser.antlr;
- import com.github.odiszapc.nginxparser.*;
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParser.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParser.java
deleted file mode 100644
index b95afe3..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParser.java
+++ /dev/null
@@ -1,704 +0,0 @@
-/* NginxConfigParser.java */
-/* Generated By:JavaCC: Do not edit this line. NginxConfigParser.java */
-package com.github.odiszapc.nginxparser.javacc;
-import com.github.odiszapc.nginxparser.*;
-@SuppressWarnings("ConstantConditions")
-public class NginxConfigParser implements NginxConfigParserConstants {
- private boolean isDebug = false;
-
- public void setDebug(boolean val) {
- isDebug = val;
- }
-
- private void debug(String message) {
- debug(message, false);
- }
-
- private void debugLn(String message) {
- debug(message, true);
- }
-
- private void debug(String message, boolean appendLineEnding) {
- if (isDebug) {
- System.out.print(message);
- if (appendLineEnding) System.out.println();
- }
- }
-
-/*
- Main method
-*/
- final public NgxConfig parse() throws ParseException {NgxConfig config;
- config = statements();
-{if ("" != null) return config;}
- throw new Error("Missing return statement in function");
- }
-
- final public NgxConfig statements() throws ParseException {NgxConfig config = new NgxConfig();
- NgxEntry curEntry;
- label_1:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:
- case SINGLE_LINE_COMMENT:{
- ;
- break;
- }
- default:
- jj_la1[0] = jj_gen;
- break label_1;
- }
- if (jj_2_1(4)) {
- curEntry = param();
- } else {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:{
- curEntry = block();
- break;
- }
- case SINGLE_LINE_COMMENT:{
- curEntry = comment();
- break;
- }
- default:
- jj_la1[1] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
-config.addEntry(curEntry);
- }
-{if ("" != null) return config;}
- throw new Error("Missing return statement in function");
- }
-
-/*
- Block
-
- Example:
- http {
- ...
- }
-*/
- final public NgxBlock block() throws ParseException {String blockName = "";
- NgxBlock block = new NgxBlock();
- NgxToken curToken;
- NgxEntry curEntry;
- curToken = id();
-blockName += token.image+" ";
- block.getTokens().add(curToken);
- label_2:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:{
- ;
- break;
- }
- default:
- jj_la1[2] = jj_gen;
- break label_2;
- }
- curToken = id();
-blockName += token.image+" ";
- block.getTokens().add(curToken);
- }
-debugLn("BLOCK=" + blockName + "{");
- jj_consume_token(LBRACE);
- label_3:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case IF:
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:
- case SINGLE_LINE_COMMENT:{
- ;
- break;
- }
- default:
- jj_la1[3] = jj_gen;
- break label_3;
- }
- if (jj_2_2(4)) {
- curEntry = param();
- } else {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:{
- curEntry = block();
- break;
- }
- case SINGLE_LINE_COMMENT:{
- curEntry = comment();
- break;
- }
- case IF:{
- curEntry = if_block();
- break;
- }
- default:
- jj_la1[4] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
-block.addEntry(curEntry);
- }
- jj_consume_token(RBRACE);
-debugLn("}");
- {if ("" != null) return block;}
- throw new Error("Missing return statement in function");
- }
-
-/*
- "if" statement
-
- Example:
- if ($arg_val !~ '^\d+$') {
- return 400;
- break;
- }
-*/
- final public NgxBlock if_block() throws ParseException {NgxIfBlock block = new NgxIfBlock();
- NgxEntry curEntry = null;
- jj_consume_token(IF);
-debug(token.image + " ");
- block.addValue(new NgxToken(token.image));
- jj_consume_token(IF_BODY);
-debug(token.image + " ");
- block.addValue(new NgxToken(token.image));
- jj_consume_token(LBRACE);
-debugLn(token.image);
- label_4:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:
- case SINGLE_LINE_COMMENT:{
- ;
- break;
- }
- default:
- jj_la1[5] = jj_gen;
- break label_4;
- }
- if (jj_2_3(4)) {
- curEntry = param();
- } else {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:{
- curEntry = block();
- break;
- }
- case SINGLE_LINE_COMMENT:{
- curEntry = comment();
- break;
- }
- default:
- jj_la1[6] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
-block.addEntry(curEntry);
- }
- jj_consume_token(RBRACE);
-debugLn(token.image);
- {if ("" != null) return block;}
- throw new Error("Missing return statement in function");
- }
-
-/*
- Single line parameter
-
- Examples:
- listen 80;
- server_name localhost;
- root /var/www;
- index index.html index.htm;
- array_map '[$array_it]' $list;
- echo_exec /safe-memc?cmd=incr&key=$arg_key&val=$arg_val;
-*/
- final public NgxParam param() throws ParseException {NgxParam param = new NgxParam();
- NgxToken curToken = null;
- curToken = id();
-debug("KEY=" + token.image +", VALUE=");
- param.getTokens().add(curToken);
- label_5:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case NUMBER:
- case STRING:
- case QUOTED_STRING:
- case SINGLE_QUOTED_STRING:{
- ;
- break;
- }
- default:
- jj_la1[7] = jj_gen;
- break label_5;
- }
- curToken = value();
-debug(token.image + " | ");
- param.getTokens().add(curToken);
- }
-debugLn("");
- jj_consume_token(SEMICOLON);
-{if ("" != null) return param;}
- throw new Error("Missing return statement in function");
- }
-
-/*
- Comment
- Example:
- # Comment here
-*/
- final public NgxComment comment() throws ParseException {NgxComment comment;
- jj_consume_token(SINGLE_LINE_COMMENT);
-debugLn("COMMENT=" + token.image);
- {if ("" != null) return new NgxComment(token.image);}
- throw new Error("Missing return statement in function");
- }
-
-/*
- Parameter/block names and/or values
- Example:
- # id occurs 6 times
- gzip_types text/plain application/xml application/x-javascript text/css application/json;
-
-*/
- final public NgxToken id() throws ParseException {NgxToken val = null;
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case STRING:{
- jj_consume_token(STRING);
- break;
- }
- case QUOTED_STRING:{
- jj_consume_token(QUOTED_STRING);
- break;
- }
- case SINGLE_QUOTED_STRING:{
- jj_consume_token(SINGLE_QUOTED_STRING);
- break;
- }
- default:
- jj_la1[8] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
-{if ("" != null) return new NgxToken(token.image);};
- throw new Error("Missing return statement in function");
- }
-
-/*
- Parameter values
-*/
- final public NgxToken value() throws ParseException {NgxToken val = null;
- switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
- case NUMBER:{
- jj_consume_token(NUMBER);
- break;
- }
- case STRING:{
- jj_consume_token(STRING);
- break;
- }
- case QUOTED_STRING:{
- jj_consume_token(QUOTED_STRING);
- break;
- }
- case SINGLE_QUOTED_STRING:{
- jj_consume_token(SINGLE_QUOTED_STRING);
- break;
- }
- default:
- jj_la1[9] = jj_gen;
- jj_consume_token(-1);
- throw new ParseException();
- }
-{if ("" != null) return new NgxToken(token.image);};
- throw new Error("Missing return statement in function");
- }
-
- private boolean jj_2_1(int xla)
- {
- jj_la = xla; jj_lastpos = jj_scanpos = token;
- try { return !jj_3_1(); }
- catch(LookaheadSuccess ls) { return true; }
- finally { jj_save(0, xla); }
- }
-
- private boolean jj_2_2(int xla)
- {
- jj_la = xla; jj_lastpos = jj_scanpos = token;
- try { return !jj_3_2(); }
- catch(LookaheadSuccess ls) { return true; }
- finally { jj_save(1, xla); }
- }
-
- private boolean jj_2_3(int xla)
- {
- jj_la = xla; jj_lastpos = jj_scanpos = token;
- try { return !jj_3_3(); }
- catch(LookaheadSuccess ls) { return true; }
- finally { jj_save(2, xla); }
- }
-
- private boolean jj_3R_8()
- {
- if (jj_3R_9()) return true;
- return false;
- }
-
- private boolean jj_3R_7()
- {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(13)) {
- jj_scanpos = xsp;
- if (jj_scan_token(14)) {
- jj_scanpos = xsp;
- if (jj_scan_token(15)) return true;
- }
- }
- return false;
- }
-
- private boolean jj_3_2()
- {
- if (jj_3R_6()) return true;
- return false;
- }
-
- private boolean jj_3R_9()
- {
- Token xsp;
- xsp = jj_scanpos;
- if (jj_scan_token(12)) {
- jj_scanpos = xsp;
- if (jj_scan_token(13)) {
- jj_scanpos = xsp;
- if (jj_scan_token(14)) {
- jj_scanpos = xsp;
- if (jj_scan_token(15)) return true;
- }
- }
- }
- return false;
- }
-
- private boolean jj_3_3()
- {
- if (jj_3R_6()) return true;
- return false;
- }
-
- private boolean jj_3_1()
- {
- if (jj_3R_6()) return true;
- return false;
- }
-
- private boolean jj_3R_6()
- {
- if (jj_3R_7()) return true;
- Token xsp;
- while (true) {
- xsp = jj_scanpos;
- if (jj_3R_8()) { jj_scanpos = xsp; break; }
- }
- if (jj_scan_token(SEMICOLON)) return true;
- return false;
- }
-
- /** Generated Token Manager. */
- public NginxConfigParserTokenManager token_source;
- SimpleCharStream jj_input_stream;
- /** Current token. */
- public Token token;
- /** Next token. */
- public Token jj_nt;
- private int jj_ntk;
- private Token jj_scanpos, jj_lastpos;
- private int jj_la;
- private int jj_gen;
- final private int[] jj_la1 = new int[10];
- static private int[] jj_la1_0;
- static {
- jj_la1_init_0();
- }
- private static void jj_la1_init_0() {
- jj_la1_0 = new int[] {0x1e000,0x1e000,0xe000,0x1e400,0x1e400,0x1e000,0x1e000,0xf000,0xe000,0xf000,};
- }
- final private JJCalls[] jj_2_rtns = new JJCalls[3];
- private boolean jj_rescan = false;
- private int jj_gc = 0;
-
- /** Constructor with InputStream. */
- public NginxConfigParser(java.io.InputStream stream) {
- this(stream, null);
- }
- /** Constructor with InputStream and supplied encoding */
- public NginxConfigParser(java.io.InputStream stream, String encoding) {
- try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
- token_source = new NginxConfigParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.InputStream stream) {
- ReInit(stream, null);
- }
- /** Reinitialise. */
- public void ReInit(java.io.InputStream stream, String encoding) {
- try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
- token_source.ReInit(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- /** Constructor. */
- public NginxConfigParser(java.io.Reader stream) {
- jj_input_stream = new SimpleCharStream(stream, 1, 1);
- token_source = new NginxConfigParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.Reader stream) {
- jj_input_stream.ReInit(stream, 1, 1);
- token_source.ReInit(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- /** Constructor with generated Token Manager. */
- public NginxConfigParser(NginxConfigParserTokenManager tm) {
- token_source = tm;
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- /** Reinitialise. */
- public void ReInit(NginxConfigParserTokenManager tm) {
- token_source = tm;
- token = new Token();
- jj_ntk = -1;
- jj_gen = 0;
- for (int i = 0; i < 10; i++) jj_la1[i] = -1;
- for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
- }
-
- private Token jj_consume_token(int kind) throws ParseException {
- Token oldToken;
- if ((oldToken = token).next != null) token = token.next;
- else token = token.next = token_source.getNextToken();
- jj_ntk = -1;
- if (token.kind == kind) {
- jj_gen++;
- if (++jj_gc > 100) {
- jj_gc = 0;
- for (int i = 0; i < jj_2_rtns.length; i++) {
- JJCalls c = jj_2_rtns[i];
- while (c != null) {
- if (c.gen < jj_gen) c.first = null;
- c = c.next;
- }
- }
- }
- return token;
- }
- token = oldToken;
- jj_kind = kind;
- throw generateParseException();
- }
-
- @SuppressWarnings("serial")
- static private final class LookaheadSuccess extends java.lang.Error { }
- final private LookaheadSuccess jj_ls = new LookaheadSuccess();
- private boolean jj_scan_token(int kind) {
- if (jj_scanpos == jj_lastpos) {
- jj_la--;
- if (jj_scanpos.next == null) {
- jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
- } else {
- jj_lastpos = jj_scanpos = jj_scanpos.next;
- }
- } else {
- jj_scanpos = jj_scanpos.next;
- }
- if (jj_rescan) {
- int i = 0; Token tok = token;
- while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
- if (tok != null) jj_add_error_token(kind, i);
- }
- if (jj_scanpos.kind != kind) return true;
- if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
- return false;
- }
-
-
-/** Get the next Token. */
- final public Token getNextToken() {
- if (token.next != null) token = token.next;
- else token = token.next = token_source.getNextToken();
- jj_ntk = -1;
- jj_gen++;
- return token;
- }
-
-/** Get the specific Token. */
- final public Token getToken(int index) {
- Token t = token;
- for (int i = 0; i < index; i++) {
- if (t.next != null) t = t.next;
- else t = t.next = token_source.getNextToken();
- }
- return t;
- }
-
- private int jj_ntk_f() {
- if ((jj_nt=token.next) == null)
- return (jj_ntk = (token.next=token_source.getNextToken()).kind);
- else
- return (jj_ntk = jj_nt.kind);
- }
-
- private java.util.List jj_expentries = new java.util.ArrayList();
- private int[] jj_expentry;
- private int jj_kind = -1;
- private int[] jj_lasttokens = new int[100];
- private int jj_endpos;
-
- private void jj_add_error_token(int kind, int pos) {
- if (pos >= 100) return;
- if (pos == jj_endpos + 1) {
- jj_lasttokens[jj_endpos++] = kind;
- } else if (jj_endpos != 0) {
- jj_expentry = new int[jj_endpos];
- for (int i = 0; i < jj_endpos; i++) {
- jj_expentry[i] = jj_lasttokens[i];
- }
- jj_entries_loop: for (java.util.Iterator> it = jj_expentries.iterator(); it.hasNext();) {
- int[] oldentry = (int[])(it.next());
- if (oldentry.length == jj_expentry.length) {
- for (int i = 0; i < jj_expentry.length; i++) {
- if (oldentry[i] != jj_expentry[i]) {
- continue jj_entries_loop;
- }
- }
- jj_expentries.add(jj_expentry);
- break jj_entries_loop;
- }
- }
- if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
- }
- }
-
- /** Generate ParseException. */
- public ParseException generateParseException() {
- jj_expentries.clear();
- boolean[] la1tokens = new boolean[19];
- if (jj_kind >= 0) {
- la1tokens[jj_kind] = true;
- jj_kind = -1;
- }
- for (int i = 0; i < 10; i++) {
- if (jj_la1[i] == jj_gen) {
- for (int j = 0; j < 32; j++) {
- if ((jj_la1_0[i] & (1< jj_gen) {
- jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
- switch (i) {
- case 0: jj_3_1(); break;
- case 1: jj_3_2(); break;
- case 2: jj_3_3(); break;
- }
- }
- p = p.next;
- } while (p != null);
- } catch(LookaheadSuccess ls) { }
- }
- jj_rescan = false;
- }
-
- private void jj_save(int index, int xla) {
- JJCalls p = jj_2_rtns[index];
- while (p.gen > jj_gen) {
- if (p.next == null) { p = p.next = new JJCalls(); break; }
- p = p.next;
- }
- p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
- }
-
- static final class JJCalls {
- int gen;
- Token first;
- int arg;
- JJCalls next;
- }
-
-}
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserConstants.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserConstants.java
deleted file mode 100644
index 6c0aaa6..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserConstants.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/* Generated By:JavaCC: Do not edit this line. NginxConfigParserConstants.java */
-package com.github.odiszapc.nginxparser.javacc;
-
-
-/**
- * Token literal values and constants.
- * Generated by org.javacc.parser.OtherFilesGen#start()
- */
-public interface NginxConfigParserConstants {
-
- /** End of File. */
- int EOF = 0;
- /** RegularExpression Id. */
- int LPAREN = 5;
- /** RegularExpression Id. */
- int RPAREN = 6;
- /** RegularExpression Id. */
- int LBRACE = 7;
- /** RegularExpression Id. */
- int RBRACE = 8;
- /** RegularExpression Id. */
- int SEMICOLON = 9;
- /** RegularExpression Id. */
- int IF = 10;
- /** RegularExpression Id. */
- int IF_BODY = 11;
- /** RegularExpression Id. */
- int NUMBER = 12;
- /** RegularExpression Id. */
- int STRING = 13;
- /** RegularExpression Id. */
- int QUOTED_STRING = 14;
- /** RegularExpression Id. */
- int SINGLE_QUOTED_STRING = 15;
- /** RegularExpression Id. */
- int SINGLE_LINE_COMMENT = 16;
- /** RegularExpression Id. */
- int COMMENT_SIGN = 17;
- /** RegularExpression Id. */
- int COMMENT_BODY = 18;
-
- /** Lexical state. */
- int DEFAULT = 0;
-
- /** Literal token values. */
- String[] tokenImage = {
- "",
- "\" \"",
- "\"\\t\"",
- "\"\\r\"",
- "\"\\n\"",
- "\"(\"",
- "\")\"",
- "\"{\"",
- "\"}\"",
- "\";\"",
- "\"if\"",
- "",
- "",
- "",
- "",
- "",
- "",
- "\"#\"",
- "",
- };
-
-}
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserTokenManager.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserTokenManager.java
deleted file mode 100644
index 06755a7..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/NginxConfigParserTokenManager.java
+++ /dev/null
@@ -1,524 +0,0 @@
-/* NginxConfigParserTokenManager.java */
-/* Generated By:JavaCC: Do not edit this line. NginxConfigParserTokenManager.java */
-package com.github.odiszapc.nginxparser.javacc;
-
-/** Token Manager. */
-@SuppressWarnings("unused")public class NginxConfigParserTokenManager implements NginxConfigParserConstants {
-
- /** Debug output. */
- public java.io.PrintStream debugStream = System.out;
- /** Set debug output. */
- public void setDebugStream(java.io.PrintStream ds) { debugStream = ds; }
-private final int jjStopStringLiteralDfa_0(int pos, long active0){
- switch (pos)
- {
- case 0:
- if ((active0 & 0x400L) != 0L)
- {
- jjmatchedKind = 13;
- return 5;
- }
- if ((active0 & 0x20L) != 0L)
- return 20;
- if ((active0 & 0x40L) != 0L)
- return 5;
- return -1;
- default :
- return -1;
- }
-}
-private final int jjStartNfa_0(int pos, long active0){
- return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1);
-}
-private int jjStopAtPos(int pos, int kind)
-{
- jjmatchedKind = kind;
- jjmatchedPos = pos;
- return pos + 1;
-}
-private int jjMoveStringLiteralDfa0_0(){
- switch(curChar)
- {
- case 40:
- return jjStartNfaWithStates_0(0, 5, 20);
- case 41:
- return jjStartNfaWithStates_0(0, 6, 5);
- case 59:
- return jjStopAtPos(0, 9);
- case 105:
- return jjMoveStringLiteralDfa1_0(0x400L);
- case 123:
- return jjStopAtPos(0, 7);
- case 125:
- return jjStopAtPos(0, 8);
- default :
- return jjMoveNfa_0(0, 0);
- }
-}
-private int jjMoveStringLiteralDfa1_0(long active0){
- try { curChar = input_stream.readChar(); }
- catch(java.io.IOException e) {
- jjStopStringLiteralDfa_0(0, active0);
- return 1;
- }
- switch(curChar)
- {
- case 102:
- if ((active0 & 0x400L) != 0L)
- return jjStartNfaWithStates_0(1, 10, 5);
- break;
- default :
- break;
- }
- return jjStartNfa_0(0, active0);
-}
-private int jjStartNfaWithStates_0(int pos, int kind, int state)
-{
- jjmatchedKind = kind;
- jjmatchedPos = pos;
- try { curChar = input_stream.readChar(); }
- catch(java.io.IOException e) { return pos + 1; }
- return jjMoveNfa_0(state, pos + 1);
-}
-static final long[] jjbitVec0 = {
- 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL
-};
-private int jjMoveNfa_0(int startState, int curPos)
-{
- int startsAt = 0;
- jjnewStateCnt = 20;
- int i = 1;
- jjstateSet[0] = startState;
- int kind = 0x7fffffff;
- for (;;)
- {
- if (++jjround == 0x7fffffff)
- ReInitRounds();
- if (curChar < 64)
- {
- long l = 1L << curChar;
- do
- {
- switch(jjstateSet[--i])
- {
- case 20:
- if ((0xfffffdffffffffffL & l) != 0L)
- { jjCheckNAddTwoStates(1, 2); }
- if ((0xa7ffef5000000000L & l) != 0L)
- {
- if (kind > 13)
- kind = 13;
- { jjCheckNAdd(5); }
- }
- break;
- case 0:
- if ((0xa7ffef5000000000L & l) != 0L)
- {
- if (kind > 13)
- kind = 13;
- { jjCheckNAdd(5); }
- }
- else if (curChar == 35)
- {
- if (kind > 16)
- kind = 16;
- { jjCheckNAdd(19); }
- }
- else if (curChar == 39)
- { jjCheckNAddTwoStates(16, 17); }
- else if (curChar == 34)
- { jjCheckNAddStates(0, 2); }
- if ((0x3fe000000000000L & l) != 0L)
- {
- if (kind > 12)
- kind = 12;
- { jjCheckNAdd(4); }
- }
- else if (curChar == 40)
- { jjCheckNAdd(1); }
- break;
- case 1:
- if ((0xfffffdffffffffffL & l) != 0L)
- { jjCheckNAddTwoStates(1, 2); }
- break;
- case 2:
- if (curChar == 41 && kind > 11)
- kind = 11;
- break;
- case 3:
- if ((0x3fe000000000000L & l) == 0L)
- break;
- if (kind > 12)
- kind = 12;
- { jjCheckNAdd(4); }
- break;
- case 4:
- if ((0x3ff000000000000L & l) == 0L)
- break;
- if (kind > 12)
- kind = 12;
- { jjCheckNAdd(4); }
- break;
- case 5:
- if ((0xa7ffef5000000000L & l) == 0L)
- break;
- if (kind > 13)
- kind = 13;
- { jjCheckNAdd(5); }
- break;
- case 6:
- if (curChar == 34)
- { jjCheckNAddStates(0, 2); }
- break;
- case 7:
- if ((0xfffffffbffffffffL & l) != 0L)
- { jjCheckNAddStates(0, 2); }
- break;
- case 9:
- if ((0x8400000000L & l) != 0L)
- { jjCheckNAddStates(0, 2); }
- break;
- case 10:
- if (curChar == 34 && kind > 14)
- kind = 14;
- break;
- case 11:
- if ((0xff000000000000L & l) != 0L)
- { jjCheckNAddStates(3, 6); }
- break;
- case 12:
- if ((0xff000000000000L & l) != 0L)
- { jjCheckNAddStates(0, 2); }
- break;
- case 13:
- if ((0xf000000000000L & l) != 0L)
- jjstateSet[jjnewStateCnt++] = 14;
- break;
- case 14:
- if ((0xff000000000000L & l) != 0L)
- { jjCheckNAdd(12); }
- break;
- case 15:
- if (curChar == 39)
- { jjCheckNAddTwoStates(16, 17); }
- break;
- case 16:
- if ((0xffffff7fffffffffL & l) != 0L)
- { jjCheckNAddTwoStates(16, 17); }
- break;
- case 17:
- if (curChar == 39 && kind > 15)
- kind = 15;
- break;
- case 18:
- if (curChar != 35)
- break;
- if (kind > 16)
- kind = 16;
- { jjCheckNAdd(19); }
- break;
- case 19:
- if ((0xffffffffffffdbffL & l) == 0L)
- break;
- if (kind > 16)
- kind = 16;
- { jjCheckNAdd(19); }
- break;
- default : break;
- }
- } while(i != startsAt);
- }
- else if (curChar < 128)
- {
- long l = 1L << (curChar & 077);
- do
- {
- switch(jjstateSet[--i])
- {
- case 20:
- { jjCheckNAddTwoStates(1, 2); }
- if ((0x57fffffed7ffffffL & l) != 0L)
- {
- if (kind > 13)
- kind = 13;
- { jjCheckNAdd(5); }
- }
- break;
- case 0:
- case 5:
- if ((0x57fffffed7ffffffL & l) == 0L)
- break;
- if (kind > 13)
- kind = 13;
- { jjCheckNAdd(5); }
- break;
- case 1:
- { jjCheckNAddTwoStates(1, 2); }
- break;
- case 7:
- if ((0xffffffffefffffffL & l) != 0L)
- { jjCheckNAddStates(0, 2); }
- break;
- case 8:
- if (curChar == 92)
- { jjAddStates(7, 9); }
- break;
- case 9:
- if ((0x14404410000000L & l) != 0L)
- { jjCheckNAddStates(0, 2); }
- break;
- case 16:
- { jjAddStates(10, 11); }
- break;
- case 19:
- if (kind > 16)
- kind = 16;
- jjstateSet[jjnewStateCnt++] = 19;
- break;
- default : break;
- }
- } while(i != startsAt);
- }
- else
- {
- int i2 = (curChar & 0xff) >> 6;
- long l2 = 1L << (curChar & 077);
- do
- {
- switch(jjstateSet[--i])
- {
- case 20:
- case 1:
- if ((jjbitVec0[i2] & l2) != 0L)
- { jjCheckNAddTwoStates(1, 2); }
- break;
- case 7:
- if ((jjbitVec0[i2] & l2) != 0L)
- { jjAddStates(0, 2); }
- break;
- case 16:
- if ((jjbitVec0[i2] & l2) != 0L)
- { jjAddStates(10, 11); }
- break;
- case 19:
- if ((jjbitVec0[i2] & l2) == 0L)
- break;
- if (kind > 16)
- kind = 16;
- jjstateSet[jjnewStateCnt++] = 19;
- break;
- default : break;
- }
- } while(i != startsAt);
- }
- if (kind != 0x7fffffff)
- {
- jjmatchedKind = kind;
- jjmatchedPos = curPos;
- kind = 0x7fffffff;
- }
- ++curPos;
- if ((i = jjnewStateCnt) == (startsAt = 20 - (jjnewStateCnt = startsAt)))
- return curPos;
- try { curChar = input_stream.readChar(); }
- catch(java.io.IOException e) { return curPos; }
- }
-}
-static final int[] jjnextStates = {
- 7, 8, 10, 7, 8, 12, 10, 9, 11, 13, 16, 17,
-};
-
-/** Token literal values. */
-public static final String[] jjstrLiteralImages = {
-"", null, null, null, null, "\50", "\51", "\173", "\175", "\73", "\151\146",
-null, null, null, null, null, null, null, null, };
-protected Token jjFillToken()
-{
- final Token t;
- final String curTokenImage;
- final int beginLine;
- final int endLine;
- final int beginColumn;
- final int endColumn;
- String im = jjstrLiteralImages[jjmatchedKind];
- curTokenImage = (im == null) ? input_stream.GetImage() : im;
- beginLine = input_stream.getBeginLine();
- beginColumn = input_stream.getBeginColumn();
- endLine = input_stream.getEndLine();
- endColumn = input_stream.getEndColumn();
- t = Token.newToken(jjmatchedKind, curTokenImage);
-
- t.beginLine = beginLine;
- t.endLine = endLine;
- t.beginColumn = beginColumn;
- t.endColumn = endColumn;
-
- return t;
-}
-
-int curLexState = 0;
-int defaultLexState = 0;
-int jjnewStateCnt;
-int jjround;
-int jjmatchedPos;
-int jjmatchedKind;
-
-/** Get the next Token. */
-public Token getNextToken()
-{
- Token matchedToken;
- int curPos = 0;
-
- EOFLoop :
- for (;;)
- {
- try
- {
- curChar = input_stream.BeginToken();
- }
- catch(java.io.IOException e)
- {
- jjmatchedKind = 0;
- jjmatchedPos = -1;
- matchedToken = jjFillToken();
- return matchedToken;
- }
-
- try { input_stream.backup(0);
- while (curChar <= 32 && (0x100002600L & (1L << curChar)) != 0L)
- curChar = input_stream.BeginToken();
- }
- catch (java.io.IOException e1) { continue EOFLoop; }
- jjmatchedKind = 0x7fffffff;
- jjmatchedPos = 0;
- curPos = jjMoveStringLiteralDfa0_0();
- if (jjmatchedKind != 0x7fffffff)
- {
- if (jjmatchedPos + 1 < curPos)
- input_stream.backup(curPos - jjmatchedPos - 1);
- if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
- {
- matchedToken = jjFillToken();
- return matchedToken;
- }
- else
- {
- continue EOFLoop;
- }
- }
- int error_line = input_stream.getEndLine();
- int error_column = input_stream.getEndColumn();
- String error_after = null;
- boolean EOFSeen = false;
- try { input_stream.readChar(); input_stream.backup(1); }
- catch (java.io.IOException e1) {
- EOFSeen = true;
- error_after = curPos <= 1 ? "" : input_stream.GetImage();
- if (curChar == '\n' || curChar == '\r') {
- error_line++;
- error_column = 0;
- }
- else
- error_column++;
- }
- if (!EOFSeen) {
- input_stream.backup(1);
- error_after = curPos <= 1 ? "" : input_stream.GetImage();
- }
- throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
- }
-}
-
-private void jjCheckNAdd(int state)
-{
- if (jjrounds[state] != jjround)
- {
- jjstateSet[jjnewStateCnt++] = state;
- jjrounds[state] = jjround;
- }
-}
-private void jjAddStates(int start, int end)
-{
- do {
- jjstateSet[jjnewStateCnt++] = jjnextStates[start];
- } while (start++ != end);
-}
-private void jjCheckNAddTwoStates(int state1, int state2)
-{
- jjCheckNAdd(state1);
- jjCheckNAdd(state2);
-}
-
-private void jjCheckNAddStates(int start, int end)
-{
- do {
- jjCheckNAdd(jjnextStates[start]);
- } while (start++ != end);
-}
-
- /** Constructor. */
- public NginxConfigParserTokenManager(SimpleCharStream stream){
-
- if (SimpleCharStream.staticFlag)
- throw new Error("ERROR: Cannot use a static CharStream class with a non-static lexical analyzer.");
-
- input_stream = stream;
- }
-
- /** Constructor. */
- public NginxConfigParserTokenManager (SimpleCharStream stream, int lexState){
- ReInit(stream);
- SwitchTo(lexState);
- }
-
- /** Reinitialise parser. */
- public void ReInit(SimpleCharStream stream)
- {
- jjmatchedPos = jjnewStateCnt = 0;
- curLexState = defaultLexState;
- input_stream = stream;
- ReInitRounds();
- }
-
- private void ReInitRounds()
- {
- int i;
- jjround = 0x80000001;
- for (i = 20; i-- > 0;)
- jjrounds[i] = 0x80000000;
- }
-
- /** Reinitialise parser. */
- public void ReInit(SimpleCharStream stream, int lexState)
- {
- ReInit(stream);
- SwitchTo(lexState);
- }
-
- /** Switch to specified lex state. */
- public void SwitchTo(int lexState)
- {
- if (lexState >= 1 || lexState < 0)
- throw new TokenMgrError("Error: Ignoring invalid lexical state : " + lexState + ". State unchanged.", TokenMgrError.INVALID_LEXICAL_STATE);
- else
- curLexState = lexState;
- }
-
-/** Lexer state names. */
-public static final String[] lexStateNames = {
- "DEFAULT",
-};
-static final long[] jjtoToken = {
- 0x1ffe1L,
-};
-static final long[] jjtoSkip = {
- 0x1eL,
-};
- protected SimpleCharStream input_stream;
-
- private final int[] jjrounds = new int[20];
- private final int[] jjstateSet = new int[2 * 20];
-
-
- protected char curChar;
-}
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/ParseException.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/ParseException.java
deleted file mode 100644
index ea96571..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/ParseException.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright 2014 Alexey Plotnik
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 6.0 */
-/* JavaCCOptions:KEEP_LINE_COL=null */
-package com.github.odiszapc.nginxparser.javacc;
-
-/**
- * This exception is thrown when parse errors are encountered.
- * You can explicitly create objects of this exception type by
- * calling the method generateParseException in the generated
- * parser.
- *
- * You can modify this class to customize your error reporting
- * mechanisms so long as you retain the public fields.
- */
-public class ParseException extends Exception {
-
- /**
- * The version identifier for this Serializable class.
- * Increment only if the serialized form of the
- * class changes.
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * This constructor is used by the method "generateParseException"
- * in the generated parser. Calling this constructor generates
- * a new object of this type with the fields "currentToken",
- * "expectedTokenSequences", and "tokenImage" set.
- */
- public ParseException(Token currentTokenVal,
- int[][] expectedTokenSequencesVal,
- String[] tokenImageVal
- )
- {
- super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
- currentToken = currentTokenVal;
- expectedTokenSequences = expectedTokenSequencesVal;
- tokenImage = tokenImageVal;
- }
-
- /**
- * The following constructors are for use by you for whatever
- * purpose you can think of. Constructing the exception in this
- * manner makes the exception behave in the normal way - i.e., as
- * documented in the class "Throwable". The fields "errorToken",
- * "expectedTokenSequences", and "tokenImage" do not contain
- * relevant information. The JavaCC generated code does not use
- * these constructors.
- */
-
- public ParseException() {
- super();
- }
-
- /** Constructor with message. */
- public ParseException(String message) {
- super(message);
- }
-
-
- /**
- * This is the last token that has been consumed successfully. If
- * this object has been created due to a parse error, the token
- * followng this token will (therefore) be the first error token.
- */
- public Token currentToken;
-
- /**
- * Each entry in this array is an array of integers. Each array
- * of integers represents a sequence of tokens (by their ordinal
- * values) that is expected at this point of the parse.
- */
- public int[][] expectedTokenSequences;
-
- /**
- * This is a reference to the "tokenImage" array of the generated
- * parser within which the parse error occurred. This array is
- * defined in the generated ...Constants interface.
- */
- public String[] tokenImage;
-
- /**
- * It uses "currentToken" and "expectedTokenSequences" to generate a parse
- * error message and returns it. If this object has been created
- * due to a parse error, and you do not catch it (it gets thrown
- * from the parser) the correct error message
- * gets displayed.
- */
- private static String initialise(Token currentToken,
- int[][] expectedTokenSequences,
- String[] tokenImage) {
- String eol = System.getProperty("line.separator", "\n");
- StringBuffer expected = new StringBuffer();
- int maxSize = 0;
- for (int i = 0; i < expectedTokenSequences.length; i++) {
- if (maxSize < expectedTokenSequences[i].length) {
- maxSize = expectedTokenSequences[i].length;
- }
- for (int j = 0; j < expectedTokenSequences[i].length; j++) {
- expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
- }
- if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
- expected.append("...");
- }
- expected.append(eol).append(" ");
- }
- String retval = "Encountered \"";
- Token tok = currentToken.next;
- for (int i = 0; i < maxSize; i++) {
- if (i != 0) retval += " ";
- if (tok.kind == 0) {
- retval += tokenImage[0];
- break;
- }
- retval += " " + tokenImage[tok.kind];
- retval += " \"";
- retval += add_escapes(tok.image);
- retval += " \"";
- tok = tok.next;
- }
- retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
- retval += "." + eol;
- if (expectedTokenSequences.length == 1) {
- retval += "Was expecting:" + eol + " ";
- } else {
- retval += "Was expecting one of:" + eol + " ";
- }
- retval += expected.toString();
- return retval;
- }
-
- /**
- * The end of line string for this machine.
- */
- protected String eol = System.getProperty("line.separator", "\n");
-
- /**
- * Used to convert raw characters to their escaped version
- * when these raw version cannot be used as part of an ASCII
- * string literal.
- */
- static String add_escapes(String str) {
- StringBuffer retval = new StringBuffer();
- char ch;
- for (int i = 0; i < str.length(); i++) {
- switch (str.charAt(i))
- {
- case 0 :
- continue;
- case '\b':
- retval.append("\\b");
- continue;
- case '\t':
- retval.append("\\t");
- continue;
- case '\n':
- retval.append("\\n");
- continue;
- case '\f':
- retval.append("\\f");
- continue;
- case '\r':
- retval.append("\\r");
- continue;
- case '\"':
- retval.append("\\\"");
- continue;
- case '\'':
- retval.append("\\\'");
- continue;
- case '\\':
- retval.append("\\\\");
- continue;
- default:
- if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u" + s.substring(s.length() - 4, s.length()));
- } else {
- retval.append(ch);
- }
- continue;
- }
- }
- return retval.toString();
- }
-
-}
-/* JavaCC - OriginalChecksum=42e27b2a91e2c9ca72969cbdcda10071 (do not edit this line) */
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/SimpleCharStream.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/SimpleCharStream.java
deleted file mode 100644
index a33e8a1..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/SimpleCharStream.java
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
- * Copyright 2014 Alexey Plotnik
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 6.0 */
-/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
-package com.github.odiszapc.nginxparser.javacc;
-
-/**
- * An implementation of interface CharStream, where the stream is assumed to
- * contain only ASCII characters (without unicode processing).
- */
-
-public class SimpleCharStream
-{
-/** Whether parser is static. */
- public static final boolean staticFlag = false;
- int bufsize;
- int available;
- int tokenBegin;
-/** Position in buffer. */
- public int bufpos = -1;
- protected int bufline[];
- protected int bufcolumn[];
-
- protected int column = 0;
- protected int line = 1;
-
- protected boolean prevCharIsCR = false;
- protected boolean prevCharIsLF = false;
-
- protected java.io.Reader inputStream;
-
- protected char[] buffer;
- protected int maxNextCharInd = 0;
- protected int inBuf = 0;
- protected int tabSize = 8;
- protected boolean trackLineColumn = true;
-
- public void setTabSize(int i) { tabSize = i; }
- public int getTabSize() { return tabSize; }
-
-
- protected void ExpandBuff(boolean wrapAround)
- {
- char[] newbuffer = new char[bufsize + 2048];
- int newbufline[] = new int[bufsize + 2048];
- int newbufcolumn[] = new int[bufsize + 2048];
-
- try
- {
- if (wrapAround)
- {
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
- buffer = newbuffer;
-
- System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
- System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
- bufline = newbufline;
-
- System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
- System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
- bufcolumn = newbufcolumn;
-
- maxNextCharInd = (bufpos += (bufsize - tokenBegin));
- }
- else
- {
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- buffer = newbuffer;
-
- System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
- bufline = newbufline;
-
- System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
- bufcolumn = newbufcolumn;
-
- maxNextCharInd = (bufpos -= tokenBegin);
- }
- }
- catch (Throwable t)
- {
- throw new Error(t.getMessage());
- }
-
-
- bufsize += 2048;
- available = bufsize;
- tokenBegin = 0;
- }
-
- protected void FillBuff() throws java.io.IOException
- {
- if (maxNextCharInd == available)
- {
- if (available == bufsize)
- {
- if (tokenBegin > 2048)
- {
- bufpos = maxNextCharInd = 0;
- available = tokenBegin;
- }
- else if (tokenBegin < 0)
- bufpos = maxNextCharInd = 0;
- else
- ExpandBuff(false);
- }
- else if (available > tokenBegin)
- available = bufsize;
- else if ((tokenBegin - available) < 2048)
- ExpandBuff(true);
- else
- available = tokenBegin;
- }
-
- int i;
- try {
- if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1)
- {
- inputStream.close();
- throw new java.io.IOException();
- }
- else
- maxNextCharInd += i;
- return;
- }
- catch(java.io.IOException e) {
- --bufpos;
- backup(0);
- if (tokenBegin == -1)
- tokenBegin = bufpos;
- throw e;
- }
- }
-
-/** Start. */
- public char BeginToken() throws java.io.IOException
- {
- tokenBegin = -1;
- char c = readChar();
- tokenBegin = bufpos;
-
- return c;
- }
-
- protected void UpdateLineColumn(char c)
- {
- column++;
-
- if (prevCharIsLF)
- {
- prevCharIsLF = false;
- line += (column = 1);
- }
- else if (prevCharIsCR)
- {
- prevCharIsCR = false;
- if (c == '\n')
- {
- prevCharIsLF = true;
- }
- else
- line += (column = 1);
- }
-
- switch (c)
- {
- case '\r' :
- prevCharIsCR = true;
- break;
- case '\n' :
- prevCharIsLF = true;
- break;
- case '\t' :
- column--;
- column += (tabSize - (column % tabSize));
- break;
- default :
- break;
- }
-
- bufline[bufpos] = line;
- bufcolumn[bufpos] = column;
- }
-
-/** Read a character. */
- public char readChar() throws java.io.IOException
- {
- if (inBuf > 0)
- {
- --inBuf;
-
- if (++bufpos == bufsize)
- bufpos = 0;
-
- return buffer[bufpos];
- }
-
- if (++bufpos >= maxNextCharInd)
- FillBuff();
-
- char c = buffer[bufpos];
-
- UpdateLineColumn(c);
- return c;
- }
-
- @Deprecated
- /**
- * @deprecated
- * @see #getEndColumn
- */
-
- public int getColumn() {
- return bufcolumn[bufpos];
- }
-
- @Deprecated
- /**
- * @deprecated
- * @see #getEndLine
- */
-
- public int getLine() {
- return bufline[bufpos];
- }
-
- /** Get token end column number. */
- public int getEndColumn() {
- return bufcolumn[bufpos];
- }
-
- /** Get token end line number. */
- public int getEndLine() {
- return bufline[bufpos];
- }
-
- /** Get token beginning column number. */
- public int getBeginColumn() {
- return bufcolumn[tokenBegin];
- }
-
- /** Get token beginning line number. */
- public int getBeginLine() {
- return bufline[tokenBegin];
- }
-
-/** Backup a number of characters. */
- public void backup(int amount) {
-
- inBuf += amount;
- if ((bufpos -= amount) < 0)
- bufpos += bufsize;
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.Reader dstream, int startline,
- int startcolumn, int buffersize)
- {
- inputStream = dstream;
- line = startline;
- column = startcolumn - 1;
-
- available = bufsize = buffersize;
- buffer = new char[buffersize];
- bufline = new int[buffersize];
- bufcolumn = new int[buffersize];
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.Reader dstream, int startline,
- int startcolumn)
- {
- this(dstream, startline, startcolumn, 4096);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.Reader dstream)
- {
- this(dstream, 1, 1, 4096);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.Reader dstream, int startline,
- int startcolumn, int buffersize)
- {
- inputStream = dstream;
- line = startline;
- column = startcolumn - 1;
-
- if (buffer == null || buffersize != buffer.length)
- {
- available = bufsize = buffersize;
- buffer = new char[buffersize];
- bufline = new int[buffersize];
- bufcolumn = new int[buffersize];
- }
- prevCharIsLF = prevCharIsCR = false;
- tokenBegin = inBuf = maxNextCharInd = 0;
- bufpos = -1;
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.Reader dstream, int startline,
- int startcolumn)
- {
- ReInit(dstream, startline, startcolumn, 4096);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.Reader dstream)
- {
- ReInit(dstream, 1, 1, 4096);
- }
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
- {
- this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream, int startline,
- int startcolumn, int buffersize)
- {
- this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn) throws java.io.UnsupportedEncodingException
- {
- this(dstream, encoding, startline, startcolumn, 4096);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream, int startline,
- int startcolumn)
- {
- this(dstream, startline, startcolumn, 4096);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
- {
- this(dstream, encoding, 1, 1, 4096);
- }
-
- /** Constructor. */
- public SimpleCharStream(java.io.InputStream dstream)
- {
- this(dstream, 1, 1, 4096);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
- {
- ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, int startline,
- int startcolumn, int buffersize)
- {
- ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
- {
- ReInit(dstream, encoding, 1, 1, 4096);
- }
-
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream)
- {
- ReInit(dstream, 1, 1, 4096);
- }
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn) throws java.io.UnsupportedEncodingException
- {
- ReInit(dstream, encoding, startline, startcolumn, 4096);
- }
- /** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, int startline,
- int startcolumn)
- {
- ReInit(dstream, startline, startcolumn, 4096);
- }
- /** Get token literal value. */
- public String GetImage()
- {
- if (bufpos >= tokenBegin)
- return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
- else
- return new String(buffer, tokenBegin, bufsize - tokenBegin) +
- new String(buffer, 0, bufpos + 1);
- }
-
- /** Get the suffix. */
- public char[] GetSuffix(int len)
- {
- char[] ret = new char[len];
-
- if ((bufpos + 1) >= len)
- System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
- else
- {
- System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
- len - bufpos - 1);
- System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
- }
-
- return ret;
- }
-
- /** Reset buffer when finished. */
- public void Done()
- {
- buffer = null;
- bufline = null;
- bufcolumn = null;
- }
-
- /**
- * Method to adjust line and column numbers for the start of a token.
- */
- public void adjustBeginLineColumn(int newLine, int newCol)
- {
- int start = tokenBegin;
- int len;
-
- if (bufpos >= tokenBegin)
- {
- len = bufpos - tokenBegin + inBuf + 1;
- }
- else
- {
- len = bufsize - tokenBegin + bufpos + 1 + inBuf;
- }
-
- int i = 0, j = 0, k = 0;
- int nextColDiff = 0, columnDiff = 0;
-
- while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
- {
- bufline[j] = newLine;
- nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
- bufcolumn[j] = newCol + columnDiff;
- columnDiff = nextColDiff;
- i++;
- }
-
- if (i < len)
- {
- bufline[j] = newLine++;
- bufcolumn[j] = newCol + columnDiff;
-
- while (i++ < len)
- {
- if (bufline[j = start % bufsize] != bufline[++start % bufsize])
- bufline[j] = newLine++;
- else
- bufline[j] = newLine;
- }
- }
-
- line = bufline[j];
- column = bufcolumn[j];
- }
-
- boolean getTrackLineColumn() { return trackLineColumn; }
- void setTrackLineColumn(boolean tlc) { trackLineColumn = tlc; }
-}
-/* JavaCC - OriginalChecksum=c5fb9c6097675098012d33ed3750e072 (do not edit this line) */
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/Token.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/Token.java
deleted file mode 100644
index 2f09b2c..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/Token.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2014 Alexey Plotnik
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Generated By:JavaCC: Do not edit this line. Token.java Version 6.0 */
-/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
-package com.github.odiszapc.nginxparser.javacc;
-
-/**
- * Describes the input token stream.
- */
-
-public class Token implements java.io.Serializable {
-
- /**
- * The version identifier for this Serializable class.
- * Increment only if the serialized form of the
- * class changes.
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * An integer that describes the kind of this token. This numbering
- * system is determined by JavaCCParser, and a table of these numbers is
- * stored in the file ...Constants.java.
- */
- public int kind;
-
- /** The line number of the first character of this Token. */
- public int beginLine;
- /** The column number of the first character of this Token. */
- public int beginColumn;
- /** The line number of the last character of this Token. */
- public int endLine;
- /** The column number of the last character of this Token. */
- public int endColumn;
-
- /**
- * The string image of the token.
- */
- public String image;
-
- /**
- * A reference to the next regular (non-special) token from the input
- * stream. If this is the last token from the input stream, or if the
- * token manager has not read tokens beyond this one, this field is
- * set to null. This is true only if this token is also a regular
- * token. Otherwise, see below for a description of the contents of
- * this field.
- */
- public Token next;
-
- /**
- * This field is used to access special tokens that occur prior to this
- * token, but after the immediately preceding regular (non-special) token.
- * If there are no such special tokens, this field is set to null.
- * When there are more than one such special token, this field refers
- * to the last of these special tokens, which in turn refers to the next
- * previous special token through its specialToken field, and so on
- * until the first special token (whose specialToken field is null).
- * The next fields of special tokens refer to other special tokens that
- * immediately follow it (without an intervening regular token). If there
- * is no such token, this field is null.
- */
- public Token specialToken;
-
- /**
- * An optional attribute value of the Token.
- * Tokens which are not used as syntactic sugar will often contain
- * meaningful values that will be used later on by the compiler or
- * interpreter. This attribute value is often different from the image.
- * Any subclass of Token that actually wants to return a non-null value can
- * override this method as appropriate.
- */
- public Object getValue() {
- return null;
- }
-
- /**
- * No-argument constructor
- */
- public Token() {}
-
- /**
- * Constructs a new token for the specified Image.
- */
- public Token(int kind)
- {
- this(kind, null);
- }
-
- /**
- * Constructs a new token for the specified Image and Kind.
- */
- public Token(int kind, String image)
- {
- this.kind = kind;
- this.image = image;
- }
-
- /**
- * Returns the image.
- */
- public String toString()
- {
- return image;
- }
-
- /**
- * Returns a new Token object, by default. However, if you want, you
- * can create and return subclass objects based on the value of ofKind.
- * Simply add the cases to the switch for all those special cases.
- * For example, if you have a subclass of Token called IDToken that
- * you want to create if ofKind is ID, simply add something like :
- *
- * case MyParserConstants.ID : return new IDToken(ofKind, image);
- *
- * to the following switch statement. Then you can cast matchedToken
- * variable to the appropriate type and use sit in your lexical actions.
- */
- public static Token newToken(int ofKind, String image)
- {
- switch(ofKind)
- {
- default : return new Token(ofKind, image);
- }
- }
-
- public static Token newToken(int ofKind)
- {
- return newToken(ofKind, null);
- }
-
-}
-/* JavaCC - OriginalChecksum=b8649760b6928b6fdb5df5faf087ef02 (do not edit this line) */
diff --git a/src/main/java/com/github/odiszapc/nginxparser/javacc/TokenMgrError.java b/src/main/java/com/github/odiszapc/nginxparser/javacc/TokenMgrError.java
deleted file mode 100644
index 88ccd19..0000000
--- a/src/main/java/com/github/odiszapc/nginxparser/javacc/TokenMgrError.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright 2014 Alexey Plotnik
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 6.0 */
-/* JavaCCOptions: */
-package com.github.odiszapc.nginxparser.javacc;
-
-/** Token Manager Error. */
-public class TokenMgrError extends Error
-{
-
- /**
- * The version identifier for this Serializable class.
- * Increment only if the serialized form of the
- * class changes.
- */
- private static final long serialVersionUID = 1L;
-
- /*
- * Ordinals for various reasons why an Error of this type can be thrown.
- */
-
- /**
- * Lexical error occurred.
- */
- static final int LEXICAL_ERROR = 0;
-
- /**
- * An attempt was made to create a second instance of a static token manager.
- */
- static final int STATIC_LEXER_ERROR = 1;
-
- /**
- * Tried to change to an invalid lexical state.
- */
- static final int INVALID_LEXICAL_STATE = 2;
-
- /**
- * Detected (and bailed out of) an infinite loop in the token manager.
- */
- static final int LOOP_DETECTED = 3;
-
- /**
- * Indicates the reason why the exception is thrown. It will have
- * one of the above 4 values.
- */
- int errorCode;
-
- /**
- * Replaces unprintable characters by their escaped (or unicode escaped)
- * equivalents in the given string
- */
- protected static final String addEscapes(String str) {
- StringBuffer retval = new StringBuffer();
- char ch;
- for (int i = 0; i < str.length(); i++) {
- switch (str.charAt(i))
- {
- case 0 :
- continue;
- case '\b':
- retval.append("\\b");
- continue;
- case '\t':
- retval.append("\\t");
- continue;
- case '\n':
- retval.append("\\n");
- continue;
- case '\f':
- retval.append("\\f");
- continue;
- case '\r':
- retval.append("\\r");
- continue;
- case '\"':
- retval.append("\\\"");
- continue;
- case '\'':
- retval.append("\\\'");
- continue;
- case '\\':
- retval.append("\\\\");
- continue;
- default:
- if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
- String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u" + s.substring(s.length() - 4, s.length()));
- } else {
- retval.append(ch);
- }
- continue;
- }
- }
- return retval.toString();
- }
-
- /**
- * Returns a detailed message for the Error when it is thrown by the
- * token manager to indicate a lexical error.
- * Parameters :
- * EOFSeen : indicates if EOF caused the lexical error
- * curLexState : lexical state in which this error occurred
- * errorLine : line number when the error occurred
- * errorColumn : column number when the error occurred
- * errorAfter : prefix that was seen before this error occurred
- * curchar : the offending character
- * Note: You can customize the lexical error message by modifying this method.
- */
- protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
- return("Lexical error at line " +
- errorLine + ", column " +
- errorColumn + ". Encountered: " +
- (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
- "after : \"" + addEscapes(errorAfter) + "\"");
- }
-
- /**
- * You can also modify the body of this method to customize your error messages.
- * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
- * of end-users concern, so you can return something like :
- *
- * "Internal Error : Please file a bug report .... "
- *
- * from this method for such cases in the release version of your parser.
- */
- public String getMessage() {
- return super.getMessage();
- }
-
- /*
- * Constructors of various flavors follow.
- */
-
- /** No arg constructor. */
- public TokenMgrError() {
- }
-
- /** Constructor with message and reason. */
- public TokenMgrError(String message, int reason) {
- super(message);
- errorCode = reason;
- }
-
- /** Full Constructor. */
- public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
- this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
- }
-}
-/* JavaCC - OriginalChecksum=5f0ac55433b166fece155f995c9aa2a9 (do not edit this line) */
diff --git a/src/main/resources/grammar/grammar.jj b/src/main/resources/grammar/grammar.jj
deleted file mode 100644
index 814cb75..0000000
--- a/src/main/resources/grammar/grammar.jj
+++ /dev/null
@@ -1,330 +0,0 @@
-options
-{
- FORCE_LA_CHECK = true;
- STATIC = false;
-}
-
-PARSER_BEGIN(NginxConfigParser)
-
-package com.github.odiszapc.nginxparser.parser;
-import com.github.odiszapc.nginxparser.*;
-@SuppressWarnings("ConstantConditions")
-public class NginxConfigParser
-{
- private boolean isDebug = false;
-
- public void setDebug(boolean val) {
- isDebug = val;
- }
-
- private void debug(String message) {
- debug(message, false);
- }
-
- private void debugLn(String message) {
- debug(message, true);
- }
-
- private void debug(String message, boolean appendLineEnding) {
- if (isDebug) {
- System.out.print(message);
- if (appendLineEnding) System.out.println();
- }
- }
-}
-
-PARSER_END(NginxConfigParser)
-
-SKIP :
-{
- " "
-| "\t"
-| "\r"
-| "\n"
-}
-
-
-/* SEPARATORS */
-
-TOKEN:
-{
- < LPAREN: "(" >
- | < RPAREN: ")" >
- | < LBRACE: "{" >
- | < RBRACE: "}" >
- | < SEMICOLON: ";">
-}
-
-
-TOKEN:
-{
- < IF: "if">
- | < IF_BODY: (~[")"])+>
- | < NUMBER: ["1"-"9"] (["0"-"9"])* >
- | < STRING: (["0"-"9", "a"-"z", "A"-"Z",
- "_", "/", ".", "-", ":", "=", "~",
- "(", ")", "+", "?", "$", "&", "^", "*", "@", "\\", "|"])+>
- |
- < QUOTED_STRING:
- "\""
- (
- (~["\"","\\"])
- |
- ("\\"
- ( ["n","t","b","r","f","\\","'","\""]
- | ["0"-"7"] ( ["0"-"7"] )?
- | ["0"-"3"] ["0"-"7"] ["0"-"7"]
- )
- )
- )*
- "\""
- >
- | < SINGLE_QUOTED_STRING: "'" (~["'"])* "'" >
-}
-
-TOKEN:
-{
- >
- | <#COMMENT_SIGN: "#">
- | <#COMMENT_BODY: (~["\n", "\r"])*>
-}
-
-
-/*
- Main method
-*/
-NgxConfig parse():
-{
- NgxConfig config;
-}
-{
- config=statements()
- {
- return config;
- }
-}
-
-
-NgxConfig statements():
-{
- NgxConfig config = new NgxConfig();
- NgxEntry curEntry;
-}
-{
- (
- (
- LOOKAHEAD (4)
- curEntry=param()
- | curEntry=block()
- | curEntry=comment()
- )
- {
- config.addEntry(curEntry);
- }
- )*
- {
- return config;
- }
-}
-
-
-/*
- Block
-
- Example:
- http {
- ...
- }
-*/
-NgxBlock block():
-{
- String blockName = "";
- NgxBlock block = new NgxBlock();
- NgxToken curToken;
- NgxEntry curEntry;
-}
-{
- curToken=id()
- {
- blockName += token.image+" ";
- block.getTokens().add(curToken);
- }
-
- (
- curToken=id()
- {
- blockName += token.image+" ";
- block.getTokens().add(curToken);
- }
- )*
- {
- debugLn("BLOCK=" + blockName + "{");
- }
-
- (
- (
- LOOKAHEAD (4)
- curEntry=param()
- | curEntry=block()
- | curEntry=comment()
- | curEntry=if_block()
- )
- {
- block.addEntry(curEntry);
- }
- )*
-
- {
- debugLn("}");
- return block;
- }
-}
-
-/*
- "if" statement
-
- Example:
- if ($arg_val !~ '^\d+$') {
- return 400;
- break;
- }
-*/
-NgxBlock if_block():
-{
- NgxIfBlock block = new NgxIfBlock();
- NgxEntry curEntry = null;
-}
-{
-
- {
- debug(token.image + " ");
- block.addValue(new NgxToken(token.image));
- }
-
-
- {
- debug(token.image + " ");
- block.addValue(new NgxToken(token.image));
- }
-
-
- {
- debugLn(token.image);
- }
-
- (
- (
- LOOKAHEAD (4)
- curEntry=param()
- | curEntry=block()
- | curEntry=comment()
- )
- {
- block.addEntry(curEntry);
- }
- )*
-
- {
- debugLn(token.image);
- return block;
- }
-}
-
-/*
- Single line parameter
-
- Examples:
- listen 80;
- server_name localhost;
- root /var/www;
- index index.html index.htm;
- array_map '[$array_it]' $list;
- echo_exec /safe-memc?cmd=incr&key=$arg_key&val=$arg_val;
-*/
-NgxParam param():
-{
- NgxParam param = new NgxParam();
- NgxToken curToken = null;
-}
-{
- curToken=id()
- {
- debug("KEY=" + token.image +", VALUE=");
- param.getTokens().add(curToken);
- }
-
- (
- curToken=value()
- {
- debug(token.image + " | ");
- param.getTokens().add(curToken);
- }
- )*
-
- {
- debugLn("");
- }
-
- {
- return param;
- }
-}
-
-/*
- Comment
- Example:
- # Comment here
-*/
-NgxComment comment():
-{
- NgxComment comment;
-}
-{
-
- {
- debugLn("COMMENT=" + token.image);
- return new NgxComment(token.image);
- }
-}
-
-/*
- Parameter/block names and/or values
- Example:
- # id occurs 6 times
- gzip_types text/plain application/xml application/x-javascript text/css application/json;
-
-*/
-NgxToken id():
-{
- NgxToken val = null;
-}
-{
- (
-
- |
- |
- )
- {
- return new NgxToken(token.image);;
- }
-}
-
-/*
- Parameter values
-*/
-NgxToken value():
-{
- NgxToken val = null;
-}
-{
- (
-
- |
- |
- |
- )
- {
- return new NgxToken(token.image);;
- }
-}
-
diff --git a/src/test/java/com/github/odiszapc/nginxparser/NestedTest.java b/src/test/java/com/github/odiszapc/nginxparser/NestedTest.java
index cdc8e36..022f999 100644
--- a/src/test/java/com/github/odiszapc/nginxparser/NestedTest.java
+++ b/src/test/java/com/github/odiszapc/nginxparser/NestedTest.java
@@ -16,7 +16,6 @@
package com.github.odiszapc.nginxparser;
-import org.junit.Assert;
import org.junit.Test;
import java.util.Iterator;
diff --git a/src/test/java/com/github/odiszapc/nginxparser/TestUtils.java b/src/test/java/com/github/odiszapc/nginxparser/TestUtils.java
index 707ac92..50e3e65 100644
--- a/src/test/java/com/github/odiszapc/nginxparser/TestUtils.java
+++ b/src/test/java/com/github/odiszapc/nginxparser/TestUtils.java
@@ -22,10 +22,6 @@
import java.util.Iterator;
public class TestUtils {
- public static NgxConfig parseJavaCC(String path) throws Exception {
- InputStream input = getStream(path);
- return NgxConfig.readJavaCC(input);
- }
public static NgxConfig parseAntlr(String path) throws Exception {
return NgxConfig.read(getStream(path));
@@ -78,8 +74,7 @@ public static NgxIfBlock assertIfBlock(NgxEntry entry, String name, String... va
return (NgxIfBlock) entry;
}
- @SuppressWarnings("UnusedReturnValue")
- public static NgxComment assertComment(NgxEntry entry, @SuppressWarnings("SameParameterValue") String value) {
+ public static NgxComment assertComment(NgxEntry entry, String value) {
Assert.assertTrue(entry instanceof NgxComment);
Assert.assertEquals(((NgxComment) entry).getValue(), value);
return (NgxComment) entry;