From cfce3e4dbb94bd23401a2b43bd17e6cd38703f61 Mon Sep 17 00:00:00 2001 From: Johan Maasing Date: Mon, 24 Mar 2025 21:44:21 +0100 Subject: [PATCH] Initial ANTLR grammar --- .gitignore | 35 ++++++++++++ assembly/pom.xml | 24 ++++++++ parser/pom.xml | 55 +++++++++++++++++++ .../antlr4/nu/zoom/dsl/parser/Endpoints.g4 | 23 ++++++++ parser/src/main/java/nu/zoom/dsl/Main.java | 7 +++ .../nu/zoom/dsl/parser/ParserFactory.java | 4 ++ pom.xml | 23 ++++++++ 7 files changed, 171 insertions(+) create mode 100644 .gitignore create mode 100644 assembly/pom.xml create mode 100644 parser/pom.xml create mode 100644 parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4 create mode 100644 parser/src/main/java/nu/zoom/dsl/Main.java create mode 100644 parser/src/main/java/nu/zoom/dsl/parser/ParserFactory.java create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48010bb --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/assembly/pom.xml b/assembly/pom.xml new file mode 100644 index 0000000..43bb1e9 --- /dev/null +++ b/assembly/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + + nu.zoom.dsl + endgen + 1.0-SNAPSHOT + + + nu.zoom.dsl + assembly + + + + nu.zoom.dsl + parser + ${parent.version} + + + + \ No newline at end of file diff --git a/parser/pom.xml b/parser/pom.xml new file mode 100644 index 0000000..0c1f9b6 --- /dev/null +++ b/parser/pom.xml @@ -0,0 +1,55 @@ + + + 4.0.0 + + + nu.zoom.dsl + endgen + 1.0-SNAPSHOT + + + nu.zoom.dsl + parser + + + org.antlr + antlr4-runtime + 4.13.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 24 + 24 + + + + + org.antlr + antlr4-maven-plugin + 4.13.1 + + + + antlr4 + + + + + + + \ No newline at end of file diff --git a/parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4 b/parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4 new file mode 100644 index 0000000..7fc1d09 --- /dev/null +++ b/parser/src/main/antlr4/nu/zoom/dsl/parser/Endpoints.g4 @@ -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/<>"']+ ; diff --git a/parser/src/main/java/nu/zoom/dsl/Main.java b/parser/src/main/java/nu/zoom/dsl/Main.java new file mode 100644 index 0000000..c57eaa0 --- /dev/null +++ b/parser/src/main/java/nu/zoom/dsl/Main.java @@ -0,0 +1,7 @@ +package nu.zoom.dsl; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello, World!"); + } +} \ No newline at end of file diff --git a/parser/src/main/java/nu/zoom/dsl/parser/ParserFactory.java b/parser/src/main/java/nu/zoom/dsl/parser/ParserFactory.java new file mode 100644 index 0000000..370386c --- /dev/null +++ b/parser/src/main/java/nu/zoom/dsl/parser/ParserFactory.java @@ -0,0 +1,4 @@ +package nu.zoom.dsl.parser; + +public class ParserFactory { +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2ede1fb --- /dev/null +++ b/pom.xml @@ -0,0 +1,23 @@ + + + 4.0.0 + + nu.zoom.dsl + endgen + 1.0-SNAPSHOT + pom + + + 24 + 24 + UTF-8 + + + + parser + assembly + + + \ No newline at end of file