forked from jirutka/rsql-parser
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for operators without arguments
=null=
, =notnull=
.
This commit introduces mor flexible way of parsing and validating operators and it's arguments. Two new operators `=null=` and `=notnull=` were added which wasn't possible previously due to grammar and API level limitations. Closes: gh-8
- Loading branch information
Showing
15 changed files
with
344 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cz.jirutka.rsql.parser.ast; | ||
|
||
/** | ||
* The arity of an operator. | ||
* | ||
* @since 2.3.0 | ||
*/ | ||
public interface Arity { | ||
|
||
/** | ||
* The minimum number of arguments operator can receive. | ||
* | ||
* @return The minimum number of arguments operator can receive. Positive or zero. | ||
* @apiNote The minimum values is always less than or equal to {@linkplain #max()} | ||
*/ | ||
int min(); | ||
|
||
/** | ||
* The maximum number of arguments operator can receive. | ||
* | ||
* @return The maximum number of arguments operator can receive. Positive or zero. | ||
* @apiNote The maximum values is always greater than or equal to {@linkplain #min()}. For practically unlimited | ||
* arity the implementations should return {@link Integer#MAX_VALUE}. | ||
*/ | ||
int max(); | ||
|
||
/** | ||
* Creates arity with given {@code min} and {@code max}. | ||
* | ||
* @param min The minimum number of arguments. Must be zero or positive. | ||
* @param max The maximum number of arguments. Must be zero or positive and greater than or equal to {@code min}. | ||
* @return the created arity | ||
*/ | ||
static Arity of(int min, int max) { | ||
return new DynamicArity(min, max); | ||
} | ||
|
||
/** | ||
* Creates N-ary object. | ||
* | ||
* @param n The N. | ||
* @return the created arity | ||
*/ | ||
static Arity nary(int n) { | ||
return new NAry(n); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/cz/jirutka/rsql/parser/ast/DynamicArity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cz.jirutka.rsql.parser.ast; | ||
|
||
final class DynamicArity implements Arity { | ||
|
||
private final int min; | ||
private final int max; | ||
|
||
DynamicArity(int min, int max) { | ||
if (min < 0) { | ||
throw new IllegalArgumentException("min must be positive or zero"); | ||
} | ||
if (max < 0) { | ||
throw new IllegalArgumentException("max must be positive or zero"); | ||
} | ||
if (min > max) { | ||
throw new IllegalArgumentException("min must be less than or equal to max"); | ||
} | ||
|
||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
@Override | ||
public int min() { | ||
return min; | ||
} | ||
|
||
@Override | ||
public int max() { | ||
return max; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cz.jirutka.rsql.parser.ast; | ||
|
||
final class NAry implements Arity { | ||
|
||
private final int n; | ||
|
||
NAry(int n) { | ||
if (n < 0) { | ||
throw new IllegalArgumentException("n must be positive or zero"); | ||
} | ||
|
||
this.n = n; | ||
} | ||
|
||
@Override | ||
public int min() { | ||
return n; | ||
} | ||
|
||
@Override | ||
public int max() { | ||
return n; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.