Skip to content

Commit f4fffa8

Browse files
author
Psilo
committed
Merge branch 'antlr4'
2 parents b880f7a + 335be71 commit f4fffa8

25 files changed

+1955
-11
lines changed

.classpath

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
<attribute name="maven.pomderived" value="true"/>
3535
</attributes>
3636
</classpathentry>
37+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
3738
<classpathentry kind="output" path="target/classes"/>
3839
</classpath>

antlr4/Rql.g4

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
grammar Rql;
2+
3+
/*
4+
* Parser Rules start with lower-case characters.
5+
*/
6+
eval : orExpression ;
7+
8+
orExpression : andExpression (or andExpression)* ;
9+
10+
andExpression : atomExpression (and atomExpression)* ;
11+
12+
atomExpression : atomTerm | (parOpen orExpression parClose) ;
13+
14+
atomTerm : optTerm | term ;
15+
16+
and : And ;
17+
18+
or : Or ;
19+
20+
parOpen : ParOpen ;
21+
22+
parClose : ParClose ;
23+
24+
optTerm : OptIdentifier Operator JpqlIdentifier ;
25+
term : Identifier Operator JpqlIdentifier ;
26+
27+
/*
28+
* Lexer Rules start with upper-case characters.
29+
*/
30+
Operator : ST | SEQ | GT | GEQ | EQ | NEQ | Like | NLike | NullOp | NotNullOp;
31+
Like : L I K E;
32+
NLike : Not L I K E;
33+
NullOp : Is Null;
34+
NotNullOp : Is Not Null;
35+
And : A N D;
36+
Or : O R;
37+
ParOpen : '(';
38+
ParClose : ')';
39+
Identifier : (Alpha AlphaNum* '.')* Alpha AlphaNum*;
40+
OptIdentifier : '?' Identifier;
41+
JpqlIdentifier : ':' Alpha AlphaNum*;
42+
Whitespace : [ \t\r\n]+ -> channel(HIDDEN);
43+
44+
// a fragment rule can't be used inside parser rules, only in lexer rules
45+
fragment ST : '<';
46+
fragment GT : '>';
47+
fragment SEQ : '<=';
48+
fragment GEQ : '>=';
49+
fragment EQ : '=';
50+
fragment NEQ : '<>';
51+
fragment Null : N U L L;
52+
fragment Is : I S;
53+
fragment Not : N O T;
54+
fragment UCaseAlpha : 'A'..'Z';
55+
fragment LCaseAlpha : 'a'..'z';
56+
fragment Alpha : LCaseAlpha | UCaseAlpha;
57+
fragment Num : '0'..'9';
58+
fragment AlphaNum : 'a'..'z' | 'A' .. 'Z' | '-' | '_' | '0'..'9';
59+
60+
fragment A : [aA]; // match either an 'a' or 'A'
61+
fragment B : [bB];
62+
fragment C : [cC];
63+
fragment D : [dD];
64+
fragment E : [eE];
65+
fragment F : [fF];
66+
fragment G : [gG];
67+
fragment H : [hH];
68+
fragment I : [iI];
69+
fragment J : [jJ];
70+
fragment K : [kK];
71+
fragment L : [lL];
72+
fragment M : [mM];
73+
fragment N : [nN];
74+
fragment O : [oO];
75+
fragment P : [pP];
76+
fragment Q : [qQ];
77+
fragment R : [rR];
78+
fragment S : [sS];
79+
fragment T : [tT];
80+
fragment U : [uU];
81+
fragment V : [vV];
82+
fragment W : [wW];
83+
fragment X : [xX];
84+
fragment Y : [yY];
85+
fragment Z : [zZ];

antlr4/testInput.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
userId = :userId AND (?timeFrom <= :timeFrom OR timeTo > :timeTo)

pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>info.unterrainer.commons</groupId>
77
<artifactId>parent-pom</artifactId>
8-
<version>0.0.26</version>
8+
<version>0.0.28</version>
99
</parent>
1010

1111
<properties>
@@ -17,7 +17,7 @@
1717

1818
<modelVersion>4.0.0</modelVersion>
1919
<artifactId>http-server</artifactId>
20-
<version>0.1.4</version>
20+
<version>0.1.5</version>
2121
<name>HttpServer</name>
2222
<packaging>jar</packaging>
2323

@@ -52,6 +52,11 @@
5252
<artifactId>orika-core</artifactId>
5353
<version>1.5.4</version>
5454
</dependency>
55+
<dependency>
56+
<groupId>org.antlr</groupId>
57+
<artifactId>antlr4-runtime</artifactId>
58+
<version>4.8-1</version>
59+
</dependency>
5560
<dependency>
5661
<groupId>org.eclipse.jetty</groupId>
5762
<artifactId>jetty-http</artifactId>

