Skip to content

Commit

Permalink
Refactor AccumuloSyntaxParserConstants so it is not an interface
Browse files Browse the repository at this point in the history
Refactor AccumuloSyntaxParserConstants so that it is not an interface
that consists solely of constants, but is rather a final, uninstantiable
class with constants. While not strictly an issue, it is odd for
AccumuloSyntaxParser and AccumuloSyntaxParserTokenManager to both be
considered implementations of AccumuloSyntaxParserConstants.

Closes #2739
  • Loading branch information
lbschanno committed Feb 6, 2025
1 parent 3da91f1 commit 35ee1f8
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 56 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
/* Generated By:JavaCC: Do not edit this line. AccumuloSyntaxParser.java */
package datawave.query.language.parser.lucene;

import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.AND;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.CARAT;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.FUNCTION;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.FUZZY_SLOP;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.LPAREN;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.NOT;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.NUMBER;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.OP_COLON;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.OR;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.QUOTED;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGEEX_END;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGEEX_START;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGEIN_END;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGEIN_START;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGE_GOOP;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGE_QUOTED;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RANGE_TO;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.REGEXPTERM;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.RPAREN;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.TERM;
import static datawave.query.language.parser.lucene.AccumuloSyntaxParserConstants.tokenImage;

import java.io.StringReader;
import java.util.Vector;

Expand Down Expand Up @@ -42,7 +64,7 @@
import org.apache.lucene.queryparser.flexible.standard.nodes.TermRangeQueryNode;

@SuppressWarnings("all")
public class AccumuloSyntaxParser implements SyntaxParser, AcumuloSyntaxParserConstants {
public class AccumuloSyntaxParser implements SyntaxParser {

private static final int CONJ_NONE = 0;
private static final int CONJ_AND = 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* Generated By:JavaCC: Do not edit this line. AccumuloSyntaxParserConstants.java */
package datawave.query.language.parser.lucene;

import java.util.List;

public final class AccumuloSyntaxParserConstants {

public static final int EOF = 0;
public static final int _NUM_CHAR = 1;
public static final int _ESCAPED_CHAR = 2;
public static final int _TERM_START_CHAR = 3;
public static final int _TERM_CHAR = 4;
public static final int _FUNCTION_ARG_CHAR = 5;
public static final int _FUNCTION_ARG_BEGINEND_CHAR = 6;
public static final int _FUNCTION_ARG_ALL_CHAR1 = 7;
public static final int _FUNCTION_ARG_ALL_CHAR2 = 8;
public static final int _FUNCTION_ARG = 9;
public static final int _WHITESPACE = 10;
public static final int _QUOTED_CHAR = 11;
public static final int AND = 13;
public static final int OR = 14;
public static final int NOT = 15;
public static final int FUNCTION = 16;
public static final int LPAREN = 17;
public static final int RPAREN = 18;
public static final int OP_COLON = 19;
public static final int CARAT = 20;
public static final int QUOTED = 21;
public static final int TERM = 22;
public static final int FUZZY_SLOP = 23;
public static final int REGEXPTERM = 24;
public static final int RANGEIN_START = 25;
public static final int RANGEEX_START = 26;
public static final int NUMBER = 27;
public static final int RANGE_TO = 28;
public static final int RANGEIN_END = 29;
public static final int RANGEEX_END = 30;
public static final int RANGE_QUOTED = 31;
public static final int RANGE_GOOP = 32;

public static final int Boost = 0;
public static final int Range = 1;
public static final int DEFAULT = 2;

// @formatter:off
public static final List<String> tokenImage = List.of(
"<EOF>",
"<_NUM_CHAR>",
"<_ESCAPED_CHAR>",
"<_TERM_START_CHAR>",
"<_TERM_CHAR>",
"<_FUNCTION_ARG_CHAR>",
"<_FUNCTION_ARG_BEGINEND_CHAR>",
"<_FUNCTION_ARG_ALL_CHAR1>",
"<_FUNCTION_ARG_ALL_CHAR2>",
"<_FUNCTION_ARG>",
"<_WHITESPACE>",
"<_QUOTED_CHAR>",
"<token of kind 12>",
"\"AND\"",
"\"OR\"",
"\"NOT\"",
"<FUNCTION>",
"\"(\"",
"\")\"",
"\":\"",
"\"^\"",
"<QUOTED>",
"<TERM>",
"<FUZZY_SLOP>",
"<REGEXPTERM>",
"\"[\"",
"\"{\"",
"<NUMBER>",
"\"TO\"",
"\"]\"",
"\"}\"",
"<RANGE_QUOTED>",
"<RANGE_GOOP>");
// @formatter:on

/**
* Do not allow this class to be instantiated.
*/
private AccumuloSyntaxParserConstants() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

public class AccumuloSyntaxParserTokenManager implements AcumuloSyntaxParserConstants {
public class AccumuloSyntaxParserTokenManager {
public java.io.PrintStream debugStream = System.out;

public void setDebugStream(java.io.PrintStream ds) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* JavaCCOptions:KEEP_LINE_COL=null */
package datawave.query.language.parser.lucene;

import java.util.List;

import org.apache.lucene.queryparser.flexible.core.QueryNodeParseException;
import org.apache.lucene.queryparser.flexible.core.messages.QueryParserMessages;
import org.apache.lucene.queryparser.flexible.messages.Message;
Expand Down Expand Up @@ -31,7 +33,7 @@ public class ParseException extends QueryNodeParseException {
* @param tokenImageVal
* the token image
*/
public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal) {
public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, List<String> tokenImageVal) {
super(new MessageImpl(QueryParserMessages.INVALID_SYNTAX, initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)));
this.currentToken = currentTokenVal;
this.expectedTokenSequences = expectedTokenSequencesVal;
Expand Down Expand Up @@ -74,7 +76,7 @@ public ParseException(Message message) {
* 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;
public List<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
Expand All @@ -88,7 +90,7 @@ public ParseException(Message message) {
* the token image
* @return parse error message string
*/
private static String initialise(Token currentToken, int[][] expectedTokenSequences, String[] tokenImage) {
private static String initialise(Token currentToken, int[][] expectedTokenSequences, List<String> tokenImage) {
String eol = System.getProperty("line.separator", "\n");
StringBuilder expected = new StringBuilder();
int maxSize = 0;
Expand All @@ -97,7 +99,7 @@ private static String initialise(Token currentToken, int[][] expectedTokenSequen
maxSize = expectedTokenSequences[i].length;
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
expected.append(tokenImage.get(expectedTokenSequences[i][j])).append(' ');
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
expected.append("...");
Expand All @@ -110,10 +112,10 @@ private static String initialise(Token currentToken, int[][] expectedTokenSequen
if (i != 0)
retval += " ";
if (tok.kind == 0) {
retval += tokenImage[0];
retval += tokenImage.get(0);
break;
}
retval += " " + tokenImage[tok.kind];
retval += " " + tokenImage.get(tok.kind);
retval += " \"";
retval += add_escapes(tok.image);
retval += " \"";
Expand Down

0 comments on commit 35ee1f8

Please sign in to comment.