Update generated files. Maybe <javacc> is more of a pain than its worth!

Added more tests.



git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@156435 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2005-03-07 18:21:16 +00:00
parent 823851222b
commit a606c0890c
2 changed files with 55 additions and 29 deletions

View File

@ -639,13 +639,15 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
Vector clauses = new Vector(); Vector clauses = new Vector();
int modifier; int modifier;
Query q, firstQuery=null; Query q, firstQuery=null;
boolean orPresent = false;
modifier = Modifier(); modifier = Modifier();
q = orExpression(field); q = andExpression(field);
addClause(clauses, CONJ_NONE, modifier, q); addClause(clauses, CONJ_NONE, modifier, q);
firstQuery=q; firstQuery=q;
label_1: label_1:
while (true) { while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case OR:
case NOT: case NOT:
case PLUS: case PLUS:
case MINUS: case MINUS:
@ -663,39 +665,18 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
jj_la1[4] = jj_gen; jj_la1[4] = jj_gen;
break label_1; break label_1;
} }
modifier = Modifier();
q = orExpression(field);
addClause(clauses, CONJ_NONE, modifier, q);
}
if (clauses.size() == 1 && firstQuery != null)
{if (true) return firstQuery;}
else {
{if (true) return getBooleanQuery(clauses);}
}
throw new Error("Missing return statement in function");
}
final public Query orExpression(String field) throws ParseException {
Vector clauses = new Vector();
Query q, firstQuery=null;
int modifier;
q = andExpression(field);
addClause(clauses, CONJ_NONE, MOD_NONE, q);
firstQuery=q;
label_2:
while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case OR: case OR:
; jj_consume_token(OR);
orPresent=true;
break; break;
default: default:
jj_la1[5] = jj_gen; jj_la1[5] = jj_gen;
break label_2; ;
} }
jj_consume_token(OR);
modifier = Modifier(); modifier = Modifier();
q = andExpression(field); q = andExpression(field);
addClause(clauses, CONJ_OR, modifier, q); addClause(clauses, orPresent ? CONJ_OR : CONJ_NONE, modifier, q);
} }
if (clauses.size() == 1 && firstQuery != null) if (clauses.size() == 1 && firstQuery != null)
{if (true) return firstQuery;} {if (true) return firstQuery;}
@ -705,6 +686,32 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
throw new Error("Missing return statement in function"); throw new Error("Missing return statement in function");
} }
/*
Query orExpression(String field) :
{
Vector clauses = new Vector();
Query q, firstQuery=null;
int modifier;
}
{
q=andExpression(field)
{
addClause(clauses, CONJ_NONE, MOD_NONE, q);
firstQuery=q;
}
(
<OR> modifier=Modifier() q=andExpression(field)
{ addClause(clauses, CONJ_OR, modifier, q); }
)*
{
if (clauses.size() == 1 && firstQuery != null)
return firstQuery;
else {
return getBooleanQuery(clauses);
}
}
}
*/
final public Query andExpression(String field) throws ParseException { final public Query andExpression(String field) throws ParseException {
Vector clauses = new Vector(); Vector clauses = new Vector();
Query q, firstQuery=null; Query q, firstQuery=null;
@ -712,7 +719,7 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
q = Clause(field); q = Clause(field);
addClause(clauses, CONJ_NONE, MOD_NONE, q); addClause(clauses, CONJ_NONE, MOD_NONE, q);
firstQuery=q; firstQuery=q;
label_3: label_2:
while (true) { while (true) {
switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
case AND: case AND:
@ -720,7 +727,7 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
break; break;
default: default:
jj_la1[6] = jj_gen; jj_la1[6] = jj_gen;
break label_3; break label_2;
} }
jj_consume_token(AND); jj_consume_token(AND);
modifier = Modifier(); modifier = Modifier();
@ -1058,7 +1065,7 @@ public class PrecedenceQueryParser implements PrecedenceQueryParserConstants {
jj_la1_0(); jj_la1_0();
} }
private static void jj_la1_0() { private static void jj_la1_0() {
jj_la1_0 = new int[] {0x180,0x180,0xe00,0xe00,0xfb1e00,0x100,0x80,0x8000,0xfb1000,0x9a0000,0x40000,0x40000,0x8000,0xc000000,0x1000000,0xc000000,0x8000,0xc0000000,0x10000000,0xc0000000,0x8000,0x40000,0x8000,0xfb0000,}; jj_la1_0 = new int[] {0x180,0x180,0xe00,0xe00,0xfb1f00,0x100,0x80,0x8000,0xfb1000,0x9a0000,0x40000,0x40000,0x8000,0xc000000,0x1000000,0xc000000,0x8000,0xc0000000,0x10000000,0xc0000000,0x8000,0x40000,0x8000,0xfb0000,};
} }
final private JJCalls[] jj_2_rtns = new JJCalls[1]; final private JJCalls[] jj_2_rtns = new JJCalls[1];
private boolean jj_rescan = false; private boolean jj_rescan = false;

View File

@ -532,6 +532,25 @@ public class TestPrecedenceQueryParser extends TestCase {
assertEquals(query1, query2); assertEquals(query1, query2);
} }
public void testPrecedenceWithNot() throws Exception {
Query query1 = PrecedenceQueryParser.parse("A OR B C", "field", new WhitespaceAnalyzer());
Query query2 = PrecedenceQueryParser.parse("A B C", "field", new WhitespaceAnalyzer());
assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A AND B C", "field", new WhitespaceAnalyzer());
query2 = PrecedenceQueryParser.parse("(+A +B) C", "field", new WhitespaceAnalyzer());
assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A AND NOT B", "field", new WhitespaceAnalyzer());
query2 = PrecedenceQueryParser.parse("+A -B", "field", new WhitespaceAnalyzer());
assertEquals(query1, query2);
query1 = PrecedenceQueryParser.parse("A OR NOT B", "field", new WhitespaceAnalyzer());
query2 = PrecedenceQueryParser.parse("A -B", "field", new WhitespaceAnalyzer());
assertEquals(query1, query2);
}
public void tearDown() { public void tearDown() {
BooleanQuery.setMaxClauseCount(originalMaxClauses); BooleanQuery.setMaxClauseCount(originalMaxClauses);