From 6b5d34b1d09f792a6582cfc90fd691a79c2405bd Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 01:26:22 +0300 Subject: [PATCH 01/12] Create maven.yml Closing #2. --- .github/workflows/maven.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 00000000..1e6c0e04 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,20 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Maven + run: mvn -B package --file pom.xml From 0aa87286e7b4e6f174b0786f1cd163f97a5f7ecc Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 01:29:26 +0300 Subject: [PATCH 02/12] Resolving #1 - supporting intelliJ, generating sources, .gitignoring Mac garbage. --- .gitignore | 8 +++++++- pom.xml | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 415cdef9..ba136c70 100644 --- a/.gitignore +++ b/.gitignore @@ -100,7 +100,6 @@ $.* texput.* Untitled* .~lock.* -_* # Prefixes // vim: +,/^\s*$/-1!sort -u a.out @@ -148,3 +147,10 @@ out/ .classpath .project .settings/ + +# MacOS junk +.DS_Store + +# IntelliJunk +.idea/ +.iml diff --git a/pom.xml b/pom.xml index 51606fba..343fea50 100644 --- a/pom.xml +++ b/pom.xml @@ -86,6 +86,23 @@ maven-javadoc-plugin 3.1.0 + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + generate-sources + process-sources + + java + + + + + test + il.ac.technion.cs.fling.examples.LoopOverLanguageDefinitions + + From a77dabc41b4a7b71848f9bb340be6437b06026c6 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 01:34:51 +0300 Subject: [PATCH 03/12] Update maven.yml --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1e6c0e04..93b29d8f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -17,4 +17,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn -B package --file pom.xml + run: mvn install --file pom.xml From 63ad8aff83c3b366da5bd0cdc766a23e9b032ff7 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 01:55:12 +0300 Subject: [PATCH 04/12] Update maven.yml --- .github/workflows/maven.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 93b29d8f..ad0aaf5f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -7,7 +7,6 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest steps: From f685df8a0f806f0307d144cb0678fc7c706f5961 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 01:58:37 +0300 Subject: [PATCH 05/12] Update maven.yml --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ad0aaf5f..d3ef419e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,4 +16,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn install --file pom.xml + run: mvn -X install --file pom.xml From 473556031632dac7329e6ac72d99dd17af713801 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 02:00:47 +0300 Subject: [PATCH 06/12] Update maven.yml --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d3ef419e..01af6551 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -16,4 +16,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn -X install --file pom.xml + run: mvn -e install --file pom.xml From a5295fa6cda998a9763ed97d78bdb85ac0c90157 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 11:51:50 +0300 Subject: [PATCH 07/12] Update maven.yml Caching dependencies; Trying to generate sources. --- .github/workflows/maven.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 01af6551..777a0791 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -15,5 +15,11 @@ jobs: uses: actions/setup-java@v1 with: java-version: 1.8 + - name: Cache Maven packages + uses: actions/cache@v1 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 - name: Build with Maven - run: mvn -e install --file pom.xml + run: mvn -X -B compile --file pom.xml From f0067a8f8c32f4f9908631b3e902b085361f8cf7 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 12:05:56 +0300 Subject: [PATCH 08/12] Update maven.yml Adding github's token. Will it help? --- .github/workflows/maven.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 777a0791..bccbf24f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,4 +22,6 @@ jobs: key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Build with Maven + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: mvn -X -B compile --file pom.xml From e43fef93d4a951353ba84ea4893f34f3961488dd Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 12:17:23 +0300 Subject: [PATCH 09/12] Resolving #1 - generated sources require compilation and then run. Trying to make it compile first. --- pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 343fea50..cc0ddfee 100644 --- a/pom.xml +++ b/pom.xml @@ -86,13 +86,14 @@ maven-javadoc-plugin 3.1.0 - org.codehaus.mojo + + org.codehaus.mojo exec-maven-plugin 1.6.0 - generate-sources - process-sources + generate-languages + generate-sources java From c401d0384d32f9e52ec5ee17cd62925b4af380e9 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 12:38:05 +0300 Subject: [PATCH 10/12] Resolving #1 - Trying to compile LoopOverLanguageDefinitions.java, then execute it. --- pom.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pom.xml b/pom.xml index cc0ddfee..a18be2a9 100644 --- a/pom.xml +++ b/pom.xml @@ -51,6 +51,22 @@ maven-compiler-plugin 3.6.0 + + + compile-generator + generate-sources + + compile + + + + + test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java + + + + + eclipse From 6b73ad64ed260e761981b40c055a700c9592b368 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 12:40:11 +0300 Subject: [PATCH 11/12] Update maven.yml Removing the debug log, in which I drown... --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index bccbf24f..13723fdb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,4 +24,4 @@ jobs: - name: Build with Maven env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: mvn -X -B compile --file pom.xml + run: mvn -B compile --file pom.xml From f8299651002a230aa2b8382350595539f49a1dc9 Mon Sep 17 00:00:00 2001 From: Noam Rotem Date: Sat, 23 May 2020 18:48:38 +0300 Subject: [PATCH 12/12] =?UTF-8?q?#3=20-=20adding=20a=20Json=20BNF=20and=20?= =?UTF-8?q?a=20demonstrating=20use-case.=20#2=20-=20reverting,=20since=20I?= =?UTF-8?q?=20could=20find=20yet=20a=20way=20with=20maven(=F0=9F=98=A1)=20?= =?UTF-8?q?to=20compile=20only=20LoopOverLanguageDefinitions.java=20and=20?= =?UTF-8?q?direct=20dependencies,=20to=20generate=20sources=20before=20ful?= =?UTF-8?q?l=20compilation.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 36 +-------------- .../examples/LoopOverLanguageDefinitions.java | 1 + .../cs/fling/examples/languages/Json.java | 45 +++++++++++++++++++ .../cs/fling/examples/usecases/Json.java | 44 ++++++++++++++++++ 4 files changed, 91 insertions(+), 35 deletions(-) create mode 100644 src/test/java/il/ac/technion/cs/fling/examples/languages/Json.java create mode 100644 src/test/java/il/ac/technion/cs/fling/examples/usecases/Json.java diff --git a/pom.xml b/pom.xml index a18be2a9..72074003 100644 --- a/pom.xml +++ b/pom.xml @@ -51,22 +51,6 @@ maven-compiler-plugin 3.6.0 - - - compile-generator - generate-sources - - compile - - - - - test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java - - - - - eclipse @@ -102,24 +86,6 @@ maven-javadoc-plugin 3.1.0 - - org.codehaus.mojo - exec-maven-plugin - 1.6.0 - - - generate-languages - generate-sources - - java - - - - - test - il.ac.technion.cs.fling.examples.LoopOverLanguageDefinitions - - - + \ No newline at end of file diff --git a/src/test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java b/src/test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java index 8ee9ce02..82516a42 100644 --- a/src/test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java +++ b/src/test/java/il/ac/technion/cs/fling/examples/LoopOverLanguageDefinitions.java @@ -27,6 +27,7 @@ new RegularExpression(), // new HTMLTable(), // new SimpleArithmetic(), // + new Json(), }; private static final Map files = ((Supplier>) () -> { final Map $ = new LinkedHashMap<>(); diff --git a/src/test/java/il/ac/technion/cs/fling/examples/languages/Json.java b/src/test/java/il/ac/technion/cs/fling/examples/languages/Json.java new file mode 100644 index 00000000..9eb4307d --- /dev/null +++ b/src/test/java/il/ac/technion/cs/fling/examples/languages/Json.java @@ -0,0 +1,45 @@ +package il.ac.technion.cs.fling.examples.languages; + +import il.ac.technion.cs.fling.BNF; +import il.ac.technion.cs.fling.Terminal; +import il.ac.technion.cs.fling.Variable; +import il.ac.technion.cs.fling.examples.FluentLanguageAPI; +import il.ac.technion.cs.fling.examples.languages.Json.V; +import il.ac.technion.cs.fling.examples.languages.Json.Σ; + +import static il.ac.technion.cs.fling.Symbol.noneOrMore; +import static il.ac.technion.cs.fling.examples.languages.Json.V.*; +import static il.ac.technion.cs.fling.examples.languages.Json.Σ.*; +import static il.ac.technion.cs.fling.grammars.api.BNFAPI.bnf; + +@SuppressWarnings("NonAsciiCharacters") +public class Json implements FluentLanguageAPI<Σ, V> { + public enum Σ implements Terminal { + array, end, isSetTo, key, object, value, _null_ + } + + public enum V implements Variable { + Element, Field, Json, Value + } + + @Override public Class<Σ> Σ() { + return Σ.class; + } + @Override public Class V() { + return V.class; + } + @Override public BNF BNF() { + return bnf(). + start(Json). + derive(Json).to(Element). + derive(Element).to(object, noneOrMore(Field), end). + or(array, noneOrMore(Element), end). + or(Value). + derive(Value).to(value.with(String.class)). + or(value.with(Number.class)). + or(value.with(Boolean.class)). + or(_null_). + derive(Field).to(key.with(String.class), isSetTo, Element). + build(); + } +} diff --git a/src/test/java/il/ac/technion/cs/fling/examples/usecases/Json.java b/src/test/java/il/ac/technion/cs/fling/examples/usecases/Json.java new file mode 100644 index 00000000..890207db --- /dev/null +++ b/src/test/java/il/ac/technion/cs/fling/examples/usecases/Json.java @@ -0,0 +1,44 @@ +package il.ac.technion.cs.fling.examples.usecases; + +import static il.ac.technion.cs.fling.examples.generated.Json.value; +import static il.ac.technion.cs.fling.examples.generated.Json.array; +import static il.ac.technion.cs.fling.examples.generated.Json.object; + +// @formatter:off +public class Json { + public static void main(String[] args) { + value("f"); + value(8); + value(true); + array(); //TODO: how come this is legal? + array().end(); + array().value("f").end(); + array() + .value(8) + .value("fg") + .array().end() + .end(); + + object().end(); + + object().key("name").isSetTo().value(8).end(); + + object() + .key("name").isSetTo().value("Joe") + .key("age").isSetTo().value(8) + .end(); + + object(). + key("name").isSetTo() + .object() + .key("first").isSetTo().value("Joe") + .key("last").isSetTo()._null_() + .end(). + key("ages").isSetTo() + .array() + .value(60) + .value(70) + .end() + .end(); + } +}