Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
axiom: Introduced base parser and stream APIs
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
- Loading branch information
1 parent
73ec8e0
commit 95577d4
Showing
22 changed files
with
921 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ Copyright (c) 2010-2018 Evolveum and contributors | ||
~ | ||
~ This work is dual-licensed under the Apache License 2.0 | ||
~ and European Union Public License. See LICENSE file for details. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<artifactId>infra</artifactId> | ||
<groupId>com.evolveum.midpoint.infra</groupId> | ||
<version>4.2-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>com.evolveum.axiom</groupId> | ||
<artifactId>axiom</artifactId> | ||
|
||
<name>Axiom</name> | ||
|
||
<properties> | ||
<maven.test.skip>true</maven.test.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-runtime</artifactId> | ||
<version>4.8-1</version> | ||
</dependency> | ||
<!-- test dependencies --> | ||
<dependency> | ||
<groupId>org.testng</groupId> | ||
<artifactId>testng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.evolveum.midpoint.tools</groupId> | ||
<artifactId>test-ng</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>antlr4-maven-plugin</artifactId> | ||
<version>4.8-1</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>antlr4</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<visitor>true</visitor> | ||
<listener>true</listener> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
45 changes: 45 additions & 0 deletions
45
infra/axiom/src/main/antlr4/com/evolveum/axiom/lang/antlr/Axiom.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,45 @@ | ||
grammar Axiom; | ||
|
||
SEMICOLON : ';'; | ||
LEFT_BRACE : '{'; | ||
RIGHT_BRACE : '}'; | ||
COLON : ':'; | ||
PLUS : '+'; | ||
LINE_COMMENT : [ \n\r\t]* ('//' (~[\r\n]*)) [ \n\r\t]* -> skip; | ||
SEP: [ \n\r\t]+; | ||
IDENTIFIER : [a-zA-Z_/][a-zA-Z0-9_\-./]*; | ||
|
||
fragment SQOUTE : '\''; | ||
fragment DQOUTE : '"'; | ||
|
||
|
||
//fragment SUB_STRING : ('"' (ESC | ~["])*? '"') | ('\'' (ESC | ~['])* '\''); | ||
//fragment ESC : '\\' (["\\/bfnrt] | UNICODE); | ||
//fragment UNICODE : 'u' HEX HEX HEX HEX; | ||
//fragment HEX : [0-9a-fA-F] ; | ||
//STRING: ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '\'' | '}' | '/' | '+')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '}' )* ) | SUB_STRING ); | ||
|
||
fragment ESC : '\\'; | ||
|
||
STRING_SINGLEQUOTE: SQOUTE ((ESC SQOUTE) | ~[\n'])* SQOUTE; | ||
STRING_DOUBLEQUOTE: DQOUTE ((ESC DQOUTE) | ~[\n"])* DQOUTE; | ||
//STRING_MULTILINE: '"""' (ESC | ~('"""'))* '"""'; | ||
statement : SEP* identifier SEP* (argument)? SEP* (SEMICOLON | LEFT_BRACE SEP* (statement)* SEP* RIGHT_BRACE SEP*) SEP*; | ||
identifier : (prefix COLON)? localIdentifier; | ||
prefix : IDENTIFIER; | ||
localIdentifier : IDENTIFIER; | ||
// argument : STRING (SEP* PLUS SEP* STRING)* | IDENTIFIER; | ||
argument : identifier | string; | ||
string : singleQuoteString | doubleQuoteString | multilineString; | ||
singleQuoteString : STRING_SINGLEQUOTE; | ||
doubleQuoteString : STRING_DOUBLEQUOTE; | ||
multilineString: '"""\n' (~('"""'))*'"""'; | ||
68 changes: 68 additions & 0 deletions
68
infra/axiom/src/main/java/com/evolveum/axiom/api/AxiomIdentifier.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,68 @@ | ||
package com.evolveum.axiom.api; | ||
|
||
import java.util.Objects; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
public class AxiomIdentifier { | ||
|
||
public static final String AXIOM_NAMESPACE = "https://ns.evolveum.com/axiom"; | ||
private final String namespace; | ||
private final String localName; | ||
|
||
public AxiomIdentifier(String namespace, String localName) { | ||
this.namespace = Preconditions.checkNotNull(namespace, "namespace"); | ||
this.localName = Preconditions.checkNotNull(localName, "localName"); | ||
} | ||
|
||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
public String getLocalName() { | ||
return localName; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
result = prime * result + ((localName == null) ? 0 : localName.hashCode()); | ||
result = prime * result + ((namespace == null) ? 0 : namespace.hashCode()); | ||
return result; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (!(obj instanceof AxiomIdentifier)) | ||
return false; | ||
AxiomIdentifier other = (AxiomIdentifier) obj; | ||
if (localName == null) { | ||
if (other.localName != null) | ||
return false; | ||
} else if (!localName.equals(other.localName)) | ||
return false; | ||
if (namespace == null) { | ||
if (other.namespace != null) | ||
return false; | ||
} else if (!namespace.equals(other.namespace)) | ||
return false; | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return localName; | ||
} | ||
|
||
public static AxiomIdentifier axiom(String identifier) { | ||
return new AxiomIdentifier(AXIOM_NAMESPACE, identifier); | ||
} | ||
|
||
public static AxiomIdentifier from(String namespace, String localName) { | ||
return new AxiomIdentifier(namespace, localName); | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltInProperty.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,29 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
|
||
class AxiomBuiltInProperty implements AxiomPropertyDefinition { | ||
|
||
private final AxiomIdentifier argument; | ||
private final AxiomTypeDefinition type; | ||
|
||
public AxiomBuiltInProperty(AxiomIdentifier argument, AxiomTypeDefinition type) { | ||
this.argument = argument; | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public AxiomIdentifier getIdentifier() { | ||
return argument; | ||
} | ||
|
||
@Override | ||
public AxiomTypeDefinition getType() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public boolean required() { | ||
return true; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomBuiltInSimpleType.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,20 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
|
||
public enum AxiomBuiltInSimpleType implements AxiomTypeDefinition { | ||
|
||
IDENTIFIER("identifier"), | ||
STRING("string"), | ||
SEMANTIC_VERSION("SemanticVersion"); | ||
|
||
private final AxiomIdentifier identifier; | ||
|
||
AxiomBuiltInSimpleType(String identifier) { | ||
this.identifier = AxiomIdentifier.axiom(identifier); | ||
} | ||
|
||
public AxiomIdentifier getIdentifier() { | ||
return identifier; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomPropertyDefinition.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,10 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
|
||
public interface AxiomPropertyDefinition { | ||
|
||
AxiomIdentifier getIdentifier(); | ||
AxiomTypeDefinition getType(); | ||
boolean required(); | ||
} |
16 changes: 16 additions & 0 deletions
16
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomStatement.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,16 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
import java.util.Collection; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
|
||
public interface AxiomStatement<V> { | ||
|
||
AxiomIdentifier keyword(); | ||
V value(); | ||
|
||
Collection<AxiomStatement<?>> children(); | ||
Collection<AxiomStatement<?>> children(AxiomIdentifier type); | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomStatementStreamListener.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,11 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
|
||
public interface AxiomStatementStreamListener { | ||
|
||
void startStatement(AxiomIdentifier statement); | ||
void argument(AxiomIdentifier identifier); | ||
void argument(String identifier); | ||
void endStatement(); | ||
} |
5 changes: 5 additions & 0 deletions
5
infra/axiom/src/main/java/com/evolveum/axiom/lang/api/AxiomTypeDefinition.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,5 @@ | ||
package com.evolveum.axiom.lang.api; | ||
|
||
public interface AxiomTypeDefinition { | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
infra/axiom/src/main/java/com/evolveum/axiom/lang/impl/AxiomAntlrAdapter.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,60 @@ | ||
package com.evolveum.axiom.lang.impl; | ||
|
||
import com.evolveum.axiom.api.AxiomIdentifier; | ||
import com.evolveum.axiom.lang.antlr.AxiomBaseListener; | ||
import com.evolveum.axiom.lang.antlr.AxiomParser.ArgumentContext; | ||
import com.evolveum.axiom.lang.antlr.AxiomParser.DoubleQuoteStringContext; | ||
import com.evolveum.axiom.lang.antlr.AxiomParser.IdentifierContext; | ||
import com.evolveum.axiom.lang.antlr.AxiomParser.StatementContext; | ||
import com.evolveum.axiom.lang.api.AxiomStatementStreamListener; | ||
|
||
public class AxiomAntlrAdapter extends AxiomBaseListener { | ||
|
||
private final AxiomIdentifierResolver statements; | ||
private final AxiomStatementStreamListener delegate; | ||
|
||
|
||
|
||
public AxiomAntlrAdapter(AxiomIdentifierResolver statements, AxiomStatementStreamListener delegate) { | ||
this.statements = statements; | ||
this.delegate = delegate; | ||
} | ||
|
||
|
||
|
||
@Override | ||
public void enterStatement(StatementContext ctx) { | ||
AxiomIdentifier identifier = statementIdentifier(ctx.identifier()); | ||
delegate.startStatement(identifier); | ||
super.enterStatement(ctx); | ||
} | ||
|
||
@Override | ||
public void enterArgument(ArgumentContext ctx) { | ||
if (ctx.identifier() != null) { | ||
enterArgument(ctx.identifier()); | ||
} else { | ||
enterStringArgument(ctx.identifier()); | ||
} | ||
|
||
|
||
|
||
super.enterArgument(ctx); | ||
} | ||
|
||
private void enterStringArgument(IdentifierContext identifier) { | ||
// TODO Auto-generated method stub | ||
|
||
} | ||
|
||
private void enterArgument(IdentifierContext identifier) { | ||
delegate.argument(statementIdentifier(identifier)); | ||
} | ||
|
||
private AxiomIdentifier statementIdentifier(IdentifierContext identifier) { | ||
String prefix = identifier.prefix().getText(); | ||
String localName = identifier.localIdentifier().getText(); | ||
return statements.resolveStatementIdentifier(prefix,localName); | ||
} | ||
|
||
} |
Oops, something went wrong.