Skip to content

Commit

Permalink
[s1ck#49] cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
lc0197 committed Jun 5, 2020
1 parent 3dae776 commit 404b71a
Show file tree
Hide file tree
Showing 35 changed files with 1,758 additions and 2,860 deletions.
17 changes: 13 additions & 4 deletions src/main/antlr4/org/s1ck/gdl/GDL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ literal
// time-related
//________________________

// temporal query constraints

temporalComparison
: timePoint ComparisonOP timePoint
;
Expand All @@ -145,13 +147,14 @@ timeFunc
| Identifier '.asOf(' timePoint ')' #asOf
;

// intervals

interval
: intervalSelector
| intervalFromStamps
| complexInterval
;


intervalSelector
: Identifier '.' IntervalConst
| IntervalConst
Expand All @@ -161,7 +164,6 @@ intervalFromStamps
: 'Interval(' timePoint ',' timePoint ')'
;

// TODO: change (only placeholder yet)
complexInterval
: complexIntervalArgument '.merge(' complexIntervalArgument ')'
| complexIntervalArgument '.join(' complexIntervalArgument ')'
Expand All @@ -172,7 +174,8 @@ complexIntervalArgument
| intervalFromStamps
;

// TODO: add functions that yield timePoint
// time points

timePoint
: timeLiteral
| timeSelector
Expand Down Expand Up @@ -201,6 +204,9 @@ complexTimePointArgument
| timeSelector
;


// interval functions

intervalFunc
: overlapsIntervallOperator
| fromToOperator
Expand All @@ -216,11 +222,11 @@ intervalFunc
| lengthAtLeastOperator
| lengthAtMostOperator
;

overlapsIntervallOperator
: 'overlaps(' interval ')'
;


fromToOperator
: 'fromTo(' timePoint ',' timePoint ')'
;
Expand Down Expand Up @@ -278,6 +284,9 @@ timeConstant
| 'Days(' IntegerLiteral ')'
;


// time stamp/point functions

stampFunc
: beforePointOperator
| afterPointOperator
Expand Down
22 changes: 3 additions & 19 deletions src/main/java/org/s1ck/gdl/GDLHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class GDLHandler {
/**
* GDL listener implementation.
*/
private GDLLoader loader;
private final GDLLoader loader;

/**
* Private constructor to avoid external initialization.
Expand Down Expand Up @@ -199,11 +199,6 @@ public static class Builder {
*/
private boolean useDefaultEdgeLabel = true;

/**
* Flag to indicate if the query should be postprocessed, i.e. reduced to simple comparisons.
*/
private boolean processQuery = false;

/**
* Strategy for handling parser errors.
*/
Expand Down Expand Up @@ -313,17 +308,6 @@ public Builder setErrorStrategy(ANTLRErrorStrategy errorStrategy) {
return this;
}

/**
* Sets the processQuery parameter for the {@link GDLLoader}.
*
* @param processQuery processQuery flag (true iff query should be postprocessed)
* @return builder
*/
public Builder setProcessQuery(boolean processQuery){
this.processQuery = processQuery;
return this;
}

/**
* Initialize GDL Handler from given ASCII String.
*
Expand All @@ -340,7 +324,7 @@ public GDLHandler buildFromString(String asciiString) {
*
* @param stream InputStream (must not be {@code null}).
* @return GDL handler
* @throws IOException
* @throws IOException if stream processing fails
*/
public GDLHandler buildFromStream(InputStream stream) throws IOException {
ANTLRInputStream antlrInputStream = new ANTLRInputStream(stream);
Expand Down Expand Up @@ -383,7 +367,7 @@ private GDLHandler build(ANTLRInputStream antlrInputStream) {
parser.setErrorHandler(errorStrategy);

GDLLoader loader = new GDLLoader(graphLabel, vertexLabel, edgeLabel,
useDefaultGraphLabel, useDefaultVertexLabel, useDefaultEdgeLabel, processQuery);
useDefaultGraphLabel, useDefaultVertexLabel, useDefaultEdgeLabel);
new ParseTreeWalker().walk(loader, parser.database());
return new GDLHandler(loader);
}
Expand Down
Loading

0 comments on commit 404b71a

Please sign in to comment.