Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
746 additions
and
16 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
75 changes: 75 additions & 0 deletions
75
infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/query/AxiomQuery.g4
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,75 @@ | ||
grammar AxiomQuery; | ||
|
||
SEMICOLON : ';'; | ||
LEFT_BRACE : '{'; | ||
RIGHT_BRACE : '}'; | ||
COLON : ':'; | ||
PLUS : '+'; | ||
LINE_COMMENT : [ \n\r\t]* ('//' (~[\r\n]*)) [ \n\r\t]* -> skip; | ||
SEP: [ \n\r\t]+; | ||
|
||
AND_KEYWORD: 'and'; | ||
OR_KEYWORD: 'or'; | ||
NOT_KEYWORD: 'not'; | ||
IDENTIFIER : [a-zA-Z_][a-zA-Z0-9_\-]*; | ||
|
||
fragment SQOUTE : '\''; | ||
fragment DQOUTE : '"'; | ||
|
||
fragment ESC : '\\'; | ||
|
||
STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE; | ||
STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE; | ||
STRING_MULTILINE_START: '"""' ('\r')? '\n'; | ||
//statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; | ||
itemName: prefixedName #dataName | ||
| '@' prefixedName #infraName; | ||
prefixedName: (prefix=IDENTIFIER COLON)? localName=IDENTIFIER | ||
| (prefix=IDENTIFIER)? COLON localName=(AND_KEYWORD | NOT_KEYWORD | OR_KEYWORD); | ||
argument : prefixedName | string; | ||
string : STRING_SINGLEQUOTE #singleQuoteString | ||
| STRING_DOUBLEQUOTE #doubleQuoteString | ||
| STRING_MULTILINE_START (~('"""'))*'"""' # multilineString; | ||
variable: '$' itemName; | ||
parent: '..'; | ||
// Path could start with ../ or context variable ($var) or item name | ||
firstComponent: (parent ( '/' parent )*) | variable | pathComponent; | ||
path: firstComponent ( '/' pathComponent)*; | ||
pathComponent: itemName (pathValue)?; | ||
pathValue: '[' argument ']'; | ||
// Aliases for basic filters (equals, less, greater, lessOrEquals, greaterOrEquals | ||
// | ||
filterNameAlias: '=' | '<' | '>' | '<=' | '>='; | ||
filterName: prefixedName | filterNameAlias; | ||
matchingRule: '[' prefixedName ']'; | ||
// Currently value could be string or path | ||
valueSpecification: string | path; | ||
negation: NOT_KEYWORD; | ||
// Filter could be Value filter or Logic Filter | ||
filter: left=filter (SEP+ AND_KEYWORD SEP+ right=filter) #andFilter | ||
| left=filter (SEP+ OR_KEYWORD SEP+ right=filter) #orFilter | ||
| itemFilter #genFilter | ||
| subfilter #subFilter; | ||
subfilter: '(' SEP* filter SEP* ')'; | ||
itemFilter: path (SEP+ negation)? SEP+ filterName (matchingRule)? (SEP+ (subfilterOrValue))?; | ||
subfilterOrValue : subfilter | valueSpecification; | ||
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
18 changes: 18 additions & 0 deletions
18
infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomAntlrLiterals.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,18 @@ | ||
package com.evolveum.axiom.lang.antlr; | ||
|
||
public class AxiomAntlrLiterals { | ||
|
||
public static String convertSingleQuote(String text) { | ||
int stop = text.length(); | ||
return text.substring(1, stop - 1); | ||
} | ||
|
||
public static String convertDoubleQuote(String text) { | ||
int stop = text.length(); | ||
return text.substring(1, stop - 1); | ||
} | ||
|
||
public static String convertMultiline(String text) { | ||
return text.replace("\"\"\"", ""); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
infra/axiom/src/main/java/com/evolveum/axiom/lang/antlr/AxiomQuerySource.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,30 @@ | ||
package com.evolveum.axiom.lang.antlr; | ||
|
||
import org.antlr.v4.runtime.CharStreams; | ||
import org.antlr.v4.runtime.CodePointCharStream; | ||
import org.antlr.v4.runtime.CommonTokenStream; | ||
|
||
import com.evolveum.axiom.lang.antlr.query.AxiomQueryLexer; | ||
import com.evolveum.axiom.lang.antlr.query.AxiomQueryParser; | ||
import com.evolveum.axiom.lang.antlr.query.AxiomQueryParser.FilterContext; | ||
|
||
public class AxiomQuerySource { | ||
|
||
private final FilterContext root; | ||
|
||
public AxiomQuerySource(FilterContext root) { | ||
this.root = root; | ||
} | ||
|
||
public static final AxiomQuerySource from(String query) { | ||
CodePointCharStream stream = CharStreams.fromString(query); | ||
AxiomQueryLexer lexer = new AxiomQueryLexer(stream); | ||
AxiomQueryParser parser = new AxiomQueryParser(new CommonTokenStream(lexer)); | ||
FilterContext root = parser.filter(); | ||
return new AxiomQuerySource(root); | ||
} | ||
|
||
public FilterContext root() { | ||
return root; | ||
} | ||
} |
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.