Initial ANTLR grammar
This commit is contained in:
commit
cfce3e4dbb
7 changed files with 171 additions and 0 deletions
35
.gitignore
vendored
Normal file
35
.gitignore
vendored
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
target/
|
||||||
|
!.mvn/wrapper/maven-wrapper.jar
|
||||||
|
!**/src/main/**/target/
|
||||||
|
!**/src/test/**/target/
|
||||||
|
|
||||||
|
### IntelliJ IDEA ###
|
||||||
|
.idea/**
|
||||||
|
*.iws
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
build/
|
||||||
|
!**/src/main/**/build/
|
||||||
|
!**/src/test/**/build/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
24
assembly/pom.xml
Normal file
24
assembly/pom.xml
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>endgen</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>assembly</artifactId>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>parser</artifactId>
|
||||||
|
<version>${parent.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
55
parser/pom.xml
Normal file
55
parser/pom.xml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>endgen</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>parser</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.antlr</groupId>
|
||||||
|
<artifactId>antlr4-runtime</artifactId>
|
||||||
|
<version>4.13.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- This plugin sets up maven to use Java 7 -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.13.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>24</source>
|
||||||
|
<target>24</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<!-- Plugin to compile the g4 files ahead of the java files
|
||||||
|
See https://github.com/antlr/antlr4/blob/master/antlr4-maven-plugin/src/site/apt/examples/simple.apt.vm
|
||||||
|
Except that the grammar does not need to contain the package declaration as stated in the documentation (I do not know why)
|
||||||
|
To use this plugin, type:
|
||||||
|
mvn antlr4:antlr4
|
||||||
|
In any case, Maven will invoke this plugin before the Java source is compiled
|
||||||
|
-->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.antlr</groupId>
|
||||||
|
<artifactId>antlr4-maven-plugin</artifactId>
|
||||||
|
<version>4.13.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>antlr4</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
23
parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4
Normal file
23
parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
grammar Endpoints;
|
||||||
|
|
||||||
|
generatorconfig : '{' (configitem)? (',' configitem)* '}';
|
||||||
|
configitem : configkey ':' configvalue ;
|
||||||
|
configkey : IDENTIFIER ;
|
||||||
|
configvalue : (IDENTIFIER|VALUE) ;
|
||||||
|
fieldName : IDENTIFIER ;
|
||||||
|
fieldType : IDENTIFIER ;
|
||||||
|
compoundTypeName : IDENTIFIER ;
|
||||||
|
compoundField : fieldName ':' fieldType ;
|
||||||
|
compoundFields : '(' compoundField (',' compoundField)* ')' ;
|
||||||
|
compoundType : compoundTypeName compoundFields ;
|
||||||
|
pathSegment : '/' (IDENTIFIER|VALUE) ;
|
||||||
|
path : (pathSegment)+ ;
|
||||||
|
endpoint : path '<' (compoundFields | IDENTIFIER) ;
|
||||||
|
|
||||||
|
|
||||||
|
fragment DIGIT : [0-9] ;
|
||||||
|
fragment LOWERCASE : [a-z] ;
|
||||||
|
fragment UPPERCASE : [A-Z] ;
|
||||||
|
WS : [ \t\n\r]+ -> skip;
|
||||||
|
IDENTIFIER : (LOWERCASE | UPPERCASE) (LOWERCASE | UPPERCASE | DIGIT)* ;
|
||||||
|
VALUE : ~[ ,{}:()\n\t\r/<>"']+ ;
|
7
parser/src/main/java/nu/zoom/dsl/Main.java
Normal file
7
parser/src/main/java/nu/zoom/dsl/Main.java
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package nu.zoom.dsl;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Hello, World!");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package nu.zoom.dsl.parser;
|
||||||
|
|
||||||
|
public class ParserFactory {
|
||||||
|
}
|
23
pom.xml
Normal file
23
pom.xml
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<groupId>nu.zoom.dsl</groupId>
|
||||||
|
<artifactId>endgen</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>24</maven.compiler.source>
|
||||||
|
<maven.compiler.target>24</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>parser</module>
|
||||||
|
<module>assembly</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Add table
Reference in a new issue