Skip to content

Apache Lucene open-source search software

LUCENE-9134: Port ant-regenerate tasks to Gradle build (#1230)

Erick Ericksonb0bb299dc42a
diff --git a/gradle/generation/javacc.gradle b/gradle/generation/javacc.gradle
index 9a21b556cfe..ff9311730b0 100644
--- a/gradle/generation/javacc.gradle
+++ b/gradle/generation/javacc.gradle
@@ -33,6 +33,7 @@ configure(rootProject) {
dependsOn ":lucene:queryparser:javaccParserClassic"
dependsOn ":lucene:queryparser:javaccParserSurround"
dependsOn ":lucene:queryparser:javaccParserFlexible"
+ dependsOn ":solr:core:javaccSolrParser"
}
}
@@ -128,7 +129,7 @@ class JavaCCTask extends DefaultTask {
configure(project(":lucene:queryparser")) {
task javaccParserClassic(type: JavaCCTask) {
- description "Regenerate classic query parser from java CC.java"
+ description "Regenerate classic query parser from lucene/queryparser/classic/QueryParser.jj"
group "generation"
javaccFile = file('src/java/org/apache/lucene/queryparser/classic/QueryParser.jj')
@@ -185,7 +186,7 @@ configure(project(":lucene:queryparser")) {
configure(project(":lucene:queryparser")) {
task javaccParserSurround(type: JavaCCTask) {
- description "Regenerate surround query parser from java CC.java"
+ description "Regenerate surround query parser from lucene/queryparser/surround/parser/QueryParser.jj"
group "generation"
javaccFile = file('src/java/org/apache/lucene/queryparser/surround/parser/QueryParser.jj')
@@ -228,13 +229,12 @@ configure(project(":lucene:queryparser")) {
replace: "",
encoding: "UTF-8")
}
-
}
}
}
configure(project(":lucene:queryparser")) {
task javaccParserFlexible(type: JavaCCTask) {
- description "Regenerate Flexible query parser from java CC.java"
+ description "Regenerate Flexible query parser from queryparser/flexible/standard/parser/StandardSyntaxParser.jj"
group "generation"
javaccFile = file('src/java/org/apache/lucene/queryparser/flexible/standard/parser/StandardSyntaxParser.jj')
@@ -336,4 +336,50 @@ configure(project(":lucene:queryparser")) {
}
}
}
-}
\ No newline at end of file
+}
+configure(project(":solr:core")) {
+ task javaccSolrParser(type: JavaCCTask) {
+ description "Regenerate Solr query parser from solr/parser/QueryParser.jj"
+ group "generation"
+
+ javaccFile = file('src/java/org/apache/solr/parser/QueryParser.jj')
+
+ doLast {
+ def separator = System.getProperty('line.separator')
+ def parentDir = javaccFile.parentFile
+
+ [/import java\.io\.StringReader;/,
+ /import java\.util\.ArrayList;/,
+ /import java\.util\.Arrays;/,
+ /import java\.util\.HashSet;/,
+ /import java\.util\.List;/,
+ /import java\.util\.Set;/,
+ /import org\.apache\.lucene\.analysis\.Analyzer;/,
+ /import org\.apache\.lucene\.search\.BooleanClause;/,
+ /import org\.apache\.lucene\.search\.Query;/,
+ /import org\.apache\.solr\.search\.SyntaxError;/,
+ /import org\.apache\.solr\.search\.QParser;/
+ ].each {
+ ant.replaceregexp(file: file("${parentDir}/QueryParserTokenManager.java"),
+ match: "${it}\\s*${separator}",
+ replace: "",
+ encoding: "UTF-8")
+ }
+
+ ant.replace(file: "${parentDir}/QueryParser.java",
+ token: "public QueryParser(CharStream ",
+ value: "protected QueryParser(CharStream ",
+ encoding: "UTF-8")
+
+ ant.replace(file: "${parentDir}/QueryParser.java",
+ token: "public QueryParser(QueryParserTokenManager ",
+ value: "protected QueryParser(QueryParserTokenManager ",
+ encoding: "UTF-8")
+
+ ant.replace(file: "${parentDir}/QueryParser.java",
+ token: "final private LookaheadSuccess jj_ls =",
+ value: "static final private LookaheadSuccess jj_ls =",
+ encoding: "UTF-8")
+ }
+ }
+}
diff --git a/solr/core/src/java/org/apache/solr/parser/CharStream.java b/solr/core/src/java/org/apache/solr/parser/CharStream.java
index 9bec5a6e9d5..c83353ba447 100644
--- a/solr/core/src/java/org/apache/solr/parser/CharStream.java
+++ b/solr/core/src/java/org/apache/solr/parser/CharStream.java
@@ -27,6 +27,22 @@ interface CharStream {
*/
char readChar() throws java.io.IOException;
+ @Deprecated
+ /**
+ * Returns the column position of the character last read.
+ * @deprecated
+ * @see #getEndColumn
+ */
+ int getColumn();
+
+ @Deprecated
+ /**
+ * Returns the line number of the character last read.
+ * @deprecated
+ * @see #getEndLine
+ */
+ int getLine();
+
/**
* Returns the column number of the last character for current token (being
* matched after the last call to BeginTOken).
@@ -55,7 +71,7 @@ interface CharStream {
* Backs up the input stream by amount steps. Lexer calls this method if it
* had already read some characters, but could not use them to match a
* (longer) token. So, they will be used again as the prefix of the next
- * token and it is the implemetation's responsibility to do this right.
+ * token and it is the implementation's responsibility to do this right.
*/
void backup(int amount);
diff --git a/solr/core/src/java/org/apache/solr/parser/FastCharStream.java b/solr/core/src/java/org/apache/solr/parser/FastCharStream.java
index b9cb27abd9d..d2fb50fb1ef 100644
--- a/solr/core/src/java/org/apache/solr/parser/FastCharStream.java
+++ b/solr/core/src/java/org/apache/solr/parser/FastCharStream.java
@@ -109,7 +109,14 @@ public final class FastCharStream implements CharStream {
} catch (IOException e) {
}
}
-
+ @Override
+ public final int getLine() {
+ return 1;
+ }
+ @Override
+ public final int getColumn() {
+ return bufferStart + bufferPosition;
+ }
@Override
public final int getEndColumn() {
return bufferStart + bufferPosition;
diff --git a/solr/core/src/java/org/apache/solr/parser/ParseException.java b/solr/core/src/java/org/apache/solr/parser/ParseException.java
index 6806d6a0041..7732a7d5295 100644
--- a/solr/core/src/java/org/apache/solr/parser/ParseException.java
+++ b/solr/core/src/java/org/apache/solr/parser/ParseException.java
@@ -173,7 +173,7 @@ public class ParseException extends Exception {
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u").append(s.substring(s.length() - 4, s.length()));
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParser.java b/solr/core/src/java/org/apache/solr/parser/QueryParser.java
index 518cdefaa79..f2b792e46b0 100644
--- a/solr/core/src/java/org/apache/solr/parser/QueryParser.java
+++ b/solr/core/src/java/org/apache/solr/parser/QueryParser.java
@@ -52,14 +52,16 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
@Override
protected Query newFieldQuery(Analyzer analyzer, String field, String queryText,
- boolean quoted, boolean fieldAutoGenPhraseQueries, boolean fieldEnableGraphQueries,
- SynonymQueryStyle synonymQueryStyle)
+ boolean quoted, boolean fieldAutoGenPhraseQueries,
+ boolean fieldEnableGraphQueries,
+ SynonymQueryStyle synonymQueryStyle)
throws SyntaxError {
setAutoGenerateMultiTermSynonymsPhraseQuery(fieldAutoGenPhraseQueries || getAutoGeneratePhraseQueries());
// Don't auto-quote graph-aware field queries
boolean treatAsQuoted = getSplitOnWhitespace()
? (quoted || fieldAutoGenPhraseQueries || getAutoGeneratePhraseQueries()) : quoted;
- return super.newFieldQuery(analyzer, field, queryText, treatAsQuoted, false, fieldEnableGraphQueries, synonymQueryStyle);
+ return super.newFieldQuery(analyzer, field, queryText, treatAsQuoted, false,
+ fieldEnableGraphQueries, synonymQueryStyle);
}
// * Query ::= ( Clause )*
@@ -616,22 +618,6 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
finally { jj_save(2, xla); }
}
- private boolean jj_3R_7() {
- if (jj_scan_token(TERM)) return true;
- return false;
- }
-
- private boolean jj_3R_4() {
- if (jj_scan_token(TERM)) return true;
- if (jj_scan_token(COLON)) return true;
- return false;
- }
-
- private boolean jj_3_1() {
- if (jj_3R_3()) return true;
- return false;
- }
-
private boolean jj_3R_6() {
return false;
}
@@ -672,6 +658,22 @@ public class QueryParser extends SolrQueryParserBase implements QueryParserConst
return false;
}
+ private boolean jj_3R_7() {
+ if (jj_scan_token(TERM)) return true;
+ return false;
+ }
+
+ private boolean jj_3R_4() {
+ if (jj_scan_token(TERM)) return true;
+ if (jj_scan_token(COLON)) return true;
+ return false;
+ }
+
+ private boolean jj_3_1() {
+ if (jj_3R_3()) return true;
+ return false;
+ }
+
/** Generated Token Manager. */
public QueryParserTokenManager token_source;
/** Current token. */
diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParser.jj b/solr/core/src/java/org/apache/solr/parser/QueryParser.jj
index 58adcd9bc58..1da42dfd92f 100644
--- a/solr/core/src/java/org/apache/solr/parser/QueryParser.jj
+++ b/solr/core/src/java/org/apache/solr/parser/QueryParser.jj
@@ -76,13 +76,16 @@ public class QueryParser extends SolrQueryParserBase {
@Override
protected Query newFieldQuery(Analyzer analyzer, String field, String queryText,
- boolean quoted, boolean fieldAutoGenPhraseQueries, boolean fieldEnableGraphQueries)
+ boolean quoted, boolean fieldAutoGenPhraseQueries,
+ boolean fieldEnableGraphQueries,
+ SynonymQueryStyle synonymQueryStyle)
throws SyntaxError {
setAutoGenerateMultiTermSynonymsPhraseQuery(fieldAutoGenPhraseQueries || getAutoGeneratePhraseQueries());
// Don't auto-quote graph-aware field queries
boolean treatAsQuoted = getSplitOnWhitespace()
? (quoted || fieldAutoGenPhraseQueries || getAutoGeneratePhraseQueries()) : quoted;
- return super.newFieldQuery(analyzer, field, queryText, treatAsQuoted, false, fieldEnableGraphQueries);
+ return super.newFieldQuery(analyzer, field, queryText, treatAsQuoted, false,
+ fieldEnableGraphQueries, synonymQueryStyle);
}
}
diff --git a/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java b/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java
index 16676431a1f..cf0c02f487b 100644
--- a/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java
+++ b/solr/core/src/java/org/apache/solr/parser/QueryParserTokenManager.java
@@ -1,11 +1,11 @@
/* Generated By:JavaCC: Do not edit this line. QueryParserTokenManager.java */
package org.apache.solr.parser;
-
/** Token Manager. */
public class QueryParserTokenManager implements QueryParserConstants
{
int commentNestingDepth ;
+
private final int jjStopStringLiteralDfa_3(int pos, long active0)
{
switch (pos)
@@ -761,7 +761,7 @@ private int jjMoveNfa_3(int startState, int curPos)
}
else
{
- int hiByte = (int)(curChar >> 8);
+ int hiByte = curChar >> 8;
int i1 = hiByte >> 6;
long l1 = 1L << (hiByte & 077);
int i2 = (curChar & 0xff) >> 6;
@@ -1001,7 +1001,7 @@ private int jjMoveNfa_2(int startState, int curPos)
}
else
{
- int hiByte = (int)(curChar >> 8);
+ int hiByte = curChar >> 8;
int i1 = hiByte >> 6;
long l1 = 1L << (hiByte & 077);
int i2 = (curChar & 0xff) >> 6;
@@ -1104,7 +1104,7 @@ private int jjMoveNfa_0(int startState, int curPos)
}
else
{
- int hiByte = (int)(curChar >> 8);
+ int hiByte = curChar >> 8;
int i1 = hiByte >> 6;
long l1 = 1L << (hiByte & 077);
int i2 = (curChar & 0xff) >> 6;
@@ -1277,7 +1277,7 @@ private int jjMoveNfa_1(int startState, int curPos)
}
else
{
- int hiByte = (int)(curChar >> 8);
+ int hiByte = curChar >> 8;
int i1 = hiByte >> 6;
long l1 = 1L << (hiByte & 077);
int i2 = (curChar & 0xff) >> 6;
@@ -1328,9 +1328,9 @@ private int jjMoveNfa_1(int startState, int curPos)
}
}
static final int[] jjnextStates = {
- 32, 34, 35, 31, 36, 17, 18, 20, 56, 59, 25, 60, 57, 59, 25, 60,
- 22, 23, 38, 39, 46, 38, 39, 40, 46, 38, 39, 41, 49, 54, 46, 42,
- 43, 45, 50, 51, 53, 38, 39, 54, 46, 58, 61, 29, 2, 4, 5,
+ 32, 34, 35, 31, 36, 17, 18, 20, 56, 59, 25, 60, 57, 59, 25, 60,
+ 22, 23, 38, 39, 46, 38, 39, 40, 46, 38, 39, 41, 49, 54, 46, 42,
+ 43, 45, 50, 51, 53, 38, 39, 54, 46, 58, 61, 29, 2, 4, 5,
};
private static final boolean jjCanMove_0(int hiByte, int i1, int i2, long l1, long l2)
{
@@ -1371,9 +1371,9 @@ private static final boolean jjCanMove_2(int hiByte, int i1, int i2, long l1, lo
/** Token literal values. */
public static final String[] jjstrLiteralImages = {
-"", null, null, null, null, null, null, null, null, null, null, null, null,
-null, null, null, "\53", "\55", null, "\50", "\51", "\72", "\52", "\136", null, null,
-null, null, null, null, "\133", "\173", null, "\146\151\154\164\145\162\50", null,
+"", null, null, null, null, null, null, null, null, null, null, null, null,
+null, null, null, "\53", "\55", null, "\50", "\51", "\72", "\52", "\136", null, null,
+null, null, null, null, "\133", "\173", null, "\146\151\154\164\145\162\50", null,
"\124\117", "\135", "\175", null, null, };
/** Lexer state names. */
@@ -1386,14 +1386,14 @@ public static final String[] lexStateNames = {
/** Lex State array. */
public static final int[] jjnewLexState = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,
- -1, -1, -1, -1, -1, 1, 1, -1, -1, 3, -1, 3, 3, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1,
+ -1, -1, -1, -1, -1, 1, 1, -1, -1, 3, -1, 3, 3, -1, -1,
};
static final long[] jjtoToken = {
- 0xffffffe001L,
+ 0xffffffe001L,
};
static final long[] jjtoSkip = {
- 0x1f00L,
+ 0x1f00L,
};
protected CharStream input_stream;
private final int[] jjrounds = new int[63];
@@ -1478,7 +1478,7 @@ int jjmatchedPos;
int jjmatchedKind;
/** Get the next Token. */
-public Token getNextToken()
+public Token getNextToken()
{
Token matchedToken;
int curPos = 0;
diff --git a/solr/core/src/java/org/apache/solr/parser/TokenMgrError.java b/solr/core/src/java/org/apache/solr/parser/TokenMgrError.java
index e50936f46ed..ecdcc539d66 100644
--- a/solr/core/src/java/org/apache/solr/parser/TokenMgrError.java
+++ b/solr/core/src/java/org/apache/solr/parser/TokenMgrError.java
@@ -82,7 +82,7 @@ public class TokenMgrError extends Error
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
- retval.append("\\u").append(s.substring(s.length() - 4, s.length()));
+ retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}