src/main/java/info/unterrainer/commons/httpserver/GenericHandlerGroup.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import info.unterrainer.commons.httpserver.enums.Endpoint;
1515
import info.unterrainer.commons.httpserver.enums.QueryField;
1616
import info.unterrainer.commons.httpserver.exceptions.BadRequestException;
17-
import info.unterrainer.commons.httpserver.interceptors.GetListInterceptorResult;
17+
import info.unterrainer.commons.httpserver.interceptors.InterceptorData;
1818
import info.unterrainer.commons.httpserver.interceptors.delegates.GetListInterceptor;
1919
import info.unterrainer.commons.httpserver.jsons.ListJson;
2020
import info.unterrainer.commons.rdbutils.entities.BasicJpa;
@@ -104,7 +104,7 @@ private void getList(final Context ctx) {
104104
Long offset = hu.getQueryParamAsLong(ctx, QueryField.PAGINATION_OFFSET, 0L);
105105
Long size = hu.getQueryParamAsLong(ctx, QueryField.PAGINATION_SIZE, Long.MAX_VALUE);
106106

107-
GetListInterceptorResult interceptorResult = GetListInterceptorResult.builder()
107+
InterceptorData interceptorResult = InterceptorData.builder()
108108
.selectClause("o")
109109
.joinClause("")
110110
.whereClause("")
@@ -113,7 +113,7 @@ private void getList(final Context ctx) {
113113
.build();
114114
for (GetListInterceptor interceptor : getListInterceptors)
115115
try {
116-
GetListInterceptorResult result = interceptor.intercept(ctx, hu);
116+
InterceptorData result = interceptor.intercept(ctx, hu);
117117
if (result != null) {
118118
interceptorResult = result;
119119
break;

src/main/java/info/unterrainer/commons/httpserver/GenericHandlerGroupBuilder.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99
import info.unterrainer.commons.httpserver.daos.BasicDao;
1010
import info.unterrainer.commons.httpserver.daos.DaoTransactionManager;
1111
import info.unterrainer.commons.httpserver.enums.Endpoint;
12+
import info.unterrainer.commons.httpserver.interceptors.InterceptorParamBuilder;
1213
import info.unterrainer.commons.httpserver.interceptors.delegates.GetListInterceptor;
14+
import info.unterrainer.commons.httpserver.rql.RqlUtils;
1315
import info.unterrainer.commons.rdbutils.entities.BasicJpa;
1416
import info.unterrainer.commons.serialization.JsonMapper;
1517
import info.unterrainer.commons.serialization.jsons.BasicJson;
1618
import io.javalin.core.security.Role;
19+
import io.javalin.http.Context;
1720
import lombok.AccessLevel;
1821
import lombok.RequiredArgsConstructor;
1922
import ma.glasnost.orika.MapperFactory;
@@ -34,6 +37,10 @@ public class GenericHandlerGroupBuilder<P extends BasicJpa, J extends BasicJson,
3437
private List<GetListInterceptor> getListInterceptors = new ArrayList<>();
3538
private ExecutorService executorService;
3639

40+
private Context ctx;
41+
private HandlerUtils hu = new HandlerUtils();
42+
private RqlUtils rqlUtils = new RqlUtils(ctx, hu);
43+
3744
HandlerExtensions<P, J, E> extensions = new HandlerExtensions<>();
3845
private LinkedHashMap<Endpoint, Role[]> accessRoles = new LinkedHashMap<>();
3946

@@ -94,4 +101,10 @@ public GenericHandlerGroupBuilder<P, J, E> getListInterceptor(final GetListInter
94101
getListInterceptors.add(interceptor);
95102
return this;
96103
}
104+
105+
public InterceptorParamBuilder<P, J, E> getListInterceptor() {
106+
return new InterceptorParamBuilder<>(this, rqlUtils, data -> {
107+
getListInterceptors.add((ctx, hu) -> data);
108+
});
109+
}
97110
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
// Generated from c:\code\java-http-server\antlr4\Rql.g4 by ANTLR 4.8
2+
package info.unterrainer.commons.httpserver.antlr;
3+
4+
import org.antlr.v4.runtime.ParserRuleContext;
5+
import org.antlr.v4.runtime.tree.ErrorNode;
6+
import org.antlr.v4.runtime.tree.TerminalNode;
7+
8+
/**
9+
* This class provides an empty implementation of {@link RqlListener},
10+
* which can be extended to create a listener which only needs to handle a subset
11+
* of the available methods.
12+
*/
13+
public class RqlBaseListener implements RqlListener {
14+
/**
15+
* {@inheritDoc}
16+
*
17+
* <p>The default implementation does nothing.</p>
18+
*/
19+
@Override public void enterEval(RqlParser.EvalContext ctx) { }
20+
/**
21+
* {@inheritDoc}
22+
*
23+
* <p>The default implementation does nothing.</p>
24+
*/
25+
@Override public void exitEval(RqlParser.EvalContext ctx) { }
26+
/**
27+
* {@inheritDoc}
28+
*
29+
* <p>The default implementation does nothing.</p>
30+
*/
31+
@Override public void enterOrExpression(RqlParser.OrExpressionContext ctx) { }
32+
/**
33+
* {@inheritDoc}
34+
*
35+
* <p>The default implementation does nothing.</p>
36+
*/
37+
@Override public void exitOrExpression(RqlParser.OrExpressionContext ctx) { }
38+
/**
39+
* {@inheritDoc}
40+
*
41+
* <p>The default implementation does nothing.</p>
42+
*/
43+
@Override public void enterAndExpression(RqlParser.AndExpressionContext ctx) { }
44+
/**
45+
* {@inheritDoc}
46+
*
47+
* <p>The default implementation does nothing.</p>
48+
*/
49+
@Override public void exitAndExpression(RqlParser.AndExpressionContext ctx) { }
50+
/**
51+
* {@inheritDoc}
52+
*
53+
* <p>The default implementation does nothing.</p>
54+
*/
55+
@Override public void enterAtomExpression(RqlParser.AtomExpressionContext ctx) { }
56+
/**
57+
* {@inheritDoc}
58+
*
59+
* <p>The default implementation does nothing.</p>
60+
*/
61+
@Override public void exitAtomExpression(RqlParser.AtomExpressionContext ctx) { }
62+
/**
63+
* {@inheritDoc}
64+
*
65+
* <p>The default implementation does nothing.</p>
66+
*/
67+
@Override public void enterAtomTerm(RqlParser.AtomTermContext ctx) { }
68+
/**
69+
* {@inheritDoc}
70+
*
71+
* <p>The default implementation does nothing.</p>
72+
*/
73+
@Override public void exitAtomTerm(RqlParser.AtomTermContext ctx) { }
74+
/**
75+
* {@inheritDoc}
76+
*
77+
* <p>The default implementation does nothing.</p>
78+
*/
79+
@Override public void enterAnd(RqlParser.AndContext ctx) { }
80+
/**
81+
* {@inheritDoc}
82+
*
83+
* <p>The default implementation does nothing.</p>
84+
*/
85+
@Override public void exitAnd(RqlParser.AndContext ctx) { }
86+
/**
87+
* {@inheritDoc}
88+
*
89+
* <p>The default implementation does nothing.</p>
90+
*/
91+
@Override public void enterOr(RqlParser.OrContext ctx) { }
92+
/**
93+
* {@inheritDoc}
94+
*
95+
* <p>The default implementation does nothing.</p>
96+
*/
97+
@Override public void exitOr(RqlParser.OrContext ctx) { }
98+
/**
99+
* {@inheritDoc}
100+
*
101+
* <p>The default implementation does nothing.</p>
102+
*/
103+
@Override public void enterParOpen(RqlParser.ParOpenContext ctx) { }
104+
/**
105+
* {@inheritDoc}
106+
*
107+
* <p>The default implementation does nothing.</p>
108+
*/
109+
@Override public void exitParOpen(RqlParser.ParOpenContext ctx) { }
110+
/**
111+
* {@inheritDoc}
112+
*
113+
* <p>The default implementation does nothing.</p>
114+
*/
115+
@Override public void enterParClose(RqlParser.ParCloseContext ctx) { }
116+
/**
117+
* {@inheritDoc}
118+
*
119+
* <p>The default implementation does nothing.</p>
120+
*/
121+
@Override public void exitParClose(RqlParser.ParCloseContext ctx) { }
122+
/**
123+
* {@inheritDoc}
124+
*
125+
* <p>The default implementation does nothing.</p>
126+
*/
127+
@Override public void enterOptTerm(RqlParser.OptTermContext ctx) { }
128+
/**
129+
* {@inheritDoc}
130+
*
131+
* <p>The default implementation does nothing.</p>
132+
*/
133+
@Override public void exitOptTerm(RqlParser.OptTermContext ctx) { }
134+
/**
135+
* {@inheritDoc}
136+
*
137+
* <p>The default implementation does nothing.</p>
138+
*/
139+
@Override public void enterTerm(RqlParser.TermContext ctx) { }
140+
/**
141+
* {@inheritDoc}
142+
*
143+
* <p>The default implementation does nothing.</p>
144+
*/
145+
@Override public void exitTerm(RqlParser.TermContext ctx) { }
146+
147+
/**
148+
* {@inheritDoc}
149+
*
150+
* <p>The default implementation does nothing.</p>
151+
*/
152+
@Override public void enterEveryRule(ParserRuleContext ctx) { }
153+
/**
154+
* {@inheritDoc}
155+
*
156+
* <p>The default implementation does nothing.</p>
157+
*/
158+
@Override public void exitEveryRule(ParserRuleContext ctx) { }
159+
/**
160+
* {@inheritDoc}
161+
*
162+
* <p>The default implementation does nothing.</p>
163+
*/
164+
@Override public void visitTerminal(TerminalNode node) { }
165+
/**
166+
* {@inheritDoc}
167+
*
168+
* <p>The default implementation does nothing.</p>
169+
*/
170+
@Override public void visitErrorNode(ErrorNode node) { }
171+
}

0 commit comments

Comments
 (0)