From 2bb86e7296036130fc60de215805f6ec9188cbeb Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 2 Aug 2022 18:01:20 +0200 Subject: [PATCH 01/71] Replace CI configuration file by ci.yml --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++++++ bitbucket-pipelines.yml | 24 ------------------------ 2 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 bitbucket-pipelines.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..7360d73f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,35 @@ +--- +# CI configuration +# https://docs.github.com/en/actions/guides/building-and-testing-java-with-maven +# https://github.com/actions/setup-java + +name: Scala CI + +on: +- push + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + java: + - 11 + - 17 + scala: + - 2.11.12 + - 2.12.16 + - 2.13.8 + - 3.1.3 + steps: + - name: Check out + uses: actions/checkout@v3 + - name: Set up Java + uses: actions/setup-java@v3 + with: + java-version: ${{ matrix.java }} + distribution: zulu + - name: Build with sbt + run: sbt '++ ${{ matrix.scala }}' scalaVersion sbtVersion version clean compile test package assembly + + diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml deleted file mode 100644 index 5ba93578..00000000 --- a/bitbucket-pipelines.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Configuration file for Bitbucket Pipelines - -# https://hub.docker.com/r/hseeberger/scala-sbt/ -image: hseeberger/scala-sbt:17.0.2_1.6.2_3.1.1 - -pipelines: - default: - - step: - name: Build - caches: - - sbt - script: - - sbt '++ 3.1.3' scalaVersion sbtVersion version clean compile test package assembly - - apt update - - apt install -y texlive-latex-recommended texlive-latex-extra - - cd documentation/src/site/tex - - pdflatex main.tex - - cd ../../../.. - - sbt '++ 2.13.8' scalaVersion sbtVersion version clean compile test package assembly - - sbt '++ 2.12.16' scalaVersion sbtVersion version clean compile test package assembly - - sbt '++ 2.11.12' scalaVersion sbtVersion version clean compile test package assembly - - From 96524b0ac769752a540f9e271eba07e32965bde0 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 2 Aug 2022 18:37:55 +0200 Subject: [PATCH 02/71] Update version to 0.17.0-SNAPSHOT --- build.sbt | 2 +- docs/README.md | 2 +- docs/RELEASE-NOTES.md | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 843434b3..156b7824 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,7 @@ lazy val scala3_1 = "3.1.3" lazy val commonSettings = Seq( organization := "se.umu.cs.rai.soda", - version := "0.16.0", + version := "0.17.0-SNAPSHOT", description := "Functional language to describe ethical problems", homepage := Some(url("https://bitbucket.org/mendezjulian/soda")), startYear := Some(2020), diff --git a/docs/README.md b/docs/README.md index 0565871d..77afda9e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -105,7 +105,7 @@ The following tools can be configured to have syntax highlighting: ## Build -The project can be build with [sbt](https://www.scala-sbt.org/). +The project can be built with [sbt](https://www.scala-sbt.org/). The command is: `sbt clean compile test package assembly` diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index 9ad7a5f8..e214d23d 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -1,4 +1,8 @@ --- +- - version: v0.17.0 + - date: unreleased + - build: sbt '++ 3.1.3' clean compile test package assembly + - release: target/scala-3.1.3/soda-0.17.0.jar - - version: v0.16.0 - date: '2022-08-02' - new_features: From 8a6df8dfd2267735b0581bff071c51007b5a873c Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 20 Sep 2022 01:38:31 +0200 Subject: [PATCH 03/71] Use Scala 3.2.0 --- .github/workflows/ci.yml | 1 + build.sbt | 6 ++++-- docs/RELEASE-NOTES.md | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7360d73f..3ca2c527 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: - 2.12.16 - 2.13.8 - 3.1.3 + - 3.2.0 steps: - name: Check out uses: actions/checkout@v3 diff --git a/build.sbt b/build.sbt index 156b7824..edd614fa 100644 --- a/build.sbt +++ b/build.sbt @@ -8,6 +8,8 @@ lazy val scala2_13 = "2.13.8" lazy val scala3_1 = "3.1.3" +lazy val scala3_2 = "3.2.0" + lazy val commonSettings = Seq( organization := "se.umu.cs.rai.soda", @@ -28,8 +30,8 @@ lazy val commonSettings = * [[https://repo1.maven.org/maven2/org/scala-lang/scalap/]] * [[https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/]] */ - crossScalaVersions := Seq(scala2_11, scala2_12, scala2_13, scala3_1), - scalaVersion := scala3_1, + crossScalaVersions := Seq(scala2_11, scala2_12, scala2_13, scala3_1, scala3_2), + scalaVersion := scala3_2, /** * ScalaTest * [[https://www.scalatest.org]] diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index e214d23d..075ab134 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -1,8 +1,8 @@ --- - - version: v0.17.0 - date: unreleased - - build: sbt '++ 3.1.3' clean compile test package assembly - - release: target/scala-3.1.3/soda-0.17.0.jar + - build: sbt '++ 3.2.0' clean compile test package assembly + - release: target/scala-3.2.0/soda-0.17.0.jar - - version: v0.16.0 - date: '2022-08-02' - new_features: From 4d26fe9d6b65d476a29fe9d2d80de87f5afd055e Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 20 Sep 2022 01:46:25 +0200 Subject: [PATCH 04/71] Use sbt-assembly 1.2.0 --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 2e441086..487b15a3 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,7 +4,7 @@ * [[https://github.com/sbt/sbt-assembly]] * [[https://repo1.maven.org/maven2/com/eed3si9n/sbt-assembly_2.12_1.0/]] */ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") /** * scalastyle-sbt-plugin From 587d2e683ff9913ff318fd313737e8d202985791 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 20 Sep 2022 13:16:51 +0200 Subject: [PATCH 05/71] Update build.sbt --- .github/workflows/ci.yml | 3 +-- build.sbt | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ca2c527..d955a3e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,9 +18,8 @@ jobs: - 17 scala: - 2.11.12 - - 2.12.16 + - 2.12.17 - 2.13.8 - - 3.1.3 - 3.2.0 steps: - name: Check out diff --git a/build.sbt b/build.sbt index edd614fa..dfa16dac 100644 --- a/build.sbt +++ b/build.sbt @@ -2,12 +2,10 @@ import sbt.Keys.scalacOptions lazy val scala2_11 = "2.11.12" -lazy val scala2_12 = "2.12.16" +lazy val scala2_12 = "2.12.17" lazy val scala2_13 = "2.13.8" -lazy val scala3_1 = "3.1.3" - lazy val scala3_2 = "3.2.0" lazy val commonSettings = @@ -30,7 +28,7 @@ lazy val commonSettings = * [[https://repo1.maven.org/maven2/org/scala-lang/scalap/]] * [[https://repo1.maven.org/maven2/org/scala-lang/scala3-compiler_3/]] */ - crossScalaVersions := Seq(scala2_11, scala2_12, scala2_13, scala3_1, scala3_2), + crossScalaVersions := Seq(scala2_11, scala2_12, scala2_13, scala3_2), scalaVersion := scala3_2, /** * ScalaTest From 3fe383da09e8ca3b277ee909585611b8ea0111d7 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Fri, 9 Dec 2022 12:02:21 +0100 Subject: [PATCH 06/71] Make minor changes --- .../ethicalissues/pricemonitor/Requirement1Monitor.soda | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda index 2a81b46b..b8256a5e 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda @@ -35,10 +35,14 @@ class Requirement1Monitor 1.0 * (min (x) (y) ) / (max (x) (y) ) min (x : Int) (y : Int) : Int = - if x < y then x else y + if x < y + then x + else y max (x : Int) (y : Int) : Int = - if x < y then y else x + if x < y + then y + else x end From c9998226d8871360f836664595b38a72bb5b5c3f Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 13 Dec 2022 18:28:44 +0100 Subject: [PATCH 07/71] Normalize match-case structures --- .../example/algorithms/FizzBuzzPatternMatching.scala | 2 +- .../example/algorithms/FizzBuzzPatternMatching.soda | 2 +- .../soda/example/algorithms/PatternMatching.scala | 4 ++-- .../soda/example/algorithms/PatternMatching.soda | 4 ++-- .../pricemonitor/Requirement1Monitor.scala | 8 ++++++-- .../pricemonitor/Requirement3Monitor.scala | 4 ++-- .../pricemonitor/Requirement3Monitor.soda | 4 ++-- .../example/forcoq/algorithms/RecursionForCoq.scala | 4 ++-- .../example/forcoq/algorithms/RecursionForCoq.soda | 4 ++-- .../main/scala/soda/example/forcoq/lib/List.scala | 6 +++--- .../src/main/scala/soda/example/forcoq/lib/List.soda | 6 +++--- .../src/main/scala/soda/example/forcoq/lib/Nat.scala | 2 +- .../src/main/scala/soda/example/forcoq/lib/Nat.soda | 2 +- .../example/forcoq/mathematics/FactorialForCoq.scala | 2 +- .../example/forcoq/mathematics/FactorialForCoq.soda | 2 +- .../forcoq/mathematics/FiboExampleInSodaForCoq.scala | 2 +- .../forcoq/mathematics/FiboExampleInSodaForCoq.soda | 2 +- .../forcoq/mathematics/TriangularNumberForCoq.scala | 2 +- .../forcoq/mathematics/TriangularNumberForCoq.soda | 2 +- .../mathematics/FactorialPatternMatching.scala | 2 +- .../mathematics/FactorialPatternMatching.soda | 2 +- library/src/main/scala/soda/collection/MSeq.scala | 6 +++--- library/src/main/scala/soda/collection/MSeq.soda | 6 +++--- .../src/main/resources/lib/soda/lib/OptionSD.scala | 12 ++++++------ .../src/main/resources/lib/soda/lib/OptionSD.soda | 12 ++++++------ .../src/main/resources/lib/soda/lib/SeqSD.scala | 2 +- .../src/main/resources/lib/soda/lib/SeqSD.soda | 2 +- .../soda/translator/documentation/Manual.scala | 4 ++-- .../soda/translator/documentation/Manual.soda | 4 ++-- .../example/forcoq/algorithms/RecursionForCoq.scala | 4 ++-- .../example/forcoq/algorithms/RecursionForCoq.soda | 4 ++-- .../soda/translator/example/forcoq/lib/List.scala | 6 +++--- .../soda/translator/example/forcoq/lib/List.soda | 6 +++--- .../soda/translator/example/forcoq/lib/Nat.scala | 2 +- .../soda/translator/example/forcoq/lib/Nat.soda | 2 +- .../example/forcoq/mathematics/FactorialForCoq.scala | 2 +- .../example/forcoq/mathematics/FactorialForCoq.soda | 2 +- .../forcoq/mathematics/FiboExampleInSodaForCoq.scala | 2 +- .../forcoq/mathematics/FiboExampleInSodaForCoq.soda | 2 +- .../forcoq/mathematics/TriangularNumberForCoq.scala | 2 +- .../forcoq/mathematics/TriangularNumberForCoq.soda | 2 +- .../forcoq/mathematics/TriangularNumberForCoq.v | 2 +- .../mathematics/FactorialPatternMatching.scala | 2 +- .../mathematics/FactorialPatternMatching.soda | 2 +- .../toscala/MicroTranslatorToScalaSpec.scala | 8 ++++---- .../toscala/MicroTranslatorToScalaSpec.soda | 8 ++++---- 46 files changed, 89 insertions(+), 85 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala index eac94e5f..a3d2d622 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala @@ -20,7 +20,7 @@ trait FizzBuzzPatternMatching case Tuple2 (0, 0) => fizz + buzz case Tuple2 (0, x) => fizz case Tuple2 (x, 0) => buzz - case otherwise => n.toString + case x => n.toString } } diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda index ce7ebfbc..ca2478c4 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda @@ -20,7 +20,7 @@ class FizzBuzzPatternMatching case Tuple2 (0, 0) ==> fizz + buzz case Tuple2 (0, x) ==> fizz case Tuple2 (x, 0) ==> buzz - case otherwise ==> n.toString + case x ==> n.toString end end diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala index 59eaa1b9..647ea947 100644 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala @@ -17,7 +17,7 @@ trait PatternMatching case Singleton_ (x) => x case Pair_ (x, y) => (x + y) / 2 case Triplet_ (x, y, z) => (x + y + z) / 3 - case otherwise => 0 + case x => 0 } def get_type_name (p : Parameter) : String = @@ -25,7 +25,7 @@ trait PatternMatching case Singleton_ (x) => (Singleton_ (x) ).name + "(x)" case Pair_ (x, y) => (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) => (Triplet_ (x, y, z) ).name + "(x, y, z)" - case otherwise => "" + case x => "" } } diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda index c9eb4082..ca1c8307 100644 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda @@ -14,7 +14,7 @@ class PatternMatching case Singleton_ (x) ==> x case Pair_ (x, y) ==> (x + y) / 2 case Triplet_ (x, y, z) ==> (x + y + z) / 3 - case otherwise ==> 0 + case x ==> 0 end get_type_name (p : Parameter) : String = @@ -22,7 +22,7 @@ class PatternMatching case Singleton_ (x) ==> (Singleton_ (x) ).name + "(x)" case Pair_ (x, y) ==> (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) ==> (Triplet_ (x, y, z) ).name + "(x, y, z)" - case otherwise ==> "" + case x ==> "" end end diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index e8c12ffa..730db703 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -37,10 +37,14 @@ trait Requirement1Monitor 1.0 * (min (x) (y) ) / (max (x) (y) ) def min (x : Int) (y : Int) : Int = - if ( x < y ) x else y + if ( x < y + ) x + else y def max (x : Int) (y : Int) : Int = - if ( x < y ) y else x + if ( x < y + ) y + else x } diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 7bd4b38c..03940a9b 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -64,8 +64,8 @@ trait SegmentsForFlight def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = intermediate_stops match { - case Nil => Nil.+: (Segment_ (first_airport, last_airport) ) - case x :: xs => (rec_segments_multi (x) (xs) (last_airport) ).+: (Segment_ (first_airport, x) ) + case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x => Nil.+: (Segment_ (first_airport, last_airport) ) } } diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index d85825f0..1417f084 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -58,8 +58,8 @@ class SegmentsForFlight rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = match intermediate_stops - case Nil ==> Nil.+: (Segment_ (first_airport, last_airport) ) - case x :: xs ==> (rec_segments_multi (x) (xs) (last_airport) ).+: (Segment_ (first_airport, x) ) + case head :: tail ==> (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x ==> Nil.+: (Segment_ (first_airport, last_airport) ) end end diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala index 9a09349e..f17155c8 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala @@ -11,11 +11,11 @@ trait RecursionForCoq @tailrec final private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = sequence match { - case Nil => current_value case (head) :: (tail) => if ( ( ! (condition (current_value) (head) ) ) ) current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) + case x => current_value } def fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = @@ -25,8 +25,8 @@ trait RecursionForCoq @tailrec final private def _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = sequence match { - case Nil => current_value case (head) :: (tail) => _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) + case x => current_value } def fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda index 33ee450b..ec15803b 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda @@ -9,11 +9,11 @@ class RecursionForCoq @tailrec _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = match sequence - case Nil ==> current_value case (head) :: (tail) ==> if ( not (condition (current_value) (head) ) ) then current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) + case x ==> current_value end fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = @@ -22,8 +22,8 @@ class RecursionForCoq @tailrec _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = match sequence - case Nil ==> current_value case (head) :: (tail) ==> _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) + case x ==> current_value end fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.scala b/examples/src/main/scala/soda/example/forcoq/lib/List.scala index 9d55494c..d08bfdd5 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/List.scala @@ -35,8 +35,8 @@ trait SeqList @tailrec final private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = a match { - case nil_ () => b case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) + case x => b } def reverse [A] (s : list [A] ) : list [A] = @@ -46,8 +46,8 @@ trait SeqList @tailrec final private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = a match { - case Nil => b case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) + case x => b } def from_Seq [A] (a : Seq [A] ) : list [A] = @@ -57,8 +57,8 @@ trait SeqList @tailrec final private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = a match { - case nil_ () => b case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) + case x => b } def to_Seq [A] (a : list [A] ) : Seq [A] = diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.soda b/examples/src/main/scala/soda/example/forcoq/lib/List.soda index 1f630afb..ffe89ada 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/List.soda @@ -25,8 +25,8 @@ class SeqList @tailrec _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = match a - case nil_ () ==> b case cons_ (e, s) ==> _tailrec_reverse (s) ( cons_ (e, b) ) + case x ==> b end reverse [A] (s : list [A] ) : list [A] = @@ -35,8 +35,8 @@ class SeqList @tailrec _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = match a - case Nil ==> b case (e) :: (s) ==> _tailrec_from_Seq (s) (cons_ (e, b) ) + case x ==> b end from_Seq [A] (a : Seq [A] ) : list [A] = @@ -45,8 +45,8 @@ class SeqList @tailrec _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = match a - case nil_ () ==> b case cons_ (e, s) ==> _tailrec_to_Seq (s) ( b .+: (e) ) + case x ==> b end to_Seq [A] (a : list [A] ) : Seq [A] = diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala b/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala index 4e184a39..435fbd5b 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala @@ -80,8 +80,8 @@ trait IntNat def to_Int (a : nat) : Int = a match { - case O_ () => 0 case S_ (k) => 1 + to_Int (k) + case x => 0 } } diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda index db7d45d6..371501c5 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda @@ -72,8 +72,8 @@ class IntNat to_Int (a : nat) : Int = match a - case O_ () ==> 0 case S_ (k) ==> 1 + to_Int (k) + case x ==> 0 end end diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala index fe37fef9..36f039b6 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala @@ -11,8 +11,8 @@ trait FactorialForCoq @tailrec final private def _tailrec_get_factorial (m : nat) (product : nat) : nat = m match { - case O_ () => product case S_ (k) => _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) + case x => product } def get_factorial (n : nat) : nat = diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda index 9e675a99..10f9a691 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda @@ -10,8 +10,8 @@ class FactorialForCoq @tailrec _tailrec_get_factorial (m : nat) (product : nat) : nat = match m - case O_ () ==> product case S_ (k) ==> _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) + case x ==> product end get_factorial (n : nat) : nat = diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala index db3e540a..f9345f4f 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala @@ -11,9 +11,9 @@ trait FiboExampleInSodaForCoq @tailrec final private def _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = m match { - case O_ () => a case S_ (O_ () ) => b case S_ (k) => _tailrec_fib (k) (b) (a .add (b) ) + case x => a } def fib (n : nat) = diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 4ee70a5d..728d0456 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -10,9 +10,9 @@ class FiboExampleInSodaForCoq @tailrec _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = match m - case O_ () ==> a case S_ (O_ () ) ==> b case S_ (k) ==> _tailrec_fib (k) (b) (a .add (b) ) + case x ==> a end fib (n : nat) = diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala index 07ba6150..19db2a1a 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -11,8 +11,8 @@ trait TriangularNumberForCoq @tailrec final private def _tailrec_get_number (m : nat) (acc : nat) : nat = m match { - case O_ () => acc case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x => acc } def get_number (n : nat) : nat = diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda index 6b25a522..c911c46a 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -10,8 +10,8 @@ class TriangularNumberForCoq @tailrec _tailrec_get_number (m : nat) (acc : nat) : nat = match m - case O_ () ==> acc case S_ (k) ==> _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x ==> acc end get_number (n : nat) : nat = diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala index 7d24d277..41089561 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala @@ -10,7 +10,7 @@ trait FactorialPatternMatching private def _tailrec_get_factorial (n : Int) (product : Int) : Int = n match { case 0 => product - case k => _tailrec_get_factorial (k - 1) (k * product) + case x => _tailrec_get_factorial (x - 1) (x * product) } lazy val get_factorial : Int => Int = diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda index f8cd4f96..dea900b7 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda @@ -8,7 +8,7 @@ class FactorialPatternMatching _tailrec_get_factorial (n : Int) (product : Int) : Int = match n case 0 ==> product - case k ==> _tailrec_get_factorial (k - 1) (k * product) + case x ==> _tailrec_get_factorial (x - 1) (x * product) end get_factorial : Int -> Int = diff --git a/library/src/main/scala/soda/collection/MSeq.scala b/library/src/main/scala/soda/collection/MSeq.scala index 1f0b3df3..019ad904 100644 --- a/library/src/main/scala/soda/collection/MSeq.scala +++ b/library/src/main/scala/soda/collection/MSeq.scala @@ -7,8 +7,8 @@ trait MSeq [A] def opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] => B) : B = this match { - case ESeq_ () => ifEmpty case NESeq_ (head, tail) => ifNonEmpty (NESeq_ (head, tail) ) + case x => ifEmpty } } @@ -22,12 +22,12 @@ trait MSeqRec [A] @tailrec final private def _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = sequence match { - case ESeq_ () => current_value case NESeq_ (head, tail) => if ( ! condition (current_value) (head) ) current_value else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) - } + case x => current_value + } def fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) diff --git a/library/src/main/scala/soda/collection/MSeq.soda b/library/src/main/scala/soda/collection/MSeq.soda index 4bea50ba..d2e1530d 100644 --- a/library/src/main/scala/soda/collection/MSeq.soda +++ b/library/src/main/scala/soda/collection/MSeq.soda @@ -7,8 +7,8 @@ class MSeq [A] opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] -> B) : B = match this - case ESeq_ () ==> ifEmpty case NESeq_ (head, tail) ==> ifNonEmpty (NESeq_ (head, tail) ) + case x ==> ifEmpty end end @@ -18,12 +18,12 @@ class MSeqRec [A] @tailrec _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = match sequence - case ESeq_ () ==> current_value case NESeq_ (head, tail) ==> if not condition (current_value) (head) then current_value else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) - end + case x ==> current_value + end fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.scala b/translator/src/main/resources/lib/soda/lib/OptionSD.scala index 5de0f322..983629ac 100644 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.scala +++ b/translator/src/main/resources/lib/soda/lib/OptionSD.scala @@ -19,32 +19,32 @@ trait OptionSD [A] def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = this match { - case NoneSD_ () => ifEmpty case SomeSD_ (element) => ifNonEmpty (element) + case x => ifEmpty } def map [B] (mapping : A => B) : OptionSD [B] = this match { - case NoneSD_ () => NoneSD_ [B] () case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) + case x => NoneSD_ [B] () } def getOrElse (default : A) : A = this match { - case NoneSD_ () => default case SomeSD_ (element) => element + case x => default } def fold [B] (ifEmpty : B) (f : A => B) : B = this match { - case NoneSD_ () => ifEmpty case SomeSD_ (element) => f (element) + case x => ifEmpty } def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = this match { - case NoneSD_ () => NoneSD_ () case SomeSD_ (element) => mapping (element) + case x => NoneSD_ () } def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = @@ -52,11 +52,11 @@ trait OptionSD [A] def filter (predicate : A => Boolean) : OptionSD [A] = this match { - case NoneSD_ () => NoneSD_ () case SomeSD_ (element) => if ( predicate (element) ) this else NoneSD_ [A] () + case x => NoneSD_ () } } diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.soda b/translator/src/main/resources/lib/soda/lib/OptionSD.soda index 543e4d90..ddd44ab0 100644 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.soda +++ b/translator/src/main/resources/lib/soda/lib/OptionSD.soda @@ -19,32 +19,32 @@ class OptionSD [A] opt [B] (ifEmpty : B) (ifNonEmpty : A -> B) : B = match this - case NoneSD_ () ==> ifEmpty case SomeSD_ (element) ==> ifNonEmpty (element) + case x ==> ifEmpty end map [B] (mapping : A -> B) : OptionSD [B] = match this - case NoneSD_ () ==> NoneSD_ [B] () case SomeSD_ (element) ==> SomeSD_ [B] (mapping (element) ) + case x ==> NoneSD_ [B] () end getOrElse (default : A) : A = match this - case NoneSD_ () ==> default case SomeSD_ (element) ==> element + case x ==> default end fold [B] (ifEmpty : B) (f : A -> B) : B = match this - case NoneSD_ () ==> ifEmpty case SomeSD_ (element) ==> f (element) + case x ==> ifEmpty end flatMap [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = match this - case NoneSD_ () ==> NoneSD_ () case SomeSD_ (element) ==> mapping (element) + case x ==> NoneSD_ () end bind [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = @@ -52,11 +52,11 @@ class OptionSD [A] filter (predicate : A -> Boolean) : OptionSD [A] = match this - case NoneSD_ () ==> NoneSD_ () case SomeSD_ (element) ==> if predicate (element) then this else NoneSD_ [A] () + case x ==> NoneSD_ () end end diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.scala b/translator/src/main/resources/lib/soda/lib/SeqSD.scala index bdfcd233..75a7b9a0 100644 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.scala +++ b/translator/src/main/resources/lib/soda/lib/SeqSD.scala @@ -16,8 +16,8 @@ trait SeqSD [A] def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = this match { - case EmptySeqSD_ () => ifEmpty case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty } } diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.soda b/translator/src/main/resources/lib/soda/lib/SeqSD.soda index bd3b5183..5da35057 100644 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.soda +++ b/translator/src/main/resources/lib/soda/lib/SeqSD.soda @@ -16,8 +16,8 @@ class SeqSD [A] opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] -> B) : B = match this - case EmptySeqSD_ () ==> ifEmpty case NonEmptySeqSD_ (toSeq) ==> ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x ==> ifEmpty end end diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index d0bfaab2..8aaa7a98 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -243,7 +243,7 @@ trait Manual def if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = condition match { case true => if_true - case false => if_false + case x => if_false } /* A vertical bar `|` can be used as an abbreviation for `case`. */ @@ -251,7 +251,7 @@ trait Manual def another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = condition match { case true => if_true - case false => if_false + case x => if_false } def sum (n : Int) = diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 93ee5591..1fc1da74 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -217,7 +217,7 @@ class Manual if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = match condition case true ==> if_true - case false ==> if_false + case x ==> if_false end /* A vertical bar `|` can be used as an abbreviation for `case`. */ @@ -225,7 +225,7 @@ class Manual another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = match condition case true ==> if_true - case false ==> if_false + case x ==> if_false end sum (n : Int) = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala index 9a09349e..f17155c8 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala @@ -11,11 +11,11 @@ trait RecursionForCoq @tailrec final private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = sequence match { - case Nil => current_value case (head) :: (tail) => if ( ( ! (condition (current_value) (head) ) ) ) current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) + case x => current_value } def fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = @@ -25,8 +25,8 @@ trait RecursionForCoq @tailrec final private def _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = sequence match { - case Nil => current_value case (head) :: (tail) => _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) + case x => current_value } def fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda index 33ee450b..ec15803b 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda @@ -9,11 +9,11 @@ class RecursionForCoq @tailrec _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = match sequence - case Nil ==> current_value case (head) :: (tail) ==> if ( not (condition (current_value) (head) ) ) then current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) + case x ==> current_value end fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = @@ -22,8 +22,8 @@ class RecursionForCoq @tailrec _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = match sequence - case Nil ==> current_value case (head) :: (tail) ==> _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) + case x ==> current_value end fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala index 9d55494c..d08bfdd5 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala @@ -35,8 +35,8 @@ trait SeqList @tailrec final private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = a match { - case nil_ () => b case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) + case x => b } def reverse [A] (s : list [A] ) : list [A] = @@ -46,8 +46,8 @@ trait SeqList @tailrec final private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = a match { - case Nil => b case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) + case x => b } def from_Seq [A] (a : Seq [A] ) : list [A] = @@ -57,8 +57,8 @@ trait SeqList @tailrec final private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = a match { - case nil_ () => b case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) + case x => b } def to_Seq [A] (a : list [A] ) : Seq [A] = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda index 1f630afb..ffe89ada 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda @@ -25,8 +25,8 @@ class SeqList @tailrec _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = match a - case nil_ () ==> b case cons_ (e, s) ==> _tailrec_reverse (s) ( cons_ (e, b) ) + case x ==> b end reverse [A] (s : list [A] ) : list [A] = @@ -35,8 +35,8 @@ class SeqList @tailrec _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = match a - case Nil ==> b case (e) :: (s) ==> _tailrec_from_Seq (s) (cons_ (e, b) ) + case x ==> b end from_Seq [A] (a : Seq [A] ) : list [A] = @@ -45,8 +45,8 @@ class SeqList @tailrec _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = match a - case nil_ () ==> b case cons_ (e, s) ==> _tailrec_to_Seq (s) ( b .+: (e) ) + case x ==> b end to_Seq [A] (a : list [A] ) : Seq [A] = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala index 4e184a39..435fbd5b 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala @@ -80,8 +80,8 @@ trait IntNat def to_Int (a : nat) : Int = a match { - case O_ () => 0 case S_ (k) => 1 + to_Int (k) + case x => 0 } } diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda index db7d45d6..371501c5 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda @@ -72,8 +72,8 @@ class IntNat to_Int (a : nat) : Int = match a - case O_ () ==> 0 case S_ (k) ==> 1 + to_Int (k) + case x ==> 0 end end diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala index fe37fef9..36f039b6 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala @@ -11,8 +11,8 @@ trait FactorialForCoq @tailrec final private def _tailrec_get_factorial (m : nat) (product : nat) : nat = m match { - case O_ () => product case S_ (k) => _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) + case x => product } def get_factorial (n : nat) : nat = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda index 9e675a99..10f9a691 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda @@ -10,8 +10,8 @@ class FactorialForCoq @tailrec _tailrec_get_factorial (m : nat) (product : nat) : nat = match m - case O_ () ==> product case S_ (k) ==> _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) + case x ==> product end get_factorial (n : nat) : nat = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala index db3e540a..f9345f4f 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala @@ -11,9 +11,9 @@ trait FiboExampleInSodaForCoq @tailrec final private def _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = m match { - case O_ () => a case S_ (O_ () ) => b case S_ (k) => _tailrec_fib (k) (b) (a .add (b) ) + case x => a } def fib (n : nat) = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 4ee70a5d..728d0456 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -10,9 +10,9 @@ class FiboExampleInSodaForCoq @tailrec _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = match m - case O_ () ==> a case S_ (O_ () ) ==> b case S_ (k) ==> _tailrec_fib (k) (b) (a .add (b) ) + case x ==> a end fib (n : nat) = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala index 07ba6150..19db2a1a 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -11,8 +11,8 @@ trait TriangularNumberForCoq @tailrec final private def _tailrec_get_number (m : nat) (acc : nat) : nat = m match { - case O_ () => acc case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x => acc } def get_number (n : nat) : nat = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda index 6b25a522..c911c46a 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -10,8 +10,8 @@ class TriangularNumberForCoq @tailrec _tailrec_get_number (m : nat) (acc : nat) : nat = match m - case O_ () ==> acc case S_ (k) ==> _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x ==> acc end get_number (n : nat) : nat = diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v index 39a8e387..67403689 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v @@ -17,8 +17,8 @@ Module TriangularNumberForCoq . Fixpoint @tailrec _tailrec_get_number (m : nat) (acc : nat) : nat := match m with - | O_ () => acc | S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + | x => acc end . diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala index 7d24d277..41089561 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala @@ -10,7 +10,7 @@ trait FactorialPatternMatching private def _tailrec_get_factorial (n : Int) (product : Int) : Int = n match { case 0 => product - case k => _tailrec_get_factorial (k - 1) (k * product) + case x => _tailrec_get_factorial (x - 1) (x * product) } lazy val get_factorial : Int => Int = diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda index f8cd4f96..dea900b7 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda @@ -8,7 +8,7 @@ class FactorialPatternMatching _tailrec_get_factorial (n : Int) (product : Int) : Int = match n case 0 ==> product - case k ==> _tailrec_get_factorial (k - 1) (k * product) + case x ==> _tailrec_get_factorial (x - 1) (x * product) end get_factorial : Int -> Int = diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala index 5b67c413..64240739 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala @@ -223,7 +223,7 @@ case class MicroTranslatorToScalaSpec () "\n match n" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n end" + "\n" ) @@ -232,7 +232,7 @@ case class MicroTranslatorToScalaSpec () "\n n match {" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n }" + "\n" ) @@ -244,7 +244,7 @@ case class MicroTranslatorToScalaSpec () "\n match n" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n end" + "\n" ) @@ -253,7 +253,7 @@ case class MicroTranslatorToScalaSpec () "\n n match {" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n }" + "\n" ) diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda index ce7a32d9..cc97086d 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda @@ -223,7 +223,7 @@ class MicroTranslatorToScalaSpec () "\n match n" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n end" + "\n" ) @@ -232,7 +232,7 @@ class MicroTranslatorToScalaSpec () "\n n match {" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n }" + "\n" ) @@ -244,7 +244,7 @@ class MicroTranslatorToScalaSpec () "\n match n" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n end" + "\n" ) @@ -253,7 +253,7 @@ class MicroTranslatorToScalaSpec () "\n n match {" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n }" + "\n" ) From e18b1debee69bc1afa525ea27805aae4b29cfd8d Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 13 Dec 2022 19:00:50 +0100 Subject: [PATCH 08/71] Update manual --- .../soda/translator/documentation/Manual.scala | 10 +--------- .../soda/translator/documentation/Manual.soda | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index 8aaa7a98..c2bd7cf2 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -3,7 +3,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. * Copyright 2021 Julian Mendez - * Version: 2021-11-19 + * Version: 2022-12-13 */ /* @@ -246,14 +246,6 @@ trait Manual case x => if_false } - /* A vertical bar `|` can be used as an abbreviation for `case`. */ - - def another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - condition match { - case true => if_true - case x => if_false - } - def sum (n : Int) = _tailrec_ (n) (0) diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 1fc1da74..557867aa 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -3,7 +3,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. * Copyright 2021 Julian Mendez - * Version: 2021-11-19 + * Version: 2022-12-13 */ /* @@ -220,14 +220,6 @@ class Manual case x ==> if_false end - /* A vertical bar `|` can be used as an abbreviation for `case`. */ - - another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - match condition - case true ==> if_true - case x ==> if_false - end - sum (n : Int) = _tailrec_ (n) (0) From 81b544a7ef5954935bb049ddc19ba67d8aa7e93b Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 13 Dec 2022 19:03:37 +0100 Subject: [PATCH 09/71] Update library --- translator/src/main/scala/soda/lib/OptionSD.scala | 12 ++++++------ translator/src/main/scala/soda/lib/OptionSD.soda | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/translator/src/main/scala/soda/lib/OptionSD.scala b/translator/src/main/scala/soda/lib/OptionSD.scala index 5de0f322..983629ac 100644 --- a/translator/src/main/scala/soda/lib/OptionSD.scala +++ b/translator/src/main/scala/soda/lib/OptionSD.scala @@ -19,32 +19,32 @@ trait OptionSD [A] def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = this match { - case NoneSD_ () => ifEmpty case SomeSD_ (element) => ifNonEmpty (element) + case x => ifEmpty } def map [B] (mapping : A => B) : OptionSD [B] = this match { - case NoneSD_ () => NoneSD_ [B] () case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) + case x => NoneSD_ [B] () } def getOrElse (default : A) : A = this match { - case NoneSD_ () => default case SomeSD_ (element) => element + case x => default } def fold [B] (ifEmpty : B) (f : A => B) : B = this match { - case NoneSD_ () => ifEmpty case SomeSD_ (element) => f (element) + case x => ifEmpty } def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = this match { - case NoneSD_ () => NoneSD_ () case SomeSD_ (element) => mapping (element) + case x => NoneSD_ () } def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = @@ -52,11 +52,11 @@ trait OptionSD [A] def filter (predicate : A => Boolean) : OptionSD [A] = this match { - case NoneSD_ () => NoneSD_ () case SomeSD_ (element) => if ( predicate (element) ) this else NoneSD_ [A] () + case x => NoneSD_ () } } diff --git a/translator/src/main/scala/soda/lib/OptionSD.soda b/translator/src/main/scala/soda/lib/OptionSD.soda index 883bc977..483c9c74 100644 --- a/translator/src/main/scala/soda/lib/OptionSD.soda +++ b/translator/src/main/scala/soda/lib/OptionSD.soda @@ -19,32 +19,32 @@ class OptionSD [A] opt [B] (ifEmpty : B) (ifNonEmpty : A -> B) : B = match this - case NoneSD_ () ==> ifEmpty case SomeSD_ (element) ==> ifNonEmpty (element) + case x ==> ifEmpty end map [B] (mapping : A -> B) : OptionSD [B] = match this - case NoneSD_ () ==> NoneSD_ [B] () case SomeSD_ (element) ==> SomeSD_ [B] (mapping (element) ) + case x ==> NoneSD_ [B] () end getOrElse (default : A) : A = match this - case NoneSD_ () ==> default case SomeSD_ (element) ==> element + case x ==> default end fold [B] (ifEmpty : B) (f : A -> B) : B = match this - case NoneSD_ () ==> ifEmpty case SomeSD_ (element) ==> f (element) + case x ==> ifEmpty end flatMap [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = match this - case NoneSD_ () ==> NoneSD_ () case SomeSD_ (element) ==> mapping (element) + case x ==> NoneSD_ () end bind [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = @@ -52,11 +52,11 @@ class OptionSD [A] filter (predicate : A -> Boolean) : OptionSD [A] = match this - case NoneSD_ () ==> NoneSD_ () case SomeSD_ (element) ==> if predicate (element) then this else NoneSD_ [A] () + case x ==> NoneSD_ () end end From 073afb596bfce15b0472e5e29e1600909f586d87 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 13 Dec 2022 19:26:40 +0100 Subject: [PATCH 10/71] Update library --- translator/src/main/scala/soda/lib/SeqSD.scala | 2 +- translator/src/main/scala/soda/lib/SeqSD.soda | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/translator/src/main/scala/soda/lib/SeqSD.scala b/translator/src/main/scala/soda/lib/SeqSD.scala index bdfcd233..75a7b9a0 100644 --- a/translator/src/main/scala/soda/lib/SeqSD.scala +++ b/translator/src/main/scala/soda/lib/SeqSD.scala @@ -16,8 +16,8 @@ trait SeqSD [A] def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = this match { - case EmptySeqSD_ () => ifEmpty case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty } } diff --git a/translator/src/main/scala/soda/lib/SeqSD.soda b/translator/src/main/scala/soda/lib/SeqSD.soda index 3b61be61..3fe4d31f 100644 --- a/translator/src/main/scala/soda/lib/SeqSD.soda +++ b/translator/src/main/scala/soda/lib/SeqSD.soda @@ -16,8 +16,8 @@ class SeqSD [A] opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] -> B) : B = match this - case EmptySeqSD_ () ==> ifEmpty case NonEmptySeqSD_ (toSeq) ==> ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x ==> ifEmpty end end From 849a20d6433a750fc1615e99436344bdac0dfdc4 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 17 Jan 2023 13:15:56 +0100 Subject: [PATCH 11/71] Update manual --- .../translator/documentation/Manual.scala | 23 ++++++----- .../soda/translator/documentation/Manual.soda | 23 ++++++----- .../translator/documentation/Manual.scala | 33 ++++++---------- .../soda/translator/documentation/Manual.soda | 33 ++++++---------- .../soda/translator/documentation/Manual.tex | 39 ++++++------------- 5 files changed, 58 insertions(+), 93 deletions(-) diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index c2bd7cf2..f02aef6b 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -2,8 +2,8 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021 Julian Mendez - * Version: 2022-12-13 + * Copyright 2021--2023 Julian Mendez + * Version: 2023-01-17 */ /* @@ -41,7 +41,7 @@ trait Movable case class Movable_ () extends Movable -/* A class can be parameterized. +/* A class can be parameterized using square brackets ('[' and ']'). * The parameter type can be constrained using `subtype` and `supertype`. * For example, `A subtype B` means that `A` is a subtype of `B`. */ @@ -115,8 +115,7 @@ trait Agent case class Agent_ (identifier : String) extends Agent -/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. - * Please note that an abstract class might have constants and functions that are not defined in its ancestor classes. */ +/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. */ trait RegisteredPersonAgent extends @@ -210,7 +209,7 @@ trait Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a right arrow (`->`). */ + * Lambda functions are declared using a long right arrow (`-->`). */ def plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( element => element + 1) @@ -238,7 +237,7 @@ trait Manual (x || y) && ! (x && y) /* It is possible to use pattern matching with `match` and `case`. - * Please observe the long double arrow `==>`. */ + * The result of the matching case is put after a long double arrow `==>`. */ def if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = condition match { @@ -326,20 +325,20 @@ trait Recursion import scala.annotation.tailrec @tailrec final - private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = if ( sequence.isEmpty ) current_value else if ( ! condition (current_value) (sequence.head) ) current_value - else _tailrec_fold4 (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) import scala.annotation.tailrec @tailrec final - private def _tailrec_range (n : Int, sequence : Seq [Int] ) : Seq [Int] = + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if ( n <= 0 ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 557867aa..a7298a32 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -2,8 +2,8 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021 Julian Mendez - * Version: 2022-12-13 + * Copyright 2021--2023 Julian Mendez + * Version: 2023-01-17 */ /* @@ -35,7 +35,7 @@ class Movable end -/* A class can be parameterized. +/* A class can be parameterized using square brackets ('[' and ']'). * The parameter type can be constrained using `subtype` and `supertype`. * For example, `A subtype B` means that `A` is a subtype of `B`. */ @@ -99,8 +99,7 @@ class Agent end -/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. - * Please note that an abstract class might have constants and functions that are not defined in its ancestor classes. */ +/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. */ class RegisteredPersonAgent extends @@ -184,7 +183,7 @@ class Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a right arrow (`->`). */ + * Lambda functions are declared using a long right arrow (`-->`). */ plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( lambda element --> element + 1) @@ -212,7 +211,7 @@ class Manual (x or y) and not (x and y) /* It is possible to use pattern matching with `match` and `case`. - * Please observe the long double arrow `==>`. */ + * The result of the matching case is put after a long double arrow `==>`. */ if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = match condition @@ -283,19 +282,19 @@ end class Recursion @tailrec - _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = if sequence.isEmpty then current_value else if not condition (current_value) (sequence.head) then current_value - else _tailrec_fold4 (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) @tailrec - _tailrec_range (n : Int, sequence : Seq [Int] ) : Seq [Int] = + _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.scala b/translator/src/test/resources/soda/translator/documentation/Manual.scala index d0bfaab2..f02aef6b 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/test/resources/soda/translator/documentation/Manual.scala @@ -2,8 +2,8 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021 Julian Mendez - * Version: 2021-11-19 + * Copyright 2021--2023 Julian Mendez + * Version: 2023-01-17 */ /* @@ -41,7 +41,7 @@ trait Movable case class Movable_ () extends Movable -/* A class can be parameterized. +/* A class can be parameterized using square brackets ('[' and ']'). * The parameter type can be constrained using `subtype` and `supertype`. * For example, `A subtype B` means that `A` is a subtype of `B`. */ @@ -115,8 +115,7 @@ trait Agent case class Agent_ (identifier : String) extends Agent -/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. - * Please note that an abstract class might have constants and functions that are not defined in its ancestor classes. */ +/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. */ trait RegisteredPersonAgent extends @@ -210,7 +209,7 @@ trait Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a right arrow (`->`). */ + * Lambda functions are declared using a long right arrow (`-->`). */ def plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( element => element + 1) @@ -238,20 +237,12 @@ trait Manual (x || y) && ! (x && y) /* It is possible to use pattern matching with `match` and `case`. - * Please observe the long double arrow `==>`. */ + * The result of the matching case is put after a long double arrow `==>`. */ def if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = condition match { case true => if_true - case false => if_false - } - - /* A vertical bar `|` can be used as an abbreviation for `case`. */ - - def another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - condition match { - case true => if_true - case false => if_false + case x => if_false } def sum (n : Int) = @@ -334,20 +325,20 @@ trait Recursion import scala.annotation.tailrec @tailrec final - private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = if ( sequence.isEmpty ) current_value else if ( ! condition (current_value) (sequence.head) ) current_value - else _tailrec_fold4 (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) import scala.annotation.tailrec @tailrec final - private def _tailrec_range (n : Int, sequence : Seq [Int] ) : Seq [Int] = + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if ( n <= 0 ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index 93ee5591..a7298a32 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -2,8 +2,8 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021 Julian Mendez - * Version: 2021-11-19 + * Copyright 2021--2023 Julian Mendez + * Version: 2023-01-17 */ /* @@ -35,7 +35,7 @@ class Movable end -/* A class can be parameterized. +/* A class can be parameterized using square brackets ('[' and ']'). * The parameter type can be constrained using `subtype` and `supertype`. * For example, `A subtype B` means that `A` is a subtype of `B`. */ @@ -99,8 +99,7 @@ class Agent end -/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. - * Please note that an abstract class might have constants and functions that are not defined in its ancestor classes. */ +/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. */ class RegisteredPersonAgent extends @@ -184,7 +183,7 @@ class Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a right arrow (`->`). */ + * Lambda functions are declared using a long right arrow (`-->`). */ plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( lambda element --> element + 1) @@ -212,20 +211,12 @@ class Manual (x or y) and not (x and y) /* It is possible to use pattern matching with `match` and `case`. - * Please observe the long double arrow `==>`. */ + * The result of the matching case is put after a long double arrow `==>`. */ if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = match condition case true ==> if_true - case false ==> if_false - end - - /* A vertical bar `|` can be used as an abbreviation for `case`. */ - - another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - match condition - case true ==> if_true - case false ==> if_false + case x ==> if_false end sum (n : Int) = @@ -291,19 +282,19 @@ end class Recursion @tailrec - _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = if sequence.isEmpty then current_value else if not condition (current_value) (sequence.head) then current_value - else _tailrec_fold4 (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) @tailrec - _tailrec_range (n : Int, sequence : Seq [Int] ) : Seq [Int] = + _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index 1f1cbbdb..46fdc64b 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -38,8 +38,8 @@ \end{lstlisting} This is a Soda tutorial written in Soda. -Copyright 2021 Julian Mendez - Version: 2021-11-19 +Copyright 2021--2023 Julian Mendez + Version: 2023-01-17 \begin{lstlisting} @@ -87,7 +87,7 @@ \end{lstlisting} -For example, `A subtype B` means that `A` is a subtype of `B`. A class can be parameterized.The parameter type can be constrained using `subtype` and `supertype`. +For example, `A subtype B` means that `A` is a subtype of `B`. A class can be parameterized using square brackets ('[' and ']').The parameter type can be constrained using `subtype` and `supertype`. \begin{lstlisting} @@ -205,7 +205,7 @@ \end{lstlisting} -A concrete class needs as parameters all the constants and functions that have not been defined in its super classes.Please note that an abstract class might have constants and functions that are not defined in its ancestor classes. +A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. \begin{lstlisting} @@ -325,7 +325,7 @@ \end{lstlisting} -Scala sequences (`Seq`) can be used, as well as other basic Scala classes.Lambda functions are declared using a right arrow (`->`). +Scala sequences (`Seq`) can be used, as well as other basic Scala classes.Lambda functions are declared using a long right arrow (`-->`). \begin{lstlisting} @@ -373,7 +373,7 @@ \end{lstlisting} -It is possible to use pattern matching with `match` and `case`.Please observe the long double arrow `==>`. +It is possible to use pattern matching with `match` and `case`.The result of the matching case is put after a long double arrow `==>`. \begin{lstlisting} @@ -382,22 +382,7 @@ if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = match condition case true ==> if_true - case false ==> if_false - end - - -\end{lstlisting} - -A vertical bar `|` can be used as an abbreviation for `case`. - - -\begin{lstlisting} - - - another_if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - match condition - case true ==> if_true - case false ==> if_false + case x ==> if_false end sum (n : Int) = @@ -476,19 +461,19 @@ class Recursion @tailrec - _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = if sequence.isEmpty then current_value else if not condition (current_value) (sequence.head) then current_value - else _tailrec_fold4 (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) @tailrec - _tailrec_range (n : Int, sequence : Seq [Int] ) : Seq [Int] = + _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) From 42f008d052796eba104c352deecfea402ab77bc0 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 17 Jan 2023 14:17:34 +0100 Subject: [PATCH 12/71] Update examples --- .../example/algorithms/FizzBuzzPatternMatching.scala | 2 +- .../example/algorithms/FizzBuzzPatternMatching.soda | 2 +- .../translator/example/algorithms/PatternMatching.scala | 4 ++-- .../translator/example/algorithms/PatternMatching.soda | 4 ++-- .../ethicalissues/pricemonitor/Requirement1Monitor.scala | 8 ++++++-- .../ethicalissues/pricemonitor/Requirement1Monitor.soda | 8 ++++++-- .../ethicalissues/pricemonitor/Requirement3Monitor.scala | 4 ++-- .../ethicalissues/pricemonitor/Requirement3Monitor.soda | 4 ++-- 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala index eac94e5f..a3d2d622 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala @@ -20,7 +20,7 @@ trait FizzBuzzPatternMatching case Tuple2 (0, 0) => fizz + buzz case Tuple2 (0, x) => fizz case Tuple2 (x, 0) => buzz - case otherwise => n.toString + case x => n.toString } } diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda index ce7ebfbc..ca2478c4 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda @@ -20,7 +20,7 @@ class FizzBuzzPatternMatching case Tuple2 (0, 0) ==> fizz + buzz case Tuple2 (0, x) ==> fizz case Tuple2 (x, 0) ==> buzz - case otherwise ==> n.toString + case x ==> n.toString end end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala index 59eaa1b9..647ea947 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala @@ -17,7 +17,7 @@ trait PatternMatching case Singleton_ (x) => x case Pair_ (x, y) => (x + y) / 2 case Triplet_ (x, y, z) => (x + y + z) / 3 - case otherwise => 0 + case x => 0 } def get_type_name (p : Parameter) : String = @@ -25,7 +25,7 @@ trait PatternMatching case Singleton_ (x) => (Singleton_ (x) ).name + "(x)" case Pair_ (x, y) => (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) => (Triplet_ (x, y, z) ).name + "(x, y, z)" - case otherwise => "" + case x => "" } } diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda index c9eb4082..ca1c8307 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda @@ -14,7 +14,7 @@ class PatternMatching case Singleton_ (x) ==> x case Pair_ (x, y) ==> (x + y) / 2 case Triplet_ (x, y, z) ==> (x + y + z) / 3 - case otherwise ==> 0 + case x ==> 0 end get_type_name (p : Parameter) : String = @@ -22,7 +22,7 @@ class PatternMatching case Singleton_ (x) ==> (Singleton_ (x) ).name + "(x)" case Pair_ (x, y) ==> (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) ==> (Triplet_ (x, y, z) ).name + "(x, y, z)" - case otherwise ==> "" + case x ==> "" end end diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index e8c12ffa..730db703 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -37,10 +37,14 @@ trait Requirement1Monitor 1.0 * (min (x) (y) ) / (max (x) (y) ) def min (x : Int) (y : Int) : Int = - if ( x < y ) x else y + if ( x < y + ) x + else y def max (x : Int) (y : Int) : Int = - if ( x < y ) y else x + if ( x < y + ) y + else x } diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda index 2a81b46b..b8256a5e 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda @@ -35,10 +35,14 @@ class Requirement1Monitor 1.0 * (min (x) (y) ) / (max (x) (y) ) min (x : Int) (y : Int) : Int = - if x < y then x else y + if x < y + then x + else y max (x : Int) (y : Int) : Int = - if x < y then y else x + if x < y + then y + else x end diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 7bd4b38c..03940a9b 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -64,8 +64,8 @@ trait SegmentsForFlight def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = intermediate_stops match { - case Nil => Nil.+: (Segment_ (first_airport, last_airport) ) - case x :: xs => (rec_segments_multi (x) (xs) (last_airport) ).+: (Segment_ (first_airport, x) ) + case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x => Nil.+: (Segment_ (first_airport, last_airport) ) } } diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index d85825f0..1417f084 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -58,8 +58,8 @@ class SegmentsForFlight rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = match intermediate_stops - case Nil ==> Nil.+: (Segment_ (first_airport, last_airport) ) - case x :: xs ==> (rec_segments_multi (x) (xs) (last_airport) ).+: (Segment_ (first_airport, x) ) + case head :: tail ==> (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x ==> Nil.+: (Segment_ (first_airport, last_airport) ) end end From 06dc48c7a72fbaedae48d74eb2eb94cd37c04b4c Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 11:22:14 +0100 Subject: [PATCH 13/71] Make small correction --- .../extension/toscala/ClassConstructorBlockTranslator.soda | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda index 21e39a7e..6d111327 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda @@ -88,7 +88,7 @@ class ClassConstructorBlockTranslator _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = references - .flatMap ( lambda block ==> + .flatMap ( lambda block --> match block case AbstractDeclarationAnnotation_ (b, references) ==> Some (AbstractDeclarationAnnotation_ (b, references) ) case x ==> None From 83422cb5934c31022e6e25d0222d1baac6645a25 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 11:46:30 +0100 Subject: [PATCH 14/71] Include `any` as reserved word --- docs/RELEASE-NOTES.md | 4 +++- .../soda/translator/documentation/Manual.scala | 7 ++++++- .../soda/translator/documentation/Manual.soda | 7 ++++++- .../documentation/configuration_for_intellij.txt | 1 + .../soda/translator/documentation/soda.lang | 1 + .../tocoq/TranslationConstantToCoq.scala | 1 + .../tocoq/TranslationConstantToCoq.soda | 1 + .../toscala/TranslationConstantToScala.scala | 3 +-- .../toscala/TranslationConstantToScala.soda | 3 +-- .../soda/translator/parser/SodaConstant.scala | 6 +++++- .../soda/translator/parser/SodaConstant.soda | 6 +++++- .../soda/translator/documentation/Manual.scala | 7 ++++++- .../soda/translator/documentation/Manual.soda | 7 ++++++- .../soda/translator/documentation/Manual.tex | 16 ++++++++++++++-- .../toscala/MicroTranslatorToScalaSpec.scala | 15 +++++++++++++-- .../toscala/MicroTranslatorToScalaSpec.soda | 15 +++++++++++++-- 16 files changed, 83 insertions(+), 17 deletions(-) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index 075ab134..a39572ba 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -3,6 +3,8 @@ - date: unreleased - build: sbt '++ 3.2.0' clean compile test package assembly - release: target/scala-3.2.0/soda-0.17.0.jar + - new_features: + - accepts reserved word `any` as a synonym for `lambda` - - version: v0.16.0 - date: '2022-08-02' - new_features: @@ -136,7 +138,7 @@ - includes a file expansion of a basic library when it finds `lib.soda` - produces better looking Scala translated source code - deprecated_features: - - does not longer support the use of tuples on the left-hand side of a definition sign (`=`) + - does not support any longer the use of tuples on the left-hand side of a definition sign (`=`) - bug_fixes: - fixes translation of constants that are lambda functions - build: sbt '++ 3.0.0-RC2' clean compile test package assembly diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index f02aef6b..a10308d6 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -209,11 +209,16 @@ trait Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a long right arrow (`-->`). */ + * Lambda functions are declared with `lambda` and a long right arrow (`-->`). */ def plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( element => element + 1) + /* A synonym for `lambda` is `any`, which sometimes brings more readability. */ + + def plus_two (sequence : Seq [Int] ) : Seq [Int] = + sequence.map ( element => element + 2) + /* Boolean values `false` and `true` are available. */ def my_not (x : Boolean) : Boolean = diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index a7298a32..5006b25b 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -183,11 +183,16 @@ class Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a long right arrow (`-->`). */ + * Lambda functions are declared with `lambda` and a long right arrow (`-->`). */ plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( lambda element --> element + 1) + /* A synonym for `lambda` is `any`, which sometimes brings more readability. */ + + plus_two (sequence : Seq [Int] ) : Seq [Int] = + sequence.map ( any element --> element + 2) + /* Boolean values `false` and `true` are available. */ my_not (x : Boolean) : Boolean = diff --git a/translator/src/main/resources/soda/translator/documentation/configuration_for_intellij.txt b/translator/src/main/resources/soda/translator/documentation/configuration_for_intellij.txt index ea027bd5..a5a63d81 100644 --- a/translator/src/main/resources/soda/translator/documentation/configuration_for_intellij.txt +++ b/translator/src/main/resources/soda/translator/documentation/configuration_for_intellij.txt @@ -30,6 +30,7 @@ Keywords = ==> abstract +any case class else diff --git a/translator/src/main/resources/soda/translator/documentation/soda.lang b/translator/src/main/resources/soda/translator/documentation/soda.lang index ea913be7..cd34d8c7 100644 --- a/translator/src/main/resources/soda/translator/documentation/soda.lang +++ b/translator/src/main/resources/soda/translator/documentation/soda.lang @@ -149,6 +149,7 @@ lambda + any diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala index f64932f9..8bf14c43 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala @@ -219,6 +219,7 @@ trait TranslationConstantToCoq Seq ( Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda index f5c868d5..8d5c0b93 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda @@ -219,6 +219,7 @@ class TranslationConstantToCoq Seq ( Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala index 19c2490e..62fab699 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala @@ -55,8 +55,6 @@ trait TranslationConstantToScala lazy val scala_then_translation = ")" - lazy val soda_class_reserved_word = "class" - lazy val scala_abstract_function_declaration = "def" lazy val scala_definition = "def" @@ -196,6 +194,7 @@ trait TranslationConstantToScala lazy val function_symbol_translation : Seq [Tuple2 [String, String] ] = Seq ( Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), + Tuple2 (soda_constant.any_reserved_word, scala_empty_string), Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda index 7095e0c2..057454da 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda @@ -55,8 +55,6 @@ class TranslationConstantToScala scala_then_translation = ")" - soda_class_reserved_word = "class" - scala_abstract_function_declaration = "def" scala_definition = "def" @@ -196,6 +194,7 @@ class TranslationConstantToScala function_symbol_translation : Seq [Tuple2 [String, String] ] = Seq ( Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), + Tuple2 (soda_constant.any_reserved_word, scala_empty_string), Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala index ac152273..f92838fd 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala @@ -21,6 +21,8 @@ trait SodaConstant lazy val lambda_reserved_word = "lambda" + lazy val any_reserved_word = "any" + lazy val if_reserved_word = "if" lazy val then_reserved_word = "then" @@ -71,7 +73,7 @@ trait SodaConstant lazy val subtype_abbreviation = "<:" - lazy val supertype_abbreviation = ">:" + lazy val supertype_abbreviation = ">:" lazy val opening_parenthesis_symbol = "(" @@ -112,11 +114,13 @@ trait SodaConstant lazy val soda_reserved_words_words_only : Seq [String] = Seq ( lambda_reserved_word, + any_reserved_word, if_reserved_word, then_reserved_word, else_reserved_word, match_reserved_word, case_reserved_word, + match_end_reserved_word, class_reserved_word, extends_reserved_word, abstract_reserved_word, diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index 87c26da9..8b89817b 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -20,6 +20,8 @@ class SodaConstant lambda_reserved_word = "lambda" + any_reserved_word = "any" + if_reserved_word = "if" then_reserved_word = "then" @@ -70,7 +72,7 @@ class SodaConstant subtype_abbreviation = "<:" - supertype_abbreviation = ">:" + supertype_abbreviation = ">:" opening_parenthesis_symbol = "(" @@ -111,11 +113,13 @@ class SodaConstant soda_reserved_words_words_only : Seq [String] = Seq ( lambda_reserved_word, + any_reserved_word, if_reserved_word, then_reserved_word, else_reserved_word, match_reserved_word, case_reserved_word, + match_end_reserved_word, class_reserved_word, extends_reserved_word, abstract_reserved_word, diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.scala b/translator/src/test/resources/soda/translator/documentation/Manual.scala index f02aef6b..a10308d6 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/test/resources/soda/translator/documentation/Manual.scala @@ -209,11 +209,16 @@ trait Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a long right arrow (`-->`). */ + * Lambda functions are declared with `lambda` and a long right arrow (`-->`). */ def plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( element => element + 1) + /* A synonym for `lambda` is `any`, which sometimes brings more readability. */ + + def plus_two (sequence : Seq [Int] ) : Seq [Int] = + sequence.map ( element => element + 2) + /* Boolean values `false` and `true` are available. */ def my_not (x : Boolean) : Boolean = diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index a7298a32..5006b25b 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -183,11 +183,16 @@ class Manual else y /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared using a long right arrow (`-->`). */ + * Lambda functions are declared with `lambda` and a long right arrow (`-->`). */ plus_one (sequence : Seq [Int] ) : Seq [Int] = sequence.map ( lambda element --> element + 1) + /* A synonym for `lambda` is `any`, which sometimes brings more readability. */ + + plus_two (sequence : Seq [Int] ) : Seq [Int] = + sequence.map ( any element --> element + 2) + /* Boolean values `false` and `true` are available. */ my_not (x : Boolean) : Boolean = diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index 46fdc64b..59791552 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -6,7 +6,7 @@ \usepackage{listings} \lstdefinelanguage{Soda}{ - morekeywords={lambda, if, then, else, match, case, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @tailrec, @override, @new}, + morekeywords={lambda, any, if, then, else, match, case, end, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @tailrec, @override, @new}, sensitive=true, morecomment=[s]{/*}{*/}, morestring=[b]" @@ -325,7 +325,7 @@ \end{lstlisting} -Scala sequences (`Seq`) can be used, as well as other basic Scala classes.Lambda functions are declared using a long right arrow (`-->`). +Scala sequences (`Seq`) can be used, as well as other basic Scala classes.Lambda functions are declared with `lambda` and a long right arrow (`-->`). \begin{lstlisting} @@ -335,6 +335,18 @@ sequence.map ( lambda element --> element + 1) +\end{lstlisting} + +A synonym for `lambda` is `any`, which sometimes brings more readability. + + +\begin{lstlisting} + + + plus_two (sequence : Seq [Int] ) : Seq [Int] = + sequence.map ( any element --> element + 2) + + \end{lstlisting} Boolean values `false` and `true` are available. diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala index 64240739..a753e48f 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala @@ -265,7 +265,7 @@ case class MicroTranslatorToScalaSpec () "\n n match" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n" ) ) ( @@ -273,7 +273,7 @@ case class MicroTranslatorToScalaSpec () "\n n match" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n" ) ) @@ -289,4 +289,15 @@ case class MicroTranslatorToScalaSpec () ) ) + test ("should translate another explicit lambda expression") ( + check ( + obtained = instance.translate ("plus_1 : Int = any (x : Int) --> x + 1" + + "\n" + ) + ) ( + expected = "lazy val plus_1 : Int = (x : Int) => x + 1" + + "\n" + ) + ) + } diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda index cc97086d..224a4241 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda @@ -265,7 +265,7 @@ class MicroTranslatorToScalaSpec () "\n n match" + "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + - "\n case m ==> if m > 0 then fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + "\n" ) ) ( @@ -273,7 +273,7 @@ class MicroTranslatorToScalaSpec () "\n n match" + "\n case 0 => 1 " + "\n case 1 => 1 " + - "\n case m => if ( m > 0 ) fibo (m - 1) + fibo (m - 2) else 0" + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + "\n" ) ) @@ -289,5 +289,16 @@ class MicroTranslatorToScalaSpec () ) ) + test ("should translate another explicit lambda expression") ( + check ( + obtained := instance.translate ("plus_1 : Int = any (x : Int) --> x + 1" + + "\n" + ) + ) ( + expected := "lazy val plus_1 : Int = (x : Int) => x + 1" + + "\n" + ) + ) + end From fc98d7b955dc42a7b2b6e5ca8c889b8dafa962ea Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 14:02:50 +0100 Subject: [PATCH 15/71] Update examples --- .../soda/example/mathematics/FactorialConcise.scala | 12 ++++++------ .../soda/example/mathematics/FactorialConcise.soda | 12 ++++++------ .../mathematics/FactorialPatternMatching.scala | 12 ++++++------ .../mathematics/FactorialPatternMatching.soda | 12 ++++++------ .../scala/soda/example/mathematics/FiboExample.soda | 2 +- .../scala/soda/example/miniexample/MiniExample.soda | 2 +- .../example/mathematics/FactorialConcise.scala | 12 ++++++------ .../example/mathematics/FactorialConcise.soda | 12 ++++++------ .../mathematics/FactorialPatternMatching.scala | 12 ++++++------ .../mathematics/FactorialPatternMatching.soda | 12 ++++++------ .../translator/example/mathematics/FiboExample.soda | 2 +- .../translator/example/miniexample/MiniExample.soda | 2 +- 12 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala index fbcfcd86..925f7d9d 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala @@ -14,6 +14,12 @@ trait FactorialConcise AbstractFactorialConcise { + lazy val get_factorial : Int => Int = + n => get_factorial_for (n) + + def get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + import scala.annotation.tailrec @tailrec final private def _tailrec_get_factorial (n : Int) (product : Int) : Int = @@ -21,12 +27,6 @@ trait FactorialConcise ) product else _tailrec_get_factorial (n - 1) (n * product) - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - } case class FactorialConcise_ () extends FactorialConcise diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda index 7b443482..8f6db0b9 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda @@ -11,17 +11,17 @@ class FactorialConcise extends AbstractFactorialConcise + get_factorial : Int -> Int = + any n --> get_factorial_for (n) + + get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + @tailrec _tailrec_get_factorial (n : Int) (product : Int) : Int = if n == 0 then product else _tailrec_get_factorial (n - 1) (n * product) - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - end diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala index 41089561..208a2e2d 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala @@ -5,6 +5,12 @@ trait FactorialPatternMatching AbstractFactorialConcise { + lazy val get_factorial : Int => Int = + n => get_factorial_for (n) + + def get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + import scala.annotation.tailrec @tailrec final private def _tailrec_get_factorial (n : Int) (product : Int) : Int = @@ -13,12 +19,6 @@ trait FactorialPatternMatching case x => _tailrec_get_factorial (x - 1) (x * product) } - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - } case class FactorialPatternMatching_ () extends FactorialPatternMatching diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda index dea900b7..1592ef57 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda @@ -4,6 +4,12 @@ class FactorialPatternMatching extends AbstractFactorialConcise + get_factorial : Int -> Int = + lambda n --> get_factorial_for (n) + + get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + @tailrec _tailrec_get_factorial (n : Int) (product : Int) : Int = match n @@ -11,11 +17,5 @@ class FactorialPatternMatching case x ==> _tailrec_get_factorial (x - 1) (x * product) end - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - end diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda index b1a8ecb6..085a4d74 100644 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda +++ b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda @@ -17,7 +17,7 @@ class FiboExampleInSoda else _rec (m - 1) (b) (a + b) fib : Int -> Int = - lambda n --> fib_for (n) + any n --> fib_for (n) fib_for (n : Int) = _rec (n) (0) (1) diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda index 297df539..c75e830e 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda @@ -6,7 +6,7 @@ class MiniExample run () = range (50) - .map ( lambda x --> print (" " + (2 * x + 1) ) ) + .map ( any x --> print (" " + (2 * x + 1) ) ) end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala index fbcfcd86..925f7d9d 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala @@ -14,6 +14,12 @@ trait FactorialConcise AbstractFactorialConcise { + lazy val get_factorial : Int => Int = + n => get_factorial_for (n) + + def get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + import scala.annotation.tailrec @tailrec final private def _tailrec_get_factorial (n : Int) (product : Int) : Int = @@ -21,12 +27,6 @@ trait FactorialConcise ) product else _tailrec_get_factorial (n - 1) (n * product) - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - } case class FactorialConcise_ () extends FactorialConcise diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda index 7b443482..8f6db0b9 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda @@ -11,17 +11,17 @@ class FactorialConcise extends AbstractFactorialConcise + get_factorial : Int -> Int = + any n --> get_factorial_for (n) + + get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + @tailrec _tailrec_get_factorial (n : Int) (product : Int) : Int = if n == 0 then product else _tailrec_get_factorial (n - 1) (n * product) - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala index 41089561..208a2e2d 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala @@ -5,6 +5,12 @@ trait FactorialPatternMatching AbstractFactorialConcise { + lazy val get_factorial : Int => Int = + n => get_factorial_for (n) + + def get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + import scala.annotation.tailrec @tailrec final private def _tailrec_get_factorial (n : Int) (product : Int) : Int = @@ -13,12 +19,6 @@ trait FactorialPatternMatching case x => _tailrec_get_factorial (x - 1) (x * product) } - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - } case class FactorialPatternMatching_ () extends FactorialPatternMatching diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda index dea900b7..1592ef57 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda @@ -4,6 +4,12 @@ class FactorialPatternMatching extends AbstractFactorialConcise + get_factorial : Int -> Int = + lambda n --> get_factorial_for (n) + + get_factorial_for (n : Int) : Int = + _tailrec_get_factorial (n) (1) + @tailrec _tailrec_get_factorial (n : Int) (product : Int) : Int = match n @@ -11,11 +17,5 @@ class FactorialPatternMatching case x ==> _tailrec_get_factorial (x - 1) (x * product) end - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = - _tailrec_get_factorial (n) (1) - end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda index b1a8ecb6..085a4d74 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda @@ -17,7 +17,7 @@ class FiboExampleInSoda else _rec (m - 1) (b) (a + b) fib : Int -> Int = - lambda n --> fib_for (n) + any n --> fib_for (n) fib_for (n : Int) = _rec (n) (0) (1) diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda index 297df539..c75e830e 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda @@ -6,7 +6,7 @@ class MiniExample run () = range (50) - .map ( lambda x --> print (" " + (2 * x + 1) ) ) + .map ( any x --> print (" " + (2 * x + 1) ) ) end From 7c23bfb506ea68834e9f9766150fd27661ea2b3a Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 14:49:01 +0100 Subject: [PATCH 16/71] Update readme file --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index 77afda9e..a26b0ac6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,6 +16,7 @@ The reserved words are: - `=` (definition symbol) - `:=` (parameter definition symbol) - `lambda` +- `any` (synonym of `lambda`) - `-->` (lambda symbol) - `if` - `then` From 1585c0b0b7592d7cf2782e30bfa765d8e604d786 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 15:09:43 +0100 Subject: [PATCH 17/71] Add script to build binary file --- makeall.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 makeall.sh diff --git a/makeall.sh b/makeall.sh new file mode 100644 index 00000000..92c000ae --- /dev/null +++ b/makeall.sh @@ -0,0 +1,18 @@ +#/bin/bash + +# +# This script builds the Soda binary file. +# It requires `sbt` installed. +# + +sbt scalaVersion sbtVersion version clean compile test package assembly + +executableStub="exec java -jar \$0 \"\$@\" ; exit" +sodaFile="soda" +scalaVersion=$(ls "target/" | grep "scala-") +jarFile="target/${scalaVersion}/soda-*.jar" + +echo ${executableStub} >${sodaFile} +cat ${jarFile} >>${sodaFile} +chmod u+x ${sodaFile} + From e8e3c726fe598138fc5614ff1acdf7362a2f2113 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 15:21:08 +0100 Subject: [PATCH 18/71] Update copyright information --- build.sbt | 2 +- docs/README.md | 5 +++++ .../resources/soda/translator/documentation/Manual.scala | 2 +- .../main/resources/soda/translator/documentation/Manual.soda | 2 +- .../main/resources/soda/translator/documentation/NOTICE.txt | 2 +- .../main/resources/soda/translator/documentation/help.txt | 2 ++ .../main/resources/soda/translator/documentation/soda.lang | 4 ++-- .../resources/soda/translator/documentation/Manual.scala | 2 +- .../test/resources/soda/translator/documentation/Manual.soda | 2 +- .../test/resources/soda/translator/documentation/Manual.tex | 2 +- 10 files changed, 16 insertions(+), 9 deletions(-) diff --git a/build.sbt b/build.sbt index dfa16dac..13085ca0 100644 --- a/build.sbt +++ b/build.sbt @@ -19,7 +19,7 @@ lazy val commonSettings = organizationName := "Responsible Artificial Intelligence - Umea University", organizationHomepage := Some(url("https://www.umu.se/en/research/groups/responsible-artificial-intelligence")), developers := List( - Developer("julianmendez", "Julian Mendez", "julian.mendez@gmail.com", new URL("https://julianmendez.github.io")) + Developer("julianmendez", "Julian Alfredo Mendez", "julian.mendez@gmail.com", new URL("https://julianmendez.github.io")) ), /** * Scala diff --git a/docs/README.md b/docs/README.md index a26b0ac6..fda607e1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -114,3 +114,8 @@ The command is: It is also possible to compile it for different Scala versions. +## Author + +[Julian Alfredo Mendez](https://julianmendez.github.io) + + diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index a10308d6..eeab5e58 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -2,7 +2,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021--2023 Julian Mendez + * Copyright 2020--2023 Julian Alfredo Mendez * Version: 2023-01-17 */ diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 5006b25b..94efc118 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -2,7 +2,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021--2023 Julian Mendez + * Copyright 2020--2023 Julian Alfredo Mendez * Version: 2023-01-17 */ diff --git a/translator/src/main/resources/soda/translator/documentation/NOTICE.txt b/translator/src/main/resources/soda/translator/documentation/NOTICE.txt index 0ea76a54..270d2d22 100644 --- a/translator/src/main/resources/soda/translator/documentation/NOTICE.txt +++ b/translator/src/main/resources/soda/translator/documentation/NOTICE.txt @@ -1,4 +1,4 @@ -Copyright 2020-2021 Julian Mendez +Copyright 2020--2023 Julian Alfredo Mendez Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/translator/src/main/resources/soda/translator/documentation/help.txt b/translator/src/main/resources/soda/translator/documentation/help.txt index 713652b6..e7768a68 100644 --- a/translator/src/main/resources/soda/translator/documentation/help.txt +++ b/translator/src/main/resources/soda/translator/documentation/help.txt @@ -1,5 +1,7 @@ Soda - Symbolic Objective Descriptive Analysis +Copyright 2020--2023 Julian Alfredo Mendez + Soda is an object-oriented purely-functional language for descriptions. Usage: diff --git a/translator/src/main/resources/soda/translator/documentation/soda.lang b/translator/src/main/resources/soda/translator/documentation/soda.lang index cd34d8c7..e66af0dd 100644 --- a/translator/src/main/resources/soda/translator/documentation/soda.lang +++ b/translator/src/main/resources/soda/translator/documentation/soda.lang @@ -3,8 +3,8 @@ This file is part of GtkSourceView - Authors: Julian Mendez - Copyright (C) 2020 Julian Mendez + Authors: Julian Alfredo Mendez + Copyright 2020--2023 Julian Alfredo Mendez GtkSourceView is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.scala b/translator/src/test/resources/soda/translator/documentation/Manual.scala index a10308d6..eeab5e58 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/test/resources/soda/translator/documentation/Manual.scala @@ -2,7 +2,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021--2023 Julian Mendez + * Copyright 2020--2023 Julian Alfredo Mendez * Version: 2023-01-17 */ diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index 5006b25b..94efc118 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -2,7 +2,7 @@ package soda.translator.documentation /* * This is a Soda tutorial written in Soda. - * Copyright 2021--2023 Julian Mendez + * Copyright 2020--2023 Julian Alfredo Mendez * Version: 2023-01-17 */ diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index 59791552..514bdab8 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -38,7 +38,7 @@ \end{lstlisting} This is a Soda tutorial written in Soda. -Copyright 2021--2023 Julian Mendez +Copyright 2020--2023 Julian Alfredo Mendez Version: 2023-01-17 From 59c3483eb886ea6a27cb36603dee5a641ee8a697 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 16:38:36 +0100 Subject: [PATCH 19/71] Update Coq translator prelude --- .../translator/extension/tocoq/TranslationConstantToCoq.scala | 3 +++ .../translator/extension/tocoq/TranslationConstantToCoq.soda | 3 +++ 2 files changed, 6 insertions(+) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala index 8bf14c43..d44897e7 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala @@ -103,6 +103,9 @@ trait TranslationConstantToCoq "Require Import Coq.ZArith.BinInt .", "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", "", + "Require Import Coq.Lists.List .", + "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", + "", "Notation Int := Z .", "" ) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda index 8d5c0b93..6af236f7 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda @@ -103,6 +103,9 @@ class TranslationConstantToCoq "Require Import Coq.ZArith.BinInt .", "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", "", + "Require Import Coq.Lists.List .", + "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", + "", "Notation Int := Z .", "" ) From 2132a44a73f9e091e7f7d5712d71185510b2dfdf Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 16:58:54 +0100 Subject: [PATCH 20/71] Normalize match-case structures --- .../tocoq/CoqClassEndBlockTranslator.scala | 13 ++++----- .../tocoq/CoqClassEndBlockTranslator.soda | 13 ++++----- .../tocoq/CoqDefinitionBlockTranslator.scala | 10 ++++--- .../tocoq/CoqDefinitionBlockTranslator.soda | 10 ++++--- .../ClassConstructorBlockTranslator.scala | 27 ++++++++++--------- .../ClassConstructorBlockTranslator.soda | 27 ++++++++++--------- .../toscala/MainClassBlockTranslator.scala | 13 ++++----- .../toscala/MainClassBlockTranslator.soda | 13 ++++----- .../example/algorithms/SwapExample.v | 3 +++ .../mathematics/TriangularNumberForCoq.v | 3 +++ 10 files changed, 76 insertions(+), 56 deletions(-) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala index b2500f11..f563905a 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala @@ -52,14 +52,15 @@ trait CoqClassEndBlockTranslator private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( block => - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - ) + .flatMap ( block => _get_as_class_beginning_annotation (block) ) .headOption + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + } case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda index 08838c56..a6ac6cf3 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda @@ -52,13 +52,14 @@ class CoqClassEndBlockTranslator _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( lambda block --> - match block - case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) - case x ==> None - end - ) + .flatMap ( lambda block --> _get_as_class_beginning_annotation (block) ) .headOption + _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + match annotated_block + case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) + case x ==> None + end + end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala index 350cdc06..acf02bc9 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala @@ -29,10 +29,12 @@ trait CoqDefinitionBlockTranslator private def _translate_block (block : FunctionDefinitionAnnotation) : Block = if ( is_a_recursive_definition (block) ) _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) - else - if ( is_a_definition (block) - ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) - else block + else _translate_non_recursive_definition (block) + + private def _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = + if ( is_a_definition (block) + ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) + else block private def _prepend (prefix : String) (block : Block) : Block = BlockBuilder_ ().build ( diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda index 6f06343f..341f7768 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda @@ -29,10 +29,12 @@ class CoqDefinitionBlockTranslator _translate_block (block : FunctionDefinitionAnnotation) : Block = if is_a_recursive_definition (block) then _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) - else - if is_a_definition (block) - then _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) - else block + else _translate_non_recursive_definition (block) + + _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = + if is_a_definition (block) + then _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) + else block _prepend (prefix : String) (block : Block) : Block = BlockBuilder_ ().build ( diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala index e7e296e6..97452cfa 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala @@ -8,6 +8,7 @@ trait ClassConstructorBlockTranslator import soda.translator.block.AnnotatedBlock import soda.translator.parser.BlockBuilder_ import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ import soda.translator.parser.annotation.ClassBeginningAnnotation import soda.translator.parser.annotation.ClassBeginningAnnotation_ @@ -78,25 +79,27 @@ trait ClassConstructorBlockTranslator private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( block => - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - ) + .flatMap ( block => _get_as_class_beginning_annotation (block) ) .headOption + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + private def _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = references - .flatMap ( block => - block match { - case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) - case x => None - } - ) + .flatMap ( block => _get_as_abstract_declaration_annotation (block) ) .flatMap ( block => block.abstract_functions) .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) + private def _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = + block match { + case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) + case x => None + } + private def _translate_type_symbols (line : String) : String = line .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda index 6d111327..568fcdba 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda @@ -8,6 +8,7 @@ class ClassConstructorBlockTranslator soda.translator.block.AnnotatedBlock soda.translator.parser.BlockBuilder_ soda.translator.parser.SodaConstant_ + soda.translator.parser.annotation.AbstractDeclarationAnnotation soda.translator.parser.annotation.AbstractDeclarationAnnotation_ soda.translator.parser.annotation.ClassBeginningAnnotation soda.translator.parser.annotation.ClassBeginningAnnotation_ @@ -78,25 +79,27 @@ class ClassConstructorBlockTranslator _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( lambda block --> - match block - case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) - case x ==> None - end - ) + .flatMap ( lambda block --> _get_as_class_beginning_annotation (block) ) .headOption + _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + match annotated_block + case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) + case x ==> None + end + _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = references - .flatMap ( lambda block --> - match block - case AbstractDeclarationAnnotation_ (b, references) ==> Some (AbstractDeclarationAnnotation_ (b, references) ) - case x ==> None - end - ) + .flatMap ( lambda block --> _get_as_abstract_declaration_annotation (block) ) .flatMap ( lambda block --> block.abstract_functions) .map ( lambda annotated_line --> _translate_type_symbols (annotated_line.line).trim ) + _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = + match block + case AbstractDeclarationAnnotation_ (b, references) ==> Some (AbstractDeclarationAnnotation_ (b, references) ) + case x ==> None + end + _translate_type_symbols (line : String) : String = line .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala index 0c1ca023..fc3f4ba9 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala @@ -47,14 +47,15 @@ trait MainClassBlockTranslator private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( block => - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - ) + .flatMap ( block => _get_as_class_beginning_annotation (block) ) .headOption + private def _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + } case class MainClassBlockTranslator_ () extends MainClassBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda index f2cbbb8e..aa9f42a1 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda @@ -47,13 +47,14 @@ class MainClassBlockTranslator _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( lambda block --> - match block - case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) - case x ==> None - end - ) + .flatMap ( lambda block --> _get_as_class_beginning_annotation (block) ) .headOption + _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + match block + case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) + case x ==> None + end + end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v index 7ebecc43..80c2003d 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v +++ b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v @@ -5,6 +5,9 @@ package soda.example.algorithms Require Import Coq.ZArith.BinInt . (* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *) +Require Import Coq.Lists.List . +(* https://coq.inria.fr/library/Coq.Lists.List.html *) + Notation Int := Z . diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v index 67403689..906e8f88 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v @@ -5,6 +5,9 @@ package soda.example.forcoq.mathematics Require Import Coq.ZArith.BinInt . (* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *) +Require Import Coq.Lists.List . +(* https://coq.inria.fr/library/Coq.Lists.List.html *) + Notation Int := Z . From 3c8d3ed287ecc07c5d62cd809d333319c85a87a6 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 17:54:27 +0100 Subject: [PATCH 21/71] Remove `end` reserved word in `match`-`case` structures --- docs/RELEASE-NOTES.md | 5 +++- .../tocoq/MatchCaseBlockTranslator.scala | 30 +++++++++++++++++-- .../tocoq/MatchCaseBlockTranslator.soda | 30 +++++++++++++++++-- .../tocoq/TranslationConstantToCoq.scala | 2 ++ .../tocoq/TranslationConstantToCoq.soda | 2 ++ .../toscala/MatchCaseBlockTranslator.scala | 26 +++++++++++----- .../toscala/MatchCaseBlockTranslator.soda | 26 +++++++++++----- 7 files changed, 100 insertions(+), 21 deletions(-) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index a39572ba..ffe6f6d4 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -5,7 +5,10 @@ - release: target/scala-3.2.0/soda-0.17.0.jar - new_features: - accepts reserved word `any` as a synonym for `lambda` -- - version: v0.16.0 + - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure + - deprecated_features: + - the `end` reserved word for `match`-`case` is no longer used +- version: v0.16.0 - date: '2022-08-02' - new_features: - includes an extension to generate LaTeX files from source code diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala index 6bf681bf..fb6c33e3 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala @@ -41,22 +41,46 @@ trait MatchCaseBlockTranslator TestDeclarationAnnotation_ (_translate_block (block) ) private def _translate_block (block : AnnotatedBlock) : Block = - BlockBuilder_ ().build( + if ( _is_a_match_case_structure (block) + ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( line => _is_a_match_line (line) ) + + private def _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + private def _is_a_case_line (line : String) : Boolean = + line.trim.startsWith (_soda_case_pattern) + + private def _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( line => _is_a_match_line (line) ) + .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.coq_space) + + private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = + BlockBuilder_ ().build ( block.lines .map ( line => _append_with_after_match (line) ) .map ( line => _replace_case (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.coq_match_end_translation) ) ) private def _append_with_after_match (line : String) : String = - if ( line.trim ().startsWith (_soda_match_pattern) + if ( _is_a_match_line (line) ) line + _tc.coq_space + _tc.coq_with_reserved_word else line private def _replace_case (line : String) : String = - if ( line.trim.startsWith (_soda_case_pattern) + if ( _is_a_case_line (line) ) ReplacementAux_ (). replace_first (line) (_soda_case_pattern) (_tc.coq_case_translation) else line + private def _left_part (index : Int) (line : String) : String = + line.substring (0, index) + } case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda index c9d43da0..3ff1963c 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda @@ -41,21 +41,45 @@ class MatchCaseBlockTranslator TestDeclarationAnnotation_ (_translate_block (block) ) _translate_block (block : AnnotatedBlock) : Block = - BlockBuilder_ ().build( + if _is_a_match_case_structure (block) + then _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( lambda line --> _is_a_match_line (line) ) + + _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + _is_a_case_line (line : String) : Boolean = + line.trim.startsWith (_soda_case_pattern) + + _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( lambda line --> _is_a_match_line (line) ) + .map ( lambda line --> _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.coq_space) + + _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = + BlockBuilder_ ().build ( block.lines .map ( lambda line --> _append_with_after_match (line) ) .map ( lambda line --> _replace_case (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.coq_match_end_translation) ) ) _append_with_after_match (line : String) : String = - if line.trim ().startsWith (_soda_match_pattern) + if _is_a_match_line (line) then line + _tc.coq_space + _tc.coq_with_reserved_word else line _replace_case (line : String) : String = - if line.trim.startsWith (_soda_case_pattern) + if _is_a_case_line (line) then ReplacementAux_ (). replace_first (line) (_soda_case_pattern) (_tc.coq_case_translation) else line + _left_part (index : Int) (line : String) : String = + line.substring (0, index) + end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala index d44897e7..80be1b4b 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala @@ -29,6 +29,8 @@ trait TranslationConstantToCoq lazy val coq_vertical_bar_symbol = "|" + lazy val coq_match_end_translation = "end" + lazy val coq_opening_parenthesis = "(" lazy val coq_closing_parenthesis = ")" diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda index 6af236f7..e9c00756 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda @@ -29,6 +29,8 @@ class TranslationConstantToCoq coq_vertical_bar_symbol = "|" + coq_match_end_translation = "end" + coq_opening_parenthesis = "(" coq_closing_parenthesis = ")" diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala index 8c55455a..4040c4eb 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala @@ -38,22 +38,34 @@ trait MatchCaseBlockTranslator TestDeclarationAnnotation_ (_translate_block (block) ) private def _translate_block (block : AnnotatedBlock) : Block = + if ( _is_a_match_case_structure (block) + ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( line => _is_a_match_line (line) ) + + private def _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + private def _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( line => _is_a_match_line (line) ) + .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.scala_space) + + private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = BlockBuilder_ ().build ( block.lines .map ( line => _insert_match_before_brace_if_found (line) ) - .map ( line => _replace_match_end_if_found (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.scala_match_end_translation) ) ) private def _insert_match_before_brace_if_found (line : String) : String = - if ( line.trim.startsWith (_soda_match_pattern) + if ( _is_a_match_line (line) ) _assemble_parts (index = line.indexOf (_soda_match_pattern) ) (line) else line - private def _replace_match_end_if_found (line : String) : String = - if ( line.trim == _sc.match_end_reserved_word - ) line.replaceAll (_sc.match_end_reserved_word, _tc.scala_match_end_translation) - else line - private def _assemble_parts (index : Int) (line : String) : String = (_left_part (index) (line) ) + (_right_part (index) (line) ) + _tc.scala_match_translation + _tc.scala_space + _tc.scala_opening_brace diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda index 45004a2c..ff882079 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda @@ -38,22 +38,34 @@ class MatchCaseBlockTranslator TestDeclarationAnnotation_ (_translate_block (block) ) _translate_block (block : AnnotatedBlock) : Block = + if _is_a_match_case_structure (block) + then _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( lambda line --> _is_a_match_line (line) ) + + _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( lambda line --> _is_a_match_line (line) ) + .map ( lambda line --> _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.scala_space) + + _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = BlockBuilder_ ().build ( block.lines .map ( lambda line --> _insert_match_before_brace_if_found (line) ) - .map ( lambda line --> _replace_match_end_if_found (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.scala_match_end_translation) ) ) _insert_match_before_brace_if_found (line : String) : String = - if line.trim.startsWith (_soda_match_pattern) + if _is_a_match_line (line) then _assemble_parts (index := line.indexOf (_soda_match_pattern) ) (line) else line - _replace_match_end_if_found (line : String) : String = - if line.trim == _sc.match_end_reserved_word - then line.replaceAll (_sc.match_end_reserved_word, _tc.scala_match_end_translation) - else line - _assemble_parts (index : Int) (line : String) : String = (_left_part (index) (line) ) + (_right_part (index) (line) ) + _tc.scala_match_translation + _tc.scala_space + _tc.scala_opening_brace From c20034983892822c26bea46175dcf75f605323b8 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 18:23:02 +0100 Subject: [PATCH 22/71] Update `match`-`case` structures in source code --- .../example/algorithms/FizzBuzzPatternMatching.soda | 1 - .../soda/example/algorithms/PatternMatching.soda | 2 -- .../scala/soda/example/algorithms/SwapExample.soda | 2 -- .../pricemonitor/Requirement3Monitor.soda | 1 - .../example/forcoq/algorithms/RecursionForCoq.soda | 2 -- .../main/scala/soda/example/forcoq/lib/List.soda | 3 --- .../src/main/scala/soda/example/forcoq/lib/Nat.soda | 1 - .../example/forcoq/mathematics/FactorialForCoq.soda | 1 - .../forcoq/mathematics/FiboExampleInSodaForCoq.soda | 1 - .../forcoq/mathematics/TriangularNumberForCoq.soda | 1 - .../mathematics/FactorialPatternMatching.soda | 1 - library/src/main/scala/soda/collection/MSeq.soda | 2 -- .../src/main/resources/lib/soda/lib/OptionSD.soda | 6 ------ .../src/main/resources/lib/soda/lib/SeqSD.soda | 1 - .../soda/translator/documentation/Manual.soda | 1 - translator/src/main/scala/soda/lib/OptionSD.soda | 6 ------ translator/src/main/scala/soda/lib/SeqSD.soda | 1 - .../tocoq/CoqClassConstructorBlockTranslator.scala | 13 +++++++------ .../tocoq/CoqClassConstructorBlockTranslator.soda | 13 ++++++------- .../tocoq/CoqClassDeclarationBlockTranslator.soda | 1 - .../extension/tocoq/CoqClassEndBlockTranslator.soda | 2 -- .../tocoq/CoqDefinitionBlockTranslator.soda | 1 - .../tocoq/CoqImportDeclarationBlockTranslator.soda | 1 - .../tocoq/CoqPackageDeclarationBlockTranslator.soda | 1 - .../extension/tocoq/CoqProofBlockTranslator.soda | 1 - .../extension/tocoq/CoqTheoremBlockTranslator.soda | 1 - .../extension/tocoq/MatchCaseBlockTranslator.soda | 1 - .../extension/todoc/DocBlockTranslator.soda | 1 - .../toscala/AbstractDeclarationBlockTranslator.soda | 1 - .../toscala/ClassConstructorBlockTranslator.soda | 3 --- .../toscala/ClassDeclarationBlockTranslator.soda | 1 - .../extension/toscala/ClassEndBlockTranslator.soda | 1 - .../toscala/ImportDeclarationBlockTranslator.soda | 1 - .../extension/toscala/MainClassBlockTranslator.soda | 2 -- .../extension/toscala/MatchCaseBlockTranslator.soda | 1 - .../toscala/TheoremAndProofBlockTranslator.soda | 1 - .../parser/PreprocessorSequenceTranslator.soda | 2 -- .../scala/soda/translator/parser/SodaConstant.scala | 3 --- .../scala/soda/translator/parser/SodaConstant.soda | 3 --- .../parser/annotation/AnnotationFactory.soda | 2 -- .../soda/translator/documentation/Manual.soda | 1 - .../soda/translator/documentation/Manual.tex | 3 +-- .../example/algorithms/FizzBuzzPatternMatching.soda | 1 - .../example/algorithms/PatternMatching.soda | 2 -- .../translator/example/algorithms/SwapExample.soda | 2 -- .../pricemonitor/Requirement3Monitor.soda | 1 - .../example/forcoq/algorithms/RecursionForCoq.soda | 2 -- .../soda/translator/example/forcoq/lib/List.soda | 3 --- .../soda/translator/example/forcoq/lib/Nat.soda | 1 - .../example/forcoq/mathematics/FactorialForCoq.soda | 1 - .../forcoq/mathematics/FiboExampleInSodaForCoq.soda | 1 - .../forcoq/mathematics/TriangularNumberForCoq.soda | 1 - .../mathematics/FactorialPatternMatching.soda | 1 - .../toscala/MicroTranslatorToScalaSpec.scala | 4 +--- .../toscala/MicroTranslatorToScalaSpec.soda | 4 +--- .../translator/replacement/ReplacementAuxSpec.scala | 4 ++-- .../translator/replacement/ReplacementAuxSpec.soda | 4 ++-- 57 files changed, 20 insertions(+), 106 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda index ca2478c4..bdd8513b 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda @@ -21,6 +21,5 @@ class FizzBuzzPatternMatching case Tuple2 (0, x) ==> fizz case Tuple2 (x, 0) ==> buzz case x ==> n.toString - end end diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda index ca1c8307..b81ffa97 100644 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda @@ -15,7 +15,6 @@ class PatternMatching case Pair_ (x, y) ==> (x + y) / 2 case Triplet_ (x, y, z) ==> (x + y + z) / 3 case x ==> 0 - end get_type_name (p : Parameter) : String = match p @@ -23,7 +22,6 @@ class PatternMatching case Pair_ (x, y) ==> (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) ==> (Triplet_ (x, y, z) ).name + "(x, y, z)" case x ==> "" - end end diff --git a/examples/src/main/scala/soda/example/algorithms/SwapExample.soda b/examples/src/main/scala/soda/example/algorithms/SwapExample.soda index 5770d559..c56e2272 100644 --- a/examples/src/main/scala/soda/example/algorithms/SwapExample.soda +++ b/examples/src/main/scala/soda/example/algorithms/SwapExample.soda @@ -13,12 +13,10 @@ class SwapExample left (pair : PairExample) : Int = match pair case (PairExample_ (x , y) ) ==> x - end right (pair : PairExample) : Int = match pair case (PairExample_ (x , y) ) ==> y - end swap (pair : PairExample) : PairExample = PairExample_ (right (pair) , left (pair) ) diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index 1417f084..8e345fad 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -60,7 +60,6 @@ class SegmentsForFlight match intermediate_stops case head :: tail ==> (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) case x ==> Nil.+: (Segment_ (first_airport, last_airport) ) - end end diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda index ec15803b..5ecca244 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda @@ -14,7 +14,6 @@ class RecursionForCoq then current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) case x ==> current_value - end fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) @@ -24,7 +23,6 @@ class RecursionForCoq match sequence case (head) :: (tail) ==> _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) case x ==> current_value - end fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = _tailrec_fold3 (sequence) (initial_value) (next_value_function) diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.soda b/examples/src/main/scala/soda/example/forcoq/lib/List.soda index ffe89ada..099fb620 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/List.soda @@ -27,7 +27,6 @@ class SeqList match a case cons_ (e, s) ==> _tailrec_reverse (s) ( cons_ (e, b) ) case x ==> b - end reverse [A] (s : list [A] ) : list [A] = _tailrec_reverse [A] (s) (nil_ [A] () ) @@ -37,7 +36,6 @@ class SeqList match a case (e) :: (s) ==> _tailrec_from_Seq (s) (cons_ (e, b) ) case x ==> b - end from_Seq [A] (a : Seq [A] ) : list [A] = reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) @@ -47,7 +45,6 @@ class SeqList match a case cons_ (e, s) ==> _tailrec_to_Seq (s) ( b .+: (e) ) case x ==> b - end to_Seq [A] (a : list [A] ) : Seq [A] = (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda index 371501c5..88b9e767 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda @@ -74,6 +74,5 @@ class IntNat match a case S_ (k) ==> 1 + to_Int (k) case x ==> 0 - end end diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda index 10f9a691..f6fd39d2 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda @@ -12,7 +12,6 @@ class FactorialForCoq match m case S_ (k) ==> _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) case x ==> product - end get_factorial (n : nat) : nat = _tailrec_get_factorial (n) (S_ ( O_ () ) ) diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 728d0456..94e8793d 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -13,7 +13,6 @@ class FiboExampleInSodaForCoq case S_ (O_ () ) ==> b case S_ (k) ==> _tailrec_fib (k) (b) (a .add (b) ) case x ==> a - end fib (n : nat) = _tailrec_fib (n) (O_ () ) ( S_ (O_ () ) ) diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda index c911c46a..b6f3aa3f 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -12,7 +12,6 @@ class TriangularNumberForCoq match m case S_ (k) ==> _tailrec_get_number (k) (acc .add ( S_ (k) ) ) case x ==> acc - end get_number (n : nat) : nat = _tailrec_get_number (n) ( O_ () ) diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda index 1592ef57..2a307b5e 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda @@ -15,7 +15,6 @@ class FactorialPatternMatching match n case 0 ==> product case x ==> _tailrec_get_factorial (x - 1) (x * product) - end end diff --git a/library/src/main/scala/soda/collection/MSeq.soda b/library/src/main/scala/soda/collection/MSeq.soda index d2e1530d..682ddab9 100644 --- a/library/src/main/scala/soda/collection/MSeq.soda +++ b/library/src/main/scala/soda/collection/MSeq.soda @@ -9,7 +9,6 @@ class MSeq [A] match this case NESeq_ (head, tail) ==> ifNonEmpty (NESeq_ (head, tail) ) case x ==> ifEmpty - end end @@ -23,7 +22,6 @@ class MSeqRec [A] then current_value else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) case x ==> current_value - end fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.soda b/translator/src/main/resources/lib/soda/lib/OptionSD.soda index ddd44ab0..fe3aecaf 100644 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.soda +++ b/translator/src/main/resources/lib/soda/lib/OptionSD.soda @@ -21,31 +21,26 @@ class OptionSD [A] match this case SomeSD_ (element) ==> ifNonEmpty (element) case x ==> ifEmpty - end map [B] (mapping : A -> B) : OptionSD [B] = match this case SomeSD_ (element) ==> SomeSD_ [B] (mapping (element) ) case x ==> NoneSD_ [B] () - end getOrElse (default : A) : A = match this case SomeSD_ (element) ==> element case x ==> default - end fold [B] (ifEmpty : B) (f : A -> B) : B = match this case SomeSD_ (element) ==> f (element) case x ==> ifEmpty - end flatMap [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = match this case SomeSD_ (element) ==> mapping (element) case x ==> NoneSD_ () - end bind [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = flatMap [B] (mapping) @@ -57,7 +52,6 @@ class OptionSD [A] then this else NoneSD_ [A] () case x ==> NoneSD_ () - end end diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.soda b/translator/src/main/resources/lib/soda/lib/SeqSD.soda index 5da35057..0a77ed81 100644 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.soda +++ b/translator/src/main/resources/lib/soda/lib/SeqSD.soda @@ -18,7 +18,6 @@ class SeqSD [A] match this case NonEmptySeqSD_ (toSeq) ==> ifNonEmpty (NonEmptySeqSD_ (toSeq) ) case x ==> ifEmpty - end end diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 94efc118..7487d208 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -222,7 +222,6 @@ class Manual match condition case true ==> if_true case x ==> if_false - end sum (n : Int) = _tailrec_ (n) (0) diff --git a/translator/src/main/scala/soda/lib/OptionSD.soda b/translator/src/main/scala/soda/lib/OptionSD.soda index 483c9c74..b8b0d4da 100644 --- a/translator/src/main/scala/soda/lib/OptionSD.soda +++ b/translator/src/main/scala/soda/lib/OptionSD.soda @@ -21,31 +21,26 @@ class OptionSD [A] match this case SomeSD_ (element) ==> ifNonEmpty (element) case x ==> ifEmpty - end map [B] (mapping : A -> B) : OptionSD [B] = match this case SomeSD_ (element) ==> SomeSD_ [B] (mapping (element) ) case x ==> NoneSD_ [B] () - end getOrElse (default : A) : A = match this case SomeSD_ (element) ==> element case x ==> default - end fold [B] (ifEmpty : B) (f : A -> B) : B = match this case SomeSD_ (element) ==> f (element) case x ==> ifEmpty - end flatMap [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = match this case SomeSD_ (element) ==> mapping (element) case x ==> NoneSD_ () - end bind [B] (mapping : A -> OptionSD [B] ) : OptionSD [B] = flatMap [B] (mapping) @@ -57,7 +52,6 @@ class OptionSD [A] then this else NoneSD_ [A] () case x ==> NoneSD_ () - end end diff --git a/translator/src/main/scala/soda/lib/SeqSD.soda b/translator/src/main/scala/soda/lib/SeqSD.soda index 3fe4d31f..a6518792 100644 --- a/translator/src/main/scala/soda/lib/SeqSD.soda +++ b/translator/src/main/scala/soda/lib/SeqSD.soda @@ -18,7 +18,6 @@ class SeqSD [A] match this case NonEmptySeqSD_ (toSeq) ==> ifNonEmpty (NonEmptySeqSD_ (toSeq) ) case x ==> ifEmpty - end end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala index 0ff2db8c..28b42346 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala @@ -89,14 +89,15 @@ trait CoqClassConstructorBlockTranslator private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( block => - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - ) + .flatMap ( block => _get_as_class_beginning_annotation (block) ) .headOption + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + private def _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = block.abstract_functions .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda index 3cad2227..5e87565f 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda @@ -25,7 +25,6 @@ class CoqClassConstructorBlockTranslator match annotated_block case AbstractDeclarationAnnotation_ (block, references) ==> _translate_block (AbstractDeclarationAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = _translate_block_with (_get_class_beginning (block.references) ) (block) @@ -89,14 +88,14 @@ class CoqClassConstructorBlockTranslator _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = references - .flatMap ( lambda block --> - match block - case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) - case x ==> None - end - ) + .flatMap ( lambda block --> _get_as_class_beginning_annotation (block) ) .headOption + _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + match annotated_block + case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) + case x ==> None + _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = block.abstract_functions .map ( lambda annotated_line --> _translate_type_symbols (annotated_line.line).trim ) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda index 88169490..ab1d6eeb 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda @@ -31,7 +31,6 @@ class CoqClassDeclarationBlockTranslator match annotated_block case ClassBeginningAnnotation_ (block) ==> _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) case x ==> annotated_block - end _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = ClassBeginningAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda index a6ac6cf3..d990f288 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda @@ -23,7 +23,6 @@ class CoqClassEndBlockTranslator match annotated_block case ClassEndAnnotation_ (block, references) ==> _translate_block (ClassEndAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = _translate_block_with (_get_class_beginning (block.references) ) (block) @@ -59,7 +58,6 @@ class CoqClassEndBlockTranslator match annotated_block case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) case x ==> None - end end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda index 341f7768..1d50c659 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda @@ -21,7 +21,6 @@ class CoqDefinitionBlockTranslator match annotated_block case FunctionDefinitionAnnotation_ (block) ==> _translate_definition_block (FunctionDefinitionAnnotation_ (block) ) case x ==> annotated_block - end _translate_definition_block (block : FunctionDefinitionAnnotation) : FunctionDefinitionAnnotation = FunctionDefinitionAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda index c6217b11..cedfab8d 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda @@ -26,7 +26,6 @@ class CoqImportDeclarationBlockTranslator match annotated_block case ImportDeclarationAnnotation_ (block) ==> _translate_block (ImportDeclarationAnnotation_ (block) ) case x ==> annotated_block - end _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = ImportDeclarationAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda index 843cd7b9..1c6e3ad3 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda @@ -21,7 +21,6 @@ class CoqPackageDeclarationBlockTranslator match annotated_block case PackageDeclarationAnnotation_ (block) ==> _translate_block (PackageDeclarationAnnotation_ (block) ) case x ==> annotated_block - end _translate_block (block : PackageDeclarationAnnotation) : PackageDeclarationAnnotation = PackageDeclarationAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda index 89c07f16..c08a7233 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda @@ -21,7 +21,6 @@ class CoqProofBlockTranslator match annotated_block case ProofBlockAnnotation_ (block) ==> _translate_block (ProofBlockAnnotation_ (block) ) case x ==> annotated_block - end _translate_block (block : ProofBlockAnnotation) : ProofBlockAnnotation = ProofBlockAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda index f00b3edc..59bf6fe8 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda @@ -21,7 +21,6 @@ class CoqTheoremBlockTranslator match annotated_block case TheoremBlockAnnotation_ (block) ==> _translate_block (TheoremBlockAnnotation_ (block) ) case x ==> annotated_block - end _translate_block (block : TheoremBlockAnnotation) : TheoremBlockAnnotation = TheoremBlockAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda index 3ff1963c..3a150caf 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda @@ -32,7 +32,6 @@ class MatchCaseBlockTranslator case FunctionDefinitionAnnotation_ (block) ==> _translate_function_block (FunctionDefinitionAnnotation_ (block) ) case TestDeclarationAnnotation_ (block) ==> _translate_test_block (TestDeclarationAnnotation_ (block) ) case x ==> annotated_block - end _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = FunctionDefinitionAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda index c174cfb8..ba07ed1c 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda @@ -25,7 +25,6 @@ class DocBlockTranslator match annotated_block case CommentAnnotation_ (block) ==> _translate_comment (CommentAnnotation_ (block) ) case x ==> _translate_source_code (x) - end _translate_comment (block : CommentAnnotation) : CommentAnnotation = CommentAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda index a7086e17..4ca98aad 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda @@ -26,7 +26,6 @@ class AbstractDeclarationBlockTranslator match annotated_block case AbstractDeclarationAnnotation_ (block, references) ==> _translate_block (AbstractDeclarationAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = AbstractDeclarationAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda index 568fcdba..04bf404e 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda @@ -27,7 +27,6 @@ class ClassConstructorBlockTranslator match annotated_block case ClassEndAnnotation_ (block, references) ==> _translate_block (ClassEndAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = _translate_block_with (_get_class_beginning (block.references) ) (block) @@ -86,7 +85,6 @@ class ClassConstructorBlockTranslator match annotated_block case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) case x ==> None - end _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = references @@ -98,7 +96,6 @@ class ClassConstructorBlockTranslator match block case AbstractDeclarationAnnotation_ (b, references) ==> Some (AbstractDeclarationAnnotation_ (b, references) ) case x ==> None - end _translate_type_symbols (line : String) : String = line diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda index ff9fd8c1..ab5beb04 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda @@ -32,7 +32,6 @@ class ClassDeclarationBlockTranslator case ClassBeginningAnnotation_ (block) ==> _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) case ClassAliasAnnotation_ (block) ==> _translate_class_alias_block (ClassAliasAnnotation_ (block) ) case x ==> annotated_block - end _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = ClassBeginningAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda index d0998890..e7662d9a 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda @@ -20,7 +20,6 @@ class ClassEndBlockTranslator match annotated_block case ClassEndAnnotation_ (block, references) ==> _translate_block (ClassEndAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = ClassEndAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda index ff2f7259..2a76fe82 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda @@ -25,7 +25,6 @@ class ImportDeclarationBlockTranslator match annotated_block case ImportDeclarationAnnotation_ (block) ==> _translate_block (ImportDeclarationAnnotation_ (block) ) case x ==> annotated_block - end _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = ImportDeclarationAnnotation_ ( diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda index aa9f42a1..7c7c73d2 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda @@ -23,7 +23,6 @@ class MainClassBlockTranslator match annotated_block case ClassEndAnnotation_ (block, references) ==> _translate_block (ClassEndAnnotation_ (block, references) ) case x ==> annotated_block - end _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = if _get_class_name (block.references) == _tc.soda_main_class_name @@ -54,7 +53,6 @@ class MainClassBlockTranslator match block case ClassBeginningAnnotation_ (b) ==> Some (ClassBeginningAnnotation_ (b) ) case x ==> None - end end diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda index ff882079..b39ad095 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda @@ -29,7 +29,6 @@ class MatchCaseBlockTranslator case FunctionDefinitionAnnotation_ (block) ==> _translate_function_block (FunctionDefinitionAnnotation_ (block) ) case TestDeclarationAnnotation_ (block) ==> _translate_test_block (TestDeclarationAnnotation_ (block) ) case x ==> annotated_block - end _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = FunctionDefinitionAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda index dae60543..590f7e44 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda @@ -24,7 +24,6 @@ class TheoremAndProofBlockTranslator case TheoremBlockAnnotation_ (block) ==> _translate_theorem_block (TheoremBlockAnnotation_ (block) ) case ProofBlockAnnotation_ (block) ==> _translate_proof_block (ProofBlockAnnotation_ (block) ) case x ==> annotated_block - end _translate_theorem_block (block : AnnotatedBlock) : TheoremBlockAnnotation = TheoremBlockAnnotation_ (_translate_block (block) ) diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda index 6445f0f8..19d97d34 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda @@ -63,7 +63,6 @@ class PreprocessorSequenceTranslator case AbstractDeclarationAnnotation_ (block, references) ==> _get_abstract_declaration_updated_block (current) (AbstractDeclarationAnnotation_ (block, references) ) case ClassEndAnnotation_ (block, references) ==> _get_class_end_updated_block (current) (ClassEndAnnotation_ (block, references) ) case x ==> x - end _get_abstract_declaration_updated_block (current : AuxiliaryTuple) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = AbstractDeclarationAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) @@ -84,7 +83,6 @@ class PreprocessorSequenceTranslator case AbstractDeclarationAnnotation_ (b, references) ==> _update_first_element (current.references) (AbstractDeclarationAnnotation_ (b, references) ) case ClassEndAnnotation_ (b, references) ==> _tail_non_empty (current.references) case x ==> current.references - end _update_first_element (s : Seq [Seq [AnnotatedBlock] ] ) (b : AnnotatedBlock) : Seq [Seq [AnnotatedBlock] ] = _tail_non_empty (s).+: (s.headOption.getOrElse (Seq [AnnotatedBlock] () ).+: (b) ) diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala index f92838fd..d3ea3448 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala @@ -33,8 +33,6 @@ trait SodaConstant lazy val case_reserved_word = "case" - lazy val match_end_reserved_word = "end" - lazy val class_reserved_word = "class" lazy val extends_reserved_word = "extends" @@ -120,7 +118,6 @@ trait SodaConstant else_reserved_word, match_reserved_word, case_reserved_word, - match_end_reserved_word, class_reserved_word, extends_reserved_word, abstract_reserved_word, diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index 8b89817b..c9fd041f 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -32,8 +32,6 @@ class SodaConstant case_reserved_word = "case" - match_end_reserved_word = "end" - class_reserved_word = "class" extends_reserved_word = "extends" @@ -119,7 +117,6 @@ class SodaConstant else_reserved_word, match_reserved_word, case_reserved_word, - match_end_reserved_word, class_reserved_word, extends_reserved_word, abstract_reserved_word, diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda index 7ecde245..149b93c6 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda @@ -20,7 +20,6 @@ class AnnotationFactory match block case AnnotatedBlock_ (annotated_lines, block_annotation) ==> AnnotatedBlock_ (annotated_lines, block_annotation) case x ==> _get_first_or_undefined (_find_candidates (x) ) (x) - end update_block (original_content : AnnotatedBlock) (new_content : Block) : AnnotatedBlock = match original_content @@ -36,7 +35,6 @@ class AnnotationFactory case CommentAnnotation_ (b) ==> CommentAnnotation_ (new_content) case TestDeclarationAnnotation_ (b) ==> TestDeclarationAnnotation_ (new_content) case x ==> AnnotatedBlock_ (new_content.annotated_lines, x.block_annotation) - end _detectors (block : Block) : Seq [BlockAnnotationParser] = Seq ( diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index 94efc118..7487d208 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -222,7 +222,6 @@ class Manual match condition case true ==> if_true case x ==> if_false - end sum (n : Int) = _tailrec_ (n) (0) diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index 514bdab8..a8b07ebe 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -6,7 +6,7 @@ \usepackage{listings} \lstdefinelanguage{Soda}{ - morekeywords={lambda, any, if, then, else, match, case, end, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @tailrec, @override, @new}, + morekeywords={lambda, any, if, then, else, match, case, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @tailrec, @override, @new}, sensitive=true, morecomment=[s]{/*}{*/}, morestring=[b]" @@ -395,7 +395,6 @@ match condition case true ==> if_true case x ==> if_false - end sum (n : Int) = _tailrec_ (n) (0) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda index ca2478c4..bdd8513b 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda @@ -21,6 +21,5 @@ class FizzBuzzPatternMatching case Tuple2 (0, x) ==> fizz case Tuple2 (x, 0) ==> buzz case x ==> n.toString - end end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda index ca1c8307..b81ffa97 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda @@ -15,7 +15,6 @@ class PatternMatching case Pair_ (x, y) ==> (x + y) / 2 case Triplet_ (x, y, z) ==> (x + y + z) / 3 case x ==> 0 - end get_type_name (p : Parameter) : String = match p @@ -23,7 +22,6 @@ class PatternMatching case Pair_ (x, y) ==> (Pair_ (x, y) ).name + "(x, y)" case Triplet_ (x, y, z) ==> (Triplet_ (x, y, z) ).name + "(x, y, z)" case x ==> "" - end end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda index 5770d559..c56e2272 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda @@ -13,12 +13,10 @@ class SwapExample left (pair : PairExample) : Int = match pair case (PairExample_ (x , y) ) ==> x - end right (pair : PairExample) : Int = match pair case (PairExample_ (x , y) ) ==> y - end swap (pair : PairExample) : PairExample = PairExample_ (right (pair) , left (pair) ) diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index 1417f084..8e345fad 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -60,7 +60,6 @@ class SegmentsForFlight match intermediate_stops case head :: tail ==> (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) case x ==> Nil.+: (Segment_ (first_airport, last_airport) ) - end end diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda index ec15803b..5ecca244 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda @@ -14,7 +14,6 @@ class RecursionForCoq then current_value else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) case x ==> current_value - end fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) @@ -24,7 +23,6 @@ class RecursionForCoq match sequence case (head) :: (tail) ==> _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) case x ==> current_value - end fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = _tailrec_fold3 (sequence) (initial_value) (next_value_function) diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda index ffe89ada..099fb620 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda @@ -27,7 +27,6 @@ class SeqList match a case cons_ (e, s) ==> _tailrec_reverse (s) ( cons_ (e, b) ) case x ==> b - end reverse [A] (s : list [A] ) : list [A] = _tailrec_reverse [A] (s) (nil_ [A] () ) @@ -37,7 +36,6 @@ class SeqList match a case (e) :: (s) ==> _tailrec_from_Seq (s) (cons_ (e, b) ) case x ==> b - end from_Seq [A] (a : Seq [A] ) : list [A] = reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) @@ -47,7 +45,6 @@ class SeqList match a case cons_ (e, s) ==> _tailrec_to_Seq (s) ( b .+: (e) ) case x ==> b - end to_Seq [A] (a : list [A] ) : Seq [A] = (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda index 371501c5..88b9e767 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda @@ -74,6 +74,5 @@ class IntNat match a case S_ (k) ==> 1 + to_Int (k) case x ==> 0 - end end diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda index 10f9a691..f6fd39d2 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda @@ -12,7 +12,6 @@ class FactorialForCoq match m case S_ (k) ==> _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) case x ==> product - end get_factorial (n : nat) : nat = _tailrec_get_factorial (n) (S_ ( O_ () ) ) diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 728d0456..94e8793d 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -13,7 +13,6 @@ class FiboExampleInSodaForCoq case S_ (O_ () ) ==> b case S_ (k) ==> _tailrec_fib (k) (b) (a .add (b) ) case x ==> a - end fib (n : nat) = _tailrec_fib (n) (O_ () ) ( S_ (O_ () ) ) diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda index c911c46a..b6f3aa3f 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -12,7 +12,6 @@ class TriangularNumberForCoq match m case S_ (k) ==> _tailrec_get_number (k) (acc .add ( S_ (k) ) ) case x ==> acc - end get_number (n : nat) : nat = _tailrec_get_number (n) ( O_ () ) diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda index 1592ef57..2a307b5e 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda @@ -15,7 +15,6 @@ class FactorialPatternMatching match n case 0 ==> product case x ==> _tailrec_get_factorial (x - 1) (x * product) - end end diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala index a753e48f..262700b6 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala @@ -224,7 +224,6 @@ case class MicroTranslatorToScalaSpec () "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n end" + "\n" ) ) ( @@ -233,7 +232,7 @@ case class MicroTranslatorToScalaSpec () "\n case 0 => 1 " + "\n case 1 => 1 " + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + - "\n }" + + "\n }" + "\n" ) ) @@ -245,7 +244,6 @@ case class MicroTranslatorToScalaSpec () "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n end" + "\n" ) ) ( diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda index 224a4241..da76759f 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda @@ -224,7 +224,6 @@ class MicroTranslatorToScalaSpec () "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n end" + "\n" ) ) ( @@ -233,7 +232,7 @@ class MicroTranslatorToScalaSpec () "\n case 0 => 1 " + "\n case 1 => 1 " + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + - "\n }" + + "\n }" + "\n" ) ) @@ -245,7 +244,6 @@ class MicroTranslatorToScalaSpec () "\n case 0 ==> 1 " + "\n case 1 ==> 1 " + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n end" + "\n" ) ) ( diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala index 2e23f610..55e76b34 100644 --- a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala +++ b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala @@ -10,7 +10,7 @@ case class ReplacementAuxSpec () lazy val instance = ReplacementAux_ () - lazy val line_0 = "if, then, else, let, in, match, case, end" + lazy val line_0 = "lambda, if, then, else, match, case" lazy val line_1 = "class has extends with this subtype supertype " @@ -112,7 +112,7 @@ case class ReplacementAuxSpec () check ( obtained = instance.add_spaces_to_symbols (line_0) ( (Seq [Char] (',') ).toSet ) ) ( - expected = "if , then , else , let , in , match , case , end" + expected = "lambda , if , then , else , match , case" ) ) diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda index 91cc1e2e..087678c3 100644 --- a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda +++ b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda @@ -9,7 +9,7 @@ class ReplacementAuxSpec () instance = ReplacementAux_ () - line_0 = "if, then, else, let, in, match, case, end" + line_0 = "lambda, if, then, else, match, case" line_1 = "class has extends with this subtype supertype " @@ -111,7 +111,7 @@ class ReplacementAuxSpec () check ( obtained := instance.add_spaces_to_symbols (line_0) ( (Seq [Char] (',') ).toSet ) ) ( - expected := "if , then , else , let , in , match , case , end" + expected := "lambda , if , then , else , match , case" ) ) From d78c9937598042bd5bdd4c59f50d968774614c8f Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 19 Jan 2023 18:39:25 +0100 Subject: [PATCH 23/71] Update script to build binary --- makeall.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makeall.sh b/makeall.sh index 92c000ae..b6f7b123 100644 --- a/makeall.sh +++ b/makeall.sh @@ -9,8 +9,8 @@ sbt scalaVersion sbtVersion version clean compile test package assembly executableStub="exec java -jar \$0 \"\$@\" ; exit" sodaFile="soda" -scalaVersion=$(ls "target/" | grep "scala-") -jarFile="target/${scalaVersion}/soda-*.jar" +scalaVersion="3.2.0" +jarFile="target/scala-${scalaVersion}/soda-*.jar" echo ${executableStub} >${sodaFile} cat ${jarFile} >>${sodaFile} From 572de9219058d4359fcfa357b23654435afc060c Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 23 Jan 2023 17:30:38 +0100 Subject: [PATCH 24/71] Update Recursion class --- translator/src/main/resources/lib/soda/lib/Recursion.scala | 7 ++----- translator/src/main/resources/lib/soda/lib/Recursion.soda | 7 ++----- translator/src/main/scala/soda/lib/Recursion.scala | 7 ++----- translator/src/main/scala/soda/lib/Recursion.soda | 7 ++----- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.scala b/translator/src/main/resources/lib/soda/lib/Recursion.scala index 080ca232..5252ea98 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.scala +++ b/translator/src/main/resources/lib/soda/lib/Recursion.scala @@ -14,12 +14,9 @@ trait Recursion import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) ) current_value - else - if ( ! condition (current_value) (sequence.head) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.soda b/translator/src/main/resources/lib/soda/lib/Recursion.soda index 99b41ad2..19050de0 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.soda +++ b/translator/src/main/resources/lib/soda/lib/Recursion.soda @@ -12,12 +12,9 @@ class Recursion @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - if sequence.isEmpty + if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value - else - if not condition (current_value) (sequence.head) - then current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) diff --git a/translator/src/main/scala/soda/lib/Recursion.scala b/translator/src/main/scala/soda/lib/Recursion.scala index 080ca232..5252ea98 100644 --- a/translator/src/main/scala/soda/lib/Recursion.scala +++ b/translator/src/main/scala/soda/lib/Recursion.scala @@ -14,12 +14,9 @@ trait Recursion import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) ) current_value - else - if ( ! condition (current_value) (sequence.head) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) diff --git a/translator/src/main/scala/soda/lib/Recursion.soda b/translator/src/main/scala/soda/lib/Recursion.soda index 2fe78bd2..2989e7a9 100644 --- a/translator/src/main/scala/soda/lib/Recursion.soda +++ b/translator/src/main/scala/soda/lib/Recursion.soda @@ -12,12 +12,9 @@ class Recursion @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - if sequence.isEmpty + if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value - else - if not condition (current_value) (sequence.head) - then current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) From eff73f6402e4874abdd4d9848de55420659c7c4b Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 23 Jan 2023 22:05:39 +0100 Subject: [PATCH 25/71] Make small style changes --- .../example/mathematics/HardProblem.scala | 9 +++-- .../soda/example/mathematics/HardProblem.soda | 9 +++-- .../src/main/scala/soda/collection/Min.scala | 34 ++++++++++++------- .../src/main/scala/soda/collection/Min.soda | 34 ++++++++++++------- .../block/ConditionalBlockTranslator.scala | 9 +++-- .../block/ConditionalBlockTranslator.soda | 9 +++-- .../blocktr/TokenizedBlockTranslator.scala | 26 +++++++------- .../blocktr/TokenizedBlockTranslator.soda | 26 +++++++------- .../soda/translator/extension/main/Main.scala | 15 ++++---- .../soda/translator/extension/main/Main.soda | 15 ++++---- .../CoqClassDeclarationBlockTranslator.scala | 11 +++--- .../CoqClassDeclarationBlockTranslator.soda | 11 +++--- .../tocoq/DefinitionLineTranslator.scala | 9 +++-- .../tocoq/DefinitionLineTranslator.soda | 9 +++-- .../extension/tocoq/TranslatorToCoq.scala | 13 ++++--- .../extension/tocoq/TranslatorToCoq.soda | 12 ++++--- .../extension/todoc/TranslatorToDoc.scala | 13 ++++--- .../extension/todoc/TranslatorToDoc.soda | 12 ++++--- .../extension/toscala/TranslatorToScala.scala | 13 ++++--- .../extension/toscala/TranslatorToScala.soda | 12 ++++--- .../soda/translator/io/DirectoryScanner.scala | 10 +++--- .../soda/translator/io/DirectoryScanner.soda | 10 +++--- .../soda/translator/parser/BlockBuilder.scala | 10 +++--- .../soda/translator/parser/BlockBuilder.soda | 10 +++--- .../translator/replacement/CharType.scala | 32 +++++++++-------- .../soda/translator/replacement/CharType.soda | 32 +++++++++-------- .../translator/replacement/Tokenizer.scala | 11 +++--- .../translator/replacement/Tokenizer.soda | 11 +++--- 28 files changed, 265 insertions(+), 162 deletions(-) diff --git a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala b/examples/src/main/scala/soda/example/mathematics/HardProblem.scala index eb56554f..166837d7 100644 --- a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala +++ b/examples/src/main/scala/soda/example/mathematics/HardProblem.scala @@ -119,9 +119,12 @@ trait MemoizedFibonacci lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = input => - if ( input.value == 0 ) OutputPair_ (0, input.memoized_values ) - else if ( input.value == 1 ) OutputPair_ (1, input.memoized_values ) - else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) + main_function_for (input) + + def main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = + if ( (input.value == 0) || (input.value == 1) + ) OutputPair_ (input.value, input.memoized_values ) + else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) private def _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) diff --git a/examples/src/main/scala/soda/example/mathematics/HardProblem.soda b/examples/src/main/scala/soda/example/mathematics/HardProblem.soda index 37d9a410..b2c56c7e 100644 --- a/examples/src/main/scala/soda/example/mathematics/HardProblem.soda +++ b/examples/src/main/scala/soda/example/mathematics/HardProblem.soda @@ -105,9 +105,12 @@ class MemoizedFibonacci main_function : InputPair [Int, Int] -> OutputPair [Int, Int] = lambda input --> - if input.value == 0 then OutputPair_ (0, input.memoized_values ) - else if input.value == 1 then OutputPair_ (1, input.memoized_values ) - else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) + main_function_for (input) + + main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = + if (input.value == 0) or (input.value == 1) + then OutputPair_ (input.value, input.memoized_values ) + else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) diff --git a/library/src/main/scala/soda/collection/Min.scala b/library/src/main/scala/soda/collection/Min.scala index 68d091fb..8b9a493c 100644 --- a/library/src/main/scala/soda/collection/Min.scala +++ b/library/src/main/scala/soda/collection/Min.scala @@ -76,7 +76,10 @@ trait Min [A] foldLeftWhile (s) (initial_value) (next_value) ( (acc : B) => (elem : A) => true) def reverse (s : MSeq [A] ) : MSeq [A] = - s.opt [MSeq [A] ] (ifEmpty = empty) (ifNonEmpty = neseq => reverseNonEmpty (neseq) ) + s.opt [MSeq [A] ] ( + ifEmpty = empty) ( + ifNonEmpty = neseq => reverseNonEmpty (neseq) + ) def reverseNonEmpty (s : NESeq [A] ) : NESeq [A] = foldLeft (s.tail) (_reverseNonEmpty_initial_value (s) ) (_reverseNonEmpty_next_value) @@ -101,12 +104,15 @@ trait Min [A] private def _indexOf_next_value (tuple : IndexFoldTuple [A] ) (current_element : A) : IndexFoldTuple [A] = IndexFoldTuple_ [A] ( tuple.index + 1, - ( if ( current_element == tuple.element - ) tuple.index - else tuple.position), + _get_index_if_element_found (tuple) (current_element) , tuple.element ) + private def _get_index_if_element_found (tuple : IndexFoldTuple [A] ) (current_element : A) : Int = + if ( current_element == tuple.element + ) tuple.index + else tuple.position + private def _indexOf_condition (tuple : IndexFoldTuple [A] ) (elem : A) : Boolean = tuple.position == -1 @@ -125,13 +131,14 @@ trait Min [A] def at (s : MSeq [A] ) (n : Int) : OptionSD [A] = s.opt [OptionSD [A] ] ( ifEmpty = NoneSD_ [A] () ) ( - ifNonEmpty = ( neseq => - if ( n < 0 || n >= length (s) - ) NoneSD_ [A] () - else SomeSD_ [A] (_atNonEmpty (neseq ) (n) ) - ) + ifNonEmpty = ( neseq => _retrieve_if_in_range (neseq) (n) ) ) + private def _retrieve_if_in_range (xs : NESeq [A] ) (n : Int) : OptionSD [A] = + if ( n < 0 || n >= length (xs) + ) NoneSD_ [A] () + else SomeSD_ [A] (_atNonEmpty (xs) (n) ) + private def _atNonEmpty (xs : NESeq [A] ) (n : Int) : A = (foldLeftWhile (xs) (_atNonEmpty_initial_value (xs) (n) ) (_atNonEmpty_next_value) (_atNonEmpty_condition) ).elem @@ -248,12 +255,15 @@ trait Min [A] private def _filter_next_value (tuple : FilterFoldTuple [A] ) (elem : A) : FilterFoldTuple [A] = FilterFoldTuple_ ( - ( if ( tuple.condition (elem) - ) prepended (tuple.sequence) (elem) - else tuple.sequence), + _prepend_when_condition (tuple) (elem) , tuple.condition ) + private def _prepend_when_condition (tuple : FilterFoldTuple [A] ) (elem : A) : MSeq [A] = + if ( tuple.condition (elem) + ) prepended (tuple.sequence) (elem) + else tuple.sequence + def map0 (s : MSeq [A] ) (f : A => A) : MSeq [A] = reverse ( (foldLeft (s) (_map0_initial_value (f) ) (_map0_next_value) ).sequence) diff --git a/library/src/main/scala/soda/collection/Min.soda b/library/src/main/scala/soda/collection/Min.soda index 65bbf9ec..8841311c 100644 --- a/library/src/main/scala/soda/collection/Min.soda +++ b/library/src/main/scala/soda/collection/Min.soda @@ -70,7 +70,10 @@ class Min [A] foldLeftWhile (s) (initial_value) (next_value) ( lambda (acc : B) --> lambda (elem : A) --> true) reverse (s : MSeq [A] ) : MSeq [A] = - s.opt [MSeq [A] ] (ifEmpty := empty) (ifNonEmpty := lambda neseq --> reverseNonEmpty (neseq) ) + s.opt [MSeq [A] ] ( + ifEmpty := empty) ( + ifNonEmpty := lambda neseq --> reverseNonEmpty (neseq) + ) reverseNonEmpty (s : NESeq [A] ) : NESeq [A] = foldLeft (s.tail) (_reverseNonEmpty_initial_value (s) ) (_reverseNonEmpty_next_value) @@ -95,12 +98,15 @@ class Min [A] _indexOf_next_value (tuple : IndexFoldTuple [A] ) (current_element : A) : IndexFoldTuple [A] = IndexFoldTuple_ [A] ( tuple.index + 1, - ( if current_element == tuple.element - then tuple.index - else tuple.position), + _get_index_if_element_found (tuple) (current_element) , tuple.element ) + _get_index_if_element_found (tuple : IndexFoldTuple [A] ) (current_element : A) : Int = + if current_element == tuple.element + then tuple.index + else tuple.position + _indexOf_condition (tuple : IndexFoldTuple [A] ) (elem : A) : Boolean = tuple.position == -1 @@ -119,13 +125,14 @@ class Min [A] at (s : MSeq [A] ) (n : Int) : OptionSD [A] = s.opt [OptionSD [A] ] ( ifEmpty := NoneSD_ [A] () ) ( - ifNonEmpty := ( lambda neseq --> - if n < 0 or n >= length (s) - then NoneSD_ [A] () - else SomeSD_ [A] (_atNonEmpty (neseq ) (n) ) - ) + ifNonEmpty := ( lambda neseq --> _retrieve_if_in_range (neseq) (n) ) ) + _retrieve_if_in_range (xs : NESeq [A] ) (n : Int) : OptionSD [A] = + if n < 0 or n >= length (xs) + then NoneSD_ [A] () + else SomeSD_ [A] (_atNonEmpty (xs) (n) ) + _atNonEmpty (xs : NESeq [A] ) (n : Int) : A = (foldLeftWhile (xs) (_atNonEmpty_initial_value (xs) (n) ) (_atNonEmpty_next_value) (_atNonEmpty_condition) ).elem @@ -242,12 +249,15 @@ class Min [A] _filter_next_value (tuple : FilterFoldTuple [A] ) (elem : A) : FilterFoldTuple [A] = FilterFoldTuple_ ( - ( if tuple.condition (elem) - then prepended (tuple.sequence) (elem) - else tuple.sequence), + _prepend_when_condition (tuple) (elem) , tuple.condition ) + _prepend_when_condition (tuple : FilterFoldTuple [A] ) (elem : A) : MSeq [A] = + if tuple.condition (elem) + then prepended (tuple.sequence) (elem) + else tuple.sequence + map0 (s : MSeq [A] ) (f : A -> A) : MSeq [A] = reverse ( (foldLeft (s) (_map0_initial_value (f) ) (_map0_next_value) ).sequence) diff --git a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala index 0d93bfd5..fee11a43 100644 --- a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala @@ -10,9 +10,12 @@ trait ConditionalBlockTranslator lazy val translate : AnnotatedBlock => AnnotatedBlock = block => - if ( accepted_annotations.contains (block.block_annotation) - ) translator.translate (block) - else block + translate_for (block) + + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if ( accepted_annotations.contains (block.block_annotation) + ) translator.translate (block) + else block } diff --git a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda index de64eb67..72dd707e 100644 --- a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda @@ -10,9 +10,12 @@ class ConditionalBlockTranslator translate : AnnotatedBlock -> AnnotatedBlock = lambda block --> - if accepted_annotations.contains (block.block_annotation) - then translator.translate (block) - else block + translate_for (block) + + translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if accepted_annotations.contains (block.block_annotation) + then translator.translate (block) + else block end diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala index 3ecc8146..453cdc92 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala @@ -9,6 +9,7 @@ trait TokenizedBlockTranslator import soda.lib.SomeSD_ import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine import soda.translator.parser.BlockBuilder_ import soda.translator.parser.annotation.AnnotationFactory_ import soda.translator.replacement.ParserStateEnum_ @@ -27,15 +28,15 @@ trait TokenizedBlockTranslator BlockBuilder_ ().build ( block .annotated_lines - .map ( - annotated_line => - if ( annotated_line.is_comment - ) annotated_line.line - else _translate_non_comment (annotated_line.line) - ) + .map ( annotated_line => _translate_if_not_a_comment (annotated_line) ) ) ) + private def _translate_if_not_a_comment (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else _translate_non_comment (annotated_line.line) + private def _translate_non_comment (line : String) : String = SomeSD_ (line) .map ( x => Replacement_ (x).add_space_to_soda_line ().line) @@ -46,12 +47,13 @@ trait TokenizedBlockTranslator .getOrElse ("") private def _translate_line (tokens : Seq [Token] ) : Seq [Token] = - tokens.map ( - token => - if ( token.parser_state == ParserStateEnum_ ().plain - ) Token_ (replace_token (token), token.parser_state, token.index) - else token - ) + tokens + .map ( token => _get_token_translated_if_in_state (token) ) + + private def _get_token_translated_if_in_state (token : Token) : Token = + if ( token.parser_state == ParserStateEnum_ ().plain + ) Token_ (replace_token (token), token.parser_state, token.index) + else token private def _join_tokens (tokens : Seq [Token] ) : String = tokens diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda index dab7411b..d7991eea 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda @@ -10,6 +10,7 @@ class TokenizedBlockTranslator import soda.lib.SomeSD_ soda.translator.block.AnnotatedBlock + soda.translator.block.AnnotatedLine soda.translator.parser.BlockBuilder_ soda.translator.parser.annotation.AnnotationFactory_ soda.translator.replacement.ParserStateEnum_ @@ -28,15 +29,15 @@ class TokenizedBlockTranslator BlockBuilder_ ().build ( block .annotated_lines - .map ( - lambda annotated_line --> - if annotated_line.is_comment - then annotated_line.line - else _translate_non_comment (annotated_line.line) - ) + .map ( lambda annotated_line --> _translate_if_not_a_comment (annotated_line) ) ) ) + _translate_if_not_a_comment (annotated_line : AnnotatedLine) : String = + if annotated_line.is_comment + then annotated_line.line + else _translate_non_comment (annotated_line.line) + _translate_non_comment (line : String) : String = SomeSD_ (line) .map ( lambda x --> Replacement_ (x).add_space_to_soda_line ().line) @@ -47,12 +48,13 @@ class TokenizedBlockTranslator .getOrElse ("") _translate_line (tokens : Seq [Token] ) : Seq [Token] = - tokens.map ( - lambda token --> - if token.parser_state == ParserStateEnum_ ().plain - then Token_ (replace_token (token), token.parser_state, token.index) - else token - ) + tokens + .map ( lambda token --> _get_token_translated_if_in_state (token) ) + + _get_token_translated_if_in_state (token : Token) : Token = + if token.parser_state == ParserStateEnum_ ().plain + then Token_ (replace_token (token), token.parser_state, token.index) + else token _join_tokens (tokens : Seq [Token] ) : String = tokens diff --git a/translator/src/main/scala/soda/translator/extension/main/Main.scala b/translator/src/main/scala/soda/translator/extension/main/Main.scala index 88ef4767..938a4553 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Main.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Main.scala @@ -32,12 +32,15 @@ trait Main lazy val execute : Seq [String] => Boolean = arguments => - if ( arguments.length == 0 - ) help.execute (arguments.toSeq) - else - extensions - .getOrElse (arguments.head, help) - .execute (arguments.tail) + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + if ( arguments.length == 0 + ) help.execute (arguments.toSeq) + else + extensions + .getOrElse (arguments.head, help) + .execute (arguments.tail) } diff --git a/translator/src/main/scala/soda/translator/extension/main/Main.soda b/translator/src/main/scala/soda/translator/extension/main/Main.soda index 5838b93a..ea7d536a 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Main.soda +++ b/translator/src/main/scala/soda/translator/extension/main/Main.soda @@ -32,12 +32,15 @@ class Main execute : Seq [String] -> Boolean = lambda arguments --> - if arguments.length == 0 - then help.execute (arguments.toSeq) - else - extensions - .getOrElse (arguments.head, help) - .execute (arguments.tail) + execute_for (arguments) + + execute_for (arguments : Seq [String] ) : Boolean = + if arguments.length == 0 + then help.execute (arguments.toSeq) + else + extensions + .getOrElse (arguments.head, help) + .execute (arguments.tail) end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala index fc66df11..dfc1d452 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala @@ -71,11 +71,12 @@ trait CoqClassDeclarationBlockTranslator else Seq [String] () def remove_first_line (block : Block) : Block = - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) block.lines - else block.lines.tail - ) + BlockBuilder_ ().build ( _remove_first_line (block.lines) ) + + private def _remove_first_line (lines : Seq [String] ) : Seq [String] = + if ( lines.isEmpty + ) lines + else lines.tail def get_first_line (block : Block) : String = block.lines.headOption.getOrElse ("") diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda index ab1d6eeb..f799461a 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda @@ -70,11 +70,12 @@ class CoqClassDeclarationBlockTranslator else Seq [String] () remove_first_line (block : Block) : Block = - BlockBuilder_ ().build ( - if block.lines.isEmpty - then block.lines - else block.lines.tail - ) + BlockBuilder_ ().build ( _remove_first_line (block.lines) ) + + _remove_first_line (lines : Seq [String] ) : Seq [String] = + if lines.isEmpty + then lines + else lines.tail get_first_line (block : Block) : String = block.lines.headOption.getOrElse ("") diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala index c4fc9eee..8b25ea27 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala @@ -72,8 +72,13 @@ trait DefinitionLineTranslator Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) private def _try_found_definition (position : Int) : Replacement = - if ( _is_class_definition ) _translation_of_class_definition - else if ( _is_val_definition (position) ) _translation_of_val_definition + if ( _is_class_definition + ) _translation_of_class_definition + else _decide_val_or_def_translation (position) + + private def _decide_val_or_def_translation (position : Int) : Replacement = + if ( _is_val_definition (position) + ) _translation_of_val_definition else _translation_of_def_definition private def _is_val_definition (initial_position : Int) = diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda index b0abf131..26c8cd7d 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda @@ -73,8 +73,13 @@ class DefinitionLineTranslator Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) _try_found_definition (position : Int) : Replacement = - if _is_class_definition then _translation_of_class_definition - else if _is_val_definition (position) then _translation_of_val_definition + if _is_class_definition + then _translation_of_class_definition + else _decide_val_or_def_translation (position) + + _decide_val_or_def_translation (position : Int) : Replacement = + if _is_val_definition (position) + then _translation_of_val_definition else _translation_of_def_definition _is_val_definition (initial_position : Int) = diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala index dfb4d97b..60f6b867 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala @@ -31,10 +31,15 @@ trait TranslatorToCoq lazy val execute : Seq [String] => Boolean = arguments => - if ( arguments.length == 0 ) _process_directory (_default_argument) - else if ( arguments.length == 1 ) _process_directory (arguments (0) ) - else if ( arguments.length == 2 ) _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } private def _process_directory (start : String) : Boolean = DirectoryProcessor_ (start, _process_soda_file).process () diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda index f9920f92..3640afc1 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda @@ -31,10 +31,14 @@ class TranslatorToCoq execute : Seq [String] -> Boolean = lambda arguments --> - if arguments.length == 0 then _process_directory (_default_argument) - else if arguments.length == 1 then _process_directory (arguments (0) ) - else if arguments.length == 2 then _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + execute_for (arguments : Seq [String] ) : Boolean = + match arguments.length + case 0 ==> _process_directory (_default_argument) + case 1 ==> _process_directory (arguments (0) ) + case 2 ==> _translate (arguments (0) ) (arguments (1) ) + case x ==> false _process_directory (start : String) : Boolean = DirectoryProcessor_ (start, _process_soda_file).process () diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala index a91586ab..1befc849 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala @@ -33,10 +33,15 @@ trait TranslatorToDoc lazy val execute : Seq [String] => Boolean = arguments => - if ( arguments.length == 0 ) _process_directory (_default_argument) - else if ( arguments.length == 1 ) _process_directory (arguments (0) ) - else if ( arguments.length == 2 ) _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } def translate_content (input : String) : String = _tc.doc_header + _translator.translate (input) + _tc.doc_footer diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda index f855a8f3..57776e98 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda @@ -33,10 +33,14 @@ class TranslatorToDoc execute : Seq [String] -> Boolean = lambda arguments --> - if arguments.length == 0 then _process_directory (_default_argument) - else if arguments.length == 1 then _process_directory (arguments (0) ) - else if arguments.length == 2 then _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + execute_for (arguments : Seq [String] ) : Boolean = + match arguments.length + case 0 ==> _process_directory (_default_argument) + case 1 ==> _process_directory (arguments (0) ) + case 2 ==> _translate (arguments (0) ) (arguments (1) ) + case x ==> false translate_content (input : String) : String = _tc.doc_header + _translator.translate (input) + _tc.doc_footer diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala index 47c7978f..e176a7c2 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala @@ -31,10 +31,15 @@ trait TranslatorToScala lazy val execute : Seq [String] => Boolean = arguments => - if ( arguments.length == 0 ) _process_directory (_default_argument) - else if ( arguments.length == 1 ) _process_directory (arguments (0) ) - else if ( arguments.length == 2 ) _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } private def _process_directory (start : String) : Boolean = DirectoryProcessor_ (start, _process_soda_file).process () diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index 002952c3..e1ab90b4 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -31,10 +31,14 @@ class TranslatorToScala execute : Seq [String] -> Boolean = lambda arguments --> - if arguments.length == 0 then _process_directory (_default_argument) - else if arguments.length == 1 then _process_directory (arguments (0) ) - else if arguments.length == 2 then _translate (arguments (0) ) (arguments (1) ) - else false + execute_for (arguments) + + execute_for (arguments : Seq [String] ) : Boolean = + match arguments.length + case 0 ==> _process_directory (_default_argument) + case 1 ==> _process_directory (arguments (0) ) + case 2 ==> _translate (arguments (0) ) (arguments (1) ) + case x ==> false _process_directory (start : String) : Boolean = DirectoryProcessor_ (start, _process_soda_file).process () diff --git a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala b/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala index 04a4adea..f3320edd 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala +++ b/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala @@ -27,10 +27,12 @@ trait DirectoryScanner private def _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = if ( to_scan.isEmpty ) to_scan - else - if ( to_scan.head.isDirectory - ) to_scan.tail.++ (to_scan.head.listFiles () ) - else to_scan.tail + else _get_files_to_scan_with (to_scan.head) (to_scan.tail) + + private def _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = + if ( to_scan_head.isDirectory + ) to_scan_tail.++ (to_scan_head.listFiles () ) + else to_scan_tail } diff --git a/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda b/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda index 8920a55f..a2ef4527 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda +++ b/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda @@ -26,10 +26,12 @@ class DirectoryScanner _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = if to_scan.isEmpty then to_scan - else - if to_scan.head.isDirectory - then to_scan.tail.++ (to_scan.head.listFiles () ) - else to_scan.tail + else _get_files_to_scan_with (to_scan.head) (to_scan.tail) + + _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = + if to_scan_head.isDirectory + then to_scan_tail.++ (to_scan_head.listFiles () ) + else to_scan_tail end diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala index 30c6ee1e..bca62434 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala @@ -34,10 +34,12 @@ trait BlockBuilder private def _annotate_this_line (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = if ( comment_state ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) - else - if ( line.trim.startsWith (_sc.comment_opening_symbol) - ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) - else CurrentAndNewCommentState_ (false, false) + else _annotate_this_line_considering_opening_symbol (line) (comment_state) + + private def _annotate_this_line_considering_opening_symbol (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = + if ( line.trim.startsWith (_sc.comment_opening_symbol) + ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) + else CurrentAndNewCommentState_ (false, false) } diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda index 4d95cb15..3dfc4727 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda @@ -34,10 +34,12 @@ class BlockBuilder _annotate_this_line (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = if comment_state then CurrentAndNewCommentState_ (true, not line.trim.endsWith (_sc.comment_closing_symbol) ) - else - if line.trim.startsWith (_sc.comment_opening_symbol) - then CurrentAndNewCommentState_ (true, not line.trim.endsWith (_sc.comment_closing_symbol) ) - else CurrentAndNewCommentState_ (false, false) + else _annotate_this_line_considering_opening_symbol (line) (comment_state) + + _annotate_this_line_considering_opening_symbol (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = + if line.trim.startsWith (_sc.comment_opening_symbol) + then CurrentAndNewCommentState_ (true, not line.trim.endsWith (_sc.comment_closing_symbol) ) + else CurrentAndNewCommentState_ (false, false) end diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.scala b/translator/src/main/scala/soda/translator/replacement/CharType.scala index 6fc5a75b..99bbf161 100644 --- a/translator/src/main/scala/soda/translator/replacement/CharType.scala +++ b/translator/src/main/scala/soda/translator/replacement/CharType.scala @@ -45,15 +45,28 @@ trait CharTypeEnum lazy val underscore_char = '_' - lazy val symbol_chars = Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + lazy val symbol_chars : Seq [Char] = + Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + + lazy val simple_char_type_map : Map [Char , CharType] = + Map ( + Tuple2 ( quotes_char , quotes_type ), + Tuple2 ( apostrophe_char , apostrophe_type ), + Tuple2 ( backslash_char, backslash_type ) + ) def get_char_type (ch : Char) : CharType = - if ( _is_quotes (ch) ) quotes_type - else if ( _is_apostrophe (ch) ) apostrophe_type - else if ( _is_backslash (ch) ) backslash_type - else if ( _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) ) plain_type + simple_char_type_map + .getOrElse (ch, _get_char_type_if_plain (ch) ) + + private def _get_char_type_if_plain (ch : Char) : CharType = + if ( _is_plain (ch) + ) plain_type else undefined_type + private def _is_plain (ch : Char) : Boolean = + _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) + private def _is_whitespace (ch : Char) : Boolean = ch.isWhitespace @@ -63,15 +76,6 @@ trait CharTypeEnum private def _is_symbol (ch : Char) : Boolean = symbol_chars.contains (ch) - private def _is_quotes (ch : Char) : Boolean = - ch == quotes_char - - private def _is_apostrophe (ch : Char) : Boolean = - ch == apostrophe_char - - private def _is_backslash (ch : Char) : Boolean = - ch == backslash_char - } case class CharTypeEnum_ () extends CharTypeEnum diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.soda b/translator/src/main/scala/soda/translator/replacement/CharType.soda index 588c4183..13ce1b7d 100644 --- a/translator/src/main/scala/soda/translator/replacement/CharType.soda +++ b/translator/src/main/scala/soda/translator/replacement/CharType.soda @@ -42,15 +42,28 @@ class CharTypeEnum underscore_char = '_' - symbol_chars = Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + symbol_chars : Seq [Char] = + Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + + simple_char_type_map : Map [Char , CharType] = + Map ( + Tuple2 ( quotes_char , quotes_type ), + Tuple2 ( apostrophe_char , apostrophe_type ), + Tuple2 ( backslash_char, backslash_type ) + ) get_char_type (ch : Char) : CharType = - if _is_quotes (ch) then quotes_type - else if _is_apostrophe (ch) then apostrophe_type - else if _is_backslash (ch) then backslash_type - else if _is_whitespace (ch) or _is_letter_or_digit_or_underscore (ch) or _is_symbol (ch) then plain_type + simple_char_type_map + .getOrElse (ch, _get_char_type_if_plain (ch) ) + + _get_char_type_if_plain (ch : Char) : CharType = + if _is_plain (ch) + then plain_type else undefined_type + _is_plain (ch : Char) : Boolean = + _is_whitespace (ch) or _is_letter_or_digit_or_underscore (ch) or _is_symbol (ch) + _is_whitespace (ch : Char) : Boolean = ch.isWhitespace @@ -60,14 +73,5 @@ class CharTypeEnum _is_symbol (ch : Char) : Boolean = symbol_chars.contains (ch) - _is_quotes (ch : Char) : Boolean = - ch == quotes_char - - _is_apostrophe (ch : Char) : Boolean = - ch == apostrophe_char - - _is_backslash (ch : Char) : Boolean = - ch == backslash_char - end diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala index 982fbb9d..23ffd6c3 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala @@ -57,12 +57,15 @@ trait Tokenizer tuple) ( current_index) ( new_parser_state) ( - if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || - tuple.parser_state == ParserStateEnum_ ().apostrophe_state - ) current_index + 1 - else current_index + _get_new_current_index (tuple) (current_index) ) + private def _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = + if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || + tuple.parser_state == ParserStateEnum_ ().apostrophe_state + ) current_index + 1 + else current_index + private def _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = TokenizerFoldTuple_ (index, new_parser_state, tuple.rev_tokens.+: ( diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda index c1538f0a..ae0a0dc8 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda @@ -56,12 +56,15 @@ class Tokenizer tuple) ( current_index) ( new_parser_state) ( - if tuple.parser_state == ParserStateEnum_ ().quotes_state or - tuple.parser_state == ParserStateEnum_ ().apostrophe_state - then current_index + 1 - else current_index + _get_new_current_index (tuple) (current_index) ) + _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = + if tuple.parser_state == ParserStateEnum_ ().quotes_state or + tuple.parser_state == ParserStateEnum_ ().apostrophe_state + then current_index + 1 + else current_index + _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = TokenizerFoldTuple_ (index, new_parser_state, tuple.rev_tokens.+: ( From c1335db7bf481d5add0e3e9cb4051fc3f7c1336e Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 23 Jan 2023 23:17:28 +0100 Subject: [PATCH 26/71] Make minor change --- .../replacement/ParserTransition.scala | 42 +++++++++---------- .../replacement/ParserTransition.soda | 42 +++++++++---------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala b/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala index c930fe09..2018f3d1 100644 --- a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala +++ b/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala @@ -60,31 +60,31 @@ trait ParserTransition lazy val transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = Map ( /* */ - ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), - ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), + Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), /* */ - ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), - ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), /* */ - ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), /* */ - ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), /* */ - ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), - ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), - ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), - ( Tuple2 (ps.plain, ct.plain_type), ps.plain) + Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), + Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) ) def next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = diff --git a/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda b/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda index efd808c1..9c7eb3af 100644 --- a/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda +++ b/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda @@ -54,31 +54,31 @@ class ParserTransition transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = Map ( /* */ - ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), - ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), + Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), /* */ - ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), - ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), /* */ - ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), - ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), /* */ - ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), - ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), /* */ - ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), - ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), - ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), - ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), - ( Tuple2 (ps.plain, ct.plain_type), ps.plain) + Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), + Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) ) next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = From 4bf7bcb2983fba1d653b9f84711f7b68c3fdefd4 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 24 Jan 2023 10:47:11 +0100 Subject: [PATCH 27/71] Make minor change --- .../translator/parser/annotation/AnnotationFactory.scala | 9 ++++++--- .../translator/parser/annotation/AnnotationFactory.soda | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala index adbedbee..cfe6db58 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala @@ -12,9 +12,12 @@ trait AnnotationFactory lazy val translate : AnnotatedBlock => AnnotatedBlock = block => - if ( block.block_annotation == BlockAnnotationEnum_ ().undefined - ) annotate (block) - else block + translate_for (block) + + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if ( block.block_annotation == BlockAnnotationEnum_ ().undefined + ) annotate (block) + else block def annotate (block : Block) : AnnotatedBlock = block match { diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda index 149b93c6..6972a683 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda @@ -12,9 +12,12 @@ class AnnotationFactory translate : AnnotatedBlock -> AnnotatedBlock = lambda block --> - if block.block_annotation == BlockAnnotationEnum_ ().undefined - then annotate (block) - else block + translate_for (block) + + translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if block.block_annotation == BlockAnnotationEnum_ ().undefined + then annotate (block) + else block annotate (block : Block) : AnnotatedBlock = match block From 8b651316cf2cc0668cf2cab06a009de2cccca859 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 24 Jan 2023 10:54:12 +0100 Subject: [PATCH 28/71] Update example for testing --- .../parser/annotation/ExampleProgram.scala | 14 ++++++++------ .../parser/annotation/ExampleProgram.soda | 14 ++++++++------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala index 0177f1bf..feb6cd39 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala @@ -21,21 +21,23 @@ trait ExampleProgram "\n SuperClassExample" + "\n" + "\n abstract" + - "\n value: Int" + + "\n value : Int" + "\n" + "\n import" + "\n soda.lib.Recursion_" + "\n soda.lib.Enum" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + "\n test (\"should test the example\")" + - "\n let" + - "\n result = true" + - "\n in assert (result)" + + "\n check (" + + "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + + "\n ) (" + + "\n expected := Seq (\"A\", \"B\")" + + "\n )" + "\n" + "\n theorem" + "\n True" + diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda index 0fbd2fea..7a41943e 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda @@ -21,21 +21,23 @@ class ExampleProgram "\n SuperClassExample" + "\n" + "\n abstract" + - "\n value: Int" + + "\n value : Int" + "\n" + "\n import" + "\n soda.lib.Recursion_" + "\n soda.lib.Enum" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + "\n test (\"should test the example\")" + - "\n let" + - "\n result = true" + - "\n in assert (result)" + + "\n check (" + + "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + + "\n ) (" + + "\n expected := Seq (\"A\", \"B\")" + + "\n )" + "\n" + "\n theorem" + "\n True" + From a1adcaf872257d9e33fede0245736aa3b7c0e4be Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 24 Jan 2023 15:12:00 +0100 Subject: [PATCH 29/71] Make minor change --- .../extension/toscala/TheoremAndProofBlockTranslator.scala | 2 +- .../extension/toscala/TheoremAndProofBlockTranslator.soda | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala index 1b6900d1..a15fb33e 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala @@ -37,7 +37,7 @@ trait TheoremAndProofBlockTranslator private def _prepend (prefix : String) (block : Block) : Block = BlockBuilder_ ().build ( - Seq [String] (prefix + block.lines.head) ++ block.lines.tail + Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) ) private def _append (suffix : String) (block : Block) : Block = diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda index 590f7e44..d8ae6893 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda @@ -36,7 +36,7 @@ class TheoremAndProofBlockTranslator _prepend (prefix : String) (block : Block) : Block = BlockBuilder_ ().build ( - Seq [String] (prefix + block.lines.head) ++ block.lines.tail + Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) ) _append (suffix : String) (block : Block) : Block = From 054e4688d315fd3e23beb86d5e865d6859007b8c Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 24 Jan 2023 12:51:18 +0100 Subject: [PATCH 30/71] Make function definition annotation work on multiple lines --- .../FunctionDefinitionAnnotation.scala | 23 +++++++++++++++---- .../FunctionDefinitionAnnotation.soda | 23 +++++++++++++++---- .../annotation/BlockAnnotationSpec.scala | 22 ++++++++++++------ .../annotation/BlockAnnotationSpec.soda | 22 ++++++++++++------ .../ClassBeginningAnnotationSpec.scala | 2 +- .../ClassBeginningAnnotationSpec.soda | 2 +- .../parser/annotation/ExampleProgram.scala | 6 +++++ .../parser/annotation/ExampleProgram.soda | 6 +++++ 8 files changed, 80 insertions(+), 26 deletions(-) diff --git a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala index 3e3ca397..e526b282 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala @@ -28,14 +28,19 @@ trait FunctionDefinitionAnnotation private lazy val _plain_state = ParserStateEnum_ ().plain lazy val applies : Boolean = - (contains_the_equals_symbol || _starts_with_valid_annotation) && ! _is_a_class_declaration + ! is_a_theorem && + ! is_a_proof && + ! is_a_class_declaration && + (contains_the_equals_symbol || _starts_with_valid_annotation) lazy val contains_the_equals_symbol : Boolean = block.readable_lines.nonEmpty && - _contains_the_equals_symbol_with (block.readable_lines.head.line) + block.readable_lines + .filter ( annotated_line => ! annotated_line.is_comment) + .exists ( annotated_line => _contains_the_equals_symbol_in_line (annotated_line.line) ) - private def _contains_the_equals_symbol_with (first_line : String) : Boolean = - Tokenizer_ (first_line) + private def _contains_the_equals_symbol_in_line (line : String) : Boolean = + Tokenizer_ (line) .tokens .exists ( token => token.parser_state == _plain_state && @@ -56,9 +61,17 @@ trait FunctionDefinitionAnnotation ( first_line_trimmed == sc.tail_recursion_annotation || first_line_trimmed == sc.override_annotation ) - private lazy val _is_a_class_declaration : Boolean = + lazy val is_a_class_declaration : Boolean = starts_with_prefix_and_space (sc.class_reserved_word) + lazy val is_a_theorem : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + + lazy val is_a_proof : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) + } case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda index a8a8eb68..cd4456c5 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda @@ -29,14 +29,19 @@ class FunctionDefinitionAnnotation _plain_state = ParserStateEnum_ ().plain applies : Boolean = - (contains_the_equals_symbol or _starts_with_valid_annotation) and not _is_a_class_declaration + not is_a_theorem and + not is_a_proof and + not is_a_class_declaration and + (contains_the_equals_symbol or _starts_with_valid_annotation) contains_the_equals_symbol : Boolean = block.readable_lines.nonEmpty and - _contains_the_equals_symbol_with (block.readable_lines.head.line) + block.readable_lines + .filter ( lambda annotated_line --> not annotated_line.is_comment) + .exists ( lambda annotated_line --> _contains_the_equals_symbol_in_line (annotated_line.line) ) - _contains_the_equals_symbol_with (first_line : String) : Boolean = - Tokenizer_ (first_line) + _contains_the_equals_symbol_in_line (line : String) : Boolean = + Tokenizer_ (line) .tokens .exists ( lambda token --> token.parser_state == _plain_state and @@ -57,8 +62,16 @@ class FunctionDefinitionAnnotation ( first_line_trimmed == sc.tail_recursion_annotation or first_line_trimmed == sc.override_annotation ) - _is_a_class_declaration : Boolean = + is_a_class_declaration : Boolean = starts_with_prefix_and_space (sc.class_reserved_word) + is_a_theorem : Boolean = + block.readable_lines.nonEmpty and + (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + + is_a_proof : Boolean = + block.readable_lines.nonEmpty and + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) + end diff --git a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala index c6a703b7..28d73e75 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala @@ -90,9 +90,17 @@ case class BlockAnnotationSpec () ) ) - test ("should detect a test declaration") ( + test ("should detect another function declaration") ( check ( obtained = apply_detectors (example_blocks (7) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a test declaration") ( + check ( + obtained = apply_detectors (example_blocks (8) ) ) ( expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) ) @@ -100,7 +108,7 @@ case class BlockAnnotationSpec () test ("should detect a theorem block") ( check ( - obtained = apply_detectors (example_blocks (8) ) + obtained = apply_detectors (example_blocks (9) ) ) ( expected = Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) ) @@ -108,7 +116,7 @@ case class BlockAnnotationSpec () test ("should detect a proof block") ( check ( - obtained = apply_detectors (example_blocks (9) ) + obtained = apply_detectors (example_blocks (10) ) ) ( expected = Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) ) @@ -116,7 +124,7 @@ case class BlockAnnotationSpec () test ("should detect a class end") ( check ( - obtained = apply_detectors (example_blocks (10) ) + obtained = apply_detectors (example_blocks (11) ) ) ( expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) ) @@ -124,17 +132,17 @@ case class BlockAnnotationSpec () test ("should detect a class alias") ( check ( - obtained = apply_detectors (example_blocks (11) ) + obtained = apply_detectors (example_blocks (12) ) ) ( expected = Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) ) ) - test ("should find only 12 blocks") ( + test ("should find only 13 blocks") ( check ( obtained = example_blocks.length ) ( - expected = 12 + expected = 13 ) ) diff --git a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda index 745afb6e..b760cc53 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda @@ -90,9 +90,17 @@ class BlockAnnotationSpec () ) ) - test ("should detect a test declaration") ( + test ("should detect another function declaration") ( check ( obtained := apply_detectors (example_blocks (7) ) + ) ( + expected := Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a test declaration") ( + check ( + obtained := apply_detectors (example_blocks (8) ) ) ( expected := Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) ) @@ -100,7 +108,7 @@ class BlockAnnotationSpec () test ("should detect a theorem block") ( check ( - obtained := apply_detectors (example_blocks (8) ) + obtained := apply_detectors (example_blocks (9) ) ) ( expected := Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) ) @@ -108,7 +116,7 @@ class BlockAnnotationSpec () test ("should detect a proof block") ( check ( - obtained := apply_detectors (example_blocks (9) ) + obtained := apply_detectors (example_blocks (10) ) ) ( expected := Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) ) @@ -116,7 +124,7 @@ class BlockAnnotationSpec () test ("should detect a class end") ( check ( - obtained := apply_detectors (example_blocks (10) ) + obtained := apply_detectors (example_blocks (11) ) ) ( expected := Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) ) @@ -124,17 +132,17 @@ class BlockAnnotationSpec () test ("should detect a class alias") ( check ( - obtained := apply_detectors (example_blocks (11) ) + obtained := apply_detectors (example_blocks (12) ) ) ( expected := Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) ) ) - test ("should find only 12 blocks") ( + test ("should find only 13 blocks") ( check ( obtained := example_blocks.length ) ( - expected := 12 + expected := 13 ) ) diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala index 4f900e34..f0a5fc02 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala @@ -66,7 +66,7 @@ case class ClassBeginningAnnotationSpec () check ( obtained = example_blocks.map ( block => ClassBeginningAnnotation_ (block).applies ) ) ( - expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false) + expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false, false) ) ) diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda index 5d93e9e5..e67ac0e8 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda @@ -66,7 +66,7 @@ class ClassBeginningAnnotationSpec () check ( obtained := example_blocks.map ( lambda block --> ClassBeginningAnnotation_ (block).applies ) ) ( - expected := Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false) + expected := Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false, false) ) ) diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala index feb6cd39..3f4f6aa7 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala @@ -32,6 +32,12 @@ trait ExampleProgram "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function" + + "\n (x : Int)" + + "\n (y : Int)" + + "\n : Int =" + + "\n x + y" + + "\n" + "\n test (\"should test the example\")" + "\n check (" + "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda index 7a41943e..51fb1fdc 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda @@ -32,6 +32,12 @@ class ExampleProgram "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function" + + "\n (x : Int)" + + "\n (y : Int)" + + "\n : Int =" + + "\n x + y" + + "\n" + "\n test (\"should test the example\")" + "\n check (" + "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + From f664219c74bd09e709a8ae623e37c24962907644 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 24 Jan 2023 13:57:13 +0100 Subject: [PATCH 31/71] Add function definition block translator --- docs/RELEASE-NOTES.md | 3 +- .../tocoq/DefinitionLineTranslator.scala | 4 +- .../tocoq/DefinitionLineTranslator.soda | 4 +- .../FunctionDefinitionBlockTranslator.scala | 110 ++++++++++++++++++ .../FunctionDefinitionBlockTranslator.soda | 107 +++++++++++++++++ ...a => FunctionDefinitionLineDetector.scala} | 35 ++---- ...da => FunctionDefinitionLineDetector.soda} | 33 ++---- .../toscala/MicroTranslatorToScala.scala | 6 +- .../toscala/MicroTranslatorToScala.soda | 6 +- .../toscala/MicroTranslatorToScalaSpec.scala | 2 + .../toscala/MicroTranslatorToScalaSpec.soda | 2 + 11 files changed, 252 insertions(+), 60 deletions(-) create mode 100644 translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala create mode 100644 translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda rename translator/src/main/scala/soda/translator/extension/toscala/{FunctionDefinitionLineTranslator.scala => FunctionDefinitionLineDetector.scala} (68%) rename translator/src/main/scala/soda/translator/extension/toscala/{FunctionDefinitionLineTranslator.soda => FunctionDefinitionLineDetector.soda} (70%) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index ffe6f6d4..948b1f12 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -5,7 +5,8 @@ - release: target/scala-3.2.0/soda-0.17.0.jar - new_features: - accepts reserved word `any` as a synonym for `lambda` - - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure + - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure + - improves function definition by allowing multiple lines in its signature - deprecated_features: - the `end` reserved word for `match`-`case` is no longer used - version: v0.16.0 diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala index 8b25ea27..7e5323df 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala @@ -11,8 +11,8 @@ package soda.translator.extension.tocoq * It is detected in three cases. * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x: (A, B) -> C = (x, y) -> f (x,y)` - * Case 4: The first non-blank character of a line is an open parenthesis, e.g. `(x, y) = (0, 1)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` * * 'def' is for function definition. * If it does not fit in any of the 'val' cases. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda index 26c8cd7d..ba66a6dd 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda @@ -11,8 +11,8 @@ package soda.translator.extension.tocoq * It is detected in three cases. * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x: (A, B) -> C = (x, y) -> f (x,y)` - * Case 4: The first non-blank character of a line is an open parenthesis, e.g. `(x, y) = (0, 1)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` * * 'def' is for function definition. * If it does not fit in any of the 'val' cases. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala new file mode 100644 index 00000000..7b722916 --- /dev/null +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala @@ -0,0 +1,110 @@ +package soda.translator.extension.toscala + +trait FunctionDefinitionBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.block.Block_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case FunctionDefinitionAnnotation_ (block) => _translate_function_definition_block (block) + case x => annotated_block + } + + private def _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : Block) : Block = + if ( block.readable_lines.isEmpty + ) block + else _translate_block_with (block.readable_lines.head) (block) + + private def _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = + if ( _is_annotation (first_line.line) + ) _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) + else _translate_main_block (block) + + private def _translate_main_block (block : Block) : Block = + _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) + + private def _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = + detector.detect match { + case detector.val_detected => _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case detector.def_detected => _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case x => block + } + + private def _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) + ) + + private def _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) + ) + + private def _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.takeWhile ( annotated_line => annotated_line.is_comment ) + + private def _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.dropWhile ( annotated_line => annotated_line.is_comment ) + + private def _translate_val_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) + .line + + private def _translate_def_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) + .line + + private def _private_prefix_if_necessary (line : String) : String = + if ( line.trim.startsWith (_sc.private_function_prefix) + ) _tc.scala_private_reserved_word + _tc.scala_space + else "" + + private def _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = + if ( lines.isEmpty + ) Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) + else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) + + private def _remove_first_line_if_possible (block : Block) : Block = + if ( block.lines.isEmpty + ) block + else BlockBuilder_ ().build (block.lines.tail) + + private def _prepend_line (line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (line) .++ (block.lines) + ) + + private def _flatten_block (block : Block) : String = + block.lines.mkString (_sc.space) + + private def _is_annotation (line : String) : Boolean = + (line.trim == _sc.tail_recursion_annotation) || (line.trim == _sc.override_annotation) + +} + +case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda new file mode 100644 index 00000000..41b3b3a5 --- /dev/null +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda @@ -0,0 +1,107 @@ +package soda.translator.extension.toscala + +class FunctionDefinitionBlockTranslator + extends + soda.translator.block.BlockTranslator + + import + soda.translator.block.AnnotatedBlock + soda.translator.block.AnnotatedLine + soda.translator.block.AnnotatedLine_ + soda.translator.block.Block + soda.translator.block.Block_ + soda.translator.parser.BlockBuilder_ + soda.translator.parser.SodaConstant_ + soda.translator.parser.annotation.FunctionDefinitionAnnotation + soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + soda.translator.replacement.Replacement_ + + _sc = SodaConstant_ () + + _tc = TranslationConstantToScala_ () + + translate : AnnotatedBlock -> AnnotatedBlock = + lambda block --> + translate_for (block) + + translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + match annotated_block + case FunctionDefinitionAnnotation_ (block) ==> _translate_function_definition_block (block) + case x ==> annotated_block + + _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + _translate_block (block : Block) : Block = + if block.readable_lines.isEmpty + then block + else _translate_block_with (block.readable_lines.head) (block) + + _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = + if _is_annotation (first_line.line) + then _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) + else _translate_main_block (block) + + _translate_main_block (block : Block) : Block = + _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) + + _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = + match detector.detect + case detector.val_detected ==> _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case detector.def_detected ==> _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case x ==> block + + _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) + ) + + _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) + ) + + _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.takeWhile ( lambda annotated_line --> annotated_line.is_comment ) + + _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.dropWhile ( lambda annotated_line --> annotated_line.is_comment ) + + _translate_val_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) + .line + + _translate_def_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) + .line + + _private_prefix_if_necessary (line : String) : String = + if line.trim.startsWith (_sc.private_function_prefix) + then _tc.scala_private_reserved_word + _tc.scala_space + else "" + + _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = + if lines.isEmpty + then Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) + else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) + + _remove_first_line_if_possible (block : Block) : Block = + if block.lines.isEmpty + then block + else BlockBuilder_ ().build (block.lines.tail) + + _prepend_line (line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (line) .++ (block.lines) + ) + + _flatten_block (block : Block) : String = + block.lines.mkString (_sc.space) + + _is_annotation (line : String) : Boolean = + (line.trim == _sc.tail_recursion_annotation) or (line.trim == _sc.override_annotation) + +end + diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala similarity index 68% rename from translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.scala rename to translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala index babfd0c2..ff853b90 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala @@ -8,8 +8,8 @@ package soda.translator.extension.toscala * It is detected in three cases. * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x: (A, B) -> C = (x, y) -> f (x,y)` - * Case 4: The first non-blank character of a line is an open parenthesis, e.g. `(x, y) = (0, 1)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` * * 'def' is for function definition. * If it does not fit in any of the 'val' cases. @@ -22,9 +22,7 @@ package soda.translator.extension.toscala * */ -trait FunctionDefinitionLineTranslator - extends - soda.translator.block.LineTranslator +trait FunctionDefinitionLineDetector { def line: String @@ -32,33 +30,24 @@ trait FunctionDefinitionLineTranslator import soda.lib.OptionSD import soda.lib.SomeSD_ import soda.translator.parser.SodaConstant_ - import soda.translator.replacement.Replacement - import soda.translator.replacement.Replacement_ private lazy val _sc = SodaConstant_ () - private lazy val _tc = TranslationConstantToScala_ () - private lazy val _trimmed_line = line.trim - lazy val translation = - _find_definition (line).opt (ifEmpty = line) (ifNonEmpty = position => _try_found_definition (position).line) + lazy val undetected = 0 - private lazy val _translation_of_val_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary + _tc.scala_value + _tc.scala_space) + lazy val val_detected = 1 - private lazy val _translation_of_def_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary + _tc.scala_definition + _tc.scala_space) + lazy val def_detected = 2 - private lazy val _private_prefix_if_necessary : String = - if ( line.trim.startsWith (_sc.private_function_prefix) - ) _tc.scala_private_reserved_word + _tc.scala_space - else "" + lazy val detect : Int = + _find_definition (line).opt (ifEmpty = undetected) (ifNonEmpty = position => _try_found_definition (position) ) - private def _try_found_definition (position : Int) : Replacement = + private def _try_found_definition (position : Int) : Int = if ( _is_val_definition (position) - ) _translation_of_val_definition - else _translation_of_def_definition + ) val_detected + else def_detected private def _is_val_definition (initial_position : Int) = _is_val_definition_case_1 || @@ -104,4 +93,4 @@ trait FunctionDefinitionLineTranslator } -case class FunctionDefinitionLineTranslator_ (line: String) extends FunctionDefinitionLineTranslator +case class FunctionDefinitionLineDetector_ (line: String) extends FunctionDefinitionLineDetector diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda similarity index 70% rename from translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.soda rename to translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda index ddff85e7..4b163218 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda @@ -8,8 +8,8 @@ package soda.translator.extension.toscala * It is detected in three cases. * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x: (A, B) -> C = (x, y) -> f (x,y)` - * Case 4: The first non-blank character of a line is an open parenthesis, e.g. `(x, y) = (0, 1)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` * * 'def' is for function definition. * If it does not fit in any of the 'val' cases. @@ -22,9 +22,7 @@ package soda.translator.extension.toscala * */ -class FunctionDefinitionLineTranslator - extends - soda.translator.block.LineTranslator +class FunctionDefinitionLineDetector abstract line: String @@ -33,33 +31,24 @@ class FunctionDefinitionLineTranslator soda.lib.OptionSD soda.lib.SomeSD_ soda.translator.parser.SodaConstant_ - soda.translator.replacement.Replacement - soda.translator.replacement.Replacement_ _sc = SodaConstant_ () - _tc = TranslationConstantToScala_ () - _trimmed_line = line.trim - translation = - _find_definition (line).opt (ifEmpty := line) (ifNonEmpty := lambda position --> _try_found_definition (position).line) + undetected = 0 - _translation_of_val_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary + _tc.scala_value + _tc.scala_space) + val_detected = 1 - _translation_of_def_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary + _tc.scala_definition + _tc.scala_space) + def_detected = 2 - _private_prefix_if_necessary : String = - if line.trim.startsWith (_sc.private_function_prefix) - then _tc.scala_private_reserved_word + _tc.scala_space - else "" + detect : Int = + _find_definition (line).opt (ifEmpty := undetected) (ifNonEmpty := lambda position --> _try_found_definition (position) ) - _try_found_definition (position : Int) : Replacement = + _try_found_definition (position : Int) : Int = if _is_val_definition (position) - then _translation_of_val_definition - else _translation_of_def_definition + then val_detected + else def_detected _is_val_definition (initial_position : Int) = _is_val_definition_case_1 or diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala index 5c1795dc..0fe842e2 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala @@ -34,16 +34,12 @@ trait MicroTranslatorToScala block => _translation_pipeline.translate (block) - private lazy val _try_definition : Token => String = - token => - FunctionDefinitionLineTranslator_ (token.text).translation - private lazy val _translation_pipeline = BlockTranslatorPipeline_ ( Seq ( MatchCaseBlockTranslator_ (), ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), - ConditionalBlockTranslator_ (_functions_and_tests, TokenizedBlockTranslator_ (_try_definition) ), + ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), ClassDeclarationBlockTranslator_ (), diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda index 9b7e1d2c..47483f08 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda @@ -34,16 +34,12 @@ class MicroTranslatorToScala lambda block --> _translation_pipeline.translate (block) - _try_definition : Token -> String = - lambda token --> - FunctionDefinitionLineTranslator_ (token.text).translation - _translation_pipeline = BlockTranslatorPipeline_ ( Seq ( MatchCaseBlockTranslator_ (), ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), - ConditionalBlockTranslator_ (_functions_and_tests, TokenizedBlockTranslator_ (_try_definition) ), + ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), ClassDeclarationBlockTranslator_ (), diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala index 262700b6..a38ccd21 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala @@ -205,12 +205,14 @@ case class MicroTranslatorToScalaSpec () test ("should translate a tuple assignment") ( check ( obtained = instance.translate (" (x, y) = (f (a), g (a))" + + "\n" + "\n (p, q) =" + "\n h (1, 2)" + "\n" ) ) ( expected = " lazy val (x, y) = (f (a), g (a))" + + "\n" + "\n lazy val (p, q) =" + "\n h (1, 2)" + "\n" diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda index da76759f..0f2f86f7 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda @@ -205,12 +205,14 @@ class MicroTranslatorToScalaSpec () test ("should translate a tuple assignment") ( check ( obtained := instance.translate (" (x, y) = (f (a), g (a))" + + "\n" + "\n (p, q) =" + "\n h (1, 2)" + "\n" ) ) ( expected := " lazy val (x, y) = (f (a), g (a))" + + "\n" + "\n lazy val (p, q) =" + "\n h (1, 2)" + "\n" From cce2c93ae0a0e0495dc0bf0acb90d0abedb6e5e2 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 29 Jan 2023 15:58:51 +0100 Subject: [PATCH 32/71] Update Recursion class in Soda library --- .../resources/lib/soda/lib/Recursion.scala | 44 +++++++++++++++++-- .../resources/lib/soda/lib/Recursion.soda | 35 +++++++++++++-- .../src/main/scala/soda/lib/Recursion.scala | 44 +++++++++++++++++-- .../src/main/scala/soda/lib/Recursion.soda | 35 +++++++++++++-- 4 files changed, 142 insertions(+), 16 deletions(-) diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.scala b/translator/src/main/resources/lib/soda/lib/Recursion.scala index 5252ea98..074d905e 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.scala +++ b/translator/src/main/resources/lib/soda/lib/Recursion.scala @@ -8,7 +8,7 @@ package soda.lib * This class contains tail recursive auxiliary functions. */ -trait Recursion +trait FoldWhile { import scala.annotation.tailrec @@ -18,9 +18,16 @@ trait Recursion ) current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +} + +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = @@ -28,9 +35,16 @@ trait Recursion ) current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = _tailrec_fold (sequence) (initial_value) (next_value_function) +} + +case class Fold_ () extends Fold + +trait Range +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -38,9 +52,31 @@ trait Recursion ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def range (length : Int) : Seq [Int] = + def apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) } +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + case class Recursion_ () extends Recursion diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.soda b/translator/src/main/resources/lib/soda/lib/Recursion.soda index 19050de0..2493edde 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.soda +++ b/translator/src/main/resources/lib/soda/lib/Recursion.soda @@ -8,7 +8,7 @@ package soda.lib * This class contains tail recursive auxiliary functions. */ -class Recursion +class FoldWhile @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = @@ -16,26 +16,53 @@ class Recursion then current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +end + +class Fold + @tailrec _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = if sequence.isEmpty then current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = _tailrec_fold (sequence) (initial_value) (next_value_function) +end + +class Range + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - range (length : Int) : Seq [Int] = + apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) end +class Recursion + + _fold_while = FoldWhile_ () + + _fold = Fold_ () + + _range = Range_ () + + fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + range (length : Int) : Seq [Int] = + _range.apply (length) + +end + diff --git a/translator/src/main/scala/soda/lib/Recursion.scala b/translator/src/main/scala/soda/lib/Recursion.scala index 5252ea98..074d905e 100644 --- a/translator/src/main/scala/soda/lib/Recursion.scala +++ b/translator/src/main/scala/soda/lib/Recursion.scala @@ -8,7 +8,7 @@ package soda.lib * This class contains tail recursive auxiliary functions. */ -trait Recursion +trait FoldWhile { import scala.annotation.tailrec @@ -18,9 +18,16 @@ trait Recursion ) current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +} + +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = @@ -28,9 +35,16 @@ trait Recursion ) current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = _tailrec_fold (sequence) (initial_value) (next_value_function) +} + +case class Fold_ () extends Fold + +trait Range +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -38,9 +52,31 @@ trait Recursion ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def range (length : Int) : Seq [Int] = + def apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) } +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + case class Recursion_ () extends Recursion diff --git a/translator/src/main/scala/soda/lib/Recursion.soda b/translator/src/main/scala/soda/lib/Recursion.soda index 2989e7a9..59ee3d92 100644 --- a/translator/src/main/scala/soda/lib/Recursion.soda +++ b/translator/src/main/scala/soda/lib/Recursion.soda @@ -8,7 +8,7 @@ package soda.lib * This class contains tail recursive auxiliary functions. */ -class Recursion +class FoldWhile @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = @@ -16,25 +16,52 @@ class Recursion then current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +end + +class Fold + @tailrec _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = if sequence.isEmpty then current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = _tailrec_fold (sequence) (initial_value) (next_value_function) +end + +class Range + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - range (length : Int) : Seq [Int] = + apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) end + +class Recursion + + _fold_while = FoldWhile_ () + + _fold = Fold_ () + + _range = Range_ () + + fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + range (length : Int) : Seq [Int] = + _range.apply (length) + +end From 5a1159483f1a3b92fd4248bb32771679ef53825d Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 29 Jan 2023 17:12:39 +0100 Subject: [PATCH 33/71] Update CartesianProduct class in Soda library --- .../resources/lib/soda/lib/CartesianProduct.scala | 6 ++++-- .../resources/lib/soda/lib/CartesianProduct.soda | 6 ++++-- .../src/main/scala/soda/lib/CartesianProduct.scala | 6 ++++-- .../src/main/scala/soda/lib/CartesianProduct.soda | 6 ++++-- .../test/scala/soda/lib/CartesianProductSpec.scala | 12 +++++++----- .../test/scala/soda/lib/CartesianProductSpec.soda | 12 +++++++----- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala index 729bf458..f8ffca5e 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala @@ -11,6 +11,8 @@ package soda.lib trait CartesianProduct { + private lazy val _fold = Fold_ () + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = seq.map ( elem => Seq [A] (elem) ) @@ -19,9 +21,9 @@ trait CartesianProduct accum.map ( seq_b => seq_b.+: (elem_a) ) ) private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - Recursion_ ().fold (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - def get_cartesian_product [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = if ( sequences.isEmpty ) sequences else _apply_recursion (sequences.reverse) diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda index 96f6d64d..3171e40a 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda @@ -10,6 +10,8 @@ package soda.lib class CartesianProduct + _fold = Fold_ () + _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = seq.map ( lambda elem --> Seq [A] (elem) ) @@ -18,9 +20,9 @@ class CartesianProduct accum.map ( lambda seq_b --> seq_b.+: (elem_a) ) ) _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - Recursion_ ().fold (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - get_cartesian_product [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = if sequences.isEmpty then sequences else _apply_recursion (sequences.reverse) diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.scala b/translator/src/main/scala/soda/lib/CartesianProduct.scala index 729bf458..f8ffca5e 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.scala +++ b/translator/src/main/scala/soda/lib/CartesianProduct.scala @@ -11,6 +11,8 @@ package soda.lib trait CartesianProduct { + private lazy val _fold = Fold_ () + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = seq.map ( elem => Seq [A] (elem) ) @@ -19,9 +21,9 @@ trait CartesianProduct accum.map ( seq_b => seq_b.+: (elem_a) ) ) private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - Recursion_ ().fold (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - def get_cartesian_product [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = if ( sequences.isEmpty ) sequences else _apply_recursion (sequences.reverse) diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.soda b/translator/src/main/scala/soda/lib/CartesianProduct.soda index e1543f24..ebbd3faa 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.soda +++ b/translator/src/main/scala/soda/lib/CartesianProduct.soda @@ -10,6 +10,8 @@ package soda.lib class CartesianProduct + _fold = Fold_ () + _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = seq.map ( lambda elem --> Seq [A] (elem) ) @@ -18,9 +20,9 @@ class CartesianProduct accum.map ( lambda seq_b --> seq_b.+: (elem_a) ) ) _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - Recursion_ ().fold (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - get_cartesian_product [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = if sequences.isEmpty then sequences else _apply_recursion (sequences.reverse) diff --git a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala b/translator/src/test/scala/soda/lib/CartesianProductSpec.scala index ebe19e12..c7fe5cfd 100644 --- a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala +++ b/translator/src/test/scala/soda/lib/CartesianProductSpec.scala @@ -18,9 +18,11 @@ case class CartesianProductSpec () lazy val str_seq_c = Seq ("a", "b", "c", "d") + lazy val instance = CartesianProduct_ () + test ("Cartesian product of two sequences") ( check ( - obtained = CartesianProduct_ ().get_cartesian_product (Seq (int_seq_a, int_seq_b) ) + obtained = instance.apply (Seq (int_seq_a, int_seq_b) ) ) ( expected = Seq ( Seq (10, 100), Seq (10, 200), Seq (10, 300), @@ -31,7 +33,7 @@ case class CartesianProductSpec () test ("Cartesian product of an empty sequence") ( check ( - obtained = CartesianProduct_ ().get_cartesian_product (Seq () ) + obtained = instance.apply (Seq () ) ) ( expected = Seq () ) @@ -39,7 +41,7 @@ case class CartesianProductSpec () test ("Cartesian product of only empty sequences") ( check ( - obtained = CartesianProduct_ ().get_cartesian_product (Seq (Seq (), Seq (), Seq () ) ) + obtained = instance.apply (Seq (Seq (), Seq (), Seq () ) ) ) ( expected = Seq () ) @@ -47,7 +49,7 @@ case class CartesianProductSpec () test ("Cartesian product with at least one empty sequence") ( check ( - obtained = CartesianProduct_ ().get_cartesian_product (Seq (Seq ("A"), Seq () ) ) + obtained = instance.apply (Seq (Seq ("A"), Seq () ) ) ) ( expected = Seq () ) @@ -55,7 +57,7 @@ case class CartesianProductSpec () test ("Cartesian product of three sequences") ( check ( - obtained = CartesianProduct_ ().get_cartesian_product (Seq (str_seq_a, str_seq_b, str_seq_c) ) + obtained = instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) ) ( expected = Seq ( Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), diff --git a/translator/src/test/scala/soda/lib/CartesianProductSpec.soda b/translator/src/test/scala/soda/lib/CartesianProductSpec.soda index ecfd57e8..6faf1987 100644 --- a/translator/src/test/scala/soda/lib/CartesianProductSpec.soda +++ b/translator/src/test/scala/soda/lib/CartesianProductSpec.soda @@ -17,9 +17,11 @@ class CartesianProductSpec () str_seq_c = Seq ("a", "b", "c", "d") + instance = CartesianProduct_ () + test ("Cartesian product of two sequences") ( check ( - obtained := CartesianProduct_ ().get_cartesian_product (Seq (int_seq_a, int_seq_b) ) + obtained := instance.apply (Seq (int_seq_a, int_seq_b) ) ) ( expected := Seq ( Seq (10, 100), Seq (10, 200), Seq (10, 300), @@ -30,7 +32,7 @@ class CartesianProductSpec () test ("Cartesian product of an empty sequence") ( check ( - obtained := CartesianProduct_ ().get_cartesian_product (Seq () ) + obtained := instance.apply (Seq () ) ) ( expected := Seq () ) @@ -38,7 +40,7 @@ class CartesianProductSpec () test ("Cartesian product of only empty sequences") ( check ( - obtained := CartesianProduct_ ().get_cartesian_product (Seq (Seq (), Seq (), Seq () ) ) + obtained := instance.apply (Seq (Seq (), Seq (), Seq () ) ) ) ( expected := Seq () ) @@ -46,7 +48,7 @@ class CartesianProductSpec () test ("Cartesian product with at least one empty sequence") ( check ( - obtained := CartesianProduct_ ().get_cartesian_product (Seq (Seq ("A"), Seq () ) ) + obtained := instance.apply (Seq (Seq ("A"), Seq () ) ) ) ( expected := Seq () ) @@ -54,7 +56,7 @@ class CartesianProductSpec () test ("Cartesian product of three sequences") ( check ( - obtained := CartesianProduct_ ().get_cartesian_product (Seq (str_seq_a, str_seq_b, str_seq_c) ) + obtained := instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) ) ( expected := Seq ( Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), From d2f06438262608645f9111864788f52afb199c86 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 29 Jan 2023 17:37:47 +0100 Subject: [PATCH 34/71] Update use of Recursion class --- .../soda/example/algorithms/FizzBuzz.scala | 7 +++--- .../soda/example/algorithms/FizzBuzz.soda | 7 +++--- .../algorithms/FizzBuzzPatternMatching.scala | 7 +++--- .../algorithms/FizzBuzzPatternMatching.soda | 7 +++--- .../soda/example/algorithms/SortExample.scala | 12 ++++++---- .../soda/example/algorithms/SortExample.soda | 12 ++++++---- .../mathematics/FactorialWithFold.scala | 9 ++++++-- .../mathematics/FactorialWithFold.soda | 9 ++++++-- .../example/miniexample/MiniExample.scala | 8 ++++--- .../soda/example/miniexample/MiniExample.soda | 9 +++++--- .../test/scala/soda/collection/MinSpec.scala | 6 +++-- .../test/scala/soda/collection/MinSpec.soda | 6 +++-- .../translator/documentation/Manual.scala | 22 +++++++++++-------- .../soda/translator/documentation/Manual.soda | 17 +++++++------- .../block/BlockTranslatorPipeline.scala | 7 +++--- .../block/BlockTranslatorPipeline.soda | 7 +++--- .../soda/translator/parser/BlockBuilder.scala | 6 +++-- .../soda/translator/parser/BlockBuilder.soda | 6 +++-- .../PreprocessorSequenceTranslator.scala | 6 ++--- .../PreprocessorSequenceTranslator.soda | 6 ++--- .../translator/replacement/Replacement.scala | 10 +++++---- .../translator/replacement/Replacement.soda | 10 +++++---- .../translator/replacement/Replacer.scala | 9 ++++++-- .../soda/translator/replacement/Replacer.soda | 9 ++++++-- .../translator/replacement/Tokenizer.scala | 9 ++++++-- .../translator/replacement/Tokenizer.soda | 9 ++++++-- .../translator/documentation/Manual.scala | 22 +++++++++++-------- .../soda/translator/documentation/Manual.soda | 17 +++++++------- .../soda/translator/documentation/Manual.tex | 17 +++++++------- .../example/algorithms/FizzBuzz.scala | 7 +++--- .../example/algorithms/FizzBuzz.soda | 7 +++--- .../algorithms/FizzBuzzPatternMatching.scala | 7 +++--- .../algorithms/FizzBuzzPatternMatching.soda | 7 +++--- .../example/algorithms/SortExample.scala | 12 ++++++---- .../example/algorithms/SortExample.soda | 12 ++++++---- .../mathematics/FactorialWithFold.scala | 9 ++++++-- .../mathematics/FactorialWithFold.soda | 9 ++++++-- .../example/mathematics/HardProblem.scala | 9 +++++--- .../example/mathematics/HardProblem.soda | 9 +++++--- .../example/miniexample/MiniExample.scala | 8 ++++--- .../example/miniexample/MiniExample.soda | 9 +++++--- .../PreprocessorSequenceTranslatorSpec.scala | 4 ++-- .../PreprocessorSequenceTranslatorSpec.soda | 4 ++-- .../parser/annotation/ExampleProgram.scala | 2 +- .../parser/annotation/ExampleProgram.soda | 2 +- 45 files changed, 255 insertions(+), 150 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala index 7fa669aa..c10f4ff5 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala @@ -3,15 +3,16 @@ package soda.example.algorithms trait FizzBuzz { - import soda.lib.Recursion_ + import soda.lib.Range_ lazy val fizz = "Fizz" lazy val buzz = "Buzz" + private lazy val _range = Range_ () + lazy val fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( (x : Int) => x + 1) .map (get_fizz_buzz_term) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda index aa40cb26..cd715432 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda @@ -3,15 +3,16 @@ package soda.example.algorithms class FizzBuzz import - soda.lib.Recursion_ + soda.lib.Range_ fizz = "Fizz" buzz = "Buzz" + _range = Range_ () + fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( lambda (x : Int) --> x + 1) .map (get_fizz_buzz_term) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala index a3d2d622..0012013b 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala @@ -3,15 +3,16 @@ package soda.example.algorithms trait FizzBuzzPatternMatching { - import soda.lib.Recursion_ + import soda.lib.Range_ lazy val fizz = "Fizz" lazy val buzz = "Buzz" + private lazy val _range = Range_ () + lazy val fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( (x : Int) => x + 1) .map (get_fizz_buzz_term) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda index bdd8513b..a0533ca9 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda @@ -3,15 +3,16 @@ package soda.example.algorithms class FizzBuzzPatternMatching import - soda.lib.Recursion_ + soda.lib.Range_ fizz = "Fizz" buzz = "Buzz" + _range = Range_ () + fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( lambda (x : Int) --> x + 1) .map (get_fizz_buzz_term) diff --git a/examples/src/main/scala/soda/example/algorithms/SortExample.scala b/examples/src/main/scala/soda/example/algorithms/SortExample.scala index df36c8e7..a1adb336 100644 --- a/examples/src/main/scala/soda/example/algorithms/SortExample.scala +++ b/examples/src/main/scala/soda/example/algorithms/SortExample.scala @@ -58,7 +58,9 @@ trait SortAlgorithmExampleWithFold SortAlgorithmExample { - import soda.lib.Recursion_ + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () lazy val sort : Seq [Int] => Seq [Int] = sequence => sort_for (sequence) @@ -66,7 +68,7 @@ trait SortAlgorithmExampleWithFold def sort_for (sequence : Seq [Int] ) : Seq [Int] = if ( sequence.length < 2 ) sequence - else Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + else _fold.apply (sequence) (_initial_value) (_next_value_function) private lazy val _initial_value = Seq [Int] () @@ -198,10 +200,12 @@ case class NonEmptySortedSequenceAux_ [A <: Comparable [A]] () extends NonEmptyS trait SortedSequenceBuilder [A <: Comparable [A] ] { - import soda.lib.Recursion_ + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () def build (sequence : Seq [A] ) : SortedSequence [A] = - Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + _fold.apply (sequence) (_initial_value) (_next_value_function) private lazy val _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () diff --git a/examples/src/main/scala/soda/example/algorithms/SortExample.soda b/examples/src/main/scala/soda/example/algorithms/SortExample.soda index fc98beef..b2f80c48 100644 --- a/examples/src/main/scala/soda/example/algorithms/SortExample.soda +++ b/examples/src/main/scala/soda/example/algorithms/SortExample.soda @@ -48,7 +48,9 @@ class SortAlgorithmExampleWithFold SortAlgorithmExample import - soda.lib.Recursion_ + soda.lib.Fold_ + + _fold = Fold_ () sort : Seq [Int] -> Seq [Int] = lambda sequence --> sort_for (sequence) @@ -56,7 +58,7 @@ class SortAlgorithmExampleWithFold sort_for (sequence : Seq [Int] ) : Seq [Int] = if sequence.length < 2 then sequence - else Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + else _fold.apply (sequence) (_initial_value) (_next_value_function) _initial_value = Seq [Int] () @@ -172,10 +174,12 @@ end class SortedSequenceBuilder [A subtype Comparable [A] ] import - soda.lib.Recursion_ + soda.lib.Fold_ + + _fold = Fold_ () build (sequence : Seq [A] ) : SortedSequence [A] = - Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + _fold.apply (sequence) (_initial_value) (_next_value_function) _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala index bac8492c..31835fad 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala @@ -3,10 +3,15 @@ package soda.example.mathematics trait FactorialWithFold { - import soda.lib.Recursion_ + import soda.lib.Fold_ + import soda.lib.Range_ + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () def get_factorial (n : Int) : Int = - Recursion_ ().fold (Recursion_ ().range (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) + _fold.apply (_range.apply (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) } diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda index d541a941..f008cdb2 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda @@ -3,10 +3,15 @@ package soda.example.mathematics class FactorialWithFold import - soda.lib.Recursion_ + soda.lib.Fold_ + soda.lib.Range_ + + _fold = Fold_ () + + _range = Range_ () get_factorial (n : Int) : Int = - Recursion_ ().fold (Recursion_ ().range (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) + _fold.apply (_range.apply (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) end diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala index 75ba1ff3..58449904 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala @@ -1,12 +1,14 @@ package soda.example.miniexample trait MiniExample - extends - soda.lib.Recursion { + import soda.lib.Range_ + + private lazy val _range = Range_ () + def run () = - range (50) + _range.apply (50) .map ( x => print (" " + (2 * x + 1) ) ) } diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda index c75e830e..986cad19 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda @@ -1,11 +1,14 @@ package soda.example.miniexample class MiniExample - extends - soda.lib.Recursion + + import + soda.lib.Range_ + + _range = Range_ () run () = - range (50) + _range.apply (50) .map ( any x --> print (" " + (2 * x + 1) ) ) end diff --git a/library/src/test/scala/soda/collection/MinSpec.scala b/library/src/test/scala/soda/collection/MinSpec.scala index 8dfba1da..84b9ee2f 100644 --- a/library/src/test/scala/soda/collection/MinSpec.scala +++ b/library/src/test/scala/soda/collection/MinSpec.scala @@ -6,7 +6,7 @@ case class MinSpec () { import soda.lib.NoneSD_ - import soda.lib.Recursion_ + import soda.lib.Fold_ import soda.lib.SomeSD_ def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = @@ -20,10 +20,12 @@ case class MinSpec () def prepend_elem (list : MSeq [Int]) (elem : Int) : NESeq [Int] = Min_ ().prepended (list) (elem) + private lazy val _fold = Fold_ () + private lazy val _initial_value : NESeq [Int] = NESeq_ [Int] (revExampleSeq.head, ESeq_ [Int] () ) lazy val example : NESeq [Int] = - Recursion_ ().fold (revExampleSeq.tail) (_initial_value) (prepend_elem) + _fold.apply (revExampleSeq.tail) (_initial_value) (prepend_elem) test ("prepended") ( check ( diff --git a/library/src/test/scala/soda/collection/MinSpec.soda b/library/src/test/scala/soda/collection/MinSpec.soda index 6cb09ec1..ce64cf3a 100644 --- a/library/src/test/scala/soda/collection/MinSpec.soda +++ b/library/src/test/scala/soda/collection/MinSpec.soda @@ -6,7 +6,7 @@ class MinSpec () import soda.lib.NoneSD_ - soda.lib.Recursion_ + soda.lib.Fold_ soda.lib.SomeSD_ check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = @@ -20,10 +20,12 @@ class MinSpec () prepend_elem (list : MSeq [Int]) (elem : Int) : NESeq [Int] = Min_ ().prepended (list) (elem) + _fold = Fold_ () + _initial_value : NESeq [Int] = NESeq_ [Int] (revExampleSeq.head, ESeq_ [Int] () ) example : NESeq [Int] = - Recursion_ ().fold (revExampleSeq.tail) (_initial_value) (prepend_elem) + _fold.apply (revExampleSeq.tail) (_initial_value) (prepend_elem) test ("prepended") ( check ( diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index eeab5e58..d8671ff7 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -325,22 +325,26 @@ trait FactorialVerbose case class FactorialVerbose_ () extends FactorialVerbose -trait Recursion +trait FoldWhile { import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) ) current_value - else - if ( ! condition (current_value) (sequence.head) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +} + +case class FoldWhile_ () extends FoldWhile + +trait Range +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -348,12 +352,12 @@ trait Recursion ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def range (length : Int) : Seq [Int] = + def apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) } -case class Recursion_ () extends Recursion +case class Range_ () extends Range /* The main class has to be named `Main` and requires a `main` function that receives an `Array [String]` and returns a `Unit`. * Only one main class per package is allowed. */ diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index 7487d208..f767d488 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -283,27 +283,28 @@ class FactorialVerbose end -class Recursion +class FoldWhile @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - if sequence.isEmpty + if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value - else - if not condition (current_value) (sequence.head) - then current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +end + +class Range + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - range (length : Int) : Seq [Int] = + apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) end diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala index 5d0c67db..1df08514 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala +++ b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala @@ -5,14 +5,15 @@ trait BlockTranslatorPipeline BlockTranslator { - import soda.lib.Recursion_ + import soda.lib.Fold_ def pipeline : Seq [BlockTranslator] + private lazy val _fold = Fold_ () + lazy val translate : AnnotatedBlock => AnnotatedBlock = block => - Recursion_ () - .fold (pipeline) (block) (_next_value_function) + _fold.apply (pipeline) (block) (_next_value_function) private def _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = translator.translate (block) diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda index e98fc693..537722d1 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda +++ b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda @@ -5,15 +5,16 @@ class BlockTranslatorPipeline BlockTranslator import - soda.lib.Recursion_ + soda.lib.Fold_ abstract pipeline : Seq [BlockTranslator] + _fold = Fold_ () + translate : AnnotatedBlock -> AnnotatedBlock = lambda block --> - Recursion_ () - .fold (pipeline) (block) (_next_value_function) + _fold.apply (pipeline) (block) (_next_value_function) _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = translator.translate (block) diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala index bca62434..86f4e199 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala @@ -3,7 +3,7 @@ package soda.translator.parser trait BlockBuilder { - import soda.lib.Recursion_ + import soda.lib.Fold_ import soda.translator.block.AnnotatedLine import soda.translator.block.AnnotatedLine_ import soda.translator.block.AnnotatedBlock @@ -13,13 +13,15 @@ trait BlockBuilder private lazy val _sc = SodaConstant_ () + private lazy val _fold = Fold_ () + def build (lines : Seq [String] ) : Block = Block_ ( _get_annotated_lines (lines) ) private def _get_annotated_lines (lines : Seq [String] ) : Seq [AnnotatedLine] = - Recursion_ ().fold (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) + _fold.apply (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) .annotated_lines_rev .reverse diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda index 3dfc4727..11f4db8a 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda @@ -3,7 +3,7 @@ package soda.translator.parser class BlockBuilder import - soda.lib.Recursion_ + soda.lib.Fold_ soda.translator.block.AnnotatedLine soda.translator.block.AnnotatedLine_ soda.translator.block.AnnotatedBlock @@ -13,13 +13,15 @@ class BlockBuilder _sc = SodaConstant_ () + _fold = Fold_ () + build (lines : Seq [String] ) : Block = Block_ ( _get_annotated_lines (lines) ) _get_annotated_lines (lines : Seq [String] ) : Seq [AnnotatedLine] = - Recursion_ ().fold (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) + _fold.apply (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) .annotated_lines_rev .reverse diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala index aca3d285..3fa07ce6 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala @@ -7,6 +7,7 @@ trait PreprocessorSequenceTranslator def translator : soda.translator.block.BlockSequenceTranslator + import soda.lib.Fold_ import soda.translator.block.AnnotatedLine_ import soda.translator.block.AnnotatedBlock import soda.translator.parser.annotation.AnnotationFactory_ @@ -23,7 +24,7 @@ trait PreprocessorSequenceTranslator lazy val sc = SodaConstant_ () - lazy val recursion = soda.lib.Recursion_ () + private lazy val _fold = Fold_ () lazy val empty_line = AnnotatedLine_ ("", true) @@ -42,8 +43,7 @@ trait PreprocessorSequenceTranslator block_sequence.map ( block => block_annotator.translate (block) ) private def _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - recursion - .fold (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) + _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) .accumulated .reverse diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda index 19d97d34..dbb3e8ce 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda @@ -8,6 +8,7 @@ class PreprocessorSequenceTranslator translator : soda.translator.block.BlockSequenceTranslator import + soda.lib.Fold_ soda.translator.block.AnnotatedLine_ soda.translator.block.AnnotatedBlock soda.translator.parser.annotation.AnnotationFactory_ @@ -24,7 +25,7 @@ class PreprocessorSequenceTranslator sc = SodaConstant_ () - recursion = soda.lib.Recursion_ () + _fold = Fold_ () empty_line = AnnotatedLine_ ("", true) @@ -43,8 +44,7 @@ class PreprocessorSequenceTranslator block_sequence.map ( lambda block --> block_annotator.translate (block) ) _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - recursion - .fold (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) + _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) .accumulated .reverse diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.scala b/translator/src/main/scala/soda/translator/replacement/Replacement.scala index 77b34acc..2628e94a 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.scala +++ b/translator/src/main/scala/soda/translator/replacement/Replacement.scala @@ -119,7 +119,7 @@ trait ReplacementWithTranslator def translator : soda.translator.block.Translator - import soda.lib.Recursion_ + import soda.lib.Fold_ lazy val aux = ReplacementAux_ () @@ -127,27 +127,29 @@ trait ReplacementWithTranslator lazy val scala_space = aux.scala_space + private lazy val _fold = Fold_ () + def replace_at_beginning (line : String) (index : Int) : String = if ( index == 0 ) _replace_only_beginning (line) else line private def _replace_only_beginning (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value = line) (next_value_function = _next_replace_only_beginning) + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_only_beginning) private def _next_replace_only_beginning (line : String) (reserved_word : String) : String = aux.replace_if_found_at_beginning (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) def replace (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value = line) (next_value_function = _next_replace) + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace) private def _next_replace (line : String) (reserved_word : String) : String = aux.replace_if_found (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) def replace_regex (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value = line) (next_value_function = _next_replace_regex) + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_regex) private def _next_replace_regex (line : String) (regex : String) : String = line.replaceAll (regex, translator.translate (regex) ) diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.soda b/translator/src/main/scala/soda/translator/replacement/Replacement.soda index be943046..7a067bf2 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.soda +++ b/translator/src/main/scala/soda/translator/replacement/Replacement.soda @@ -116,7 +116,7 @@ class ReplacementWithTranslator translator : soda.translator.block.Translator import - soda.lib.Recursion_ + soda.lib.Fold_ aux = ReplacementAux_ () @@ -124,27 +124,29 @@ class ReplacementWithTranslator scala_space = aux.scala_space + _fold = Fold_ () + replace_at_beginning (line : String) (index : Int) : String = if index == 0 then _replace_only_beginning (line) else line _replace_only_beginning (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value := line) (next_value_function := _next_replace_only_beginning) + _fold.apply (translator.keys) (initial_value := line) (next_value_function := _next_replace_only_beginning) _next_replace_only_beginning (line : String) (reserved_word : String) : String = aux.replace_if_found_at_beginning (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) replace (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value := line) (next_value_function := _next_replace) + _fold.apply (translator.keys) (initial_value := line) (next_value_function := _next_replace) _next_replace (line : String) (reserved_word : String) : String = aux.replace_if_found (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) replace_regex (line : String) : String = - Recursion_ ().fold (translator.keys) (initial_value := line) (next_value_function := _next_replace_regex) + _fold.apply (translator.keys) (initial_value := line) (next_value_function := _next_replace_regex) _next_replace_regex (line : String) (regex : String) : String = line.replaceAll (regex, translator.translate (regex) ) diff --git a/translator/src/main/scala/soda/translator/replacement/Replacer.scala b/translator/src/main/scala/soda/translator/replacement/Replacer.scala index fff70bb7..52daee50 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacer.scala +++ b/translator/src/main/scala/soda/translator/replacement/Replacer.scala @@ -20,10 +20,15 @@ trait Replacer def pattern : String def replacement : String - import soda.lib.Recursion_ + import soda.lib.FoldWhile_ + import soda.lib.Range_ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _range = Range_ () lazy val replaced_text = - postprocess (Recursion_ ().fold_while (Recursion_ ().range (line.length) ) (initial_value) (next_value_function) (should_continue) ) + postprocess (_fold_while.apply (_range.apply (line.length) ) (initial_value) (next_value_function) (should_continue) ) lazy val initial_value : ReplacerFoldTuple = ReplacerFoldTuple_ (Seq (), 0 ) diff --git a/translator/src/main/scala/soda/translator/replacement/Replacer.soda b/translator/src/main/scala/soda/translator/replacement/Replacer.soda index 84eca21e..0a6371a9 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacer.soda +++ b/translator/src/main/scala/soda/translator/replacement/Replacer.soda @@ -19,10 +19,15 @@ class Replacer replacement : String import - soda.lib.Recursion_ + soda.lib.FoldWhile_ + soda.lib.Range_ + + _fold_while = FoldWhile_ () + + _range = Range_ () replaced_text = - postprocess (Recursion_ ().fold_while (Recursion_ ().range (line.length) ) (initial_value) (next_value_function) (should_continue) ) + postprocess (_fold_while.apply (_range.apply (line.length) ) (initial_value) (next_value_function) (should_continue) ) initial_value : ReplacerFoldTuple = ReplacerFoldTuple_ (Seq (), 0 ) diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala index 23ffd6c3..17303be7 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala @@ -26,10 +26,15 @@ trait Tokenizer def line : String - import soda.lib.Recursion_ + import soda.lib.Fold_ + import soda.lib.Range_ + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () lazy val tokens : Seq [Token] = - _postprocess (Recursion_ ().fold (Recursion_ ().range (line.length) ) (_initial_value) (_next_value_function) ) + _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) private lazy val _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda index ae0a0dc8..e581b2e7 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda @@ -25,10 +25,15 @@ class Tokenizer line : String import - soda.lib.Recursion_ + soda.lib.Fold_ + soda.lib.Range_ + + _fold = Fold_ () + + _range = Range_ () tokens : Seq [Token] = - _postprocess (Recursion_ ().fold (Recursion_ ().range (line.length) ) (_initial_value) (_next_value_function) ) + _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.scala b/translator/src/test/resources/soda/translator/documentation/Manual.scala index eeab5e58..d8671ff7 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/test/resources/soda/translator/documentation/Manual.scala @@ -325,22 +325,26 @@ trait FactorialVerbose case class FactorialVerbose_ () extends FactorialVerbose -trait Recursion +trait FoldWhile { import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) ) current_value - else - if ( ! condition (current_value) (sequence.head) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +} + +case class FoldWhile_ () extends FoldWhile + +trait Range +{ + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -348,12 +352,12 @@ trait Recursion ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def range (length : Int) : Seq [Int] = + def apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) } -case class Recursion_ () extends Recursion +case class Range_ () extends Range /* The main class has to be named `Main` and requires a `main` function that receives an `Array [String]` and returns a `Unit`. * Only one main class per package is allowed. */ diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index 7487d208..f767d488 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -283,27 +283,28 @@ class FactorialVerbose end -class Recursion +class FoldWhile @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - if sequence.isEmpty + if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value - else - if not condition (current_value) (sequence.head) - then current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +end + +class Range + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - range (length : Int) : Seq [Int] = + apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) end diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index a8b07ebe..04ea1ae7 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -469,27 +469,28 @@ end -class Recursion +class FoldWhile @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - if sequence.isEmpty + if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value - else - if not condition (current_value) (sequence.head) - then current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = + apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) +end + +class Range + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - range (length : Int) : Seq [Int] = + apply (length : Int) : Seq [Int] = _tailrec_range (length) (Seq [Int] () ) end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala index 7fa669aa..c10f4ff5 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala @@ -3,15 +3,16 @@ package soda.example.algorithms trait FizzBuzz { - import soda.lib.Recursion_ + import soda.lib.Range_ lazy val fizz = "Fizz" lazy val buzz = "Buzz" + private lazy val _range = Range_ () + lazy val fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( (x : Int) => x + 1) .map (get_fizz_buzz_term) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda index aa40cb26..cd715432 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda @@ -3,15 +3,16 @@ package soda.example.algorithms class FizzBuzz import - soda.lib.Recursion_ + soda.lib.Range_ fizz = "Fizz" buzz = "Buzz" + _range = Range_ () + fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( lambda (x : Int) --> x + 1) .map (get_fizz_buzz_term) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala index a3d2d622..0012013b 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala @@ -3,15 +3,16 @@ package soda.example.algorithms trait FizzBuzzPatternMatching { - import soda.lib.Recursion_ + import soda.lib.Range_ lazy val fizz = "Fizz" lazy val buzz = "Buzz" + private lazy val _range = Range_ () + lazy val fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( (x : Int) => x + 1) .map (get_fizz_buzz_term) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda index bdd8513b..a0533ca9 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda @@ -3,15 +3,16 @@ package soda.example.algorithms class FizzBuzzPatternMatching import - soda.lib.Recursion_ + soda.lib.Range_ fizz = "Fizz" buzz = "Buzz" + _range = Range_ () + fizz_buzz = - Recursion_ () - .range (100) + _range.apply (100) .map ( lambda (x : Int) --> x + 1) .map (get_fizz_buzz_term) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala index df36c8e7..a1adb336 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala @@ -58,7 +58,9 @@ trait SortAlgorithmExampleWithFold SortAlgorithmExample { - import soda.lib.Recursion_ + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () lazy val sort : Seq [Int] => Seq [Int] = sequence => sort_for (sequence) @@ -66,7 +68,7 @@ trait SortAlgorithmExampleWithFold def sort_for (sequence : Seq [Int] ) : Seq [Int] = if ( sequence.length < 2 ) sequence - else Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + else _fold.apply (sequence) (_initial_value) (_next_value_function) private lazy val _initial_value = Seq [Int] () @@ -198,10 +200,12 @@ case class NonEmptySortedSequenceAux_ [A <: Comparable [A]] () extends NonEmptyS trait SortedSequenceBuilder [A <: Comparable [A] ] { - import soda.lib.Recursion_ + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () def build (sequence : Seq [A] ) : SortedSequence [A] = - Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + _fold.apply (sequence) (_initial_value) (_next_value_function) private lazy val _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda index fc98beef..b2f80c48 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda @@ -48,7 +48,9 @@ class SortAlgorithmExampleWithFold SortAlgorithmExample import - soda.lib.Recursion_ + soda.lib.Fold_ + + _fold = Fold_ () sort : Seq [Int] -> Seq [Int] = lambda sequence --> sort_for (sequence) @@ -56,7 +58,7 @@ class SortAlgorithmExampleWithFold sort_for (sequence : Seq [Int] ) : Seq [Int] = if sequence.length < 2 then sequence - else Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + else _fold.apply (sequence) (_initial_value) (_next_value_function) _initial_value = Seq [Int] () @@ -172,10 +174,12 @@ end class SortedSequenceBuilder [A subtype Comparable [A] ] import - soda.lib.Recursion_ + soda.lib.Fold_ + + _fold = Fold_ () build (sequence : Seq [A] ) : SortedSequence [A] = - Recursion_ ().fold (sequence) (_initial_value) (_next_value_function) + _fold.apply (sequence) (_initial_value) (_next_value_function) _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala index bac8492c..31835fad 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala @@ -3,10 +3,15 @@ package soda.example.mathematics trait FactorialWithFold { - import soda.lib.Recursion_ + import soda.lib.Fold_ + import soda.lib.Range_ + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () def get_factorial (n : Int) : Int = - Recursion_ ().fold (Recursion_ ().range (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) + _fold.apply (_range.apply (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) } diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda index d541a941..f008cdb2 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda @@ -3,10 +3,15 @@ package soda.example.mathematics class FactorialWithFold import - soda.lib.Recursion_ + soda.lib.Fold_ + soda.lib.Range_ + + _fold = Fold_ () + + _range = Range_ () get_factorial (n : Int) : Int = - Recursion_ ().fold (Recursion_ ().range (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) + _fold.apply (_range.apply (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala index eb56554f..166837d7 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala @@ -119,9 +119,12 @@ trait MemoizedFibonacci lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = input => - if ( input.value == 0 ) OutputPair_ (0, input.memoized_values ) - else if ( input.value == 1 ) OutputPair_ (1, input.memoized_values ) - else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) + main_function_for (input) + + def main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = + if ( (input.value == 0) || (input.value == 1) + ) OutputPair_ (input.value, input.memoized_values ) + else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) private def _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) diff --git a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda index 37d9a410..b2c56c7e 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda @@ -105,9 +105,12 @@ class MemoizedFibonacci main_function : InputPair [Int, Int] -> OutputPair [Int, Int] = lambda input --> - if input.value == 0 then OutputPair_ (0, input.memoized_values ) - else if input.value == 1 then OutputPair_ (1, input.memoized_values ) - else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) + main_function_for (input) + + main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = + if (input.value == 0) or (input.value == 1) + then OutputPair_ (input.value, input.memoized_values ) + else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala index 75ba1ff3..58449904 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala @@ -1,12 +1,14 @@ package soda.example.miniexample trait MiniExample - extends - soda.lib.Recursion { + import soda.lib.Range_ + + private lazy val _range = Range_ () + def run () = - range (50) + _range.apply (50) .map ( x => print (" " + (2 * x + 1) ) ) } diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda index c75e830e..986cad19 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda @@ -1,11 +1,14 @@ package soda.example.miniexample class MiniExample - extends - soda.lib.Recursion + + import + soda.lib.Range_ + + _range = Range_ () run () = - range (50) + _range.apply (50) .map ( any x --> print (" " + (2 * x + 1) ) ) end diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala index edaed65f..3e55f81d 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala @@ -21,7 +21,7 @@ case class PreprocessorSequenceTranslatorSpec () "\nclass Example" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n abstract" + @@ -47,7 +47,7 @@ case class PreprocessorSequenceTranslatorSpec () "\nclass Example" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n abstract" + diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index 21700e7e..a77a3e25 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -21,7 +21,7 @@ class PreprocessorSequenceTranslatorSpec () "\nclass Example" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n abstract" + @@ -47,7 +47,7 @@ class PreprocessorSequenceTranslatorSpec () "\nclass Example" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n abstract" + diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala index 3f4f6aa7..26f7b18f 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala @@ -24,7 +24,7 @@ trait ExampleProgram "\n value : Int" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n my_constant : Int = 0" + diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda index 51fb1fdc..7ddcdcf5 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda @@ -24,7 +24,7 @@ class ExampleProgram "\n value : Int" + "\n" + "\n import" + - "\n soda.lib.Recursion_" + + "\n soda.lib.Fold_" + "\n soda.lib.Enum" + "\n" + "\n my_constant : Int = 0" + From 1af556266603f0a00514ae9db0f02d8c320cdf99 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 29 Jan 2023 22:36:19 +0100 Subject: [PATCH 35/71] Update unit tests --- .../src/test/scala/soda/lib/RecursionSpec.scala | 16 +++++++++++----- .../src/test/scala/soda/lib/RecursionSpec.soda | 16 +++++++++++----- .../src/test/scala/soda/lib/SeqSDSpec.scala | 4 +++- .../src/test/scala/soda/lib/SeqSDSpec.soda | 4 +++- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/translator/src/test/scala/soda/lib/RecursionSpec.scala b/translator/src/test/scala/soda/lib/RecursionSpec.scala index 7e65fde6..02b222dd 100644 --- a/translator/src/test/scala/soda/lib/RecursionSpec.scala +++ b/translator/src/test/scala/soda/lib/RecursionSpec.scala @@ -10,9 +10,15 @@ case class RecursionSpec () lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + test ("fold left while with Seq") ( check ( - obtained = Recursion_ ().fold_while (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) + obtained = _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) ) ( expected = Seq ("103", "102", "101", "101", "100") ) @@ -28,7 +34,7 @@ case class RecursionSpec () test ("fold left with Seq") ( check ( - obtained = Recursion_ ().fold (example_seq) (_fold1_initial_value) (_fold1_next_value_function) + obtained = _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) ) ( expected = Seq ("108", "105", "103", "102", "101", "101", "100") ) @@ -41,7 +47,7 @@ case class RecursionSpec () test ("range with positive number") ( check ( - obtained = Recursion_ ().range (8) + obtained = _range.apply (8) ) ( expected = Seq (0, 1, 2, 3, 4, 5, 6, 7) ) @@ -49,7 +55,7 @@ case class RecursionSpec () test ("range with zero size") ( check ( - obtained = Recursion_ ().range (-1) + obtained = _range.apply (-1) ) ( expected = Seq () ) @@ -57,7 +63,7 @@ case class RecursionSpec () test ("range with negative number") ( check ( - obtained = Recursion_ ().range (-1) + obtained = _range.apply (-1) ) ( expected = Seq () ) diff --git a/translator/src/test/scala/soda/lib/RecursionSpec.soda b/translator/src/test/scala/soda/lib/RecursionSpec.soda index 6869200a..61714969 100644 --- a/translator/src/test/scala/soda/lib/RecursionSpec.soda +++ b/translator/src/test/scala/soda/lib/RecursionSpec.soda @@ -9,9 +9,15 @@ class RecursionSpec () example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) + _fold_while = FoldWhile_ () + + _fold = Fold_ () + + _range = Range_ () + test ("fold left while with Seq") ( check ( - obtained := Recursion_ ().fold_while (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) + obtained := _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) ) ( expected := Seq ("103", "102", "101", "101", "100") ) @@ -27,7 +33,7 @@ class RecursionSpec () test ("fold left with Seq") ( check ( - obtained := Recursion_ ().fold (example_seq) (_fold1_initial_value) (_fold1_next_value_function) + obtained := _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) ) ( expected := Seq ("108", "105", "103", "102", "101", "101", "100") ) @@ -40,7 +46,7 @@ class RecursionSpec () test ("range with positive number") ( check ( - obtained := Recursion_ ().range (8) + obtained := _range.apply (8) ) ( expected := Seq (0, 1, 2, 3, 4, 5, 6, 7) ) @@ -48,7 +54,7 @@ class RecursionSpec () test ("range with zero size") ( check ( - obtained := Recursion_ ().range (-1) + obtained := _range.apply (-1) ) ( expected := Seq () ) @@ -56,7 +62,7 @@ class RecursionSpec () test ("range with negative number") ( check ( - obtained := Recursion_ ().range (-1) + obtained := _range.apply (-1) ) ( expected := Seq () ) diff --git a/translator/src/test/scala/soda/lib/SeqSDSpec.scala b/translator/src/test/scala/soda/lib/SeqSDSpec.scala index 6c643b53..24f45875 100644 --- a/translator/src/test/scala/soda/lib/SeqSDSpec.scala +++ b/translator/src/test/scala/soda/lib/SeqSDSpec.scala @@ -40,11 +40,13 @@ case class SeqSDSpec () lazy val non_empty_opt : NonEmptySeqSD [Int] => SomeSD [Int] = sequence => SomeSD_ (max (sequence) ) + private lazy val _fold = Fold_ () + def max_of_2 (a : Int) (b : Int) : Int = if ( a > b ) a else b def max (s : NonEmptySeqSD [Int]) : Int = - Recursion_ ().fold (s.tail.toSeq) (s.head) (max_of_2) + _fold.apply (s.tail.toSeq) (s.head) (max_of_2) test ("should reverse a sequence") ( check ( diff --git a/translator/src/test/scala/soda/lib/SeqSDSpec.soda b/translator/src/test/scala/soda/lib/SeqSDSpec.soda index 870ba48b..4702c28c 100644 --- a/translator/src/test/scala/soda/lib/SeqSDSpec.soda +++ b/translator/src/test/scala/soda/lib/SeqSDSpec.soda @@ -39,11 +39,13 @@ class SeqSDSpec () non_empty_opt : NonEmptySeqSD [Int] -> SomeSD [Int] = lambda sequence --> SomeSD_ (max (sequence) ) + _fold = Fold_ () + max_of_2 (a : Int) (b : Int) : Int = if a > b then a else b max (s : NonEmptySeqSD [Int]) : Int = - Recursion_ ().fold (s.tail.toSeq) (s.head) (max_of_2) + _fold.apply (s.tail.toSeq) (s.head) (max_of_2) test ("should reverse a sequence") ( check ( From e2a7bf9e3d79747605557527c4010dff29804bd0 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Sun, 29 Jan 2023 23:03:39 +0100 Subject: [PATCH 36/71] Update mathematics examples --- .../soda/example/algorithms/FizzBuzz.scala | 18 +++---- .../soda/example/algorithms/FizzBuzz.soda | 19 +++---- .../algorithms/FizzBuzzPatternMatching.scala | 10 ++-- .../algorithms/FizzBuzzPatternMatching.soda | 11 ++-- .../soda/example/algorithms/SaladMaker.scala | 13 ++--- .../soda/example/algorithms/SaladMaker.soda | 13 ++--- .../mathematics/FactorialConcise.scala | 16 +----- .../example/mathematics/FactorialConcise.soda | 14 +---- .../FactorialPatternMatching.scala | 7 +-- .../mathematics/FactorialPatternMatching.soda | 7 +-- .../mathematics/FactorialVerbose.scala | 32 ------------ .../example/mathematics/FactorialVerbose.soda | 27 ---------- .../mathematics/FactorialWithFold.scala | 11 ++-- .../mathematics/FactorialWithFold.soda | 12 ++--- .../example/mathematics/FiboExample.scala | 20 ++------ .../soda/example/mathematics/FiboExample.soda | 18 ++----- .../soda/example/mathematics/PiIterator.scala | 12 ++--- .../soda/example/mathematics/PiIterator.soda | 12 ++--- .../example/miniexample/MiniExample.scala | 2 +- .../soda/example/miniexample/MiniExample.soda | 2 +- .../example/algorithms/FizzBuzzSpec.scala | 8 ++- .../soda/example/algorithms/FizzBuzzSpec.soda | 8 ++- .../example/algorithms/SaladMakerSpec.scala | 4 +- .../example/algorithms/SaladMakerSpec.soda | 4 +- .../example/mathematics/FactorialSpec.scala | 22 ++++---- .../example/mathematics/FactorialSpec.soda | 22 ++++---- .../example/mathematics/FiboExampleSpec.scala | 4 +- .../example/mathematics/FiboExampleSpec.soda | 4 +- .../example/mathematics/PiIteratorSpec.scala | 4 +- .../example/mathematics/PiIteratorSpec.soda | 4 +- .../translator/documentation/Manual.scala | 51 +++---------------- .../soda/translator/documentation/Manual.soda | 43 +++------------- .../translator/documentation/Manual.scala | 51 +++---------------- .../soda/translator/documentation/Manual.soda | 43 +++------------- .../soda/translator/documentation/Manual.tex | 43 +++------------- .../example/algorithms/FizzBuzz.scala | 18 +++---- .../example/algorithms/FizzBuzz.soda | 19 +++---- .../algorithms/FizzBuzzPatternMatching.scala | 10 ++-- .../algorithms/FizzBuzzPatternMatching.soda | 11 ++-- .../example/algorithms/SaladMaker.scala | 13 ++--- .../example/algorithms/SaladMaker.soda | 13 ++--- .../mathematics/FactorialConcise.scala | 16 +----- .../example/mathematics/FactorialConcise.soda | 14 +---- .../FactorialPatternMatching.scala | 7 +-- .../mathematics/FactorialPatternMatching.soda | 7 +-- .../mathematics/FactorialWithFold.scala | 11 ++-- .../mathematics/FactorialWithFold.soda | 12 ++--- .../example/mathematics/FiboExample.scala | 20 ++------ .../example/mathematics/FiboExample.soda | 18 ++----- .../example/mathematics/PiIterator.scala | 12 ++--- .../example/mathematics/PiIterator.soda | 12 ++--- .../example/miniexample/MiniExample.scala | 2 +- .../example/miniexample/MiniExample.soda | 2 +- 53 files changed, 210 insertions(+), 598 deletions(-) delete mode 100644 examples/src/main/scala/soda/example/mathematics/FactorialVerbose.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/FactorialVerbose.soda diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala index c10f4ff5..d8b0e32e 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala @@ -3,26 +3,24 @@ package soda.example.algorithms trait FizzBuzz { - import soda.lib.Range_ - lazy val fizz = "Fizz" lazy val buzz = "Buzz" - private lazy val _range = Range_ () + private lazy val _range = soda.lib.Range_ () - lazy val fizz_buzz = + lazy val apply : Seq [String] = _range.apply (100) .map ( (x : Int) => x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - def get_fizz_buzz_term (n : Int) = - if ( is_divisible_by (n) (15) ) fizz + buzz - else if ( is_divisible_by (n) (3) ) fizz - else if ( is_divisible_by (n) (5) ) buzz + private def _get_fizz_buzz_term (n : Int) : String = + if ( _is_divisible_by (n) (15) ) fizz + buzz + else if ( _is_divisible_by (n) (3) ) fizz + else if ( _is_divisible_by (n) (5) ) buzz else n.toString - def is_divisible_by (n : Int) (k : Int) : Boolean = + private def _is_divisible_by (n : Int) (k : Int) : Boolean = n % k == 0 } diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda index cd715432..c918354c 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda @@ -2,27 +2,24 @@ package soda.example.algorithms class FizzBuzz - import - soda.lib.Range_ - fizz = "Fizz" buzz = "Buzz" - _range = Range_ () + _range = soda.lib.Range_ () - fizz_buzz = + apply : Seq [String] = _range.apply (100) .map ( lambda (x : Int) --> x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - get_fizz_buzz_term (n : Int) = - if is_divisible_by (n) (15) then fizz + buzz - else if is_divisible_by (n) (3) then fizz - else if is_divisible_by (n) (5) then buzz + _get_fizz_buzz_term (n : Int) : String = + if _is_divisible_by (n) (15) then fizz + buzz + else if _is_divisible_by (n) (3) then fizz + else if _is_divisible_by (n) (5) then buzz else n.toString - is_divisible_by (n : Int) (k : Int) : Boolean = + _is_divisible_by (n : Int) (k : Int) : Boolean = n % k == 0 end diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala index 0012013b..88a82ba3 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala @@ -3,20 +3,18 @@ package soda.example.algorithms trait FizzBuzzPatternMatching { - import soda.lib.Range_ - lazy val fizz = "Fizz" lazy val buzz = "Buzz" - private lazy val _range = Range_ () + private lazy val _range = soda.lib.Range_ () - lazy val fizz_buzz = + lazy val apply : Seq [String] = _range.apply (100) .map ( (x : Int) => x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - def get_fizz_buzz_term (n : Int) = + private def _get_fizz_buzz_term (n : Int) : String = Tuple2 (n % 3, n % 5) match { case Tuple2 (0, 0) => fizz + buzz case Tuple2 (0, x) => fizz diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda index a0533ca9..3d9911c7 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda @@ -2,21 +2,18 @@ package soda.example.algorithms class FizzBuzzPatternMatching - import - soda.lib.Range_ - fizz = "Fizz" buzz = "Buzz" - _range = Range_ () + _range = soda.lib.Range_ () - fizz_buzz = + apply : Seq [String] = _range.apply (100) .map ( lambda (x : Int) --> x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - get_fizz_buzz_term (n : Int) = + _get_fizz_buzz_term (n : Int) : String = match Tuple2 (n % 3, n % 5) case Tuple2 (0, 0) ==> fizz + buzz case Tuple2 (0, x) ==> fizz diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala b/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala index 678db725..3ebd2fe9 100644 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala +++ b/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala @@ -3,18 +3,15 @@ package soda.example.algorithms trait SaladMaker { + def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + import scala.annotation.tailrec @tailrec final private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - if ( ingredients_so_far.isEmpty + if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) ) salad_so_far - else - if ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) - ) salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - - def prepare_salad [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) } diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda index 94bdf309..48e6af45 100644 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda +++ b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda @@ -2,17 +2,14 @@ package soda.example.algorithms class SaladMaker + apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + @tailrec _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = - if ingredients_so_far.isEmpty + if ingredients_so_far.isEmpty or ( not condition_to_continue (salad_so_far) (ingredients_so_far.head) ) then salad_so_far - else - if not condition_to_continue (salad_so_far) (ingredients_so_far.head) - then salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - - prepare_salad [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) end diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala index 925f7d9d..e4382eaa 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala @@ -1,23 +1,9 @@ package soda.example.mathematics -trait AbstractFactorialConcise -{ - - def get_factorial : Int => Int - -} - -case class AbstractFactorialConcise_ (get_factorial : Int => Int) extends AbstractFactorialConcise - trait FactorialConcise - extends - AbstractFactorialConcise { - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = + def apply (n : Int) : Int = _tailrec_get_factorial (n) (1) import scala.annotation.tailrec diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda index 8f6db0b9..598ea596 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda @@ -1,20 +1,8 @@ package soda.example.mathematics -class AbstractFactorialConcise - - abstract - get_factorial : Int -> Int - -end - class FactorialConcise - extends - AbstractFactorialConcise - - get_factorial : Int -> Int = - any n --> get_factorial_for (n) - get_factorial_for (n : Int) : Int = + apply (n : Int) : Int = _tailrec_get_factorial (n) (1) @tailrec diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala index 208a2e2d..12b43f29 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala @@ -1,14 +1,9 @@ package soda.example.mathematics trait FactorialPatternMatching - extends - AbstractFactorialConcise { - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = + def apply (n : Int) : Int = _tailrec_get_factorial (n) (1) import scala.annotation.tailrec diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda index 2a307b5e..700e0288 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda @@ -1,13 +1,8 @@ package soda.example.mathematics class FactorialPatternMatching - extends - AbstractFactorialConcise - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = + apply (n : Int) : Int = _tailrec_get_factorial (n) (1) @tailrec diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.scala b/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.scala deleted file mode 100644 index 62d73b11..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.scala +++ /dev/null @@ -1,32 +0,0 @@ -package soda.example.mathematics - -trait AbstractFactorialVerbose -{ - - def get_factorial : Int => Int - -} - -case class AbstractFactorialVerbose_ (get_factorial : Int => Int) extends AbstractFactorialVerbose - -trait FactorialVerbose - extends - AbstractFactorialVerbose -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_factorial (n : Int) (product : Int) : Int = - if ( n == 0 - ) product - else _tailrec_get_factorial (n - 1) (n * product) - - lazy val get_factorial = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) = - _tailrec_get_factorial (n) (1) - -} - -case class FactorialVerbose_ () extends FactorialVerbose diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.soda b/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.soda deleted file mode 100644 index b2c1a86e..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FactorialVerbose.soda +++ /dev/null @@ -1,27 +0,0 @@ -package soda.example.mathematics - -class AbstractFactorialVerbose - - abstract - get_factorial : Int -> Int - -end - -class FactorialVerbose - extends - AbstractFactorialVerbose - - @tailrec - _tailrec_get_factorial (n : Int) (product : Int) : Int = - if n == 0 - then product - else _tailrec_get_factorial (n - 1) (n * product) - - get_factorial = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) = - _tailrec_get_factorial (n) (1) - -end - diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala index 31835fad..4516b427 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala @@ -3,15 +3,12 @@ package soda.example.mathematics trait FactorialWithFold { - import soda.lib.Fold_ - import soda.lib.Range_ + private lazy val _fold = soda.lib.Fold_ () - private lazy val _fold = Fold_ () + private lazy val _range = soda.lib.Range_ () - private lazy val _range = Range_ () - - def get_factorial (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) + def apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) } diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda index f008cdb2..5ba3fdf3 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda @@ -2,16 +2,12 @@ package soda.example.mathematics class FactorialWithFold - import - soda.lib.Fold_ - soda.lib.Range_ + _fold = soda.lib.Fold_ () - _fold = Fold_ () + _range = soda.lib.Range_ () - _range = Range_ () - - get_factorial (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) + apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( any product --> any k --> (product * (k + 1) ) ) end diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala b/examples/src/main/scala/soda/example/mathematics/FiboExample.scala index c8092779..138b9767 100644 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala +++ b/examples/src/main/scala/soda/example/mathematics/FiboExample.scala @@ -1,30 +1,16 @@ package soda.example.mathematics -trait FiboExample -{ - - def fib : Int => Int - -} - -case class FiboExample_ (fib : Int => Int) extends FiboExample - trait FiboExampleInSoda - extends - FiboExample { + def apply (n : Int) = + _rec (n) (0) (1) + private def _rec (m : Int) (a : Int) (b : Int) : Int = if ( m == 0 ) a else if ( m == 1 ) b else _rec (m - 1) (b) (a + b) - lazy val fib : Int => Int = - n => fib_for (n) - - def fib_for (n : Int) = - _rec (n) (0) (1) - } case class FiboExampleInSoda_ () extends FiboExampleInSoda diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda index 085a4d74..5d13702d 100644 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda +++ b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda @@ -1,25 +1,13 @@ package soda.example.mathematics -class FiboExample - - abstract - fib : Int -> Int - -end - class FiboExampleInSoda - extends - FiboExample + + apply (n : Int) = + _rec (n) (0) (1) _rec (m : Int) (a : Int) (b : Int) : Int = if m == 0 then a else if m == 1 then b else _rec (m - 1) (b) (a + b) - fib : Int -> Int = - any n --> fib_for (n) - - fib_for (n : Int) = - _rec (n) (0) (1) - end diff --git a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala b/examples/src/main/scala/soda/example/mathematics/PiIterator.scala index 42836482..5ee1b158 100644 --- a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala +++ b/examples/src/main/scala/soda/example/mathematics/PiIterator.scala @@ -20,7 +20,10 @@ case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : In trait PiIterator { - lazy val initial_status = + def apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + + private lazy val _initial_status = Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) import scala.annotation.tailrec @@ -40,7 +43,7 @@ trait PiIterator ) ) - def compute_new_status (s : Status) : Status = + private def _compute_new_status (s : Status) : Status = _tailrec_compute_new_status (s) import scala.annotation.tailrec @@ -50,11 +53,8 @@ trait PiIterator ) rev_seq.reverse else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) - def take (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (initial_status) (_get_next (initial_status) ) - private def _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (compute_new_status (s) ) + _get_next_with_new_status (_compute_new_status (s) ) private def _get_next_with_new_status (s : Status) : IntAndStatus = IntAndStatus_ ( diff --git a/examples/src/main/scala/soda/example/mathematics/PiIterator.soda b/examples/src/main/scala/soda/example/mathematics/PiIterator.soda index 14dfffe8..a4ebc608 100644 --- a/examples/src/main/scala/soda/example/mathematics/PiIterator.soda +++ b/examples/src/main/scala/soda/example/mathematics/PiIterator.soda @@ -17,7 +17,10 @@ end class PiIterator - initial_status = + apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + + _initial_status = Status_ (r := 0, n := 3, q := 1, t := 1, l := 3, k := 1) @tailrec @@ -36,7 +39,7 @@ class PiIterator ) ) - compute_new_status (s : Status) : Status = + _compute_new_status (s : Status) : Status = _tailrec_compute_new_status (s) @tailrec @@ -45,11 +48,8 @@ class PiIterator then rev_seq.reverse else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) - take (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (initial_status) (_get_next (initial_status) ) - _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (compute_new_status (s) ) + _get_next_with_new_status (_compute_new_status (s) ) _get_next_with_new_status (s : Status) : IntAndStatus = IntAndStatus_ ( diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala index 58449904..70d61712 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala @@ -7,7 +7,7 @@ trait MiniExample private lazy val _range = Range_ () - def run () = + def run () : Seq [Unit] = _range.apply (50) .map ( x => print (" " + (2 * x + 1) ) ) diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda index 986cad19..9f2f55ec 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda @@ -7,7 +7,7 @@ class MiniExample _range = Range_ () - run () = + run () : Seq [Unit] = _range.apply (50) .map ( any x --> print (" " + (2 * x + 1) ) ) diff --git a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala index a69d1761..3c678781 100644 --- a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala @@ -21,9 +21,13 @@ case class FizzBuzzSpec () "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" ) + private lazy val _fizz_buzz = FizzBuzz_ () + + private lazy val _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () + test ("first elements of FizzBuzz") ( check ( - obtained = FizzBuzz_ ().fizz_buzz + obtained = _fizz_buzz.apply ) ( expected = expected_result ) @@ -31,7 +35,7 @@ case class FizzBuzzSpec () test ("first elements of FizzBuzz with pattern matching") ( check ( - obtained = FizzBuzzPatternMatching_ ().fizz_buzz + obtained = _fizz_buzz_pattern_matching.apply ) ( expected = expected_result ) diff --git a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda index d5dfcb78..b243725e 100644 --- a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda @@ -20,9 +20,13 @@ class FizzBuzzSpec () "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" ) + _fizz_buzz = FizzBuzz_ () + + _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () + test ("first elements of FizzBuzz") ( check ( - obtained := FizzBuzz_ ().fizz_buzz + obtained := _fizz_buzz.apply ) ( expected := expected_result ) @@ -30,7 +34,7 @@ class FizzBuzzSpec () test ("first elements of FizzBuzz with pattern matching") ( check ( - obtained := FizzBuzzPatternMatching_ ().fizz_buzz + obtained := _fizz_buzz_pattern_matching.apply ) ( expected := expected_result ) diff --git a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala index 8515d028..84771d41 100644 --- a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala @@ -44,9 +44,11 @@ case class SaladMakerSpec () def has_salad_at_most_2_ingredients (salad_so_far : Seq [SaladIngredient] ) (next_ingredient : SaladIngredient) : Boolean = salad_so_far.length < 3 + private lazy val _salad_maker = SaladMaker_ () + test ("salad maker") ( check ( - obtained = SaladMaker_ ().prepare_salad ( + obtained = _salad_maker.apply ( list_of_ingredients = SaladIngredient_values) ( initial_bowl = Seq [SaladIngredient] () ) ( next_ingredient_function = add_next_ingredient) ( diff --git a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda index f2dc3578..b8f54804 100644 --- a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda @@ -38,9 +38,11 @@ class SaladMakerSpec () has_salad_at_most_2_ingredients (salad_so_far : Seq [SaladIngredient] ) (next_ingredient : SaladIngredient) : Boolean = salad_so_far.length < 3 + _salad_maker = SaladMaker_ () + test ("salad maker") ( check ( - obtained := SaladMaker_ ().prepare_salad ( + obtained := _salad_maker.apply ( list_of_ingredients := SaladIngredient_values) ( initial_bowl := Seq [SaladIngredient] () ) ( next_ingredient_function := add_next_ingredient) ( diff --git a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala index 3b787978..5ab5aa79 100644 --- a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala @@ -12,21 +12,17 @@ case class FactorialSpec () (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720), (7, 5040), (8, 40320), (9, 362880), (10, 3628800) ) - test ("should test the factorial - concise version") ( - check ( - obtained = factorial_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, FactorialConcise_ ().get_factorial (n) ) ) - ) ( - expected = factorial_values - ) - ) + private lazy val _factorial_concise = FactorialConcise_ () + + private lazy val _factorial_patten_matching = FactorialPatternMatching_ () - test ("should test the factorial - verbose version") ( + private lazy val _factorial_with_fold = FactorialWithFold_ () + + test ("should test the factorial - concise version") ( check ( obtained = factorial_values .map ( pair => pair._1) - .map ( n => Tuple2 (n, FactorialVerbose_ ().get_factorial (n) ) ) + .map ( n => Tuple2 (n, _factorial_concise.apply (n) ) ) ) ( expected = factorial_values ) @@ -36,7 +32,7 @@ case class FactorialSpec () check ( obtained = factorial_values .map ( pair => pair._1) - .map ( n => Tuple2 (n, FactorialPatternMatching_ ().get_factorial (n) ) ) + .map ( n => Tuple2 (n, _factorial_patten_matching.apply (n) ) ) ) ( expected = factorial_values ) @@ -46,7 +42,7 @@ case class FactorialSpec () check ( obtained = factorial_values .map ( pair => pair._1) - .map ( n => Tuple2 (n, FactorialWithFold_ ().get_factorial (n) ) ) + .map ( n => Tuple2 (n, _factorial_with_fold.apply (n) ) ) ) ( expected = factorial_values ) diff --git a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda index 827eaacc..4fb82157 100644 --- a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda @@ -11,21 +11,17 @@ class FactorialSpec () (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720), (7, 5040), (8, 40320), (9, 362880), (10, 3628800) ) - test ("should test the factorial - concise version") ( - check ( - obtained := factorial_values - .map ( lambda pair --> pair._1) - .map ( lambda n --> Tuple2 (n, FactorialConcise_ ().get_factorial (n) ) ) - ) ( - expected := factorial_values - ) - ) + _factorial_concise = FactorialConcise_ () + + _factorial_patten_matching = FactorialPatternMatching_ () - test ("should test the factorial - verbose version") ( + _factorial_with_fold = FactorialWithFold_ () + + test ("should test the factorial - concise version") ( check ( obtained := factorial_values .map ( lambda pair --> pair._1) - .map ( lambda n --> Tuple2 (n, FactorialVerbose_ ().get_factorial (n) ) ) + .map ( lambda n --> Tuple2 (n, _factorial_concise.apply (n) ) ) ) ( expected := factorial_values ) @@ -35,7 +31,7 @@ class FactorialSpec () check ( obtained := factorial_values .map ( lambda pair --> pair._1) - .map ( lambda n --> Tuple2 (n, FactorialPatternMatching_ ().get_factorial (n) ) ) + .map ( lambda n --> Tuple2 (n, _factorial_patten_matching.apply (n) ) ) ) ( expected := factorial_values ) @@ -45,7 +41,7 @@ class FactorialSpec () check ( obtained := factorial_values .map ( lambda pair --> pair._1) - .map ( lambda n --> Tuple2 (n, FactorialWithFold_ ().get_factorial (n) ) ) + .map ( lambda n --> Tuple2 (n, _factorial_with_fold.apply (n) ) ) ) ( expected := factorial_values ) diff --git a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala index f4a4a3ec..e16c2fa8 100644 --- a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala @@ -12,11 +12,13 @@ case class FiboExampleSpec () (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) ) + private lazy val _fibo_example_in_soda = FiboExampleInSoda_ () + test ("should test the fibonacci function") ( check ( obtained = fibonacci_values .map ( pair => pair._1) - .map ( n => Tuple2 (n, FiboExampleInSoda_ ().fib (n) ) ) + .map ( n => Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) ) ( expected = fibonacci_values ) diff --git a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda index e45734e9..532560a0 100644 --- a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda @@ -11,11 +11,13 @@ class FiboExampleSpec () (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) ) + _fibo_example_in_soda = FiboExampleInSoda_ () + test ("should test the fibonacci function") ( check ( obtained := fibonacci_values .map ( lambda pair --> pair._1) - .map ( lambda n --> Tuple2 (n, FiboExampleInSoda_ ().fib (n) ) ) + .map ( lambda n --> Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) ) ( expected := fibonacci_values ) diff --git a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala index 55ccbaa7..26e4ea0d 100644 --- a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala @@ -10,7 +10,9 @@ case class PiIteratorSpec () lazy val pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" - lazy val pi_sequence = PiIterator_ ().take (128) + private lazy val _pi_iterator = PiIterator_ () + + lazy val pi_sequence = _pi_iterator.apply (128) test ("first digits of Pi") ( check ( diff --git a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda index 7e695a92..a5485831 100644 --- a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda @@ -9,7 +9,9 @@ class PiIteratorSpec () pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" - pi_sequence = PiIterator_ ().take (128) + _pi_iterator = PiIterator_ () + + pi_sequence = _pi_iterator.apply (128) test ("first digits of Pi") ( check ( diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala index d8671ff7..b469ccd8 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/main/resources/soda/translator/documentation/Manual.scala @@ -196,7 +196,7 @@ trait Manual /* An instance of a JVM class can be created with the `@new` annotation. * If the code is translated to Scala 3, this annotation is not required. */ - lazy val now = new Date () + lazy val now : Date = new Date () def plus_one (x : Int) : Int = x + 1 @@ -267,64 +267,25 @@ trait Manual case class Manual_ () extends Manual -trait AbstractFactorialConcise -{ - - def factorial : Int => Int - -} - -case class AbstractFactorialConcise_ (factorial : Int => Int) extends AbstractFactorialConcise +/* The function used to compare equality is a long equals (`==`). */ trait FactorialConcise - extends - AbstractFactorialConcise { - /* The function used to compare equality is a long equals (`==`). */ + def apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) import scala.annotation.tailrec @tailrec final - private def _tailrec_ (n : Int) (product : Int) : Int = + private def _tailrec_get_factorial (n : Int) (product : Int) : Int = if ( n == 0 ) product - else _tailrec_ (n - 1) (n * product) - - def factorial (n : Int) : Int = - _tailrec_ (n) (1) + else _tailrec_get_factorial (n - 1) (n * product) } case class FactorialConcise_ () extends FactorialConcise -trait AbstractFactorialVerbose -{ - - def factorial : Int => Int - -} - -case class AbstractFactorialVerbose_ (factorial : Int => Int) extends AbstractFactorialVerbose - -trait FactorialVerbose - extends AbstractFactorialVerbose -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_ (n : Int) (product : Int) : Int = - if ( n == 0 - ) product - else _tailrec_ (n - 1) (n * product) - - lazy val factorial : Int => Int = - n => - _tailrec_ (n) (1) - -} - -case class FactorialVerbose_ () extends FactorialVerbose - trait FoldWhile { diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.soda b/translator/src/main/resources/soda/translator/documentation/Manual.soda index f767d488..6b222fea 100644 --- a/translator/src/main/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/main/resources/soda/translator/documentation/Manual.soda @@ -170,7 +170,7 @@ class Manual /* An instance of a JVM class can be created with the `@new` annotation. * If the code is translated to Scala 3, this annotation is not required. */ - now = @new Date () + now : Date = @new Date () plus_one (x : Int) : Int = x + 1 @@ -237,49 +237,18 @@ class Manual end -class AbstractFactorialConcise - - abstract - factorial : Int -> Int - -end +/* The function used to compare equality is a long equals (`==`). */ class FactorialConcise - extends - AbstractFactorialConcise - /* The function used to compare equality is a long equals (`==`). */ + apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) @tailrec - _tailrec_ (n : Int) (product : Int) : Int = + _tailrec_get_factorial (n : Int) (product : Int) : Int = if n == 0 then product - else _tailrec_ (n - 1) (n * product) - - factorial (n : Int) : Int = - _tailrec_ (n) (1) - -end - -class AbstractFactorialVerbose - - abstract - factorial : Int -> Int - -end - -class FactorialVerbose - extends AbstractFactorialVerbose - - @tailrec - _tailrec_ (n : Int) (product : Int) : Int = - if n == 0 - then product - else _tailrec_ (n - 1) (n * product) - - factorial : Int -> Int = - lambda n --> - _tailrec_ (n) (1) + else _tailrec_get_factorial (n - 1) (n * product) end diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.scala b/translator/src/test/resources/soda/translator/documentation/Manual.scala index d8671ff7..b469ccd8 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.scala +++ b/translator/src/test/resources/soda/translator/documentation/Manual.scala @@ -196,7 +196,7 @@ trait Manual /* An instance of a JVM class can be created with the `@new` annotation. * If the code is translated to Scala 3, this annotation is not required. */ - lazy val now = new Date () + lazy val now : Date = new Date () def plus_one (x : Int) : Int = x + 1 @@ -267,64 +267,25 @@ trait Manual case class Manual_ () extends Manual -trait AbstractFactorialConcise -{ - - def factorial : Int => Int - -} - -case class AbstractFactorialConcise_ (factorial : Int => Int) extends AbstractFactorialConcise +/* The function used to compare equality is a long equals (`==`). */ trait FactorialConcise - extends - AbstractFactorialConcise { - /* The function used to compare equality is a long equals (`==`). */ + def apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) import scala.annotation.tailrec @tailrec final - private def _tailrec_ (n : Int) (product : Int) : Int = + private def _tailrec_get_factorial (n : Int) (product : Int) : Int = if ( n == 0 ) product - else _tailrec_ (n - 1) (n * product) - - def factorial (n : Int) : Int = - _tailrec_ (n) (1) + else _tailrec_get_factorial (n - 1) (n * product) } case class FactorialConcise_ () extends FactorialConcise -trait AbstractFactorialVerbose -{ - - def factorial : Int => Int - -} - -case class AbstractFactorialVerbose_ (factorial : Int => Int) extends AbstractFactorialVerbose - -trait FactorialVerbose - extends AbstractFactorialVerbose -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_ (n : Int) (product : Int) : Int = - if ( n == 0 - ) product - else _tailrec_ (n - 1) (n * product) - - lazy val factorial : Int => Int = - n => - _tailrec_ (n) (1) - -} - -case class FactorialVerbose_ () extends FactorialVerbose - trait FoldWhile { diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.soda b/translator/src/test/resources/soda/translator/documentation/Manual.soda index f767d488..6b222fea 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.soda +++ b/translator/src/test/resources/soda/translator/documentation/Manual.soda @@ -170,7 +170,7 @@ class Manual /* An instance of a JVM class can be created with the `@new` annotation. * If the code is translated to Scala 3, this annotation is not required. */ - now = @new Date () + now : Date = @new Date () plus_one (x : Int) : Int = x + 1 @@ -237,49 +237,18 @@ class Manual end -class AbstractFactorialConcise - - abstract - factorial : Int -> Int - -end +/* The function used to compare equality is a long equals (`==`). */ class FactorialConcise - extends - AbstractFactorialConcise - /* The function used to compare equality is a long equals (`==`). */ + apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) @tailrec - _tailrec_ (n : Int) (product : Int) : Int = + _tailrec_get_factorial (n : Int) (product : Int) : Int = if n == 0 then product - else _tailrec_ (n - 1) (n * product) - - factorial (n : Int) : Int = - _tailrec_ (n) (1) - -end - -class AbstractFactorialVerbose - - abstract - factorial : Int -> Int - -end - -class FactorialVerbose - extends AbstractFactorialVerbose - - @tailrec - _tailrec_ (n : Int) (product : Int) : Int = - if n == 0 - then product - else _tailrec_ (n - 1) (n * product) - - factorial : Int -> Int = - lambda n --> - _tailrec_ (n) (1) + else _tailrec_get_factorial (n - 1) (n * product) end diff --git a/translator/src/test/resources/soda/translator/documentation/Manual.tex b/translator/src/test/resources/soda/translator/documentation/Manual.tex index 04ea1ae7..2b1f812b 100644 --- a/translator/src/test/resources/soda/translator/documentation/Manual.tex +++ b/translator/src/test/resources/soda/translator/documentation/Manual.tex @@ -304,7 +304,7 @@ \begin{lstlisting} - now = @new Date () + now : Date = @new Date () plus_one (x : Int) : Int = x + 1 @@ -416,17 +416,6 @@ end -class AbstractFactorialConcise - - abstract - factorial : Int -> Int - -end - -class FactorialConcise - extends - AbstractFactorialConcise - \end{lstlisting} @@ -436,36 +425,16 @@ \begin{lstlisting} - @tailrec - _tailrec_ (n : Int) (product : Int) : Int = - if n == 0 - then product - else _tailrec_ (n - 1) (n * product) - - factorial (n : Int) : Int = - _tailrec_ (n) (1) - -end - -class AbstractFactorialVerbose - - abstract - factorial : Int -> Int - -end +class FactorialConcise -class FactorialVerbose - extends AbstractFactorialVerbose + apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) @tailrec - _tailrec_ (n : Int) (product : Int) : Int = + _tailrec_get_factorial (n : Int) (product : Int) : Int = if n == 0 then product - else _tailrec_ (n - 1) (n * product) - - factorial : Int -> Int = - lambda n --> - _tailrec_ (n) (1) + else _tailrec_get_factorial (n - 1) (n * product) end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala index c10f4ff5..d8b0e32e 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala @@ -3,26 +3,24 @@ package soda.example.algorithms trait FizzBuzz { - import soda.lib.Range_ - lazy val fizz = "Fizz" lazy val buzz = "Buzz" - private lazy val _range = Range_ () + private lazy val _range = soda.lib.Range_ () - lazy val fizz_buzz = + lazy val apply : Seq [String] = _range.apply (100) .map ( (x : Int) => x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - def get_fizz_buzz_term (n : Int) = - if ( is_divisible_by (n) (15) ) fizz + buzz - else if ( is_divisible_by (n) (3) ) fizz - else if ( is_divisible_by (n) (5) ) buzz + private def _get_fizz_buzz_term (n : Int) : String = + if ( _is_divisible_by (n) (15) ) fizz + buzz + else if ( _is_divisible_by (n) (3) ) fizz + else if ( _is_divisible_by (n) (5) ) buzz else n.toString - def is_divisible_by (n : Int) (k : Int) : Boolean = + private def _is_divisible_by (n : Int) (k : Int) : Boolean = n % k == 0 } diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda index cd715432..c918354c 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda @@ -2,27 +2,24 @@ package soda.example.algorithms class FizzBuzz - import - soda.lib.Range_ - fizz = "Fizz" buzz = "Buzz" - _range = Range_ () + _range = soda.lib.Range_ () - fizz_buzz = + apply : Seq [String] = _range.apply (100) .map ( lambda (x : Int) --> x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - get_fizz_buzz_term (n : Int) = - if is_divisible_by (n) (15) then fizz + buzz - else if is_divisible_by (n) (3) then fizz - else if is_divisible_by (n) (5) then buzz + _get_fizz_buzz_term (n : Int) : String = + if _is_divisible_by (n) (15) then fizz + buzz + else if _is_divisible_by (n) (3) then fizz + else if _is_divisible_by (n) (5) then buzz else n.toString - is_divisible_by (n : Int) (k : Int) : Boolean = + _is_divisible_by (n : Int) (k : Int) : Boolean = n % k == 0 end diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala index 0012013b..88a82ba3 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala @@ -3,20 +3,18 @@ package soda.example.algorithms trait FizzBuzzPatternMatching { - import soda.lib.Range_ - lazy val fizz = "Fizz" lazy val buzz = "Buzz" - private lazy val _range = Range_ () + private lazy val _range = soda.lib.Range_ () - lazy val fizz_buzz = + lazy val apply : Seq [String] = _range.apply (100) .map ( (x : Int) => x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - def get_fizz_buzz_term (n : Int) = + private def _get_fizz_buzz_term (n : Int) : String = Tuple2 (n % 3, n % 5) match { case Tuple2 (0, 0) => fizz + buzz case Tuple2 (0, x) => fizz diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda index a0533ca9..3d9911c7 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda @@ -2,21 +2,18 @@ package soda.example.algorithms class FizzBuzzPatternMatching - import - soda.lib.Range_ - fizz = "Fizz" buzz = "Buzz" - _range = Range_ () + _range = soda.lib.Range_ () - fizz_buzz = + apply : Seq [String] = _range.apply (100) .map ( lambda (x : Int) --> x + 1) - .map (get_fizz_buzz_term) + .map (_get_fizz_buzz_term) - get_fizz_buzz_term (n : Int) = + _get_fizz_buzz_term (n : Int) : String = match Tuple2 (n % 3, n % 5) case Tuple2 (0, 0) ==> fizz + buzz case Tuple2 (0, x) ==> fizz diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala index 678db725..3ebd2fe9 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala @@ -3,18 +3,15 @@ package soda.example.algorithms trait SaladMaker { + def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + import scala.annotation.tailrec @tailrec final private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - if ( ingredients_so_far.isEmpty + if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) ) salad_so_far - else - if ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) - ) salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - - def prepare_salad [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) } diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda index 94bdf309..48e6af45 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda @@ -2,17 +2,14 @@ package soda.example.algorithms class SaladMaker + apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + @tailrec _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = - if ingredients_so_far.isEmpty + if ingredients_so_far.isEmpty or ( not condition_to_continue (salad_so_far) (ingredients_so_far.head) ) then salad_so_far - else - if not condition_to_continue (salad_so_far) (ingredients_so_far.head) - then salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - - prepare_salad [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala index 925f7d9d..e4382eaa 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala @@ -1,23 +1,9 @@ package soda.example.mathematics -trait AbstractFactorialConcise -{ - - def get_factorial : Int => Int - -} - -case class AbstractFactorialConcise_ (get_factorial : Int => Int) extends AbstractFactorialConcise - trait FactorialConcise - extends - AbstractFactorialConcise { - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = + def apply (n : Int) : Int = _tailrec_get_factorial (n) (1) import scala.annotation.tailrec diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda index 8f6db0b9..598ea596 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda @@ -1,20 +1,8 @@ package soda.example.mathematics -class AbstractFactorialConcise - - abstract - get_factorial : Int -> Int - -end - class FactorialConcise - extends - AbstractFactorialConcise - - get_factorial : Int -> Int = - any n --> get_factorial_for (n) - get_factorial_for (n : Int) : Int = + apply (n : Int) : Int = _tailrec_get_factorial (n) (1) @tailrec diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala index 208a2e2d..12b43f29 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala @@ -1,14 +1,9 @@ package soda.example.mathematics trait FactorialPatternMatching - extends - AbstractFactorialConcise { - lazy val get_factorial : Int => Int = - n => get_factorial_for (n) - - def get_factorial_for (n : Int) : Int = + def apply (n : Int) : Int = _tailrec_get_factorial (n) (1) import scala.annotation.tailrec diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda index 2a307b5e..700e0288 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda @@ -1,13 +1,8 @@ package soda.example.mathematics class FactorialPatternMatching - extends - AbstractFactorialConcise - get_factorial : Int -> Int = - lambda n --> get_factorial_for (n) - - get_factorial_for (n : Int) : Int = + apply (n : Int) : Int = _tailrec_get_factorial (n) (1) @tailrec diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala index 31835fad..4516b427 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala @@ -3,15 +3,12 @@ package soda.example.mathematics trait FactorialWithFold { - import soda.lib.Fold_ - import soda.lib.Range_ + private lazy val _fold = soda.lib.Fold_ () - private lazy val _fold = Fold_ () + private lazy val _range = soda.lib.Range_ () - private lazy val _range = Range_ () - - def get_factorial (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( (product : Int) => (k : Int) => (product * (k + 1) ) ) + def apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) } diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda index f008cdb2..5ba3fdf3 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda @@ -2,16 +2,12 @@ package soda.example.mathematics class FactorialWithFold - import - soda.lib.Fold_ - soda.lib.Range_ + _fold = soda.lib.Fold_ () - _fold = Fold_ () + _range = soda.lib.Range_ () - _range = Range_ () - - get_factorial (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( lambda (product : Int) --> lambda (k : Int) --> (product * (k + 1) ) ) + apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( any product --> any k --> (product * (k + 1) ) ) end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala index c8092779..138b9767 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala @@ -1,30 +1,16 @@ package soda.example.mathematics -trait FiboExample -{ - - def fib : Int => Int - -} - -case class FiboExample_ (fib : Int => Int) extends FiboExample - trait FiboExampleInSoda - extends - FiboExample { + def apply (n : Int) = + _rec (n) (0) (1) + private def _rec (m : Int) (a : Int) (b : Int) : Int = if ( m == 0 ) a else if ( m == 1 ) b else _rec (m - 1) (b) (a + b) - lazy val fib : Int => Int = - n => fib_for (n) - - def fib_for (n : Int) = - _rec (n) (0) (1) - } case class FiboExampleInSoda_ () extends FiboExampleInSoda diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda index 085a4d74..5d13702d 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda @@ -1,25 +1,13 @@ package soda.example.mathematics -class FiboExample - - abstract - fib : Int -> Int - -end - class FiboExampleInSoda - extends - FiboExample + + apply (n : Int) = + _rec (n) (0) (1) _rec (m : Int) (a : Int) (b : Int) : Int = if m == 0 then a else if m == 1 then b else _rec (m - 1) (b) (a + b) - fib : Int -> Int = - any n --> fib_for (n) - - fib_for (n : Int) = - _rec (n) (0) (1) - end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala index 42836482..5ee1b158 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala @@ -20,7 +20,10 @@ case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : In trait PiIterator { - lazy val initial_status = + def apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + + private lazy val _initial_status = Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) import scala.annotation.tailrec @@ -40,7 +43,7 @@ trait PiIterator ) ) - def compute_new_status (s : Status) : Status = + private def _compute_new_status (s : Status) : Status = _tailrec_compute_new_status (s) import scala.annotation.tailrec @@ -50,11 +53,8 @@ trait PiIterator ) rev_seq.reverse else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) - def take (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (initial_status) (_get_next (initial_status) ) - private def _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (compute_new_status (s) ) + _get_next_with_new_status (_compute_new_status (s) ) private def _get_next_with_new_status (s : Status) : IntAndStatus = IntAndStatus_ ( diff --git a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda index 14dfffe8..a4ebc608 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda @@ -17,7 +17,10 @@ end class PiIterator - initial_status = + apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + + _initial_status = Status_ (r := 0, n := 3, q := 1, t := 1, l := 3, k := 1) @tailrec @@ -36,7 +39,7 @@ class PiIterator ) ) - compute_new_status (s : Status) : Status = + _compute_new_status (s : Status) : Status = _tailrec_compute_new_status (s) @tailrec @@ -45,11 +48,8 @@ class PiIterator then rev_seq.reverse else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) - take (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (initial_status) (_get_next (initial_status) ) - _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (compute_new_status (s) ) + _get_next_with_new_status (_compute_new_status (s) ) _get_next_with_new_status (s : Status) : IntAndStatus = IntAndStatus_ ( diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala index 58449904..70d61712 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala @@ -7,7 +7,7 @@ trait MiniExample private lazy val _range = Range_ () - def run () = + def run () : Seq [Unit] = _range.apply (50) .map ( x => print (" " + (2 * x + 1) ) ) diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda index 986cad19..9f2f55ec 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda @@ -7,7 +7,7 @@ class MiniExample _range = Range_ () - run () = + run () : Seq [Unit] = _range.apply (50) .map ( any x --> print (" " + (2 * x + 1) ) ) From 03608b7c66cd3e4ec7dd1f2214bf0c4b5259122e Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 13 Feb 2023 09:53:28 +0100 Subject: [PATCH 37/71] Make small changes in library --- .../lib/soda/lib/CartesianProduct.scala | 16 +++++------ .../lib/soda/lib/CartesianProduct.soda | 16 +++++------ .../resources/lib/soda/lib/Recursion.scala | 27 ++++++++++++------- .../resources/lib/soda/lib/Recursion.soda | 27 ++++++++++++------- .../scala/soda/lib/CartesianProduct.scala | 16 +++++------ .../main/scala/soda/lib/CartesianProduct.soda | 16 +++++------ .../src/main/scala/soda/lib/Recursion.scala | 27 ++++++++++++------- .../src/main/scala/soda/lib/Recursion.soda | 27 ++++++++++++------- 8 files changed, 104 insertions(+), 68 deletions(-) diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala index f8ffca5e..c1f92f14 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala @@ -11,6 +11,14 @@ package soda.lib trait CartesianProduct { + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) + + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + private lazy val _fold = Fold_ () private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = @@ -20,14 +28,6 @@ trait CartesianProduct seq_a.flatMap ( elem_a => accum.map ( seq_b => seq_b.+: (elem_a) ) ) - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - } case class CartesianProduct_ () extends CartesianProduct diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda index 3171e40a..12412e4b 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda @@ -10,6 +10,14 @@ package soda.lib class CartesianProduct + apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if sequences.isEmpty + then sequences + else _apply_recursion (sequences.reverse) + + _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold = Fold_ () _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = @@ -19,13 +27,5 @@ class CartesianProduct seq_a.flatMap ( lambda elem_a --> accum.map ( lambda seq_b --> seq_b.+: (elem_a) ) ) - _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if sequences.isEmpty - then sequences - else _apply_recursion (sequences.reverse) - end diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.scala b/translator/src/main/resources/lib/soda/lib/Recursion.scala index 074d905e..1b34296f 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.scala +++ b/translator/src/main/resources/lib/soda/lib/Recursion.scala @@ -11,6 +11,14 @@ package soda.lib trait FoldWhile { + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = @@ -18,9 +26,6 @@ trait FoldWhile ) current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - } case class FoldWhile_ () extends FoldWhile @@ -28,6 +33,13 @@ case class FoldWhile_ () extends FoldWhile trait Fold { + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + import scala.annotation.tailrec @tailrec final private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = @@ -35,9 +47,6 @@ trait Fold ) current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - } case class Fold_ () extends Fold @@ -45,6 +54,9 @@ case class Fold_ () extends Fold trait Range { + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -52,9 +64,6 @@ trait Range ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - } case class Range_ () extends Range diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.soda b/translator/src/main/resources/lib/soda/lib/Recursion.soda index 2493edde..56b11030 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.soda +++ b/translator/src/main/resources/lib/soda/lib/Recursion.soda @@ -10,41 +10,50 @@ package soda.lib class FoldWhile + apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B -> A -> B) + (condition : B -> A -> Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - end class Fold + apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B -> A -> B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + @tailrec _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = if sequence.isEmpty then current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - end class Range + apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - end class Recursion diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.scala b/translator/src/main/scala/soda/lib/CartesianProduct.scala index f8ffca5e..c1f92f14 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.scala +++ b/translator/src/main/scala/soda/lib/CartesianProduct.scala @@ -11,6 +11,14 @@ package soda.lib trait CartesianProduct { + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) + + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + private lazy val _fold = Fold_ () private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = @@ -20,14 +28,6 @@ trait CartesianProduct seq_a.flatMap ( elem_a => accum.map ( seq_b => seq_b.+: (elem_a) ) ) - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - } case class CartesianProduct_ () extends CartesianProduct diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.soda b/translator/src/main/scala/soda/lib/CartesianProduct.soda index ebbd3faa..705ad910 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.soda +++ b/translator/src/main/scala/soda/lib/CartesianProduct.soda @@ -10,6 +10,14 @@ package soda.lib class CartesianProduct + apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if sequences.isEmpty + then sequences + else _apply_recursion (sequences.reverse) + + _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + _fold = Fold_ () _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = @@ -19,12 +27,4 @@ class CartesianProduct seq_a.flatMap ( lambda elem_a --> accum.map ( lambda seq_b --> seq_b.+: (elem_a) ) ) - _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if sequences.isEmpty - then sequences - else _apply_recursion (sequences.reverse) - end diff --git a/translator/src/main/scala/soda/lib/Recursion.scala b/translator/src/main/scala/soda/lib/Recursion.scala index 074d905e..1b34296f 100644 --- a/translator/src/main/scala/soda/lib/Recursion.scala +++ b/translator/src/main/scala/soda/lib/Recursion.scala @@ -11,6 +11,14 @@ package soda.lib trait FoldWhile { + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + import scala.annotation.tailrec @tailrec final private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = @@ -18,9 +26,6 @@ trait FoldWhile ) current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - } case class FoldWhile_ () extends FoldWhile @@ -28,6 +33,13 @@ case class FoldWhile_ () extends FoldWhile trait Fold { + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + import scala.annotation.tailrec @tailrec final private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = @@ -35,9 +47,6 @@ trait Fold ) current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - } case class Fold_ () extends Fold @@ -45,6 +54,9 @@ case class Fold_ () extends Fold trait Range { + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + import scala.annotation.tailrec @tailrec final private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = @@ -52,9 +64,6 @@ trait Range ) sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - } case class Range_ () extends Range diff --git a/translator/src/main/scala/soda/lib/Recursion.soda b/translator/src/main/scala/soda/lib/Recursion.soda index 59ee3d92..178a1960 100644 --- a/translator/src/main/scala/soda/lib/Recursion.soda +++ b/translator/src/main/scala/soda/lib/Recursion.soda @@ -10,41 +10,50 @@ package soda.lib class FoldWhile + apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B -> A -> B) + (condition : B -> A -> Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + @tailrec _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = if sequence.isEmpty or ( not condition (current_value) (sequence.head) ) then current_value else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) (condition : B -> A -> Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - end class Fold + apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B -> A -> B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + @tailrec _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B -> A -> B) : B = if sequence.isEmpty then current_value else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B -> A -> B) : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - end class Range + apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + @tailrec _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = if n <= 0 then sequence else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - end class Recursion From 259774b72f9cf06892919b9c962719cc664d42ee Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 17:57:35 +0100 Subject: [PATCH 38/71] Make Scala translator read Package.soda files as prelude --- docs/RELEASE-NOTES.md | 2 + .../extension/toscala/TranslatorToScala.scala | 39 +++++++++++++++---- .../extension/toscala/TranslatorToScala.soda | 39 +++++++++++++++---- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index 948b1f12..33d8a40e 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -4,9 +4,11 @@ - build: sbt '++ 3.2.0' clean compile test package assembly - release: target/scala-3.2.0/soda-0.17.0.jar - new_features: + - reads `Package.soda` as prelude for a Soda file in the same directory - accepts reserved word `any` as a synonym for `lambda` - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure - improves function definition by allowing multiple lines in its signature + - includes a Bash script to build the project and create the binary file - deprecated_features: - the `end` reserved word for `match`-`case` is no longer used - version: v0.16.0 diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala index e176a7c2..3e270509 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala @@ -16,6 +16,16 @@ trait TranslatorToScala import soda.translator.parser.BlockProcessor_ import java.io.File + lazy val prelude_file_name : String = "Package.soda" + + lazy val default_prelude : String = "" + + lazy val new_line : String = "\n" + + lazy val prelude_separation : String = new_line + new_line + + lazy val prelude_file_body : String = new_line + "trait Package" + prelude_separation + private lazy val _soda_extension : String = ".soda" private lazy val _scala_extension : String = ".scala" @@ -57,16 +67,29 @@ trait TranslatorToScala else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) + _translate_with_input ( _read_input (input_file_name) ) (output_file_name) private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content = _translator.translate (input) - ) + SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) + + private def _read_input (input_file_name : String) : String = + if ( _is_a_prelude_file (input_file_name) + ) SimpleFileReader_ ().read_file (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + SimpleFileReader_ ().read_file (input_file_name) + + private def _get_prelude (input_file_name : String) : String = + _get_prelude_with (_get_prelude_file (input_file_name) ) + + private def _get_prelude_with (prelude_file : File) : String = + if ( prelude_file.exists + ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation + else default_prelude + + private def _get_prelude_file (input_file_name : String) : File = + new File ( new File (input_file_name) .getParentFile , prelude_file_name ) + + private def _is_a_prelude_file (input_file_name : String) : Boolean = + prelude_file_name == ( ( new File (input_file_name) ) .getName) } diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index e1ab90b4..5e1f2a79 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -16,6 +16,16 @@ class TranslatorToScala soda.translator.parser.BlockProcessor_ java.io.File + prelude_file_name : String = "Package.soda" + + default_prelude : String = "" + + new_line : String = "\n" + + prelude_separation : String = new_line + new_line + + prelude_file_body : String = new_line + "trait Package" + prelude_separation + _soda_extension : String = ".soda" _scala_extension : String = ".scala" @@ -56,16 +66,29 @@ class TranslatorToScala else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) + _translate_with_input ( _read_input (input_file_name) ) (output_file_name) _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content := _translator.translate (input) - ) + SimpleFileWriter_ ().write_file (output_file_name) (content := _translator.translate (input) ) + + _read_input (input_file_name : String) : String = + if _is_a_prelude_file (input_file_name) + then SimpleFileReader_ ().read_file (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + SimpleFileReader_ ().read_file (input_file_name) + + _get_prelude (input_file_name : String) : String = + _get_prelude_with (_get_prelude_file (input_file_name) ) + + _get_prelude_with (prelude_file : File) : String = + if prelude_file.exists + then (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation + else default_prelude + + _get_prelude_file (input_file_name : String) : File = + @new File ( @new File (input_file_name) .getParentFile , prelude_file_name ) + + _is_a_prelude_file (input_file_name : String) : Boolean = + prelude_file_name == ( ( @new File (input_file_name) ) .getName) end From 5c1f7dca18c0ca9a4b23d77b403be7e379d6da8f Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 21:04:23 +0100 Subject: [PATCH 39/71] Add Package.soda files --- .../src/main/scala/soda/example/algorithms/Package.scala | 6 ++++++ .../src/main/scala/soda/example/algorithms/Package.soda | 6 ++++++ .../src/main/scala/soda/example/mathematics/Package.scala | 6 ++++++ .../src/main/scala/soda/example/mathematics/Package.soda | 6 ++++++ .../src/main/scala/soda/collection/example/Package.scala | 5 +++++ library/src/main/scala/soda/collection/example/Package.soda | 5 +++++ .../scala/soda/translator/parser/annotation/Package.scala | 5 +++++ .../scala/soda/translator/parser/annotation/Package.soda | 6 ++++++ 8 files changed, 45 insertions(+) create mode 100644 examples/src/main/scala/soda/example/algorithms/Package.scala create mode 100644 examples/src/main/scala/soda/example/algorithms/Package.soda create mode 100644 examples/src/main/scala/soda/example/mathematics/Package.scala create mode 100644 examples/src/main/scala/soda/example/mathematics/Package.soda create mode 100644 library/src/main/scala/soda/collection/example/Package.scala create mode 100644 library/src/main/scala/soda/collection/example/Package.soda create mode 100644 translator/src/main/scala/soda/translator/parser/annotation/Package.scala create mode 100644 translator/src/main/scala/soda/translator/parser/annotation/Package.soda diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala new file mode 100644 index 00000000..e7660f81 --- /dev/null +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -0,0 +1,6 @@ +package soda.example.algorithms + +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ diff --git a/examples/src/main/scala/soda/example/algorithms/Package.soda b/examples/src/main/scala/soda/example/algorithms/Package.soda new file mode 100644 index 00000000..e7660f81 --- /dev/null +++ b/examples/src/main/scala/soda/example/algorithms/Package.soda @@ -0,0 +1,6 @@ +package soda.example.algorithms + +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala new file mode 100644 index 00000000..a71ca0e6 --- /dev/null +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -0,0 +1,6 @@ +package soda.example.mathematics + +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ diff --git a/examples/src/main/scala/soda/example/mathematics/Package.soda b/examples/src/main/scala/soda/example/mathematics/Package.soda new file mode 100644 index 00000000..a71ca0e6 --- /dev/null +++ b/examples/src/main/scala/soda/example/mathematics/Package.soda @@ -0,0 +1,6 @@ +package soda.example.mathematics + +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala new file mode 100644 index 00000000..798111fd --- /dev/null +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -0,0 +1,5 @@ +package soda.collection.example + +/* + * This package contains examples for Soda. + */ diff --git a/library/src/main/scala/soda/collection/example/Package.soda b/library/src/main/scala/soda/collection/example/Package.soda new file mode 100644 index 00000000..798111fd --- /dev/null +++ b/library/src/main/scala/soda/collection/example/Package.soda @@ -0,0 +1,5 @@ +package soda.collection.example + +/* + * This package contains examples for Soda. + */ diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala new file mode 100644 index 00000000..6b4f971d --- /dev/null +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -0,0 +1,5 @@ +package soda.translator.parser.annotation + +/* + * This package contains classes to handle block annotations for parsing. + */ diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.soda b/translator/src/main/scala/soda/translator/parser/annotation/Package.soda new file mode 100644 index 00000000..fadcf16b --- /dev/null +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.soda @@ -0,0 +1,6 @@ +package soda.translator.parser.annotation + +/* + * This package contains classes to handle block annotations for parsing. + */ + From 190bd3a3c710c1f4aff4654e1d5176a5d6b8e3c6 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 21:19:51 +0100 Subject: [PATCH 40/71] Update Package.soda files --- library/src/main/scala/soda/collection/Package.soda | 5 +---- translator/src/main/resources/lib/soda/lib/Package.soda | 5 +---- translator/src/main/scala/soda/lib/Package.soda | 5 +---- translator/src/main/scala/soda/translator/Package.soda | 5 +---- translator/src/main/scala/soda/translator/block/Package.soda | 5 +---- .../src/main/scala/soda/translator/blocktr/Package.soda | 5 +---- .../src/main/scala/soda/translator/extension/Package.soda | 5 +---- .../main/scala/soda/translator/extension/common/Package.soda | 5 +---- .../main/scala/soda/translator/extension/help/Package.soda | 5 +---- .../main/scala/soda/translator/extension/main/Package.soda | 5 +---- .../main/scala/soda/translator/extension/tocoq/Package.soda | 5 +---- .../main/scala/soda/translator/extension/todoc/Package.soda | 5 +---- .../scala/soda/translator/extension/toscala/Package.soda | 5 +---- translator/src/main/scala/soda/translator/io/Package.soda | 5 +---- .../src/main/scala/soda/translator/parser/Package.soda | 5 +---- .../src/main/scala/soda/translator/replacement/Package.soda | 5 +---- 16 files changed, 16 insertions(+), 64 deletions(-) diff --git a/library/src/main/scala/soda/collection/Package.soda b/library/src/main/scala/soda/collection/Package.soda index 7449f1c0..cbc31798 100644 --- a/library/src/main/scala/soda/collection/Package.soda +++ b/library/src/main/scala/soda/collection/Package.soda @@ -1,12 +1,9 @@ package soda.collection -/** +/* * This package contains examples for Soda. * They can be used as libraries, but their main purpose is * to show possible implementations of functions for list manipulation. */ -class Package - -end diff --git a/translator/src/main/resources/lib/soda/lib/Package.soda b/translator/src/main/resources/lib/soda/lib/Package.soda index ccda1f64..bc1564d0 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.soda +++ b/translator/src/main/resources/lib/soda/lib/Package.soda @@ -4,13 +4,10 @@ package soda.lib -/** +/* * This package contains a small collection of classes that are useful in Soda. * These classes can be imported instead of the Scala or Java classes, * or can be used as an inspiration for similar developments. */ -class Package - -end diff --git a/translator/src/main/scala/soda/lib/Package.soda b/translator/src/main/scala/soda/lib/Package.soda index 725162c6..5a48bad8 100644 --- a/translator/src/main/scala/soda/lib/Package.soda +++ b/translator/src/main/scala/soda/lib/Package.soda @@ -4,12 +4,9 @@ package soda.lib -/** +/* * This package contains a small collection of classes that are useful in Soda. * These classes can be imported instead of the Scala or Java classes, * or can be used as an inspiration for similar developments. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/Package.soda b/translator/src/main/scala/soda/translator/Package.soda index 2eaed00a..4329136b 100644 --- a/translator/src/main/scala/soda/translator/Package.soda +++ b/translator/src/main/scala/soda/translator/Package.soda @@ -1,12 +1,9 @@ package soda.translator -/** +/* * This contains packages for an implementation that translates Soda source code. * At the moment, the available translators are to Scala and to Gallina. * Gallina is the specification language used by Coq. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/block/Package.soda b/translator/src/main/scala/soda/translator/block/Package.soda index c027b4ad..0967023d 100644 --- a/translator/src/main/scala/soda/translator/block/Package.soda +++ b/translator/src/main/scala/soda/translator/block/Package.soda @@ -1,10 +1,7 @@ package soda.translator.block -/** +/* * This package contains abstract and concrete classes to define a block and a block translator. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.soda b/translator/src/main/scala/soda/translator/blocktr/Package.soda index a59cf10c..d46ff367 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.soda +++ b/translator/src/main/scala/soda/translator/blocktr/Package.soda @@ -1,12 +1,9 @@ package soda.translator.blocktr -/** +/* * This package contains shared block translators. * * @see soda.translator.block.BlockTranslator */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/Package.soda b/translator/src/main/scala/soda/translator/extension/Package.soda index b3680fb5..b118d822 100644 --- a/translator/src/main/scala/soda/translator/extension/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/Package.soda @@ -1,12 +1,9 @@ package soda.translator.extension -/** +/* * This package contains all the packages with the extensions. * * @see soda.translator.extension.common.Extension */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.soda b/translator/src/main/scala/soda/translator/extension/common/Package.soda index c7273d53..894e1d69 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/common/Package.soda @@ -1,10 +1,7 @@ package soda.translator.extension.common -/** +/* * This package contains common classes used by the extensions. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.soda b/translator/src/main/scala/soda/translator/extension/help/Package.soda index e88b7302..861be5c1 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/help/Package.soda @@ -1,10 +1,7 @@ package soda.translator.extension.help -/** +/* * This package is for the help extension. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.soda b/translator/src/main/scala/soda/translator/extension/main/Package.soda index 29e55a72..505b9df9 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/main/Package.soda @@ -1,11 +1,8 @@ package soda.translator.extension.main -/** +/* * This package is for the main extension. * This is the entry point when the application is executed from a terminal. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.soda b/translator/src/main/scala/soda/translator/extension/tocoq/Package.soda index 39fc8bd5..609f27a1 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.soda @@ -1,11 +1,8 @@ package soda.translator.extension.tocoq -/** +/* * This package contains classes for the translation to Gallina, the specification language used by Coq. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.soda b/translator/src/main/scala/soda/translator/extension/todoc/Package.soda index ee24ead8..97af6411 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.soda @@ -1,11 +1,8 @@ package soda.translator.extension.todoc -/** +/* * This package contains classes for documentation generation. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.soda b/translator/src/main/scala/soda/translator/extension/toscala/Package.soda index 03ae17e2..bf6b1c1b 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.soda @@ -1,10 +1,7 @@ package soda.translator.extension.toscala -/** +/* * This package contains classes for the translation to Scala. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/io/Package.soda b/translator/src/main/scala/soda/translator/io/Package.soda index 8a607b1e..1b19cd93 100644 --- a/translator/src/main/scala/soda/translator/io/Package.soda +++ b/translator/src/main/scala/soda/translator/io/Package.soda @@ -1,11 +1,8 @@ package soda.translator.io -/** +/* * This package contains all the classes for I/O communication. * It is also the entry point for the translator. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/parser/Package.soda b/translator/src/main/scala/soda/translator/parser/Package.soda index 73a1788c..ed713485 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.soda +++ b/translator/src/main/scala/soda/translator/parser/Package.soda @@ -1,10 +1,7 @@ package soda.translator.parser -/** +/* * This package contains common classes used to describe and parse the Soda language. */ -class Package - -end diff --git a/translator/src/main/scala/soda/translator/replacement/Package.soda b/translator/src/main/scala/soda/translator/replacement/Package.soda index 2be4c609..7165603f 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.soda +++ b/translator/src/main/scala/soda/translator/replacement/Package.soda @@ -1,11 +1,8 @@ package soda.translator.replacement -/** +/* * This package contains auxiliary classes for string manipulation, * especially related to replacement. */ -class Package - -end From 9c8e1c5f5fd06a0d390136d68fd7d807296a5a3b Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 21:21:34 +0100 Subject: [PATCH 41/71] Remove 'package' line in Soda files with Package.soda --- examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda | 1 - .../scala/soda/example/algorithms/FizzBuzzPatternMatching.soda | 1 - examples/src/main/scala/soda/example/algorithms/HelloWorld.soda | 1 - .../src/main/scala/soda/example/algorithms/PatternMatching.soda | 1 - examples/src/main/scala/soda/example/algorithms/SaladMaker.soda | 1 - .../scala/soda/example/algorithms/ScalaReservedWordEscaping.soda | 1 - examples/src/main/scala/soda/example/algorithms/SortExample.soda | 1 - examples/src/main/scala/soda/example/algorithms/SwapExample.soda | 1 - .../main/scala/soda/example/mathematics/FactorialConcise.soda | 1 - .../scala/soda/example/mathematics/FactorialPatternMatching.soda | 1 - .../main/scala/soda/example/mathematics/FactorialWithFold.soda | 1 - .../src/main/scala/soda/example/mathematics/FiboExample.soda | 1 - .../src/main/scala/soda/example/mathematics/HardProblem.soda | 1 - examples/src/main/scala/soda/example/mathematics/PiIterator.soda | 1 - library/src/main/scala/soda/collection/MSeq.soda | 1 - library/src/main/scala/soda/collection/Min.soda | 1 - library/src/main/scala/soda/collection/example/ListExample.soda | 1 - library/src/main/scala/soda/collection/example/Main.soda | 1 - translator/src/main/resources/lib/soda/lib/CartesianProduct.soda | 1 - translator/src/main/resources/lib/soda/lib/Doc.soda | 1 - translator/src/main/resources/lib/soda/lib/EnumConstant.soda | 1 - translator/src/main/resources/lib/soda/lib/OptionSD.soda | 1 - translator/src/main/resources/lib/soda/lib/Recursion.soda | 1 - translator/src/main/resources/lib/soda/lib/SeqSD.soda | 1 - translator/src/main/scala/soda/lib/CartesianProduct.soda | 1 - translator/src/main/scala/soda/lib/Doc.soda | 1 - translator/src/main/scala/soda/lib/EnumConstant.soda | 1 - translator/src/main/scala/soda/lib/OptionSD.soda | 1 - translator/src/main/scala/soda/lib/Recursion.soda | 1 - translator/src/main/scala/soda/lib/SeqSD.soda | 1 - .../src/main/scala/soda/translator/block/AnnotatedBlock.soda | 1 - translator/src/main/scala/soda/translator/block/Block.soda | 1 - .../main/scala/soda/translator/block/BlockAnnotationEnum.soda | 1 - .../scala/soda/translator/block/BlockSequenceTranslator.soda | 1 - .../src/main/scala/soda/translator/block/BlockTranslator.soda | 1 - .../scala/soda/translator/block/BlockTranslatorPipeline.soda | 1 - .../scala/soda/translator/block/ConditionalBlockTranslator.soda | 1 - .../src/main/scala/soda/translator/block/LineProcessor.soda | 1 - .../src/main/scala/soda/translator/block/LineTranslator.soda | 1 - translator/src/main/scala/soda/translator/block/PlainBlock.soda | 1 - translator/src/main/scala/soda/translator/block/Translator.soda | 1 - .../src/main/scala/soda/translator/blocktr/TableTranslator.soda | 1 - .../src/main/scala/soda/translator/blocktr/TokenReplacement.soda | 1 - .../scala/soda/translator/blocktr/TokenizedBlockTranslator.soda | 1 - .../main/scala/soda/translator/extension/common/Extension.soda | 1 - .../src/main/scala/soda/translator/extension/help/Help.soda | 1 - .../src/main/scala/soda/translator/extension/main/Main.soda | 1 - .../extension/tocoq/CoqClassConstructorBlockTranslator.soda | 1 - .../extension/tocoq/CoqClassDeclarationBlockTranslator.soda | 1 - .../translator/extension/tocoq/CoqClassEndBlockTranslator.soda | 1 - .../translator/extension/tocoq/CoqDefinitionBlockTranslator.soda | 1 - .../extension/tocoq/CoqImportDeclarationBlockTranslator.soda | 1 - .../extension/tocoq/CoqPackageDeclarationBlockTranslator.soda | 1 - .../soda/translator/extension/tocoq/CoqProofBlockTranslator.soda | 1 - .../translator/extension/tocoq/CoqTheoremBlockTranslator.soda | 1 - .../translator/extension/tocoq/DefinitionLineTranslator.soda | 1 - .../translator/extension/tocoq/MatchCaseBlockTranslator.soda | 1 - .../soda/translator/extension/tocoq/MicroTranslatorToCoq.soda | 1 - .../translator/extension/tocoq/TranslationConstantToCoq.soda | 1 - .../scala/soda/translator/extension/tocoq/TranslatorToCoq.soda | 1 - .../soda/translator/extension/todoc/DocBlockTranslator.soda | 1 - .../soda/translator/extension/todoc/MicroTranslatorToDoc.soda | 1 - .../translator/extension/todoc/TranslationConstantToDoc.soda | 1 - .../scala/soda/translator/extension/todoc/TranslatorToDoc.soda | 1 - .../extension/toscala/AbstractDeclarationBlockTranslator.soda | 1 - .../extension/toscala/ClassConstructorBlockTranslator.soda | 1 - .../extension/toscala/ClassDeclarationBlockTranslator.soda | 1 - .../translator/extension/toscala/ClassEndBlockTranslator.soda | 1 - .../extension/toscala/FunctionDefinitionBlockTranslator.soda | 1 - .../extension/toscala/FunctionDefinitionLineDetector.soda | 1 - .../extension/toscala/ImportDeclarationBlockTranslator.soda | 1 - .../translator/extension/toscala/MainClassBlockTranslator.soda | 1 - .../translator/extension/toscala/MatchCaseBlockTranslator.soda | 1 - .../translator/extension/toscala/MicroTranslatorToScala.soda | 1 - .../extension/toscala/TheoremAndProofBlockTranslator.soda | 1 - .../translator/extension/toscala/TranslationConstantToScala.soda | 1 - .../soda/translator/extension/toscala/TranslatorToScala.soda | 1 - .../src/main/scala/soda/translator/io/DirectoryProcessor.soda | 1 - .../src/main/scala/soda/translator/io/DirectoryScanner.soda | 1 - .../src/main/scala/soda/translator/io/LibraryDeployer.soda | 1 - translator/src/main/scala/soda/translator/io/SimpleIO.soda | 1 - .../src/main/scala/soda/translator/parser/BlockBuilder.soda | 1 - .../src/main/scala/soda/translator/parser/BlockProcessor.soda | 1 - .../soda/translator/parser/PreprocessorSequenceTranslator.soda | 1 - .../src/main/scala/soda/translator/parser/SodaConstant.soda | 1 - .../parser/annotation/AbstractDeclarationAnnotation.soda | 1 - .../soda/translator/parser/annotation/AnnotationFactory.soda | 1 - .../soda/translator/parser/annotation/BlockAnnotationParser.soda | 1 - .../soda/translator/parser/annotation/ClassAliasAnnotation.soda | 1 - .../translator/parser/annotation/ClassBeginningAnnotation.soda | 1 - .../soda/translator/parser/annotation/ClassEndAnnotation.soda | 1 - .../soda/translator/parser/annotation/CommentAnnotation.soda | 1 - .../parser/annotation/FunctionDefinitionAnnotation.soda | 1 - .../parser/annotation/ImportDeclarationAnnotation.soda | 1 - .../parser/annotation/PackageDeclarationAnnotation.soda | 1 - .../soda/translator/parser/annotation/ProofBlockAnnotation.soda | 1 - .../translator/parser/annotation/TestDeclarationAnnotation.soda | 1 - .../translator/parser/annotation/TheoremBlockAnnotation.soda | 1 - .../src/main/scala/soda/translator/replacement/CharType.soda | 1 - .../main/scala/soda/translator/replacement/ParserTransition.soda | 1 - .../src/main/scala/soda/translator/replacement/Replacement.soda | 1 - .../src/main/scala/soda/translator/replacement/Replacer.soda | 1 - .../src/main/scala/soda/translator/replacement/Tokenizer.soda | 1 - 103 files changed, 103 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda index c918354c..8ffcf06e 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class FizzBuzz diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda index 3d9911c7..dee9d93b 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class FizzBuzzPatternMatching diff --git a/examples/src/main/scala/soda/example/algorithms/HelloWorld.soda b/examples/src/main/scala/soda/example/algorithms/HelloWorld.soda index 7c4bb7c3..74bc3b5d 100644 --- a/examples/src/main/scala/soda/example/algorithms/HelloWorld.soda +++ b/examples/src/main/scala/soda/example/algorithms/HelloWorld.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class Main diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda index b81ffa97..d37ee2d6 100644 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda +++ b/examples/src/main/scala/soda/example/algorithms/PatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class Parameter diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda index 48e6af45..a53329de 100644 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda +++ b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SaladMaker diff --git a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.soda b/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.soda index 3bfee861..6b1165f2 100644 --- a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.soda +++ b/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class ScalaReservedWordEscaping diff --git a/examples/src/main/scala/soda/example/algorithms/SortExample.soda b/examples/src/main/scala/soda/example/algorithms/SortExample.soda index b2f80c48..05125dfc 100644 --- a/examples/src/main/scala/soda/example/algorithms/SortExample.soda +++ b/examples/src/main/scala/soda/example/algorithms/SortExample.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SortExample diff --git a/examples/src/main/scala/soda/example/algorithms/SwapExample.soda b/examples/src/main/scala/soda/example/algorithms/SwapExample.soda index c56e2272..21e04b5d 100644 --- a/examples/src/main/scala/soda/example/algorithms/SwapExample.soda +++ b/examples/src/main/scala/soda/example/algorithms/SwapExample.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class PairExample diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda index 598ea596..ee08b6ac 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialConcise diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda index 700e0288..9b932186 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialPatternMatching diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda index 5ba3fdf3..f9215b62 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialWithFold diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda index 5d13702d..b4ed46dd 100644 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.soda +++ b/examples/src/main/scala/soda/example/mathematics/FiboExample.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FiboExampleInSoda diff --git a/examples/src/main/scala/soda/example/mathematics/HardProblem.soda b/examples/src/main/scala/soda/example/mathematics/HardProblem.soda index b2c56c7e..9e69fc23 100644 --- a/examples/src/main/scala/soda/example/mathematics/HardProblem.soda +++ b/examples/src/main/scala/soda/example/mathematics/HardProblem.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class InputPair [A, B] diff --git a/examples/src/main/scala/soda/example/mathematics/PiIterator.soda b/examples/src/main/scala/soda/example/mathematics/PiIterator.soda index a4ebc608..c986df09 100644 --- a/examples/src/main/scala/soda/example/mathematics/PiIterator.soda +++ b/examples/src/main/scala/soda/example/mathematics/PiIterator.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class Status diff --git a/library/src/main/scala/soda/collection/MSeq.soda b/library/src/main/scala/soda/collection/MSeq.soda index 682ddab9..e84b2228 100644 --- a/library/src/main/scala/soda/collection/MSeq.soda +++ b/library/src/main/scala/soda/collection/MSeq.soda @@ -1,4 +1,3 @@ -package soda.collection class MSeq [A] diff --git a/library/src/main/scala/soda/collection/Min.soda b/library/src/main/scala/soda/collection/Min.soda index 8841311c..6e8afa8c 100644 --- a/library/src/main/scala/soda/collection/Min.soda +++ b/library/src/main/scala/soda/collection/Min.soda @@ -1,4 +1,3 @@ -package soda.collection class MSeqTranslator [A] diff --git a/library/src/main/scala/soda/collection/example/ListExample.soda b/library/src/main/scala/soda/collection/example/ListExample.soda index af11fa1e..2a72c7cf 100644 --- a/library/src/main/scala/soda/collection/example/ListExample.soda +++ b/library/src/main/scala/soda/collection/example/ListExample.soda @@ -1,4 +1,3 @@ -package soda.collection.example class Pair [A] diff --git a/library/src/main/scala/soda/collection/example/Main.soda b/library/src/main/scala/soda/collection/example/Main.soda index affad77d..e0f5f9b7 100644 --- a/library/src/main/scala/soda/collection/example/Main.soda +++ b/library/src/main/scala/soda/collection/example/Main.soda @@ -1,4 +1,3 @@ -package soda.collection.example class Main diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda index 12412e4b..68697f27 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This class contains auxiliary functions for combinations. diff --git a/translator/src/main/resources/lib/soda/lib/Doc.soda b/translator/src/main/resources/lib/soda/lib/Doc.soda index da88c254..a6fe09d1 100644 --- a/translator/src/main/resources/lib/soda/lib/Doc.soda +++ b/translator/src/main/resources/lib/soda/lib/Doc.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * All concrete classes extending this class need to have a 'doc' attribute. diff --git a/translator/src/main/resources/lib/soda/lib/EnumConstant.soda b/translator/src/main/resources/lib/soda/lib/EnumConstant.soda index a6a4cb54..3c1eee16 100644 --- a/translator/src/main/resources/lib/soda/lib/EnumConstant.soda +++ b/translator/src/main/resources/lib/soda/lib/EnumConstant.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is a constant to be used in enumerations. diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.soda b/translator/src/main/resources/lib/soda/lib/OptionSD.soda index fe3aecaf..ee54da2c 100644 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.soda +++ b/translator/src/main/resources/lib/soda/lib/OptionSD.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is an Option implemented without exceptions. diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.soda b/translator/src/main/resources/lib/soda/lib/Recursion.soda index 56b11030..85c35416 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.soda +++ b/translator/src/main/resources/lib/soda/lib/Recursion.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This class contains tail recursive auxiliary functions. diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.soda b/translator/src/main/resources/lib/soda/lib/SeqSD.soda index 0a77ed81..24e78c7d 100644 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.soda +++ b/translator/src/main/resources/lib/soda/lib/SeqSD.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is a Seq implemented without exceptions. diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.soda b/translator/src/main/scala/soda/lib/CartesianProduct.soda index 705ad910..7f48e50e 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.soda +++ b/translator/src/main/scala/soda/lib/CartesianProduct.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This class contains auxiliary functions for combinations. diff --git a/translator/src/main/scala/soda/lib/Doc.soda b/translator/src/main/scala/soda/lib/Doc.soda index 61cda4fe..ce7cd7ca 100644 --- a/translator/src/main/scala/soda/lib/Doc.soda +++ b/translator/src/main/scala/soda/lib/Doc.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * All concrete classes extending this class need to have a 'doc' attribute. diff --git a/translator/src/main/scala/soda/lib/EnumConstant.soda b/translator/src/main/scala/soda/lib/EnumConstant.soda index 6a7f9c56..cf9cf7c1 100644 --- a/translator/src/main/scala/soda/lib/EnumConstant.soda +++ b/translator/src/main/scala/soda/lib/EnumConstant.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is a constant to be used in enumerations. diff --git a/translator/src/main/scala/soda/lib/OptionSD.soda b/translator/src/main/scala/soda/lib/OptionSD.soda index b8b0d4da..26474ac0 100644 --- a/translator/src/main/scala/soda/lib/OptionSD.soda +++ b/translator/src/main/scala/soda/lib/OptionSD.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is an Option implemented without exceptions. diff --git a/translator/src/main/scala/soda/lib/Recursion.soda b/translator/src/main/scala/soda/lib/Recursion.soda index 178a1960..948e495f 100644 --- a/translator/src/main/scala/soda/lib/Recursion.soda +++ b/translator/src/main/scala/soda/lib/Recursion.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This class contains tail recursive auxiliary functions. diff --git a/translator/src/main/scala/soda/lib/SeqSD.soda b/translator/src/main/scala/soda/lib/SeqSD.soda index a6518792..7d6f355e 100644 --- a/translator/src/main/scala/soda/lib/SeqSD.soda +++ b/translator/src/main/scala/soda/lib/SeqSD.soda @@ -2,7 +2,6 @@ * This file is automatically generated. Do not edit. */ -package soda.lib /** * This is a Seq implemented without exceptions. diff --git a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.soda b/translator/src/main/scala/soda/translator/block/AnnotatedBlock.soda index 83490f62..4b3e219c 100644 --- a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.soda +++ b/translator/src/main/scala/soda/translator/block/AnnotatedBlock.soda @@ -1,4 +1,3 @@ -package soda.translator.block class AnnotatedBlock extends diff --git a/translator/src/main/scala/soda/translator/block/Block.soda b/translator/src/main/scala/soda/translator/block/Block.soda index 806a20d2..a6343aa3 100644 --- a/translator/src/main/scala/soda/translator/block/Block.soda +++ b/translator/src/main/scala/soda/translator/block/Block.soda @@ -1,4 +1,3 @@ -package soda.translator.block class AnnotatedLine diff --git a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.soda b/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.soda index e2141ee3..0f87de34 100644 --- a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.soda +++ b/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.soda @@ -1,4 +1,3 @@ -package soda.translator.block class BlockAnnotationId extends diff --git a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.soda b/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.soda index 340e8310..ea945fdd 100644 --- a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.soda +++ b/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.block class BlockSequenceTranslator diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslator.soda b/translator/src/main/scala/soda/translator/block/BlockTranslator.soda index edc60832..9cfc7a21 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/block/BlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.block class BlockTranslator diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda index 537722d1..424a6c46 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda +++ b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.soda @@ -1,4 +1,3 @@ -package soda.translator.block class BlockTranslatorPipeline extends diff --git a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda index 72dd707e..fb9a7ec9 100644 --- a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.block class ConditionalBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/block/LineProcessor.soda b/translator/src/main/scala/soda/translator/block/LineProcessor.soda index 3f891709..93fcf929 100644 --- a/translator/src/main/scala/soda/translator/block/LineProcessor.soda +++ b/translator/src/main/scala/soda/translator/block/LineProcessor.soda @@ -1,4 +1,3 @@ -package soda.translator.block class SingleLineProcessor diff --git a/translator/src/main/scala/soda/translator/block/LineTranslator.soda b/translator/src/main/scala/soda/translator/block/LineTranslator.soda index 36e3bbf7..78c57574 100644 --- a/translator/src/main/scala/soda/translator/block/LineTranslator.soda +++ b/translator/src/main/scala/soda/translator/block/LineTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.block class LineTranslator diff --git a/translator/src/main/scala/soda/translator/block/PlainBlock.soda b/translator/src/main/scala/soda/translator/block/PlainBlock.soda index f40dba96..90d8cd5a 100644 --- a/translator/src/main/scala/soda/translator/block/PlainBlock.soda +++ b/translator/src/main/scala/soda/translator/block/PlainBlock.soda @@ -1,4 +1,3 @@ -package soda.translator.block class PlainBlock diff --git a/translator/src/main/scala/soda/translator/block/Translator.soda b/translator/src/main/scala/soda/translator/block/Translator.soda index 9b959f6f..b1939b95 100644 --- a/translator/src/main/scala/soda/translator/block/Translator.soda +++ b/translator/src/main/scala/soda/translator/block/Translator.soda @@ -1,4 +1,3 @@ -package soda.translator.block /** * This models an abstract translator. diff --git a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.soda b/translator/src/main/scala/soda/translator/blocktr/TableTranslator.soda index 7baeb448..c594434d 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.soda +++ b/translator/src/main/scala/soda/translator/blocktr/TableTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.blocktr class Table diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.soda b/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.soda index 91a685a0..a122b0cb 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.soda +++ b/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.soda @@ -1,4 +1,3 @@ -package soda.translator.blocktr class TokenReplacement diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda index d7991eea..94778310 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.blocktr class TokenizedBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/common/Extension.soda b/translator/src/main/scala/soda/translator/extension/common/Extension.soda index c7b6d54a..bb2767c0 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Extension.soda +++ b/translator/src/main/scala/soda/translator/extension/common/Extension.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.common class Extension diff --git a/translator/src/main/scala/soda/translator/extension/help/Help.soda b/translator/src/main/scala/soda/translator/extension/help/Help.soda index d3757801..8d9139d1 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Help.soda +++ b/translator/src/main/scala/soda/translator/extension/help/Help.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.help class AbstractHelp extends diff --git a/translator/src/main/scala/soda/translator/extension/main/Main.soda b/translator/src/main/scala/soda/translator/extension/main/Main.soda index ea7d536a..ea243508 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Main.soda +++ b/translator/src/main/scala/soda/translator/extension/main/Main.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.main /** * This is the main entry point. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda index 5e87565f..5a58529d 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqClassConstructorBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda index f799461a..06204b8a 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqClassDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda index d990f288..57aeee8b 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqClassEndBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda index 1d50c659..bf7cd75e 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqDefinitionBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda index cedfab8d..28f2762e 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqImportDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda index 1c6e3ad3..82e20b4b 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqPackageDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda index c08a7233..644440e2 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqProofBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda index 59bf6fe8..6670b348 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqTheoremBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda index ba66a6dd..fd3343d0 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq /** * A line containing the definition sign will be classified as a definition. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda index 3a150caf..3b9d9a08 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class MatchCaseBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.soda index 18d4e836..d2e466e2 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq /** * This class translates Soda snippets into Coq snippets. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda index e9c00756..a4a2ac65 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda index 3640afc1..3a770cd6 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq /** * This translates Soda source code to Coq source code. diff --git a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda index ba07ed1c..1a1267cd 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc class DocBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda index abee388d..b761c14d 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc /** * This class generates documentation from Soda snippets. diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.soda b/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.soda index 6e83f036..d5b58428 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc /** * This class contains constants that are specific for the documentation generation. diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda index 57776e98..854cf323 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc /** * This generates documentation from Soda source code. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda index 4ca98aad..df337fdf 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class AbstractDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda index 04bf404e..9c303a11 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ClassConstructorBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda index ab5beb04..0412357a 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ClassDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda index e7662d9a..3e61e63a 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ClassEndBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda index 41b3b3a5..7bc6bac5 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class FunctionDefinitionBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda index 4b163218..2a2e80ca 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala /** * A line containing the definition sign will be classified as a definition. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda index 2a76fe82..b711af82 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ImportDeclarationBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda index 7c7c73d2..b736502b 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class MainClassBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda index b39ad095..2e58e25c 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class MatchCaseBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda index 47483f08..5e413547 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala /** * This class translates Soda source code into Scala source code. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda index d8ae6893..249308cd 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class TheoremAndProofBlockTranslator extends diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda index 057454da..b67b37b0 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index 5e1f2a79..ca6f71ab 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala /** * This translates Soda source code to Scala source code. diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda index 075dae77..769261f8 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda +++ b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda @@ -1,4 +1,3 @@ -package soda.translator.io class AbstractDirectoryProcessor diff --git a/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda b/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda index a2ef4527..c8aba3e6 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda +++ b/translator/src/main/scala/soda/translator/io/DirectoryScanner.soda @@ -1,4 +1,3 @@ -package soda.translator.io /** * This class is used to scan files in a given directory. diff --git a/translator/src/main/scala/soda/translator/io/LibraryDeployer.soda b/translator/src/main/scala/soda/translator/io/LibraryDeployer.soda index b13f6ae3..563cf497 100644 --- a/translator/src/main/scala/soda/translator/io/LibraryDeployer.soda +++ b/translator/src/main/scala/soda/translator/io/LibraryDeployer.soda @@ -1,4 +1,3 @@ -package soda.translator.io class LibraryDeployer diff --git a/translator/src/main/scala/soda/translator/io/SimpleIO.soda b/translator/src/main/scala/soda/translator/io/SimpleIO.soda index 744c57c2..9dd283bf 100644 --- a/translator/src/main/scala/soda/translator/io/SimpleIO.soda +++ b/translator/src/main/scala/soda/translator/io/SimpleIO.soda @@ -1,4 +1,3 @@ -package soda.translator.io /** * This is an auxiliary class to read small files. diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda index 11f4db8a..6d6eca6f 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda @@ -1,4 +1,3 @@ -package soda.translator.parser class BlockBuilder diff --git a/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda b/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda index e99c0e7c..b1023ad2 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda @@ -1,4 +1,3 @@ -package soda.translator.parser /** * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda index dbb3e8ce..a570b04f 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda @@ -1,4 +1,3 @@ -package soda.translator.parser class PreprocessorSequenceTranslator extends diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index c9fd041f..d8f30098 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -1,4 +1,3 @@ -package soda.translator.parser class SodaConstant diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.soda index 2a45c75b..14d0da73 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class AbstractDeclarationAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda index 6972a683..3a048799 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class AnnotationFactory extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.soda b/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.soda index 5dcc8050..46aae4a3 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class BlockAnnotationParser extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.soda index 99793b93..7658515a 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ClassAliasAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.soda index 78deacbe..3ec770ec 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ClassBeginningAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.soda index 0de10809..da6d103e 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ClassEndAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.soda index 7e870c75..422e1a35 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class CommentAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda index cd4456c5..44b2c26d 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class FunctionDefinitionAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.soda index 7638056d..cc2941b6 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ImportDeclarationAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.soda index db14f413..742a1b84 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class PackageDeclarationAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.soda index f7416a6d..e5b2e02b 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ProofBlockAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.soda index 6c314f06..bfa47a7c 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class TestDeclarationAnnotation extends diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.soda b/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.soda index f8ab4953..9ec0f9a8 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.soda +++ b/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class TheoremBlockAnnotation extends diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.soda b/translator/src/main/scala/soda/translator/replacement/CharType.soda index 13ce1b7d..1a746b75 100644 --- a/translator/src/main/scala/soda/translator/replacement/CharType.soda +++ b/translator/src/main/scala/soda/translator/replacement/CharType.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement /** * This is to classify characters. diff --git a/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda b/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda index 9c7eb3af..037f37b3 100644 --- a/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda +++ b/translator/src/main/scala/soda/translator/replacement/ParserTransition.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement /** * This models all the possible states that the parser can be. diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.soda b/translator/src/main/scala/soda/translator/replacement/Replacement.soda index 7a067bf2..3ed40c2d 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.soda +++ b/translator/src/main/scala/soda/translator/replacement/Replacement.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement /** * This models a collection of replacement functions. diff --git a/translator/src/main/scala/soda/translator/replacement/Replacer.soda b/translator/src/main/scala/soda/translator/replacement/Replacer.soda index 0a6371a9..34b94c3c 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacer.soda +++ b/translator/src/main/scala/soda/translator/replacement/Replacer.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement class LinePatternProcessor diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda index e581b2e7..2e4fdc99 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement /** * A token is a piece of code, that can contain one or more words combined with symbols. From 2efb66bb6493e6b477e1336f5e894fb6c3f344c3 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 21:42:59 +0100 Subject: [PATCH 42/71] Update unit tests --- .../src/test/resources/soda/example/Example.scala | 2 ++ .../soda/example/otherexample/OtherExample.scala | 2 ++ .../translator/example/algorithms/FizzBuzz.scala | 1 - .../translator/example/algorithms/FizzBuzz.soda | 1 - .../algorithms/FizzBuzzPatternMatching.scala | 1 - .../example/algorithms/FizzBuzzPatternMatching.soda | 1 - .../translator/example/algorithms/HelloWorld.scala | 1 - .../translator/example/algorithms/HelloWorld.soda | 1 - .../example/algorithms/PatternMatching.scala | 1 - .../example/algorithms/PatternMatching.soda | 1 - .../translator/example/algorithms/SaladMaker.scala | 1 - .../translator/example/algorithms/SaladMaker.soda | 1 - .../algorithms/ScalaReservedWordEscaping.scala | 2 -- .../algorithms/ScalaReservedWordEscaping.soda | 1 - .../translator/example/algorithms/SortExample.scala | 1 - .../translator/example/algorithms/SortExample.soda | 1 - .../translator/example/algorithms/SwapExample.scala | 2 -- .../translator/example/algorithms/SwapExample.soda | 1 - .../translator/example/algorithms/SwapExample.v | 13 ------------- .../ethicalissues/pricemonitor/PriceMonitor.scala | 2 ++ .../pricemonitor/Requirement1Monitor.scala | 2 ++ .../pricemonitor/Requirement2Monitor.scala | 2 ++ .../pricemonitor/Requirement3Monitor.scala | 2 ++ .../example/forcoq/algorithms/RecursionForCoq.scala | 2 ++ .../soda/translator/example/forcoq/lib/List.scala | 2 ++ .../soda/translator/example/forcoq/lib/Nat.scala | 2 ++ .../forcoq/mathematics/FactorialForCoq.scala | 1 + .../forcoq/mathematics/TriangularNumberForCoq.scala | 1 + .../example/mathematics/FactorialConcise.scala | 2 -- .../example/mathematics/FactorialConcise.soda | 1 - .../mathematics/FactorialPatternMatching.scala | 2 -- .../mathematics/FactorialPatternMatching.soda | 1 - .../example/mathematics/FactorialWithFold.scala | 2 -- .../example/mathematics/FactorialWithFold.soda | 1 - .../example/mathematics/FiboExample.scala | 2 -- .../translator/example/mathematics/FiboExample.soda | 1 - .../example/mathematics/HardProblem.scala | 2 -- .../translator/example/mathematics/HardProblem.soda | 1 - .../translator/example/mathematics/PiIterator.scala | 2 -- .../translator/example/mathematics/PiIterator.soda | 1 - .../example/miniexample/MiniExample.scala | 2 ++ 41 files changed, 22 insertions(+), 49 deletions(-) diff --git a/translator/src/test/resources/soda/example/Example.scala b/translator/src/test/resources/soda/example/Example.scala index 228d68a0..1b1712e3 100644 --- a/translator/src/test/resources/soda/example/Example.scala +++ b/translator/src/test/resources/soda/example/Example.scala @@ -1,3 +1,5 @@ + + package soda.example case class Example() diff --git a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala index 5955d364..0b156b4e 100644 --- a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala +++ b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala @@ -1,3 +1,5 @@ + + package soda.example.otherexample case class OtherExample() diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala index d8b0e32e..8c76ad3a 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait FizzBuzz { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda index c918354c..8ffcf06e 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class FizzBuzz diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala index 88a82ba3..b13c2c54 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait FizzBuzzPatternMatching { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda index 3d9911c7..dee9d93b 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class FizzBuzzPatternMatching diff --git a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala index d8dfa113..fef53a00 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait Main { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.soda b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.soda index 7c4bb7c3..74bc3b5d 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class Main diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala index 647ea947..aae49cfa 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait Parameter { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda index b81ffa97..d37ee2d6 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class Parameter diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala index 3ebd2fe9..0b689d8a 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait SaladMaker { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda index 48e6af45..a53329de 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SaladMaker diff --git a/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.scala b/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.scala index ac9810a0..17966720 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.scala @@ -1,5 +1,3 @@ -package soda.example.algorithms - trait ScalaReservedWordEscaping { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.soda b/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.soda index 3bfee861..6b1165f2 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/ScalaReservedWordEscaping.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class ScalaReservedWordEscaping diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala index a1adb336..d304514b 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala @@ -1,4 +1,3 @@ -package soda.example.algorithms trait SortExample { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda index b2f80c48..05125dfc 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SortExample diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.scala b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.scala index 9fa25a88..49b72407 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.scala @@ -1,5 +1,3 @@ -package soda.example.algorithms - trait PairExample { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda index c56e2272..21e04b5d 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class PairExample diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v index 80c2003d..04026299 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v +++ b/translator/src/test/resources/soda/translator/example/algorithms/SwapExample.v @@ -1,16 +1,3 @@ -(* -package soda.example.algorithms -*) - -Require Import Coq.ZArith.BinInt . -(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *) - -Require Import Coq.Lists.List . -(* https://coq.inria.fr/library/Coq.Lists.List.html *) - -Notation Int := Z . - - Module PairExample . (* diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala index 05c3229f..e9536bec 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala @@ -1,3 +1,5 @@ + + package soda.example.ethicalissues.pricemonitor trait Customer diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index 730db703..f26ce673 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -1,3 +1,5 @@ + + package soda.example.ethicalissues.pricemonitor trait Report1 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala index ea835c13..ddec349c 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala @@ -1,3 +1,5 @@ + + package soda.example.ethicalissues.pricemonitor trait Report2 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 03940a9b..de8b8083 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -1,3 +1,5 @@ + + package soda.example.ethicalissues.pricemonitor trait Report3 diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala index f17155c8..479a952d 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala @@ -1,3 +1,5 @@ + + package soda.example.forcoq.algorithms /** diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala index d08bfdd5..20ad91ac 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala @@ -1,3 +1,5 @@ + + package soda.example.forcoq.lib trait list [A] diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala index 435fbd5b..1a27b3be 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala @@ -1,3 +1,5 @@ + + package soda.example.forcoq.lib trait nat diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala index 36f039b6..c5d02822 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala @@ -1,3 +1,4 @@ + package soda.example.forcoq.mathematics trait FactorialForCoq diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala index 19db2a1a..db1b6147 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -1,3 +1,4 @@ + package soda.example.forcoq.mathematics trait TriangularNumberForCoq diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala index e4382eaa..adc8593c 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait FactorialConcise { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda index 598ea596..ee08b6ac 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialConcise.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialConcise diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala index 12b43f29..7e2895cf 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait FactorialPatternMatching { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda index 700e0288..9b932186 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialPatternMatching.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialPatternMatching diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala index 4516b427..d350856e 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait FactorialWithFold { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda index 5ba3fdf3..f9215b62 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FactorialWithFold.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialWithFold diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala index 138b9767..071af16d 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait FiboExampleInSoda { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda index 5d13702d..b4ed46dd 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboExample.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FiboExampleInSoda diff --git a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala index 166837d7..e230f550 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait InputPair [A, B] { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda index b2c56c7e..9e69fc23 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/HardProblem.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class InputPair [A, B] diff --git a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala index 5ee1b158..9adbdaa0 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.scala @@ -1,5 +1,3 @@ -package soda.example.mathematics - trait Status { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda index a4ebc608..c986df09 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda +++ b/translator/src/test/resources/soda/translator/example/mathematics/PiIterator.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class Status diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala index 70d61712..1ba7bc94 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala @@ -1,3 +1,5 @@ + + package soda.example.miniexample trait MiniExample From 3f7504d9996b0f14df6560aa5e40a2e77d9e3fb5 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 21:27:11 +0100 Subject: [PATCH 43/71] Update Scala files --- .../scala/soda/example/algorithms/FizzBuzz.scala | 7 +++++++ .../algorithms/FizzBuzzPatternMatching.scala | 7 +++++++ .../scala/soda/example/algorithms/HelloWorld.scala | 7 +++++++ .../scala/soda/example/algorithms/Package.scala | 2 ++ .../soda/example/algorithms/PatternMatching.scala | 7 +++++++ .../scala/soda/example/algorithms/SaladMaker.scala | 7 +++++++ .../algorithms/ScalaReservedWordEscaping.scala | 7 +++++++ .../soda/example/algorithms/SortExample.scala | 7 +++++++ .../soda/example/algorithms/SwapExample.scala | 7 +++++++ .../example/mathematics/FactorialConcise.scala | 7 +++++++ .../mathematics/FactorialPatternMatching.scala | 7 +++++++ .../example/mathematics/FactorialWithFold.scala | 7 +++++++ .../soda/example/mathematics/FiboExample.scala | 7 +++++++ .../soda/example/mathematics/HardProblem.scala | 7 +++++++ .../scala/soda/example/mathematics/Package.scala | 2 ++ .../soda/example/mathematics/PiIterator.scala | 7 +++++++ library/src/main/scala/soda/collection/MSeq.scala | 10 ++++++++++ library/src/main/scala/soda/collection/Min.scala | 10 ++++++++++ .../src/main/scala/soda/collection/Package.scala | 9 +++------ .../soda/collection/example/ListExample.scala | 6 ++++++ .../main/scala/soda/collection/example/Main.scala | 6 ++++++ .../scala/soda/collection/example/Package.scala | 2 ++ .../resources/lib/soda/lib/CartesianProduct.scala | 12 ++++++++++++ .../src/main/resources/lib/soda/lib/Doc.scala | 12 ++++++++++++ .../main/resources/lib/soda/lib/EnumConstant.scala | 12 ++++++++++++ .../src/main/resources/lib/soda/lib/OptionSD.scala | 12 ++++++++++++ .../src/main/resources/lib/soda/lib/Package.scala | 9 +++------ .../main/resources/lib/soda/lib/Recursion.scala | 12 ++++++++++++ .../src/main/resources/lib/soda/lib/SeqSD.scala | 12 ++++++++++++ .../src/main/scala/soda/lib/CartesianProduct.scala | 12 ++++++++++++ translator/src/main/scala/soda/lib/Doc.scala | 12 ++++++++++++ .../src/main/scala/soda/lib/EnumConstant.scala | 12 ++++++++++++ translator/src/main/scala/soda/lib/OptionSD.scala | 12 ++++++++++++ translator/src/main/scala/soda/lib/Package.scala | 11 +++-------- translator/src/main/scala/soda/lib/Recursion.scala | 12 ++++++++++++ translator/src/main/scala/soda/lib/SeqSD.scala | 12 ++++++++++++ translator/src/main/scala/soda/lib/lib.scala | 14 ++++++++++++++ .../src/main/scala/soda/translator/Package.scala | 9 +++------ .../soda/translator/block/AnnotatedBlock.scala | 8 ++++++++ .../main/scala/soda/translator/block/Block.scala | 8 ++++++++ .../translator/block/BlockAnnotationEnum.scala | 8 ++++++++ .../translator/block/BlockSequenceTranslator.scala | 8 ++++++++ .../soda/translator/block/BlockTranslator.scala | 8 ++++++++ .../translator/block/BlockTranslatorPipeline.scala | 8 ++++++++ .../block/ConditionalBlockTranslator.scala | 8 ++++++++ .../soda/translator/block/LineProcessor.scala | 8 ++++++++ .../soda/translator/block/LineTranslator.scala | 8 ++++++++ .../main/scala/soda/translator/block/Package.scala | 9 +++------ .../scala/soda/translator/block/PlainBlock.scala | 8 ++++++++ .../scala/soda/translator/block/Translator.scala | 8 ++++++++ .../scala/soda/translator/blocktr/Package.scala | 9 +++------ .../soda/translator/blocktr/TableTranslator.scala | 10 ++++++++++ .../soda/translator/blocktr/TokenReplacement.scala | 10 ++++++++++ .../blocktr/TokenizedBlockTranslator.scala | 10 ++++++++++ .../scala/soda/translator/extension/Package.scala | 9 +++------ .../translator/extension/common/Extension.scala | 8 ++++++++ .../soda/translator/extension/common/Package.scala | 9 +++------ .../soda/translator/extension/help/Help.scala | 8 ++++++++ .../soda/translator/extension/help/Package.scala | 9 +++------ .../soda/translator/extension/main/Main.scala | 9 +++++++++ .../soda/translator/extension/main/Package.scala | 9 +++------ .../tocoq/CoqClassConstructorBlockTranslator.scala | 8 ++++++++ .../tocoq/CoqClassDeclarationBlockTranslator.scala | 8 ++++++++ .../tocoq/CoqClassEndBlockTranslator.scala | 8 ++++++++ .../tocoq/CoqDefinitionBlockTranslator.scala | 8 ++++++++ .../CoqImportDeclarationBlockTranslator.scala | 8 ++++++++ .../CoqPackageDeclarationBlockTranslator.scala | 8 ++++++++ .../extension/tocoq/CoqProofBlockTranslator.scala | 8 ++++++++ .../tocoq/CoqTheoremBlockTranslator.scala | 8 ++++++++ .../extension/tocoq/DefinitionLineTranslator.scala | 8 ++++++++ .../extension/tocoq/MatchCaseBlockTranslator.scala | 8 ++++++++ .../extension/tocoq/MicroTranslatorToCoq.scala | 8 ++++++++ .../soda/translator/extension/tocoq/Package.scala | 13 +++---------- .../extension/tocoq/TranslationConstantToCoq.scala | 8 ++++++++ .../extension/tocoq/TranslatorToCoq.scala | 8 ++++++++ .../extension/todoc/DocBlockTranslator.scala | 8 ++++++++ .../extension/todoc/MicroTranslatorToDoc.scala | 8 ++++++++ .../soda/translator/extension/todoc/Package.scala | 13 +++---------- .../extension/todoc/TranslationConstantToDoc.scala | 8 ++++++++ .../extension/todoc/TranslatorToDoc.scala | 8 ++++++++ .../AbstractDeclarationBlockTranslator.scala | 8 ++++++++ .../toscala/ClassConstructorBlockTranslator.scala | 8 ++++++++ .../toscala/ClassDeclarationBlockTranslator.scala | 8 ++++++++ .../toscala/ClassEndBlockTranslator.scala | 8 ++++++++ .../FunctionDefinitionBlockTranslator.scala | 8 ++++++++ .../toscala/FunctionDefinitionLineDetector.scala | 8 ++++++++ .../toscala/ImportDeclarationBlockTranslator.scala | 8 ++++++++ .../toscala/MainClassBlockTranslator.scala | 8 ++++++++ .../toscala/MatchCaseBlockTranslator.scala | 8 ++++++++ .../extension/toscala/MicroTranslatorToScala.scala | 8 ++++++++ .../translator/extension/toscala/Package.scala | 9 +++------ .../toscala/TheoremAndProofBlockTranslator.scala | 8 ++++++++ .../toscala/TranslationConstantToScala.scala | 8 ++++++++ .../extension/toscala/TranslatorToScala.scala | 8 ++++++++ .../soda/translator/io/DirectoryProcessor.scala | 9 +++++++++ .../soda/translator/io/DirectoryScanner.scala | 9 +++++++++ .../scala/soda/translator/io/LibraryDeployer.scala | 9 +++++++++ .../main/scala/soda/translator/io/Package.scala | 9 +++------ .../main/scala/soda/translator/io/SimpleIO.scala | 9 +++++++++ .../soda/translator/parser/BlockBuilder.scala | 8 ++++++++ .../soda/translator/parser/BlockProcessor.scala | 8 ++++++++ .../scala/soda/translator/parser/Package.scala | 9 +++------ .../parser/PreprocessorSequenceTranslator.scala | 8 ++++++++ .../soda/translator/parser/SodaConstant.scala | 8 ++++++++ .../annotation/AbstractDeclarationAnnotation.scala | 6 ++++++ .../parser/annotation/AnnotationFactory.scala | 6 ++++++ .../parser/annotation/BlockAnnotationParser.scala | 6 ++++++ .../parser/annotation/ClassAliasAnnotation.scala | 6 ++++++ .../annotation/ClassBeginningAnnotation.scala | 6 ++++++ .../parser/annotation/ClassEndAnnotation.scala | 6 ++++++ .../parser/annotation/CommentAnnotation.scala | 6 ++++++ .../annotation/FunctionDefinitionAnnotation.scala | 6 ++++++ .../annotation/ImportDeclarationAnnotation.scala | 6 ++++++ .../translator/parser/annotation/Package.scala | 2 ++ .../annotation/PackageDeclarationAnnotation.scala | 6 ++++++ .../parser/annotation/ProofBlockAnnotation.scala | 6 ++++++ .../annotation/TestDeclarationAnnotation.scala | 6 ++++++ .../parser/annotation/TheoremBlockAnnotation.scala | 6 ++++++ .../soda/translator/replacement/CharType.scala | 9 +++++++++ .../soda/translator/replacement/Package.scala | 9 +++------ .../translator/replacement/ParserTransition.scala | 9 +++++++++ .../soda/translator/replacement/Replacement.scala | 9 +++++++++ .../soda/translator/replacement/Replacer.scala | 9 +++++++++ .../soda/translator/replacement/Tokenizer.scala | 9 +++++++++ .../src/test/resources/soda/example/Example.scala | 2 -- .../soda/example/otherexample/OtherExample.scala | 2 -- .../translator/example/algorithms/FizzBuzz.scala | 1 - .../algorithms/FizzBuzzPatternMatching.scala | 1 - .../translator/example/algorithms/HelloWorld.scala | 1 - .../example/algorithms/PatternMatching.scala | 1 - .../translator/example/algorithms/SaladMaker.scala | 1 - .../example/algorithms/SortExample.scala | 1 - .../ethicalissues/pricemonitor/PriceMonitor.scala | 2 -- .../pricemonitor/Requirement1Monitor.scala | 2 -- .../pricemonitor/Requirement2Monitor.scala | 2 -- .../pricemonitor/Requirement3Monitor.scala | 2 -- .../forcoq/algorithms/RecursionForCoq.scala | 2 -- .../soda/translator/example/forcoq/lib/List.scala | 2 -- .../soda/translator/example/forcoq/lib/Nat.scala | 2 -- .../forcoq/mathematics/FactorialForCoq.scala | 1 - .../mathematics/TriangularNumberForCoq.scala | 1 - .../example/miniexample/MiniExample.scala | 2 -- 142 files changed, 918 insertions(+), 134 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala index d8b0e32e..377572c2 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait FizzBuzz { diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala index 88a82ba3..01408a23 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait FizzBuzzPatternMatching { diff --git a/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala b/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala index d8dfa113..b38f51ed 100644 --- a/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala +++ b/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait Main { diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index e7660f81..d3f0c322 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -1,3 +1,5 @@ + + package soda.example.algorithms /* diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala index 647ea947..872f4ba9 100644 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala +++ b/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait Parameter { diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala b/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala index 3ebd2fe9..69f79af0 100644 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala +++ b/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait SaladMaker { diff --git a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala b/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala index ac9810a0..5c283b27 100644 --- a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala +++ b/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait ScalaReservedWordEscaping { diff --git a/examples/src/main/scala/soda/example/algorithms/SortExample.scala b/examples/src/main/scala/soda/example/algorithms/SortExample.scala index a1adb336..9dfc3b55 100644 --- a/examples/src/main/scala/soda/example/algorithms/SortExample.scala +++ b/examples/src/main/scala/soda/example/algorithms/SortExample.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait SortExample { diff --git a/examples/src/main/scala/soda/example/algorithms/SwapExample.scala b/examples/src/main/scala/soda/example/algorithms/SwapExample.scala index 9fa25a88..a450ec58 100644 --- a/examples/src/main/scala/soda/example/algorithms/SwapExample.scala +++ b/examples/src/main/scala/soda/example/algorithms/SwapExample.scala @@ -1,5 +1,12 @@ package soda.example.algorithms +/* + * This package contains examples in Soda. + * These examples focus on simple algorithms. + */ + + + trait PairExample { diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala index e4382eaa..aa9aeda1 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait FactorialConcise { diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala index 12b43f29..f8132c50 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait FactorialPatternMatching { diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala index 4516b427..e0e2350a 100644 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala +++ b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait FactorialWithFold { diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala b/examples/src/main/scala/soda/example/mathematics/FiboExample.scala index 138b9767..b4ee750f 100644 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala +++ b/examples/src/main/scala/soda/example/mathematics/FiboExample.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait FiboExampleInSoda { diff --git a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala b/examples/src/main/scala/soda/example/mathematics/HardProblem.scala index 166837d7..5cb88354 100644 --- a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala +++ b/examples/src/main/scala/soda/example/mathematics/HardProblem.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait InputPair [A, B] { diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index a71ca0e6..93ef5d93 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -1,3 +1,5 @@ + + package soda.example.mathematics /* diff --git a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala b/examples/src/main/scala/soda/example/mathematics/PiIterator.scala index 5ee1b158..f6aad5df 100644 --- a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala +++ b/examples/src/main/scala/soda/example/mathematics/PiIterator.scala @@ -1,5 +1,12 @@ package soda.example.mathematics +/* + * This package contains examples in Soda. + * These examples use mathematical properties. + */ + + + trait Status { diff --git a/library/src/main/scala/soda/collection/MSeq.scala b/library/src/main/scala/soda/collection/MSeq.scala index 019ad904..b13f6c10 100644 --- a/library/src/main/scala/soda/collection/MSeq.scala +++ b/library/src/main/scala/soda/collection/MSeq.scala @@ -1,5 +1,15 @@ package soda.collection +/* + * This package contains examples for Soda. + * They can be used as libraries, but their main purpose is + * to show possible implementations of functions for list manipulation. + */ + + + + + trait MSeq [A] { diff --git a/library/src/main/scala/soda/collection/Min.scala b/library/src/main/scala/soda/collection/Min.scala index 8b9a493c..93245cdd 100644 --- a/library/src/main/scala/soda/collection/Min.scala +++ b/library/src/main/scala/soda/collection/Min.scala @@ -1,5 +1,15 @@ package soda.collection +/* + * This package contains examples for Soda. + * They can be used as libraries, but their main purpose is + * to show possible implementations of functions for list manipulation. + */ + + + + + trait MSeqTranslator [A] { diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index 70673bcc..975a3c30 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -1,14 +1,11 @@ + + package soda.collection -/** +/* * This package contains examples for Soda. * They can be used as libraries, but their main purpose is * to show possible implementations of functions for list manipulation. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/library/src/main/scala/soda/collection/example/ListExample.scala b/library/src/main/scala/soda/collection/example/ListExample.scala index e84caa1c..a52f4ec8 100644 --- a/library/src/main/scala/soda/collection/example/ListExample.scala +++ b/library/src/main/scala/soda/collection/example/ListExample.scala @@ -1,5 +1,11 @@ package soda.collection.example +/* + * This package contains examples for Soda. + */ + + + trait Pair [A] { diff --git a/library/src/main/scala/soda/collection/example/Main.scala b/library/src/main/scala/soda/collection/example/Main.scala index dc639a35..12f8e13f 100644 --- a/library/src/main/scala/soda/collection/example/Main.scala +++ b/library/src/main/scala/soda/collection/example/Main.scala @@ -1,5 +1,11 @@ package soda.collection.example +/* + * This package contains examples for Soda. + */ + + + trait Main { diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala index 798111fd..57253995 100644 --- a/library/src/main/scala/soda/collection/example/Package.scala +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -1,3 +1,5 @@ + + package soda.collection.example /* diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala index c1f92f14..5d8850a5 100644 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala +++ b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This class contains auxiliary functions for combinations. */ diff --git a/translator/src/main/resources/lib/soda/lib/Doc.scala b/translator/src/main/resources/lib/soda/lib/Doc.scala index 5f11bab5..198b5f77 100644 --- a/translator/src/main/resources/lib/soda/lib/Doc.scala +++ b/translator/src/main/resources/lib/soda/lib/Doc.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * All concrete classes extending this class need to have a 'doc' attribute. */ diff --git a/translator/src/main/resources/lib/soda/lib/EnumConstant.scala b/translator/src/main/resources/lib/soda/lib/EnumConstant.scala index 4bb50daf..14ddb451 100644 --- a/translator/src/main/resources/lib/soda/lib/EnumConstant.scala +++ b/translator/src/main/resources/lib/soda/lib/EnumConstant.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is a constant to be used in enumerations. */ diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.scala b/translator/src/main/resources/lib/soda/lib/OptionSD.scala index 983629ac..7999a699 100644 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.scala +++ b/translator/src/main/resources/lib/soda/lib/OptionSD.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is an Option implemented without exceptions. */ diff --git a/translator/src/main/resources/lib/soda/lib/Package.scala b/translator/src/main/resources/lib/soda/lib/Package.scala index b092c8d2..311f5e33 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.scala +++ b/translator/src/main/resources/lib/soda/lib/Package.scala @@ -1,18 +1,15 @@ + + /* * This file is automatically generated. Do not edit. */ package soda.lib -/** +/* * This package contains a small collection of classes that are useful in Soda. * These classes can be imported instead of the Scala or Java classes, * or can be used as an inspiration for similar developments. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.scala b/translator/src/main/resources/lib/soda/lib/Recursion.scala index 1b34296f..84508f22 100644 --- a/translator/src/main/resources/lib/soda/lib/Recursion.scala +++ b/translator/src/main/resources/lib/soda/lib/Recursion.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This class contains tail recursive auxiliary functions. */ diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.scala b/translator/src/main/resources/lib/soda/lib/SeqSD.scala index 75a7b9a0..0a3886f1 100644 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.scala +++ b/translator/src/main/resources/lib/soda/lib/SeqSD.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is a Seq implemented without exceptions. */ diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.scala b/translator/src/main/scala/soda/lib/CartesianProduct.scala index c1f92f14..5d8850a5 100644 --- a/translator/src/main/scala/soda/lib/CartesianProduct.scala +++ b/translator/src/main/scala/soda/lib/CartesianProduct.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This class contains auxiliary functions for combinations. */ diff --git a/translator/src/main/scala/soda/lib/Doc.scala b/translator/src/main/scala/soda/lib/Doc.scala index 5f11bab5..198b5f77 100644 --- a/translator/src/main/scala/soda/lib/Doc.scala +++ b/translator/src/main/scala/soda/lib/Doc.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * All concrete classes extending this class need to have a 'doc' attribute. */ diff --git a/translator/src/main/scala/soda/lib/EnumConstant.scala b/translator/src/main/scala/soda/lib/EnumConstant.scala index 4bb50daf..14ddb451 100644 --- a/translator/src/main/scala/soda/lib/EnumConstant.scala +++ b/translator/src/main/scala/soda/lib/EnumConstant.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is a constant to be used in enumerations. */ diff --git a/translator/src/main/scala/soda/lib/OptionSD.scala b/translator/src/main/scala/soda/lib/OptionSD.scala index 983629ac..7999a699 100644 --- a/translator/src/main/scala/soda/lib/OptionSD.scala +++ b/translator/src/main/scala/soda/lib/OptionSD.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is an Option implemented without exceptions. */ diff --git a/translator/src/main/scala/soda/lib/Package.scala b/translator/src/main/scala/soda/lib/Package.scala index b092c8d2..6b0d4a0e 100644 --- a/translator/src/main/scala/soda/lib/Package.scala +++ b/translator/src/main/scala/soda/lib/Package.scala @@ -1,18 +1,13 @@ + + /* * This file is automatically generated. Do not edit. */ package soda.lib -/** +/* * This package contains a small collection of classes that are useful in Soda. * These classes can be imported instead of the Scala or Java classes, * or can be used as an inspiration for similar developments. */ - -trait Package -{ - -} - -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/lib/Recursion.scala b/translator/src/main/scala/soda/lib/Recursion.scala index 1b34296f..84508f22 100644 --- a/translator/src/main/scala/soda/lib/Recursion.scala +++ b/translator/src/main/scala/soda/lib/Recursion.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This class contains tail recursive auxiliary functions. */ diff --git a/translator/src/main/scala/soda/lib/SeqSD.scala b/translator/src/main/scala/soda/lib/SeqSD.scala index 75a7b9a0..0a3886f1 100644 --- a/translator/src/main/scala/soda/lib/SeqSD.scala +++ b/translator/src/main/scala/soda/lib/SeqSD.scala @@ -4,6 +4,18 @@ package soda.lib +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + +/* + * This file is automatically generated. Do not edit. + */ + /** * This is a Seq implemented without exceptions. */ diff --git a/translator/src/main/scala/soda/lib/lib.scala b/translator/src/main/scala/soda/lib/lib.scala index bd952d31..9acc7528 100644 --- a/translator/src/main/scala/soda/lib/lib.scala +++ b/translator/src/main/scala/soda/lib/lib.scala @@ -1 +1,15 @@ +/* + * This file is automatically generated. Do not edit. + */ + +package soda.lib + +/* + * This package contains a small collection of classes that are useful in Soda. + * These classes can be imported instead of the Scala or Java classes, + * or can be used as an inspiration for similar developments. + */ + + + /* Soda library */ diff --git a/translator/src/main/scala/soda/translator/Package.scala b/translator/src/main/scala/soda/translator/Package.scala index dc4c2530..dc4efe40 100644 --- a/translator/src/main/scala/soda/translator/Package.scala +++ b/translator/src/main/scala/soda/translator/Package.scala @@ -1,14 +1,11 @@ + + package soda.translator -/** +/* * This contains packages for an implementation that translates Soda source code. * At the moment, the available translators are to Scala and to Gallina. * Gallina is the specification language used by Coq. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala b/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala index e7f26ccc..1572ad5c 100644 --- a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala +++ b/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait AnnotatedBlock extends Block diff --git a/translator/src/main/scala/soda/translator/block/Block.scala b/translator/src/main/scala/soda/translator/block/Block.scala index 09fa0777..2118bd13 100644 --- a/translator/src/main/scala/soda/translator/block/Block.scala +++ b/translator/src/main/scala/soda/translator/block/Block.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait AnnotatedLine { diff --git a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala b/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala index 5f6c2387..dbc6a959 100644 --- a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala +++ b/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait BlockAnnotationId extends soda.lib.EnumConstant diff --git a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala b/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala index 7153942c..5f09fe2d 100644 --- a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala +++ b/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait BlockSequenceTranslator { diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslator.scala b/translator/src/main/scala/soda/translator/block/BlockTranslator.scala index 8ceab2e7..7d52b28b 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/block/BlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait BlockTranslator { diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala index 1df08514..38414381 100644 --- a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala +++ b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait BlockTranslatorPipeline extends BlockTranslator diff --git a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala index fee11a43..f2557da1 100644 --- a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait ConditionalBlockTranslator extends BlockTranslator diff --git a/translator/src/main/scala/soda/translator/block/LineProcessor.scala b/translator/src/main/scala/soda/translator/block/LineProcessor.scala index f85797bf..3cb8a231 100644 --- a/translator/src/main/scala/soda/translator/block/LineProcessor.scala +++ b/translator/src/main/scala/soda/translator/block/LineProcessor.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait SingleLineProcessor { diff --git a/translator/src/main/scala/soda/translator/block/LineTranslator.scala b/translator/src/main/scala/soda/translator/block/LineTranslator.scala index c0ac8d11..a5f5de48 100644 --- a/translator/src/main/scala/soda/translator/block/LineTranslator.scala +++ b/translator/src/main/scala/soda/translator/block/LineTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait LineTranslator { diff --git a/translator/src/main/scala/soda/translator/block/Package.scala b/translator/src/main/scala/soda/translator/block/Package.scala index 462798a1..090445ad 100644 --- a/translator/src/main/scala/soda/translator/block/Package.scala +++ b/translator/src/main/scala/soda/translator/block/Package.scala @@ -1,12 +1,9 @@ + + package soda.translator.block -/** +/* * This package contains abstract and concrete classes to define a block and a block translator. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/block/PlainBlock.scala b/translator/src/main/scala/soda/translator/block/PlainBlock.scala index 3446cba6..b5a1400a 100644 --- a/translator/src/main/scala/soda/translator/block/PlainBlock.scala +++ b/translator/src/main/scala/soda/translator/block/PlainBlock.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + trait PlainBlock { diff --git a/translator/src/main/scala/soda/translator/block/Translator.scala b/translator/src/main/scala/soda/translator/block/Translator.scala index 07a5de33..ddf72386 100644 --- a/translator/src/main/scala/soda/translator/block/Translator.scala +++ b/translator/src/main/scala/soda/translator/block/Translator.scala @@ -1,5 +1,13 @@ package soda.translator.block +/* + * This package contains abstract and concrete classes to define a block and a block translator. + */ + + + + + /** * This models an abstract translator. */ diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.scala b/translator/src/main/scala/soda/translator/blocktr/Package.scala index 6b8ce4d8..da7d9aaf 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.scala +++ b/translator/src/main/scala/soda/translator/blocktr/Package.scala @@ -1,14 +1,11 @@ + + package soda.translator.blocktr -/** +/* * This package contains shared block translators. * * @see soda.translator.block.BlockTranslator */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala b/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala index 88c78139..94ab06de 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala +++ b/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala @@ -1,5 +1,15 @@ package soda.translator.blocktr +/* + * This package contains shared block translators. + * + * @see soda.translator.block.BlockTranslator + */ + + + + + trait Table { diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala b/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala index 88771814..d19eba49 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala +++ b/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala @@ -1,5 +1,15 @@ package soda.translator.blocktr +/* + * This package contains shared block translators. + * + * @see soda.translator.block.BlockTranslator + */ + + + + + trait TokenReplacement { diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala index 453cdc92..032fe938 100644 --- a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala @@ -1,5 +1,15 @@ package soda.translator.blocktr +/* + * This package contains shared block translators. + * + * @see soda.translator.block.BlockTranslator + */ + + + + + trait TokenizedBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/Package.scala b/translator/src/main/scala/soda/translator/extension/Package.scala index e52e0e67..8bacd2eb 100644 --- a/translator/src/main/scala/soda/translator/extension/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/Package.scala @@ -1,14 +1,11 @@ + + package soda.translator.extension -/** +/* * This package contains all the packages with the extensions. * * @see soda.translator.extension.common.Extension */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/extension/common/Extension.scala b/translator/src/main/scala/soda/translator/extension/common/Extension.scala index b4fe6f2f..4938f412 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Extension.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Extension.scala @@ -1,5 +1,13 @@ package soda.translator.extension.common +/* + * This package contains common classes used by the extensions. + */ + + + + + trait Extension { diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.scala b/translator/src/main/scala/soda/translator/extension/common/Package.scala index 16e7e7bd..5032fe2d 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Package.scala @@ -1,12 +1,9 @@ + + package soda.translator.extension.common -/** +/* * This package contains common classes used by the extensions. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/extension/help/Help.scala b/translator/src/main/scala/soda/translator/extension/help/Help.scala index 1350128f..eff57849 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Help.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Help.scala @@ -1,5 +1,13 @@ package soda.translator.extension.help +/* + * This package is for the help extension. + */ + + + + + trait AbstractHelp extends soda.translator.extension.common.Extension diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.scala b/translator/src/main/scala/soda/translator/extension/help/Package.scala index e5285332..a0b23d2b 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Package.scala @@ -1,12 +1,9 @@ + + package soda.translator.extension.help -/** +/* * This package is for the help extension. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/extension/main/Main.scala b/translator/src/main/scala/soda/translator/extension/main/Main.scala index 938a4553..f0044ec1 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Main.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Main.scala @@ -1,5 +1,14 @@ package soda.translator.extension.main +/* + * This package is for the main extension. + * This is the entry point when the application is executed from a terminal. + */ + + + + + /** * This is the main entry point. */ diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.scala b/translator/src/main/scala/soda/translator/extension/main/Package.scala index 0110dfce..484106c5 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Package.scala @@ -1,13 +1,10 @@ + + package soda.translator.extension.main -/** +/* * This package is for the main extension. * This is the entry point when the application is executed from a terminal. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala index 28b42346..45ba738c 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqClassConstructorBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala index dfc1d452..56e18271 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqClassDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala index f563905a..3339052a 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqClassEndBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala index acf02bc9..5d446231 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqDefinitionBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala index 6771ab7a..84329d7b 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqImportDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala index b5cc6441..80af8932 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqPackageDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala index 5be26feb..ee7c5c4d 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqProofBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala index fd3e3e65..1efa1dba 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait CoqTheoremBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala index 7e5323df..8995a36c 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + /** * A line containing the definition sign will be classified as a definition. * The definitions need to be identified as 'val', 'def', or 'class'. diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala index fb6c33e3..78b37f61 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + trait MatchCaseBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala index caa9402b..7421f344 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + /** * This class translates Soda snippets into Coq snippets. */ diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala index 0bf7df7f..2b535549 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala @@ -1,14 +1,7 @@ + + package soda.translator.extension.tocoq -/** +/* * This package contains classes for the translation to Gallina, the specification language used by Coq. */ - -trait Package -{ - -} - -case class Package_ () extends Package - - diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala index 80be1b4b..c1e26c9c 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. */ diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala index 60f6b867..917c2ec8 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala @@ -1,5 +1,13 @@ package soda.translator.extension.tocoq +/* + * This package contains classes for the translation to Gallina, the specification language used by Coq. + */ + + + + + /** * This translates Soda source code to Coq source code. */ diff --git a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala index f5ee14a9..7bb46d7c 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.todoc +/* + * This package contains classes for documentation generation. + */ + + + + + trait DocBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala index e25b499a..c8447d1f 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala @@ -1,5 +1,13 @@ package soda.translator.extension.todoc +/* + * This package contains classes for documentation generation. + */ + + + + + /** * This class generates documentation from Soda snippets. */ diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index 923b61d3..7a9ad26d 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -1,14 +1,7 @@ + + package soda.translator.extension.todoc -/** +/* * This package contains classes for documentation generation. */ - -trait Package -{ - -} - -case class Package_ () extends Package - - diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala index 7448b3e8..8a107e3a 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala @@ -1,5 +1,13 @@ package soda.translator.extension.todoc +/* + * This package contains classes for documentation generation. + */ + + + + + /** * This class contains constants that are specific for the documentation generation. */ diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala index 1befc849..e1d40f2d 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala @@ -1,5 +1,13 @@ package soda.translator.extension.todoc +/* + * This package contains classes for documentation generation. + */ + + + + + /** * This generates documentation from Soda source code. */ diff --git a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala index fcc36e2c..c3120314 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait AbstractDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala index 97452cfa..ee69d721 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait ClassConstructorBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala index cc9b8dea..bd083907 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait ClassDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala index 88ba7196..5fe46ced 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait ClassEndBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala index 7b722916..4e70320f 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait FunctionDefinitionBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala index ff853b90..1ae6cede 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + /** * A line containing the definition sign will be classified as a definition. * The definitions need to be identified as 'val' or 'def'. diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala index 54d95c2f..5bbbb01c 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait ImportDeclarationBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala index fc3f4ba9..086e5003 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait MainClassBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala index 4040c4eb..c7ecf877 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait MatchCaseBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala index 0fe842e2..34fa9fcd 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + /** * This class translates Soda source code into Scala source code. */ diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index 478f5e97..01630910 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -1,12 +1,9 @@ + + package soda.translator.extension.toscala -/** +/* * This package contains classes for the translation to Scala. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala index a15fb33e..ed177d85 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + trait TheoremAndProofBlockTranslator extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala index 62fab699..4d286679 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. */ diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala index 3e270509..707d9486 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala @@ -1,5 +1,13 @@ package soda.translator.extension.toscala +/* + * This package contains classes for the translation to Scala. + */ + + + + + /** * This translates Soda source code to Scala source code. */ diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala index eea2f1cd..8a4e6f3c 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala +++ b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala @@ -1,5 +1,14 @@ package soda.translator.io +/* + * This package contains all the classes for I/O communication. + * It is also the entry point for the translator. + */ + + + + + trait AbstractDirectoryProcessor { diff --git a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala b/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala index f3320edd..a528efb8 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala +++ b/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala @@ -1,5 +1,14 @@ package soda.translator.io +/* + * This package contains all the classes for I/O communication. + * It is also the entry point for the translator. + */ + + + + + /** * This class is used to scan files in a given directory. */ diff --git a/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala b/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala index 66d925d7..6522e1b6 100644 --- a/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala +++ b/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala @@ -1,5 +1,14 @@ package soda.translator.io +/* + * This package contains all the classes for I/O communication. + * It is also the entry point for the translator. + */ + + + + + trait LibraryDeployer { diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index 54ca7b18..7d82fd54 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -1,13 +1,10 @@ + + package soda.translator.io -/** +/* * This package contains all the classes for I/O communication. * It is also the entry point for the translator. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/io/SimpleIO.scala b/translator/src/main/scala/soda/translator/io/SimpleIO.scala index f6c62466..1032bdde 100644 --- a/translator/src/main/scala/soda/translator/io/SimpleIO.scala +++ b/translator/src/main/scala/soda/translator/io/SimpleIO.scala @@ -1,5 +1,14 @@ package soda.translator.io +/* + * This package contains all the classes for I/O communication. + * It is also the entry point for the translator. + */ + + + + + /** * This is an auxiliary class to read small files. */ diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala index 86f4e199..34e90941 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala @@ -1,5 +1,13 @@ package soda.translator.parser +/* + * This package contains common classes used to describe and parse the Soda language. + */ + + + + + trait BlockBuilder { diff --git a/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala b/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala index 90cd25a8..0792f797 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala +++ b/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala @@ -1,5 +1,13 @@ package soda.translator.parser +/* + * This package contains common classes used to describe and parse the Soda language. + */ + + + + + /** * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. */ diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index 2e442f0c..ac364db3 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -1,12 +1,9 @@ + + package soda.translator.parser -/** +/* * This package contains common classes used to describe and parse the Soda language. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala index 3fa07ce6..b5f57acb 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala @@ -1,5 +1,13 @@ package soda.translator.parser +/* + * This package contains common classes used to describe and parse the Soda language. + */ + + + + + trait PreprocessorSequenceTranslator extends soda.translator.block.BlockSequenceTranslator diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala index d3ea3448..f3bbbc5f 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala @@ -1,5 +1,13 @@ package soda.translator.parser +/* + * This package contains common classes used to describe and parse the Soda language. + */ + + + + + trait SodaConstant { diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala index de631325..361c4db6 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait AbstractDeclarationAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala index cfe6db58..1c9de9ca 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait AnnotationFactory extends soda.translator.block.BlockTranslator diff --git a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala b/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala index f21cdec0..1214cc1f 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait BlockAnnotationParser extends soda.translator.block.AnnotatedBlock diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala index fde9e3c1..43b9a4c0 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait ClassAliasAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala index b72e3cd7..6203ee8e 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait ClassBeginningAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala index 967767b3..94395826 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait ClassEndAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala index ed06ef3f..f24acf94 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait CommentAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala index e526b282..a9629540 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait FunctionDefinitionAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala index 4bbe4eca..97226962 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait ImportDeclarationAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala index 6b4f971d..e522be94 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -1,3 +1,5 @@ + + package soda.translator.parser.annotation /* diff --git a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala index 260429d3..e2475fe4 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait PackageDeclarationAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala index 0f2da1a8..f02b2a8e 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait ProofBlockAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala index a99cbec1..c5513bcd 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait TestDeclarationAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala index 1f9bc8bf..eda81c0c 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains classes to handle block annotations for parsing. + */ + + + trait TheoremBlockAnnotation extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.scala b/translator/src/main/scala/soda/translator/replacement/CharType.scala index 99bbf161..23423e05 100644 --- a/translator/src/main/scala/soda/translator/replacement/CharType.scala +++ b/translator/src/main/scala/soda/translator/replacement/CharType.scala @@ -1,5 +1,14 @@ package soda.translator.replacement +/* + * This package contains auxiliary classes for string manipulation, + * especially related to replacement. + */ + + + + + /** * This is to classify characters. */ diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index 460ec1e4..90298f36 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -1,13 +1,10 @@ + + package soda.translator.replacement -/** +/* * This package contains auxiliary classes for string manipulation, * especially related to replacement. */ -trait Package -{ - -} -case class Package_ () extends Package diff --git a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala b/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala index 2018f3d1..e65cfc70 100644 --- a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala +++ b/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala @@ -1,5 +1,14 @@ package soda.translator.replacement +/* + * This package contains auxiliary classes for string manipulation, + * especially related to replacement. + */ + + + + + /** * This models all the possible states that the parser can be. */ diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.scala b/translator/src/main/scala/soda/translator/replacement/Replacement.scala index 2628e94a..75b29c6d 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.scala +++ b/translator/src/main/scala/soda/translator/replacement/Replacement.scala @@ -1,5 +1,14 @@ package soda.translator.replacement +/* + * This package contains auxiliary classes for string manipulation, + * especially related to replacement. + */ + + + + + /** * This models a collection of replacement functions. * This is intended to be used as a pipeline. diff --git a/translator/src/main/scala/soda/translator/replacement/Replacer.scala b/translator/src/main/scala/soda/translator/replacement/Replacer.scala index 52daee50..41aa09d9 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacer.scala +++ b/translator/src/main/scala/soda/translator/replacement/Replacer.scala @@ -1,5 +1,14 @@ package soda.translator.replacement +/* + * This package contains auxiliary classes for string manipulation, + * especially related to replacement. + */ + + + + + trait LinePatternProcessor { diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala index 17303be7..9f85dee4 100644 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala +++ b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala @@ -1,5 +1,14 @@ package soda.translator.replacement +/* + * This package contains auxiliary classes for string manipulation, + * especially related to replacement. + */ + + + + + /** * A token is a piece of code, that can contain one or more words combined with symbols. */ diff --git a/translator/src/test/resources/soda/example/Example.scala b/translator/src/test/resources/soda/example/Example.scala index 1b1712e3..228d68a0 100644 --- a/translator/src/test/resources/soda/example/Example.scala +++ b/translator/src/test/resources/soda/example/Example.scala @@ -1,5 +1,3 @@ - - package soda.example case class Example() diff --git a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala index 0b156b4e..5955d364 100644 --- a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala +++ b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala @@ -1,5 +1,3 @@ - - package soda.example.otherexample case class OtherExample() diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala index 8c76ad3a..27b904ff 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzz.scala @@ -1,4 +1,3 @@ - trait FizzBuzz { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala index b13c2c54..57131404 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzPatternMatching.scala @@ -1,4 +1,3 @@ - trait FizzBuzzPatternMatching { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala index fef53a00..62db3b38 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/HelloWorld.scala @@ -1,4 +1,3 @@ - trait Main { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala index aae49cfa..dab4c508 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/PatternMatching.scala @@ -1,4 +1,3 @@ - trait Parameter { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala index 0b689d8a..0de8d911 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala @@ -1,4 +1,3 @@ - trait SaladMaker { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala index d304514b..e5ec40d6 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SortExample.scala @@ -1,4 +1,3 @@ - trait SortExample { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala index e9536bec..05c3229f 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala @@ -1,5 +1,3 @@ - - package soda.example.ethicalissues.pricemonitor trait Customer diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index f26ce673..730db703 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -1,5 +1,3 @@ - - package soda.example.ethicalissues.pricemonitor trait Report1 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala index ddec349c..ea835c13 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala @@ -1,5 +1,3 @@ - - package soda.example.ethicalissues.pricemonitor trait Report2 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index de8b8083..03940a9b 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -1,5 +1,3 @@ - - package soda.example.ethicalissues.pricemonitor trait Report3 diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala index 479a952d..f17155c8 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala @@ -1,5 +1,3 @@ - - package soda.example.forcoq.algorithms /** diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala index 20ad91ac..d08bfdd5 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala @@ -1,5 +1,3 @@ - - package soda.example.forcoq.lib trait list [A] diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala index 1a27b3be..435fbd5b 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala @@ -1,5 +1,3 @@ - - package soda.example.forcoq.lib trait nat diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala index c5d02822..36f039b6 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala @@ -1,4 +1,3 @@ - package soda.example.forcoq.mathematics trait FactorialForCoq diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala index db1b6147..19db2a1a 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -1,4 +1,3 @@ - package soda.example.forcoq.mathematics trait TriangularNumberForCoq diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala index 1ba7bc94..70d61712 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala @@ -1,5 +1,3 @@ - - package soda.example.miniexample trait MiniExample From 18ce9bbb47c711ce298c783e5801290f04139370 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 22:06:44 +0100 Subject: [PATCH 44/71] Update Package.soda files --- .../src/main/scala/soda/example/algorithms/Package.scala | 4 ++-- .../src/main/scala/soda/example/mathematics/Package.scala | 4 ++-- library/src/main/scala/soda/collection/Package.scala | 4 ++-- .../src/main/scala/soda/collection/example/Package.scala | 4 ++-- translator/src/main/resources/lib/soda/lib/Package.scala | 4 ++-- translator/src/main/scala/soda/lib/Package.scala | 4 ++-- translator/src/main/scala/soda/translator/Package.scala | 4 ++-- .../src/main/scala/soda/translator/block/Package.scala | 4 ++-- .../src/main/scala/soda/translator/blocktr/Package.scala | 4 ++-- .../src/main/scala/soda/translator/extension/Package.scala | 4 ++-- .../scala/soda/translator/extension/common/Package.scala | 4 ++-- .../main/scala/soda/translator/extension/help/Package.scala | 4 ++-- .../main/scala/soda/translator/extension/main/Package.scala | 4 ++-- .../scala/soda/translator/extension/tocoq/Package.scala | 6 ++++-- .../scala/soda/translator/extension/todoc/Package.scala | 6 ++++-- .../scala/soda/translator/extension/toscala/Package.scala | 4 ++-- translator/src/main/scala/soda/translator/io/Package.scala | 4 ++-- .../src/main/scala/soda/translator/parser/Package.scala | 4 ++-- .../scala/soda/translator/parser/annotation/Package.scala | 4 ++-- .../main/scala/soda/translator/replacement/Package.scala | 4 ++-- 20 files changed, 44 insertions(+), 40 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index d3f0c322..3c0fe0b9 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -1,8 +1,8 @@ - - package soda.example.algorithms /* * This package contains examples in Soda. * These examples focus on simple algorithms. */ + +trait Package diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index 93ef5d93..5bdefb97 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -1,8 +1,8 @@ - - package soda.example.mathematics /* * This package contains examples in Soda. * These examples use mathematical properties. */ + +trait Package diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index 975a3c30..d4e34c05 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -1,5 +1,3 @@ - - package soda.collection /* @@ -9,3 +7,5 @@ package soda.collection */ + +trait Package diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala index 57253995..0a7c55d6 100644 --- a/library/src/main/scala/soda/collection/example/Package.scala +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -1,7 +1,7 @@ - - package soda.collection.example /* * This package contains examples for Soda. */ + +trait Package diff --git a/translator/src/main/resources/lib/soda/lib/Package.scala b/translator/src/main/resources/lib/soda/lib/Package.scala index 311f5e33..e4600a4b 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.scala +++ b/translator/src/main/resources/lib/soda/lib/Package.scala @@ -1,5 +1,3 @@ - - /* * This file is automatically generated. Do not edit. */ @@ -13,3 +11,5 @@ package soda.lib */ + +trait Package diff --git a/translator/src/main/scala/soda/lib/Package.scala b/translator/src/main/scala/soda/lib/Package.scala index 6b0d4a0e..229a289d 100644 --- a/translator/src/main/scala/soda/lib/Package.scala +++ b/translator/src/main/scala/soda/lib/Package.scala @@ -1,5 +1,3 @@ - - /* * This file is automatically generated. Do not edit. */ @@ -11,3 +9,5 @@ package soda.lib * These classes can be imported instead of the Scala or Java classes, * or can be used as an inspiration for similar developments. */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/Package.scala b/translator/src/main/scala/soda/translator/Package.scala index dc4efe40..46dcff85 100644 --- a/translator/src/main/scala/soda/translator/Package.scala +++ b/translator/src/main/scala/soda/translator/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator /* @@ -9,3 +7,5 @@ package soda.translator */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/block/Package.scala b/translator/src/main/scala/soda/translator/block/Package.scala index 090445ad..88436a5f 100644 --- a/translator/src/main/scala/soda/translator/block/Package.scala +++ b/translator/src/main/scala/soda/translator/block/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.block /* @@ -7,3 +5,5 @@ package soda.translator.block */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.scala b/translator/src/main/scala/soda/translator/blocktr/Package.scala index da7d9aaf..6422aa37 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.scala +++ b/translator/src/main/scala/soda/translator/blocktr/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.blocktr /* @@ -9,3 +7,5 @@ package soda.translator.blocktr */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/Package.scala b/translator/src/main/scala/soda/translator/extension/Package.scala index 8bacd2eb..1c393eb2 100644 --- a/translator/src/main/scala/soda/translator/extension/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.extension /* @@ -9,3 +7,5 @@ package soda.translator.extension */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.scala b/translator/src/main/scala/soda/translator/extension/common/Package.scala index 5032fe2d..14b3c716 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.extension.common /* @@ -7,3 +5,5 @@ package soda.translator.extension.common */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.scala b/translator/src/main/scala/soda/translator/extension/help/Package.scala index a0b23d2b..a912007d 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.extension.help /* @@ -7,3 +5,5 @@ package soda.translator.extension.help */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.scala b/translator/src/main/scala/soda/translator/extension/main/Package.scala index 484106c5..b7d97408 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.extension.main /* @@ -8,3 +6,5 @@ package soda.translator.extension.main */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala index 2b535549..d0e48f39 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala @@ -1,7 +1,9 @@ - - package soda.translator.extension.tocoq /* * This package contains classes for the translation to Gallina, the specification language used by Coq. */ + + + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index 7a9ad26d..8ae05f9e 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -1,7 +1,9 @@ - - package soda.translator.extension.todoc /* * This package contains classes for documentation generation. */ + + + +trait Package diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index 01630910..7bfe8dfd 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.extension.toscala /* @@ -7,3 +5,5 @@ package soda.translator.extension.toscala */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index 7d82fd54..0e75a3e4 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.io /* @@ -8,3 +6,5 @@ package soda.translator.io */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index ac364db3..a0c3ba4f 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.parser /* @@ -7,3 +5,5 @@ package soda.translator.parser */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala index e522be94..780ffea8 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -1,7 +1,7 @@ - - package soda.translator.parser.annotation /* * This package contains classes to handle block annotations for parsing. */ + +trait Package diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index 90298f36..348bd716 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -1,5 +1,3 @@ - - package soda.translator.replacement /* @@ -8,3 +6,5 @@ package soda.translator.replacement */ + +trait Package From bafd614d7fd7d68969f05b6325b1bf1fc8fa858c Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 14 Feb 2023 22:18:27 +0100 Subject: [PATCH 45/71] Update release notes --- docs/RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index 33d8a40e..ac0db791 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -8,7 +8,7 @@ - accepts reserved word `any` as a synonym for `lambda` - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure - improves function definition by allowing multiple lines in its signature - - includes a Bash script to build the project and create the binary file + - includes a Bash script (`makeall.sh`) to build the project and create the binary file - deprecated_features: - the `end` reserved word for `match`-`case` is no longer used - version: v0.16.0 From 3c9161163f4fe9f33e3a4de9c2d19c0a3d84129d Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 17:31:41 +0100 Subject: [PATCH 46/71] Add package option in Scala translator --- docs/RELEASE-NOTES.md | 3 +- .../extension/toscala/TranslatorToScala.scala | 58 ++++++++++++++++--- .../extension/toscala/TranslatorToScala.soda | 58 ++++++++++++++++--- .../translator/io/DirectoryProcessor.scala | 16 ++++- .../translator/io/DirectoryProcessor.soda | 16 ++++- .../scala/soda/translator/io/SimpleIO.scala | 8 ++- .../scala/soda/translator/io/SimpleIO.soda | 8 ++- 7 files changed, 146 insertions(+), 21 deletions(-) diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index ac0db791..d6399501 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -4,7 +4,8 @@ - build: sbt '++ 3.2.0' clean compile test package assembly - release: target/scala-3.2.0/soda-0.17.0.jar - new_features: - - reads `Package.soda` as prelude for a Soda file in the same directory + - includes an option to translate a whole Soda package into a single Scala file + - reads `Package.soda` as prelude for a Soda file in the same directory - accepts reserved word `any` as a synonym for `lambda` - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure - improves function definition by allowing multiple lines in its signature diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala index 707d9486..5dc3fd4c 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala @@ -24,7 +24,13 @@ trait TranslatorToScala import soda.translator.parser.BlockProcessor_ import java.io.File - lazy val prelude_file_name : String = "Package.soda" + lazy val package_file_name : String = "Package.soda" + + lazy val prelude_file_name : String = package_file_name + + lazy val package_scala_file_name : String = "Package.scala" + + lazy val file_separator : String = File.separator lazy val default_prelude : String = "" @@ -34,6 +40,10 @@ trait TranslatorToScala lazy val prelude_file_body : String = new_line + "trait Package" + prelude_separation + lazy val package_option_1 = "-p" + + lazy val package_option_2 = "--package" + private lazy val _soda_extension : String = ".soda" private lazy val _scala_extension : String = ".scala" @@ -55,7 +65,10 @@ trait TranslatorToScala arguments.length match { case 0 => _process_directory (_default_argument) case 1 => _process_directory (arguments (0) ) - case 2 => _translate (arguments (0) ) (arguments (1) ) + case 2 => + if ( _is_package_option (arguments (0) ) + ) _process_directory_with_package_option (arguments (1) ) + else _translate (arguments (0) ) (arguments (1) ) case x => false } @@ -68,22 +81,48 @@ trait TranslatorToScala private def _process_soda_file_with (pair : FileNamePair) : Boolean = _translate (pair.input_file_name) (pair.output_file_name) + private def _process_directory_with_package_option (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () + + private def _process_soda_file_with_package_option (file : File) : Boolean = + if ( file.getName == package_file_name + ) _process_soda_file (file) + else _process_soda_file_with_package_option_with ( + get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) + ) + + private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = + _translate_append (pair.input_file_name) (pair.output_file_name) + def get_input_output_file_names (input_name : String) : FileNamePair = if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + ) FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) + + def get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( _read_input (input_file_name) ) (output_file_name) + _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) private def _translate_with_input (input : String) (output_file_name : String) : Boolean = SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) - private def _read_input (input_file_name : String) : String = + private def _translate_append (input_file_name : String) (output_file_name : String) : Boolean = + _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) + + private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) ) + + private def _read_input_with_prelude (input_file_name : String) : String = if ( _is_a_prelude_file (input_file_name) - ) SimpleFileReader_ ().read_file (input_file_name) + prelude_file_body - else _get_prelude (input_file_name) + SimpleFileReader_ ().read_file (input_file_name) + ) _read_input (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + _read_input (input_file_name) + + private def _read_input (input_file_name : String) : String = + SimpleFileReader_ ().read_file (input_file_name) private def _get_prelude (input_file_name : String) : String = _get_prelude_with (_get_prelude_file (input_file_name) ) @@ -99,6 +138,9 @@ trait TranslatorToScala private def _is_a_prelude_file (input_file_name : String) : Boolean = prelude_file_name == ( ( new File (input_file_name) ) .getName) + private def _is_package_option (s : String) : Boolean = + (s == package_option_1) || (s == package_option_2) + } case class TranslatorToScala_ () extends TranslatorToScala diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index ca6f71ab..8f390624 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -15,7 +15,13 @@ class TranslatorToScala soda.translator.parser.BlockProcessor_ java.io.File - prelude_file_name : String = "Package.soda" + package_file_name : String = "Package.soda" + + prelude_file_name : String = package_file_name + + package_scala_file_name : String = "Package.scala" + + file_separator : String = File.separator default_prelude : String = "" @@ -25,6 +31,10 @@ class TranslatorToScala prelude_file_body : String = new_line + "trait Package" + prelude_separation + package_option_1 = "-p" + + package_option_2 = "--package" + _soda_extension : String = ".soda" _scala_extension : String = ".scala" @@ -46,7 +56,10 @@ class TranslatorToScala match arguments.length case 0 ==> _process_directory (_default_argument) case 1 ==> _process_directory (arguments (0) ) - case 2 ==> _translate (arguments (0) ) (arguments (1) ) + case 2 ==> + if _is_package_option (arguments (0) ) + then _process_directory_with_package_option (arguments (1) ) + else _translate (arguments (0) ) (arguments (1) ) case x ==> false _process_directory (start : String) : Boolean = @@ -58,22 +71,48 @@ class TranslatorToScala _process_soda_file_with (pair : FileNamePair) : Boolean = _translate (pair.input_file_name) (pair.output_file_name) + _process_directory_with_package_option (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () + + _process_soda_file_with_package_option (file : File) : Boolean = + if file.getName == package_file_name + then _process_soda_file (file) + else _process_soda_file_with_package_option_with ( + get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) + ) + + _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = + _translate_append (pair.input_file_name) (pair.output_file_name) + get_input_output_file_names (input_name : String) : FileNamePair = if input_name.endsWith (_soda_extension) - then FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + then FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) + + get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = + if input_name.endsWith (_soda_extension) + then FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( _read_input (input_file_name) ) (output_file_name) + _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) _translate_with_input (input : String) (output_file_name : String) : Boolean = SimpleFileWriter_ ().write_file (output_file_name) (content := _translator.translate (input) ) - _read_input (input_file_name : String) : String = + _translate_append (input_file_name : String) (output_file_name : String) : Boolean = + _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) + + _translate_append_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().append_file (output_file_name) (content := _translator.translate (input) ) + + _read_input_with_prelude (input_file_name : String) : String = if _is_a_prelude_file (input_file_name) - then SimpleFileReader_ ().read_file (input_file_name) + prelude_file_body - else _get_prelude (input_file_name) + SimpleFileReader_ ().read_file (input_file_name) + then _read_input (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + _read_input (input_file_name) + + _read_input (input_file_name : String) : String = + SimpleFileReader_ ().read_file (input_file_name) _get_prelude (input_file_name : String) : String = _get_prelude_with (_get_prelude_file (input_file_name) ) @@ -89,6 +128,9 @@ class TranslatorToScala _is_a_prelude_file (input_file_name : String) : Boolean = prelude_file_name == ( ( @new File (input_file_name) ) .getName) + _is_package_option (s : String) : Boolean = + (s == package_option_1) or (s == package_option_2) + end class FileNamePair diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala index 8a4e6f3c..99462268 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala +++ b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala @@ -31,14 +31,28 @@ trait DirectoryProcessor lazy val soda_suffix = ".soda" + lazy val package_file_name = "Package.soda" + private lazy val _all_files = DirectoryScanner_ ().get_all_files ( new File (start)) - private lazy val _soda_files = + private lazy val _all_soda_files = _all_files .filter ( x => x.isFile) .filter ( x => x.getName.endsWith (soda_suffix)) + private lazy val _package_files = + _all_files + .filter ( x => x.isFile) + .filter ( x => x.getName == package_file_name) + + private lazy val _soda_non_package_files = + _all_soda_files + .filter ( x => ! (x.getName == package_file_name) ) + + private lazy val _soda_files = + _package_files .++ (_soda_non_package_files) + private lazy val _lib_files = _all_files .filter ( x => x.isFile) diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda index 769261f8..abd9cb1f 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda +++ b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda @@ -20,14 +20,28 @@ class DirectoryProcessor soda_suffix = ".soda" + package_file_name = "Package.soda" + _all_files = DirectoryScanner_ ().get_all_files ( @new File (start)) - _soda_files = + _all_soda_files = _all_files .filter ( lambda x --> x.isFile) .filter ( lambda x --> x.getName.endsWith (soda_suffix)) + _package_files = + _all_files + .filter ( lambda x --> x.isFile) + .filter ( lambda x --> x.getName == package_file_name) + + _soda_non_package_files = + _all_soda_files + .filter ( lambda x --> not (x.getName == package_file_name) ) + + _soda_files = + _package_files .++ (_soda_non_package_files) + _lib_files = _all_files .filter ( lambda x --> x.isFile) diff --git a/translator/src/main/scala/soda/translator/io/SimpleIO.scala b/translator/src/main/scala/soda/translator/io/SimpleIO.scala index 1032bdde..8f9f5906 100644 --- a/translator/src/main/scala/soda/translator/io/SimpleIO.scala +++ b/translator/src/main/scala/soda/translator/io/SimpleIO.scala @@ -57,7 +57,13 @@ trait SimpleFileWriter write_file_with ( new File (file_name) ) (content) def write_file_with (file : File) (content : String) : Boolean = - _write_content ( new FileWriter (file) ) (content) + _write_content ( new FileWriter (file , false) ) (content) + + def append_file (file_name : String) (content : String) : Boolean = + append_file_with ( new File (file_name) ) (content) + + def append_file_with (file : File) (content : String) : Boolean = + _write_content ( new FileWriter (file , true) ) (content) private def _write_content (writer : Writer) (content : String) : Boolean = SomeSD_ (true) diff --git a/translator/src/main/scala/soda/translator/io/SimpleIO.soda b/translator/src/main/scala/soda/translator/io/SimpleIO.soda index 9dd283bf..91f92db6 100644 --- a/translator/src/main/scala/soda/translator/io/SimpleIO.soda +++ b/translator/src/main/scala/soda/translator/io/SimpleIO.soda @@ -45,7 +45,13 @@ class SimpleFileWriter write_file_with ( @new File (file_name) ) (content) write_file_with (file : File) (content : String) : Boolean = - _write_content ( @new FileWriter (file) ) (content) + _write_content ( @new FileWriter (file , false) ) (content) + + append_file (file_name : String) (content : String) : Boolean = + append_file_with ( @new File (file_name) ) (content) + + append_file_with (file : File) (content : String) : Boolean = + _write_content ( @new FileWriter (file , true) ) (content) _write_content (writer : Writer) (content : String) : Boolean = SomeSD_ (true) From b914902f7f326ad3a99099833da544d4470c0b98 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 18:04:09 +0100 Subject: [PATCH 47/71] Add Package.soda files in examples --- .../soda/example/ethicalissues/fairness/Fairness.scala | 6 ++++++ .../soda/example/ethicalissues/fairness/Fairness.soda | 2 +- .../soda/example/ethicalissues/fairness/Package.scala | 7 +++++++ .../scala/soda/example/ethicalissues/fairness/Package.soda | 5 +++++ .../soda/example/ethicalissues/pricemonitor/Package.scala | 7 +++++++ .../soda/example/ethicalissues/pricemonitor/Package.soda | 5 +++++ .../example/ethicalissues/pricemonitor/PriceMonitor.scala | 6 ++++++ .../example/ethicalissues/pricemonitor/PriceMonitor.soda | 1 - .../ethicalissues/pricemonitor/Requirement1Monitor.scala | 6 ++++++ .../ethicalissues/pricemonitor/Requirement1Monitor.soda | 1 - .../ethicalissues/pricemonitor/Requirement2Monitor.scala | 6 ++++++ .../ethicalissues/pricemonitor/Requirement2Monitor.soda | 1 - .../ethicalissues/pricemonitor/Requirement3Monitor.scala | 6 ++++++ .../ethicalissues/pricemonitor/Requirement3Monitor.soda | 1 - .../scala/soda/example/forcoq/algorithms/Package.scala | 7 +++++++ .../main/scala/soda/example/forcoq/algorithms/Package.soda | 5 +++++ .../soda/example/forcoq/algorithms/RecursionForCoq.scala | 6 ++++++ .../soda/example/forcoq/algorithms/RecursionForCoq.soda | 1 - examples/src/main/scala/soda/example/forcoq/lib/List.scala | 6 ++++++ examples/src/main/scala/soda/example/forcoq/lib/List.soda | 1 - examples/src/main/scala/soda/example/forcoq/lib/Nat.scala | 6 ++++++ examples/src/main/scala/soda/example/forcoq/lib/Nat.soda | 1 - .../src/main/scala/soda/example/forcoq/lib/Package.scala | 7 +++++++ .../src/main/scala/soda/example/forcoq/lib/Package.soda | 5 +++++ .../soda/example/forcoq/mathematics/FactorialForCoq.scala | 6 ++++++ .../soda/example/forcoq/mathematics/FactorialForCoq.soda | 1 - .../forcoq/mathematics/FiboExampleInSodaForCoq.scala | 6 ++++++ .../forcoq/mathematics/FiboExampleInSodaForCoq.soda | 1 - .../scala/soda/example/forcoq/mathematics/Package.scala | 7 +++++++ .../scala/soda/example/forcoq/mathematics/Package.soda | 5 +++++ .../forcoq/mathematics/TriangularNumberForCoq.scala | 6 ++++++ .../example/forcoq/mathematics/TriangularNumberForCoq.soda | 1 - .../main/scala/soda/example/inanutshell/InANutshell.scala | 6 ++++++ .../main/scala/soda/example/inanutshell/InANutshell.soda | 1 - .../src/main/scala/soda/example/inanutshell/Package.scala | 7 +++++++ .../src/main/scala/soda/example/inanutshell/Package.soda | 5 +++++ .../main/scala/soda/example/miniexample/MiniExample.scala | 6 ++++++ .../main/scala/soda/example/miniexample/MiniExample.soda | 1 - .../src/main/scala/soda/example/miniexample/Package.scala | 7 +++++++ .../src/main/scala/soda/example/miniexample/Package.soda | 5 +++++ .../test/scala/soda/example/algorithms/FizzBuzzSpec.scala | 6 ++++++ .../test/scala/soda/example/algorithms/FizzBuzzSpec.soda | 1 - .../src/test/scala/soda/example/algorithms/Package.scala | 7 +++++++ .../src/test/scala/soda/example/algorithms/Package.soda | 5 +++++ .../soda/example/algorithms/PatternMatchingSpec.scala | 6 ++++++ .../scala/soda/example/algorithms/PatternMatchingSpec.soda | 1 - .../scala/soda/example/algorithms/SaladMakerSpec.scala | 6 ++++++ .../test/scala/soda/example/algorithms/SaladMakerSpec.soda | 1 - .../scala/soda/example/algorithms/SortExampleSpec.scala | 6 ++++++ .../scala/soda/example/algorithms/SortExampleSpec.soda | 1 - .../soda/example/ethicalissues/fairness/FairnessSpec.scala | 6 ++++++ .../soda/example/ethicalissues/fairness/FairnessSpec.soda | 1 - .../soda/example/ethicalissues/fairness/Package.scala | 7 +++++++ .../scala/soda/example/ethicalissues/fairness/Package.soda | 5 +++++ .../soda/example/ethicalissues/pricemonitor/Package.scala | 7 +++++++ .../soda/example/ethicalissues/pricemonitor/Package.soda | 5 +++++ .../ethicalissues/pricemonitor/PriceMonitorSpec.scala | 6 ++++++ .../ethicalissues/pricemonitor/PriceMonitorSpec.soda | 1 - .../scala/soda/example/forcoq/algorithms/Package.scala | 7 +++++++ .../test/scala/soda/example/forcoq/algorithms/Package.soda | 5 +++++ .../example/forcoq/algorithms/RecursionForCoqSpec.scala | 6 ++++++ .../example/forcoq/algorithms/RecursionForCoqSpec.soda | 1 - .../src/test/scala/soda/example/forcoq/lib/ListSpec.scala | 6 ++++++ .../src/test/scala/soda/example/forcoq/lib/ListSpec.soda | 1 - .../src/test/scala/soda/example/forcoq/lib/NatSpec.scala | 6 ++++++ .../src/test/scala/soda/example/forcoq/lib/NatSpec.soda | 1 - .../src/test/scala/soda/example/forcoq/lib/Package.scala | 7 +++++++ .../src/test/scala/soda/example/forcoq/lib/Package.soda | 5 +++++ .../example/forcoq/mathematics/FactorialForCoqSpec.scala | 6 ++++++ .../example/forcoq/mathematics/FactorialForCoqSpec.soda | 1 - .../forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala | 6 ++++++ .../forcoq/mathematics/FiboExampleInSodaForCoqSpec.soda | 1 - .../scala/soda/example/forcoq/mathematics/Package.scala | 7 +++++++ .../scala/soda/example/forcoq/mathematics/Package.soda | 5 +++++ .../forcoq/mathematics/TriangularNumberForCoqSpec.scala | 6 ++++++ .../forcoq/mathematics/TriangularNumberForCoqSpec.soda | 1 - .../scala/soda/example/mathematics/FactorialSpec.scala | 6 ++++++ .../test/scala/soda/example/mathematics/FactorialSpec.soda | 1 - .../scala/soda/example/mathematics/FiboExampleSpec.scala | 6 ++++++ .../scala/soda/example/mathematics/FiboExampleSpec.soda | 1 - .../scala/soda/example/mathematics/HardProblemSpec.scala | 6 ++++++ .../scala/soda/example/mathematics/HardProblemSpec.soda | 1 - .../src/test/scala/soda/example/mathematics/Package.scala | 7 +++++++ .../src/test/scala/soda/example/mathematics/Package.soda | 5 +++++ .../scala/soda/example/mathematics/PiIteratorSpec.scala | 6 ++++++ .../scala/soda/example/mathematics/PiIteratorSpec.soda | 1 - 86 files changed, 343 insertions(+), 29 deletions(-) create mode 100644 examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala create mode 100644 examples/src/main/scala/soda/example/ethicalissues/fairness/Package.soda create mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala create mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.soda create mode 100644 examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala create mode 100644 examples/src/main/scala/soda/example/forcoq/algorithms/Package.soda create mode 100644 examples/src/main/scala/soda/example/forcoq/lib/Package.scala create mode 100644 examples/src/main/scala/soda/example/forcoq/lib/Package.soda create mode 100644 examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala create mode 100644 examples/src/main/scala/soda/example/forcoq/mathematics/Package.soda create mode 100644 examples/src/main/scala/soda/example/inanutshell/Package.scala create mode 100644 examples/src/main/scala/soda/example/inanutshell/Package.soda create mode 100644 examples/src/main/scala/soda/example/miniexample/Package.scala create mode 100644 examples/src/main/scala/soda/example/miniexample/Package.soda create mode 100644 examples/src/test/scala/soda/example/algorithms/Package.scala create mode 100644 examples/src/test/scala/soda/example/algorithms/Package.soda create mode 100644 examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala create mode 100644 examples/src/test/scala/soda/example/ethicalissues/fairness/Package.soda create mode 100644 examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala create mode 100644 examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.soda create mode 100644 examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala create mode 100644 examples/src/test/scala/soda/example/forcoq/algorithms/Package.soda create mode 100644 examples/src/test/scala/soda/example/forcoq/lib/Package.scala create mode 100644 examples/src/test/scala/soda/example/forcoq/lib/Package.soda create mode 100644 examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala create mode 100644 examples/src/test/scala/soda/example/forcoq/mathematics/Package.soda create mode 100644 examples/src/test/scala/soda/example/mathematics/Package.scala create mode 100644 examples/src/test/scala/soda/example/mathematics/Package.soda diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala index ee94b89b..04e7a018 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.fairness +/* + * This package contains examples about ethical issues. + */ + + + trait Applicant { diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda index eb623ec1..1a187f03 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda @@ -1,4 +1,4 @@ -package soda.example.ethicalissues.fairness + class Applicant diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala new file mode 100644 index 00000000..15b45e13 --- /dev/null +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala @@ -0,0 +1,7 @@ +package soda.example.ethicalissues.fairness + +/* + * This package contains examples about ethical issues. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.soda b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.soda new file mode 100644 index 00000000..20c666de --- /dev/null +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.soda @@ -0,0 +1,5 @@ +package soda.example.ethicalissues.fairness + +/* + * This package contains examples about ethical issues. + */ diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala new file mode 100644 index 00000000..762e48dd --- /dev/null +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -0,0 +1,7 @@ +package soda.example.ethicalissues.pricemonitor + +/* + * This package contains example classes for a price monitor. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.soda new file mode 100644 index 00000000..7c241cc8 --- /dev/null +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.soda @@ -0,0 +1,5 @@ +package soda.example.ethicalissues.pricemonitor + +/* + * This package contains example classes for a price monitor. + */ diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala index 05c3229f..deac457e 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.pricemonitor +/* + * This package contains example classes for a price monitor. + */ + + + trait Customer { diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.soda index c79501cb..0607bf30 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Customer diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index 730db703..ffad1b75 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.pricemonitor +/* + * This package contains example classes for a price monitor. + */ + + + trait Report1 { diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda index b8256a5e..75a8b4a6 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report1 diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala index ea835c13..e6cebfff 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.pricemonitor +/* + * This package contains example classes for a price monitor. + */ + + + trait Report2 { diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.soda index 620b7c58..82e3b3e1 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report2 diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 03940a9b..ccdd129d 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.pricemonitor +/* + * This package contains example classes for a price monitor. + */ + + + trait Report3 { diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index 8e345fad..bf157075 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report3 diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala new file mode 100644 index 00000000..98b0ee3f --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.algorithms + +/* + * This package contains examples using recursion for Coq. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.soda b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.soda new file mode 100644 index 00000000..65e02b72 --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.algorithms + +/* + * This package contains examples using recursion for Coq. + */ diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala index f17155c8..a316a4dd 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.algorithms +/* + * This package contains examples using recursion for Coq. + */ + + + /** * This class contains tail recursive auxiliary functions. */ diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda index 5ecca244..eb562420 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.algorithms /** * This class contains tail recursive auxiliary functions. diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.scala b/examples/src/main/scala/soda/example/forcoq/lib/List.scala index d08bfdd5..035debed 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/List.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.lib +/* + * This package contains helper classes that could be needed for a translation to Coq. + */ + + + trait list [A] { diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.soda b/examples/src/main/scala/soda/example/forcoq/lib/List.soda index 099fb620..a2cad06a 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/List.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class list [A] diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala b/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala index 435fbd5b..c71bdae1 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.lib +/* + * This package contains helper classes that could be needed for a translation to Coq. + */ + + + trait nat { diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda index 88b9e767..d6207e48 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda +++ b/examples/src/main/scala/soda/example/forcoq/lib/Nat.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class nat diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala new file mode 100644 index 00000000..a64c14b6 --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.lib + +/* + * This package contains helper classes that could be needed for a translation to Coq. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Package.soda b/examples/src/main/scala/soda/example/forcoq/lib/Package.soda new file mode 100644 index 00000000..aa8f1abc --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/lib/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.lib + +/* + * This package contains helper classes that could be needed for a translation to Coq. + */ diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala index 36f039b6..9bb2d636 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains examples of some mathematical functions that can be translated to Coq. + */ + + + trait FactorialForCoq { diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda index f6fd39d2..fdda5183 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FactorialForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala index f9345f4f..46fc08d2 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains examples of some mathematical functions that can be translated to Coq. + */ + + + trait FiboExampleInSodaForCoq { diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 94e8793d..4b8e9fbd 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FiboExampleInSodaForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala new file mode 100644 index 00000000..1210b73d --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.mathematics + +/* + * This package contains examples of some mathematical functions that can be translated to Coq. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.soda new file mode 100644 index 00000000..acf8534d --- /dev/null +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.mathematics + +/* + * This package contains examples of some mathematical functions that can be translated to Coq. + */ diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala index 19db2a1a..1dc51da3 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains examples of some mathematical functions that can be translated to Coq. + */ + + + trait TriangularNumberForCoq { diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda index b6f3aa3f..92de56a9 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class TriangularNumberForCoq diff --git a/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala b/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala index 1aeeee01..c301c084 100644 --- a/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala +++ b/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala @@ -1,5 +1,11 @@ package soda.example.inanutshell +/* + * This package explains Soda in a nutshell. + */ + + + trait InANutshell { diff --git a/examples/src/main/scala/soda/example/inanutshell/InANutshell.soda b/examples/src/main/scala/soda/example/inanutshell/InANutshell.soda index e8459852..fc647d38 100644 --- a/examples/src/main/scala/soda/example/inanutshell/InANutshell.soda +++ b/examples/src/main/scala/soda/example/inanutshell/InANutshell.soda @@ -1,4 +1,3 @@ -package soda.example.inanutshell class InANutshell diff --git a/examples/src/main/scala/soda/example/inanutshell/Package.scala b/examples/src/main/scala/soda/example/inanutshell/Package.scala new file mode 100644 index 00000000..602fc024 --- /dev/null +++ b/examples/src/main/scala/soda/example/inanutshell/Package.scala @@ -0,0 +1,7 @@ +package soda.example.inanutshell + +/* + * This package explains Soda in a nutshell. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/inanutshell/Package.soda b/examples/src/main/scala/soda/example/inanutshell/Package.soda new file mode 100644 index 00000000..eedd6744 --- /dev/null +++ b/examples/src/main/scala/soda/example/inanutshell/Package.soda @@ -0,0 +1,5 @@ +package soda.example.inanutshell + +/* + * This package explains Soda in a nutshell. + */ diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala index 70d61712..1b1466a5 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala @@ -1,5 +1,11 @@ package soda.example.miniexample +/* + * This package contains mini-examples. + */ + + + trait MiniExample { diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda index 9f2f55ec..6732873a 100644 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.soda +++ b/examples/src/main/scala/soda/example/miniexample/MiniExample.soda @@ -1,4 +1,3 @@ -package soda.example.miniexample class MiniExample diff --git a/examples/src/main/scala/soda/example/miniexample/Package.scala b/examples/src/main/scala/soda/example/miniexample/Package.scala new file mode 100644 index 00000000..a29edeb4 --- /dev/null +++ b/examples/src/main/scala/soda/example/miniexample/Package.scala @@ -0,0 +1,7 @@ +package soda.example.miniexample + +/* + * This package contains mini-examples. + */ + +trait Package diff --git a/examples/src/main/scala/soda/example/miniexample/Package.soda b/examples/src/main/scala/soda/example/miniexample/Package.soda new file mode 100644 index 00000000..fc121249 --- /dev/null +++ b/examples/src/main/scala/soda/example/miniexample/Package.soda @@ -0,0 +1,5 @@ +package soda.example.miniexample + +/* + * This package contains mini-examples. + */ diff --git a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala index 3c678781..3fb26ad7 100644 --- a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala @@ -1,5 +1,11 @@ package soda.example.algorithms +/* + * This package contains tests for examples of simple algorithms. + */ + + + case class FizzBuzzSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda index b243725e..e1783742 100644 --- a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class FizzBuzzSpec () extends diff --git a/examples/src/test/scala/soda/example/algorithms/Package.scala b/examples/src/test/scala/soda/example/algorithms/Package.scala new file mode 100644 index 00000000..77995fd6 --- /dev/null +++ b/examples/src/test/scala/soda/example/algorithms/Package.scala @@ -0,0 +1,7 @@ +package soda.example.algorithms + +/* + * This package contains tests for examples of simple algorithms. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/algorithms/Package.soda b/examples/src/test/scala/soda/example/algorithms/Package.soda new file mode 100644 index 00000000..ac487174 --- /dev/null +++ b/examples/src/test/scala/soda/example/algorithms/Package.soda @@ -0,0 +1,5 @@ +package soda.example.algorithms + +/* + * This package contains tests for examples of simple algorithms. + */ diff --git a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala b/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala index 0a3a2038..f2e1fef1 100644 --- a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala @@ -1,5 +1,11 @@ package soda.example.algorithms +/* + * This package contains tests for examples of simple algorithms. + */ + + + case class PatternMatchingSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.soda b/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.soda index 90b0b97d..833db25b 100644 --- a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class PatternMatchingSpec () extends diff --git a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala index 84771d41..603f7fba 100644 --- a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala @@ -1,5 +1,11 @@ package soda.example.algorithms +/* + * This package contains tests for examples of simple algorithms. + */ + + + trait SaladIngredient extends soda.lib.EnumConstant diff --git a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda index b8f54804..250b8db9 100644 --- a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SaladIngredient extends diff --git a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala b/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala index 11805a7a..e6b166d6 100644 --- a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala +++ b/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala @@ -1,5 +1,11 @@ package soda.example.algorithms +/* + * This package contains tests for examples of simple algorithms. + */ + + + case class SortExampleSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.soda b/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.soda index 84d79246..22c4aa06 100644 --- a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.soda +++ b/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.soda @@ -1,4 +1,3 @@ -package soda.example.algorithms class SortExampleSpec () extends diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala index 80f3e55f..243c566e 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.fairness +/* + * This package contains tests for examples about ethical issues. + */ + + + case class FairnessSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.soda b/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.soda index 64a32563..149469f3 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.soda +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.fairness class FairnessSpec () extends diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala new file mode 100644 index 00000000..16be32bd --- /dev/null +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala @@ -0,0 +1,7 @@ +package soda.example.ethicalissues.fairness + +/* + * This package contains tests for examples about ethical issues. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.soda b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.soda new file mode 100644 index 00000000..5aa8e3bb --- /dev/null +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.soda @@ -0,0 +1,5 @@ +package soda.example.ethicalissues.fairness + +/* + * This package contains tests for examples about ethical issues. + */ diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala new file mode 100644 index 00000000..d480d4ac --- /dev/null +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -0,0 +1,7 @@ +package soda.example.ethicalissues.pricemonitor + +/* + * This package contains tests for example classes for a price monitor. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.soda b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.soda new file mode 100644 index 00000000..fa00c453 --- /dev/null +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.soda @@ -0,0 +1,5 @@ +package soda.example.ethicalissues.pricemonitor + +/* + * This package contains tests for example classes for a price monitor. + */ diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala index 8a417198..62d69b9e 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala @@ -1,5 +1,11 @@ package soda.example.ethicalissues.pricemonitor +/* + * This package contains tests for example classes for a price monitor. + */ + + + trait UnfairPricingAgent extends PricingAgent diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.soda b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.soda index 5c0416db..0ef771b5 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.soda +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class UnfairPricingAgent extends diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala new file mode 100644 index 00000000..98b0ee3f --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.algorithms + +/* + * This package contains examples using recursion for Coq. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.soda b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.soda new file mode 100644 index 00000000..65e02b72 --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.algorithms + +/* + * This package contains examples using recursion for Coq. + */ diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala index 344eec32..36584836 100644 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.algorithms +/* + * This package contains examples using recursion for Coq. + */ + + + case class RecursionForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.soda b/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.soda index 8a2efe57..c6756c6d 100644 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.algorithms class RecursionForCoqSpec () extends diff --git a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala b/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala index 3e0ab98e..5b67a6eb 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.lib +/* + * This package contains tests for helper classes that could be needed for a translation to Coq. + */ + + + case class ListSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.soda b/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.soda index 46543f32..0a4374ec 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class ListSpec () extends diff --git a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala b/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala index 367df27e..e7824aa2 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.lib +/* + * This package contains tests for helper classes that could be needed for a translation to Coq. + */ + + + case class NatSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.soda b/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.soda index 7b02ec9a..9c85024a 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class NatSpec () extends diff --git a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala new file mode 100644 index 00000000..641afbae --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.lib + +/* + * This package contains tests for helper classes that could be needed for a translation to Coq. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/forcoq/lib/Package.soda b/examples/src/test/scala/soda/example/forcoq/lib/Package.soda new file mode 100644 index 00000000..cf2ec3de --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/lib/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.lib + +/* + * This package contains tests for helper classes that could be needed for a translation to Coq. + */ diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala index 09624f6e..a486a85a 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains tests for examples of some mathematical functions that can be translated to Coq. + */ + + + case class FactorialForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.soda b/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.soda index 06d8841a..63e41706 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FactorialForCoqSpec () extends diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala index b0e40c35..daaaefb9 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains tests for examples of some mathematical functions that can be translated to Coq. + */ + + + case class FiboExampleInSodaForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.soda b/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.soda index 7e38ad0f..5c55e9a8 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FiboExampleInSodaForCoqSpec () extends diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala new file mode 100644 index 00000000..bc586482 --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala @@ -0,0 +1,7 @@ +package soda.example.forcoq.mathematics + +/* + * This package contains tests for examples of some mathematical functions that can be translated to Coq. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.soda b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.soda new file mode 100644 index 00000000..bdf21177 --- /dev/null +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.soda @@ -0,0 +1,5 @@ +package soda.example.forcoq.mathematics + +/* + * This package contains tests for examples of some mathematical functions that can be translated to Coq. + */ diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala index 0373fa69..68332b62 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala @@ -1,5 +1,11 @@ package soda.example.forcoq.mathematics +/* + * This package contains tests for examples of some mathematical functions that can be translated to Coq. + */ + + + case class TriangularNumberForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.soda b/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.soda index 5c16ccc1..0b47560e 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.soda +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class TriangularNumberForCoqSpec () extends diff --git a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala index 5ab5aa79..798e9840 100644 --- a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala @@ -1,5 +1,11 @@ package soda.example.mathematics +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ + + + case class FactorialSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda index 4fb82157..c75a383f 100644 --- a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FactorialSpec () extends diff --git a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala index e16c2fa8..7f982269 100644 --- a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala @@ -1,5 +1,11 @@ package soda.example.mathematics +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ + + + case class FiboExampleSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda index 532560a0..7e5e2c47 100644 --- a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class FiboExampleSpec () extends diff --git a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala b/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala index ecc48baa..de5a3cde 100644 --- a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala @@ -1,5 +1,11 @@ package soda.example.mathematics +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ + + + case class HardProblemSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.soda b/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.soda index 5d3a6aab..895aced3 100644 --- a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class HardProblemSpec () extends diff --git a/examples/src/test/scala/soda/example/mathematics/Package.scala b/examples/src/test/scala/soda/example/mathematics/Package.scala new file mode 100644 index 00000000..bdc89132 --- /dev/null +++ b/examples/src/test/scala/soda/example/mathematics/Package.scala @@ -0,0 +1,7 @@ +package soda.example.mathematics + +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ + +trait Package diff --git a/examples/src/test/scala/soda/example/mathematics/Package.soda b/examples/src/test/scala/soda/example/mathematics/Package.soda new file mode 100644 index 00000000..9c175ac9 --- /dev/null +++ b/examples/src/test/scala/soda/example/mathematics/Package.soda @@ -0,0 +1,5 @@ +package soda.example.mathematics + +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ diff --git a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala index 26e4ea0d..0eae2a80 100644 --- a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala +++ b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala @@ -1,5 +1,11 @@ package soda.example.mathematics +/* + * This package contains tests for examples in Soda that use mathematical properties. + */ + + + case class PiIteratorSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda index a5485831..ee3545b7 100644 --- a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda +++ b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.soda @@ -1,4 +1,3 @@ -package soda.example.mathematics class PiIteratorSpec () extends From ad09b6fa1357a4ebdcbd199815bafd3cd10b2608 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 20:09:12 +0100 Subject: [PATCH 48/71] Add Package.soda files in library --- library/src/main/scala/soda/collection/MSeq.scala | 2 -- library/src/main/scala/soda/collection/Min.scala | 2 -- library/src/main/scala/soda/collection/Package.scala | 2 -- library/src/main/scala/soda/collection/Package.soda | 2 -- library/src/test/scala/soda/collection/MinSpec.scala | 6 ++++++ library/src/test/scala/soda/collection/MinSpec.soda | 1 - library/src/test/scala/soda/collection/Package.scala | 7 +++++++ library/src/test/scala/soda/collection/Package.soda | 5 +++++ .../scala/soda/collection/example/ListExampleSpec.scala | 6 ++++++ .../scala/soda/collection/example/ListExampleSpec.soda | 1 - .../src/test/scala/soda/collection/example/Package.scala | 7 +++++++ .../src/test/scala/soda/collection/example/Package.soda | 5 +++++ 12 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 library/src/test/scala/soda/collection/Package.scala create mode 100644 library/src/test/scala/soda/collection/Package.soda create mode 100644 library/src/test/scala/soda/collection/example/Package.scala create mode 100644 library/src/test/scala/soda/collection/example/Package.soda diff --git a/library/src/main/scala/soda/collection/MSeq.scala b/library/src/main/scala/soda/collection/MSeq.scala index b13f6c10..45eeafb5 100644 --- a/library/src/main/scala/soda/collection/MSeq.scala +++ b/library/src/main/scala/soda/collection/MSeq.scala @@ -8,8 +8,6 @@ package soda.collection - - trait MSeq [A] { diff --git a/library/src/main/scala/soda/collection/Min.scala b/library/src/main/scala/soda/collection/Min.scala index 93245cdd..c5f7462d 100644 --- a/library/src/main/scala/soda/collection/Min.scala +++ b/library/src/main/scala/soda/collection/Min.scala @@ -8,8 +8,6 @@ package soda.collection - - trait MSeqTranslator [A] { diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index d4e34c05..81106915 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -6,6 +6,4 @@ package soda.collection * to show possible implementations of functions for list manipulation. */ - - trait Package diff --git a/library/src/main/scala/soda/collection/Package.soda b/library/src/main/scala/soda/collection/Package.soda index cbc31798..98e359e6 100644 --- a/library/src/main/scala/soda/collection/Package.soda +++ b/library/src/main/scala/soda/collection/Package.soda @@ -5,5 +5,3 @@ package soda.collection * They can be used as libraries, but their main purpose is * to show possible implementations of functions for list manipulation. */ - - diff --git a/library/src/test/scala/soda/collection/MinSpec.scala b/library/src/test/scala/soda/collection/MinSpec.scala index 84b9ee2f..5397ccfd 100644 --- a/library/src/test/scala/soda/collection/MinSpec.scala +++ b/library/src/test/scala/soda/collection/MinSpec.scala @@ -1,5 +1,11 @@ package soda.collection +/* + * This package contains tests for examples for Soda. + */ + + + case class MinSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/library/src/test/scala/soda/collection/MinSpec.soda b/library/src/test/scala/soda/collection/MinSpec.soda index ce64cf3a..7a8d6c24 100644 --- a/library/src/test/scala/soda/collection/MinSpec.soda +++ b/library/src/test/scala/soda/collection/MinSpec.soda @@ -1,4 +1,3 @@ -package soda.collection class MinSpec () extends diff --git a/library/src/test/scala/soda/collection/Package.scala b/library/src/test/scala/soda/collection/Package.scala new file mode 100644 index 00000000..9b10c7e6 --- /dev/null +++ b/library/src/test/scala/soda/collection/Package.scala @@ -0,0 +1,7 @@ +package soda.collection + +/* + * This package contains tests for examples for Soda. + */ + +trait Package diff --git a/library/src/test/scala/soda/collection/Package.soda b/library/src/test/scala/soda/collection/Package.soda new file mode 100644 index 00000000..ea424107 --- /dev/null +++ b/library/src/test/scala/soda/collection/Package.soda @@ -0,0 +1,5 @@ +package soda.collection + +/* + * This package contains tests for examples for Soda. + */ diff --git a/library/src/test/scala/soda/collection/example/ListExampleSpec.scala b/library/src/test/scala/soda/collection/example/ListExampleSpec.scala index 16bb1e2d..c93b7f15 100644 --- a/library/src/test/scala/soda/collection/example/ListExampleSpec.scala +++ b/library/src/test/scala/soda/collection/example/ListExampleSpec.scala @@ -1,5 +1,11 @@ package soda.collection.example +/* + * This package contains tests for examples for Soda. + */ + + + case class ListExampleSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/library/src/test/scala/soda/collection/example/ListExampleSpec.soda b/library/src/test/scala/soda/collection/example/ListExampleSpec.soda index 76d99531..9894fe35 100644 --- a/library/src/test/scala/soda/collection/example/ListExampleSpec.soda +++ b/library/src/test/scala/soda/collection/example/ListExampleSpec.soda @@ -1,4 +1,3 @@ -package soda.collection.example class ListExampleSpec () extends diff --git a/library/src/test/scala/soda/collection/example/Package.scala b/library/src/test/scala/soda/collection/example/Package.scala new file mode 100644 index 00000000..66978c74 --- /dev/null +++ b/library/src/test/scala/soda/collection/example/Package.scala @@ -0,0 +1,7 @@ +package soda.collection.example + +/* + * This package contains tests for examples for Soda. + */ + +trait Package diff --git a/library/src/test/scala/soda/collection/example/Package.soda b/library/src/test/scala/soda/collection/example/Package.soda new file mode 100644 index 00000000..9a801de6 --- /dev/null +++ b/library/src/test/scala/soda/collection/example/Package.soda @@ -0,0 +1,5 @@ +package soda.collection.example + +/* + * This package contains tests for examples for Soda. + */ From 1f1c2f08ad3608792a3517afb889d8d72d7631aa Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 20:10:30 +0100 Subject: [PATCH 49/71] Add Package.soda files in translator --- .../src/test/resources/soda/example/Example.scala | 4 ++++ .../src/test/resources/soda/example/Example.soda | 1 - .../src/test/resources/soda/example/Package.scala | 6 ++++++ .../src/test/resources/soda/example/Package.soda | 5 +++++ .../soda/example/otherexample/OtherExample.scala | 6 ++++++ .../soda/example/otherexample/OtherExample.soda | 1 - .../soda/example/otherexample/Package.scala | 7 +++++++ .../resources/soda/example/otherexample/Package.soda | 5 +++++ .../test/scala/soda/lib/CartesianProductSpec.scala | 6 ++++++ .../test/scala/soda/lib/CartesianProductSpec.soda | 1 - translator/src/test/scala/soda/lib/EnumSpec.scala | 6 ++++++ translator/src/test/scala/soda/lib/EnumSpec.soda | 1 - .../src/test/scala/soda/lib/OptionSDSpec.scala | 6 ++++++ translator/src/test/scala/soda/lib/OptionSDSpec.soda | 1 - translator/src/test/scala/soda/lib/Package.scala | 7 +++++++ translator/src/test/scala/soda/lib/Package.soda | 5 +++++ .../src/test/scala/soda/lib/RecursionSpec.scala | 6 ++++++ .../src/test/scala/soda/lib/RecursionSpec.soda | 1 - translator/src/test/scala/soda/lib/SeqSDSpec.scala | 6 ++++++ translator/src/test/scala/soda/lib/SeqSDSpec.soda | 1 - .../block/BlockTranslatorPipelineSpec.scala | 4 ++++ .../block/BlockTranslatorPipelineSpec.soda | 1 - .../test/scala/soda/translator/block/Package.scala | 6 ++++++ .../test/scala/soda/translator/block/Package.soda | 5 +++++ .../extension/tocoq/CoqFullTranslationSpec.scala | 4 ++++ .../extension/tocoq/CoqFullTranslationSpec.soda | 1 - .../extension/tocoq/MicroTranslatorToCoqSpec.scala | 4 ++++ .../extension/tocoq/MicroTranslatorToCoqSpec.soda | 1 - .../soda/translator/extension/tocoq/Package.scala | 6 ++++++ .../soda/translator/extension/tocoq/Package.soda | 5 +++++ .../extension/todoc/DocFullTranslationSpec.scala | 4 ++++ .../extension/todoc/DocFullTranslationSpec.soda | 1 - .../extension/todoc/MicroTranslatorToDocSpec.scala | 4 ++++ .../extension/todoc/MicroTranslatorToDocSpec.soda | 1 - .../soda/translator/extension/todoc/Package.scala | 6 ++++++ .../soda/translator/extension/todoc/Package.soda | 5 +++++ .../extension/toscala/BeautifierSpec.scala | 4 ++++ .../translator/extension/toscala/BeautifierSpec.soda | 1 - .../ClassConstructorBlockTranslatorSpec.scala | 4 ++++ .../toscala/ClassConstructorBlockTranslatorSpec.soda | 1 - .../extension/toscala/FullTranslationSpec.scala | 4 ++++ .../extension/toscala/FullTranslationSpec.soda | 1 - .../extension/toscala/LazySyntaxSpec.scala | 4 ++++ .../translator/extension/toscala/LazySyntaxSpec.soda | 1 - .../toscala/MicroTranslatorToScalaSpec.scala | 4 ++++ .../toscala/MicroTranslatorToScalaSpec.soda | 1 - .../translator/extension/toscala/MultiLineSpec.scala | 4 ++++ .../translator/extension/toscala/MultiLineSpec.soda | 1 - .../soda/translator/extension/toscala/Package.scala | 6 ++++++ .../soda/translator/extension/toscala/Package.soda | 5 +++++ .../extension/toscala/ScalaNonSodaSpec.scala | 4 ++++ .../extension/toscala/ScalaNonSodaSpec.soda | 1 - .../extension/toscala/TranslatorToScalaSpec.scala | 4 ++++ .../extension/toscala/TranslatorToScalaSpec.soda | 1 - .../toscala/UpperAndLowerBoundDeclarationSpec.scala | 4 ++++ .../toscala/UpperAndLowerBoundDeclarationSpec.soda | 1 - .../soda/translator/io/DirectoryScannerSpec.scala | 12 +++++++++++- .../soda/translator/io/DirectoryScannerSpec.soda | 7 +++++-- .../src/test/scala/soda/translator/io/Package.scala | 7 +++++++ .../src/test/scala/soda/translator/io/Package.soda | 5 +++++ .../scala/soda/translator/parser/BlockSpec.scala | 6 ++++++ .../test/scala/soda/translator/parser/BlockSpec.soda | 1 - .../test/scala/soda/translator/parser/Package.scala | 7 +++++++ .../test/scala/soda/translator/parser/Package.soda | 5 +++++ .../parser/PreprocessorSequenceTranslatorSpec.scala | 6 ++++++ .../parser/PreprocessorSequenceTranslatorSpec.soda | 1 - .../parser/annotation/BlockAnnotationSpec.scala | 6 ++++++ .../parser/annotation/BlockAnnotationSpec.soda | 1 - .../annotation/ClassBeginningAnnotationSpec.scala | 6 ++++++ .../annotation/ClassBeginningAnnotationSpec.soda | 1 - .../parser/annotation/ExampleProgram.scala | 6 ++++++ .../translator/parser/annotation/ExampleProgram.soda | 1 - .../soda/translator/parser/annotation/Package.scala | 7 +++++++ .../soda/translator/parser/annotation/Package.soda | 5 +++++ .../soda/translator/replacement/CharTypeSpec.scala | 6 ++++++ .../soda/translator/replacement/CharTypeSpec.soda | 1 - .../scala/soda/translator/replacement/Package.scala | 7 +++++++ .../scala/soda/translator/replacement/Package.soda | 5 +++++ .../translator/replacement/ReplacementAuxSpec.scala | 6 ++++++ .../translator/replacement/ReplacementAuxSpec.soda | 1 - .../soda/translator/replacement/TokenizerSpec.scala | 6 ++++++ .../soda/translator/replacement/TokenizerSpec.soda | 1 - 82 files changed, 287 insertions(+), 32 deletions(-) create mode 100644 translator/src/test/resources/soda/example/Package.scala create mode 100644 translator/src/test/resources/soda/example/Package.soda create mode 100644 translator/src/test/resources/soda/example/otherexample/Package.scala create mode 100644 translator/src/test/resources/soda/example/otherexample/Package.soda create mode 100644 translator/src/test/scala/soda/lib/Package.scala create mode 100644 translator/src/test/scala/soda/lib/Package.soda create mode 100644 translator/src/test/scala/soda/translator/block/Package.scala create mode 100644 translator/src/test/scala/soda/translator/block/Package.soda create mode 100644 translator/src/test/scala/soda/translator/extension/tocoq/Package.scala create mode 100644 translator/src/test/scala/soda/translator/extension/tocoq/Package.soda create mode 100644 translator/src/test/scala/soda/translator/extension/todoc/Package.scala create mode 100644 translator/src/test/scala/soda/translator/extension/todoc/Package.soda create mode 100644 translator/src/test/scala/soda/translator/extension/toscala/Package.scala create mode 100644 translator/src/test/scala/soda/translator/extension/toscala/Package.soda create mode 100644 translator/src/test/scala/soda/translator/io/Package.scala create mode 100644 translator/src/test/scala/soda/translator/io/Package.soda create mode 100644 translator/src/test/scala/soda/translator/parser/Package.scala create mode 100644 translator/src/test/scala/soda/translator/parser/Package.soda create mode 100644 translator/src/test/scala/soda/translator/parser/annotation/Package.scala create mode 100644 translator/src/test/scala/soda/translator/parser/annotation/Package.soda create mode 100644 translator/src/test/scala/soda/translator/replacement/Package.scala create mode 100644 translator/src/test/scala/soda/translator/replacement/Package.soda diff --git a/translator/src/test/resources/soda/example/Example.scala b/translator/src/test/resources/soda/example/Example.scala index 228d68a0..7acd5dc1 100644 --- a/translator/src/test/resources/soda/example/Example.scala +++ b/translator/src/test/resources/soda/example/Example.scala @@ -1,5 +1,9 @@ package soda.example +/* + * This package is just a minimal example. + */ + case class Example() { diff --git a/translator/src/test/resources/soda/example/Example.soda b/translator/src/test/resources/soda/example/Example.soda index fdc37cea..971ae12c 100644 --- a/translator/src/test/resources/soda/example/Example.soda +++ b/translator/src/test/resources/soda/example/Example.soda @@ -1,4 +1,3 @@ -package soda.example class Example() diff --git a/translator/src/test/resources/soda/example/Package.scala b/translator/src/test/resources/soda/example/Package.scala new file mode 100644 index 00000000..ebd484d9 --- /dev/null +++ b/translator/src/test/resources/soda/example/Package.scala @@ -0,0 +1,6 @@ +package soda.example + +/* + * This package is just a minimal example. + */ +trait Package diff --git a/translator/src/test/resources/soda/example/Package.soda b/translator/src/test/resources/soda/example/Package.soda new file mode 100644 index 00000000..8e74e051 --- /dev/null +++ b/translator/src/test/resources/soda/example/Package.soda @@ -0,0 +1,5 @@ +package soda.example + +/* + * This package is just a minimal example. + */ \ No newline at end of file diff --git a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala index 5955d364..ea1f01a1 100644 --- a/translator/src/test/resources/soda/example/otherexample/OtherExample.scala +++ b/translator/src/test/resources/soda/example/otherexample/OtherExample.scala @@ -1,5 +1,11 @@ package soda.example.otherexample +/* + * This package is another minimal example. + */ + + + case class OtherExample() { diff --git a/translator/src/test/resources/soda/example/otherexample/OtherExample.soda b/translator/src/test/resources/soda/example/otherexample/OtherExample.soda index c4d9a84d..929ca686 100644 --- a/translator/src/test/resources/soda/example/otherexample/OtherExample.soda +++ b/translator/src/test/resources/soda/example/otherexample/OtherExample.soda @@ -1,4 +1,3 @@ -package soda.example.otherexample class OtherExample() diff --git a/translator/src/test/resources/soda/example/otherexample/Package.scala b/translator/src/test/resources/soda/example/otherexample/Package.scala new file mode 100644 index 00000000..28667f58 --- /dev/null +++ b/translator/src/test/resources/soda/example/otherexample/Package.scala @@ -0,0 +1,7 @@ +package soda.example.otherexample + +/* + * This package is another minimal example. + */ + +trait Package diff --git a/translator/src/test/resources/soda/example/otherexample/Package.soda b/translator/src/test/resources/soda/example/otherexample/Package.soda new file mode 100644 index 00000000..f8398472 --- /dev/null +++ b/translator/src/test/resources/soda/example/otherexample/Package.soda @@ -0,0 +1,5 @@ +package soda.example.otherexample + +/* + * This package is another minimal example. + */ diff --git a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala b/translator/src/test/scala/soda/lib/CartesianProductSpec.scala index c7fe5cfd..58be69b3 100644 --- a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala +++ b/translator/src/test/scala/soda/lib/CartesianProductSpec.scala @@ -1,5 +1,11 @@ package soda.lib +/* + * This package contains tests for the Soda library. + */ + + + case class CartesianProductSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/lib/CartesianProductSpec.soda b/translator/src/test/scala/soda/lib/CartesianProductSpec.soda index 6faf1987..cf00e09d 100644 --- a/translator/src/test/scala/soda/lib/CartesianProductSpec.soda +++ b/translator/src/test/scala/soda/lib/CartesianProductSpec.soda @@ -1,4 +1,3 @@ -package soda.lib class CartesianProductSpec () extends diff --git a/translator/src/test/scala/soda/lib/EnumSpec.scala b/translator/src/test/scala/soda/lib/EnumSpec.scala index aba3947d..0a164558 100644 --- a/translator/src/test/scala/soda/lib/EnumSpec.scala +++ b/translator/src/test/scala/soda/lib/EnumSpec.scala @@ -1,5 +1,11 @@ package soda.lib +/* + * This package contains tests for the Soda library. + */ + + + trait DayOfTheWeek extends EnumConstant diff --git a/translator/src/test/scala/soda/lib/EnumSpec.soda b/translator/src/test/scala/soda/lib/EnumSpec.soda index 16220e51..d1ae9d1c 100644 --- a/translator/src/test/scala/soda/lib/EnumSpec.soda +++ b/translator/src/test/scala/soda/lib/EnumSpec.soda @@ -1,4 +1,3 @@ -package soda.lib class DayOfTheWeek extends diff --git a/translator/src/test/scala/soda/lib/OptionSDSpec.scala b/translator/src/test/scala/soda/lib/OptionSDSpec.scala index 7c8afdfb..22594e74 100644 --- a/translator/src/test/scala/soda/lib/OptionSDSpec.scala +++ b/translator/src/test/scala/soda/lib/OptionSDSpec.scala @@ -1,5 +1,11 @@ package soda.lib +/* + * This package contains tests for the Soda library. + */ + + + case class OptionSDSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/lib/OptionSDSpec.soda b/translator/src/test/scala/soda/lib/OptionSDSpec.soda index 3f059b33..be15c977 100644 --- a/translator/src/test/scala/soda/lib/OptionSDSpec.soda +++ b/translator/src/test/scala/soda/lib/OptionSDSpec.soda @@ -1,4 +1,3 @@ -package soda.lib class OptionSDSpec () extends diff --git a/translator/src/test/scala/soda/lib/Package.scala b/translator/src/test/scala/soda/lib/Package.scala new file mode 100644 index 00000000..82a0d4c5 --- /dev/null +++ b/translator/src/test/scala/soda/lib/Package.scala @@ -0,0 +1,7 @@ +package soda.lib + +/* + * This package contains tests for the Soda library. + */ + +trait Package diff --git a/translator/src/test/scala/soda/lib/Package.soda b/translator/src/test/scala/soda/lib/Package.soda new file mode 100644 index 00000000..bfc35d2e --- /dev/null +++ b/translator/src/test/scala/soda/lib/Package.soda @@ -0,0 +1,5 @@ +package soda.lib + +/* + * This package contains tests for the Soda library. + */ diff --git a/translator/src/test/scala/soda/lib/RecursionSpec.scala b/translator/src/test/scala/soda/lib/RecursionSpec.scala index 02b222dd..5868948e 100644 --- a/translator/src/test/scala/soda/lib/RecursionSpec.scala +++ b/translator/src/test/scala/soda/lib/RecursionSpec.scala @@ -1,5 +1,11 @@ package soda.lib +/* + * This package contains tests for the Soda library. + */ + + + case class RecursionSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/lib/RecursionSpec.soda b/translator/src/test/scala/soda/lib/RecursionSpec.soda index 61714969..18d0b769 100644 --- a/translator/src/test/scala/soda/lib/RecursionSpec.soda +++ b/translator/src/test/scala/soda/lib/RecursionSpec.soda @@ -1,4 +1,3 @@ -package soda.lib class RecursionSpec () extends diff --git a/translator/src/test/scala/soda/lib/SeqSDSpec.scala b/translator/src/test/scala/soda/lib/SeqSDSpec.scala index 24f45875..8bbee88f 100644 --- a/translator/src/test/scala/soda/lib/SeqSDSpec.scala +++ b/translator/src/test/scala/soda/lib/SeqSDSpec.scala @@ -1,5 +1,11 @@ package soda.lib +/* + * This package contains tests for the Soda library. + */ + + + case class SeqSDSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/lib/SeqSDSpec.soda b/translator/src/test/scala/soda/lib/SeqSDSpec.soda index 4702c28c..21312879 100644 --- a/translator/src/test/scala/soda/lib/SeqSDSpec.soda +++ b/translator/src/test/scala/soda/lib/SeqSDSpec.soda @@ -1,4 +1,3 @@ -package soda.lib class SeqSDSpec () extends diff --git a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala b/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala index 0a60fa07..239c6c69 100644 --- a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala +++ b/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala @@ -1,5 +1,9 @@ package soda.translator.block +/* + * This package contains tests for block translators. + */ + trait BlockTranslator00 extends BlockTranslator diff --git a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.soda b/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.soda index 91237333..709e51db 100644 --- a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.soda +++ b/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.block class BlockTranslator00 extends diff --git a/translator/src/test/scala/soda/translator/block/Package.scala b/translator/src/test/scala/soda/translator/block/Package.scala new file mode 100644 index 00000000..b86c0ee0 --- /dev/null +++ b/translator/src/test/scala/soda/translator/block/Package.scala @@ -0,0 +1,6 @@ +package soda.translator.block + +/* + * This package contains tests for block translators. + */ +trait Package diff --git a/translator/src/test/scala/soda/translator/block/Package.soda b/translator/src/test/scala/soda/translator/block/Package.soda new file mode 100644 index 00000000..05b41302 --- /dev/null +++ b/translator/src/test/scala/soda/translator/block/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.block + +/* + * This package contains tests for block translators. + */ \ No newline at end of file diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala index 9e0bb81c..a5e3c32b 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.tocoq +/* + * This package contains test for the translator to Coq. + */ + case class CoqFullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.soda b/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.soda index 07eeb7a6..a1d5565a 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class CoqFullTranslationSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala b/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala index 7aa7cb80..6cfe2428 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.tocoq +/* + * This package contains test for the translator to Coq. + */ + case class MicroTranslatorToCoqSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.soda b/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.soda index 14f8689a..bbe7618a 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.tocoq class MicroTranslatorToCoqSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala new file mode 100644 index 00000000..1fc6c2b3 --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala @@ -0,0 +1,6 @@ +package soda.translator.extension.tocoq + +/* + * This package contains test for the translator to Coq. + */ +trait Package diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/Package.soda b/translator/src/test/scala/soda/translator/extension/tocoq/Package.soda new file mode 100644 index 00000000..1213a1b5 --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/tocoq/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.extension.tocoq + +/* + * This package contains test for the translator to Coq. + */ \ No newline at end of file diff --git a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala index 2ae85287..8665e24e 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.todoc +/* + * This package contains tests for the translator to documents. + */ + case class DocFullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.soda b/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.soda index 83aaced2..43103a4b 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc class DocFullTranslationSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala b/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala index 168378db..b1c10725 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.todoc +/* + * This package contains tests for the translator to documents. + */ + case class MicroTranslatorToDocSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.soda b/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.soda index dfae2f5e..32c1bd73 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.todoc class MicroTranslatorToDocSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala new file mode 100644 index 00000000..3a976d81 --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala @@ -0,0 +1,6 @@ +package soda.translator.extension.todoc + +/* + * This package contains tests for the translator to documents. + */ +trait Package diff --git a/translator/src/test/scala/soda/translator/extension/todoc/Package.soda b/translator/src/test/scala/soda/translator/extension/todoc/Package.soda new file mode 100644 index 00000000..aa4ed3a0 --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/todoc/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.extension.todoc + +/* + * This package contains tests for the translator to documents. + */ \ No newline at end of file diff --git a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala index 8bd49b6e..d5ade30e 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class BeautifierSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.soda index 6bf3452b..c1ba3230 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class BeautifierSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala index 7e1d8b4e..8c0818da 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class ClassConstructorBlockTranslatorSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.soda index 76ddb518..00cf2a4d 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ClassConstructorBlockTranslatorSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala index 8d444944..809a307b 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class FullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda index 163a1a6a..bb669c42 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class FullTranslationSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala index b17c2744..11012fff 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + trait ExampleWithWrongOrder { diff --git a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.soda index 82a29428..7c24a7c2 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class ExampleWithWrongOrder diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala index a38ccd21..cbdd5eeb 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class MicroTranslatorToScalaSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda index 0f2f86f7..28a4f8b5 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class MicroTranslatorToScalaSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala index be8249ac..134b079c 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class MultiLineSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.soda index 56f3398b..88a08b91 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class MultiLineSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala new file mode 100644 index 00000000..138179bf --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -0,0 +1,6 @@ +package soda.translator.extension.toscala + +/* + * This package contains tests for the translator to Scala. + */ +trait Package diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.soda b/translator/src/test/scala/soda/translator/extension/toscala/Package.soda new file mode 100644 index 00000000..a8e0c57d --- /dev/null +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.extension.toscala + +/* + * This package contains tests for the translator to Scala. + */ \ No newline at end of file diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala index b74765e1..05948f7d 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + /** * This tests how translation is done for Scala reserved words that are not Soda reserved words. */ diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.soda index 416957f9..d3c107e5 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala /** * This tests how translation is done for Scala reserved words that are not Soda reserved words. diff --git a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala index 42c513c1..9bab7f71 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class MainSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.soda index 5b400815..bb6c3a75 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class MainSpec () extends diff --git a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala index 071e7dc8..d3659b07 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala @@ -1,5 +1,9 @@ package soda.translator.extension.toscala +/* + * This package contains tests for the translator to Scala. + */ + case class UpperAndLowerBoundDeclarationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.soda index 55e441ad..9f38583b 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.extension.toscala class UpperAndLowerBoundDeclarationSpec () extends diff --git a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala b/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala index e09b0742..d075f049 100644 --- a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala +++ b/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala @@ -1,5 +1,11 @@ package soda.translator.io +/* + * This package contains tests for the directory scanner. + */ + + + case class DirectoryScannerSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -31,9 +37,13 @@ case class DirectoryScannerSpec () "Example.md", "Example.scala", "Example.soda", + "Package.scala", + "Package.soda", "otherexample/OtherExample.scala", "otherexample/OtherExample.soda", - "otherexample/OtherExample.txt" + "otherexample/OtherExample.txt", + "otherexample/Package.scala", + "otherexample/Package.soda" ).map ( x => new File (start, x) ).toSet ) ) diff --git a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.soda b/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.soda index 08eaf0e0..1f69ce82 100644 --- a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.soda +++ b/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.io class DirectoryScannerSpec () extends @@ -31,9 +30,13 @@ class DirectoryScannerSpec () "Example.md", "Example.scala", "Example.soda", + "Package.scala", + "Package.soda", "otherexample/OtherExample.scala", "otherexample/OtherExample.soda", - "otherexample/OtherExample.txt" + "otherexample/OtherExample.txt", + "otherexample/Package.scala", + "otherexample/Package.soda" ).map ( lambda x --> @new File (start, x) ).toSet ) ) diff --git a/translator/src/test/scala/soda/translator/io/Package.scala b/translator/src/test/scala/soda/translator/io/Package.scala new file mode 100644 index 00000000..f3f34ca3 --- /dev/null +++ b/translator/src/test/scala/soda/translator/io/Package.scala @@ -0,0 +1,7 @@ +package soda.translator.io + +/* + * This package contains tests for the directory scanner. + */ + +trait Package diff --git a/translator/src/test/scala/soda/translator/io/Package.soda b/translator/src/test/scala/soda/translator/io/Package.soda new file mode 100644 index 00000000..bb1756a7 --- /dev/null +++ b/translator/src/test/scala/soda/translator/io/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.io + +/* + * This package contains tests for the directory scanner. + */ diff --git a/translator/src/test/scala/soda/translator/parser/BlockSpec.scala b/translator/src/test/scala/soda/translator/parser/BlockSpec.scala index 1e3947ad..09141e6d 100644 --- a/translator/src/test/scala/soda/translator/parser/BlockSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/BlockSpec.scala @@ -1,5 +1,11 @@ package soda.translator.parser +/* + * This package contains tests for the Soda parser. + */ + + + case class BlockSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/parser/BlockSpec.soda b/translator/src/test/scala/soda/translator/parser/BlockSpec.soda index fa28d689..8c41c299 100644 --- a/translator/src/test/scala/soda/translator/parser/BlockSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/BlockSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.parser class BlockSpec () extends diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala new file mode 100644 index 00000000..adfd8166 --- /dev/null +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -0,0 +1,7 @@ +package soda.translator.parser + +/* + * This package contains tests for the Soda parser. + */ + +trait Package diff --git a/translator/src/test/scala/soda/translator/parser/Package.soda b/translator/src/test/scala/soda/translator/parser/Package.soda new file mode 100644 index 00000000..2f1602ab --- /dev/null +++ b/translator/src/test/scala/soda/translator/parser/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.parser + +/* + * This package contains tests for the Soda parser. + */ diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala index 3e55f81d..edf5d7c4 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala @@ -1,5 +1,11 @@ package soda.translator.parser +/* + * This package contains tests for the Soda parser. + */ + + + case class PreprocessorSequenceTranslatorSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index a77a3e25..28000751 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.parser class PreprocessorSequenceTranslatorSpec () extends diff --git a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala index 28d73e75..c2a38046 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains tests for block annotations. + */ + + + case class BlockAnnotationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda index b760cc53..8415e4f9 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class BlockAnnotationSpec () extends diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala index f0a5fc02..761afee8 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains tests for block annotations. + */ + + + case class ClassBeginningAnnotationSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda index e67ac0e8..547d0f37 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ClassBeginningAnnotationSpec () extends diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala index 26f7b18f..78042c09 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala @@ -1,5 +1,11 @@ package soda.translator.parser.annotation +/* + * This package contains tests for block annotations. + */ + + + trait ExampleProgram { diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda index 7ddcdcf5..f55115d8 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda @@ -1,4 +1,3 @@ -package soda.translator.parser.annotation class ExampleProgram diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala new file mode 100644 index 00000000..c42eab1d --- /dev/null +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala @@ -0,0 +1,7 @@ +package soda.translator.parser.annotation + +/* + * This package contains tests for block annotations. + */ + +trait Package diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.soda b/translator/src/test/scala/soda/translator/parser/annotation/Package.soda new file mode 100644 index 00000000..178375d8 --- /dev/null +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.parser.annotation + +/* + * This package contains tests for block annotations. + */ diff --git a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala b/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala index bdbe7072..abd8f6e4 100644 --- a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala +++ b/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala @@ -1,5 +1,11 @@ package soda.translator.replacement +/* + * This package contains tests for replacement helper functions. + */ + + + case class CharTypeSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.soda b/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.soda index b33a4a1c..a04953bf 100644 --- a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.soda +++ b/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement class CharTypeSpec () extends diff --git a/translator/src/test/scala/soda/translator/replacement/Package.scala b/translator/src/test/scala/soda/translator/replacement/Package.scala new file mode 100644 index 00000000..4bb16f74 --- /dev/null +++ b/translator/src/test/scala/soda/translator/replacement/Package.scala @@ -0,0 +1,7 @@ +package soda.translator.replacement + +/* + * This package contains tests for replacement helper functions. + */ + +trait Package diff --git a/translator/src/test/scala/soda/translator/replacement/Package.soda b/translator/src/test/scala/soda/translator/replacement/Package.soda new file mode 100644 index 00000000..697fa0ef --- /dev/null +++ b/translator/src/test/scala/soda/translator/replacement/Package.soda @@ -0,0 +1,5 @@ +package soda.translator.replacement + +/* + * This package contains tests for replacement helper functions. + */ diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala index 55e76b34..d201f989 100644 --- a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala +++ b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala @@ -1,5 +1,11 @@ package soda.translator.replacement +/* + * This package contains tests for replacement helper functions. + */ + + + case class ReplacementAuxSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda index 087678c3..5084b117 100644 --- a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda +++ b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement class ReplacementAuxSpec () extends diff --git a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala b/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala index e3118ce7..191acab2 100644 --- a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala +++ b/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala @@ -1,5 +1,11 @@ package soda.translator.replacement +/* + * This package contains tests for replacement helper functions. + */ + + + case class TokenizerSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.soda b/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.soda index 53aa378c..3a6fa044 100644 --- a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.soda +++ b/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.soda @@ -1,4 +1,3 @@ -package soda.translator.replacement class TokenizerSpec () extends From 6098a2583c26901f2939c3f32b185a9757d6deba Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 20:58:41 +0100 Subject: [PATCH 50/71] Replace Scala files by Package.scala in examples --- .../soda/example/algorithms/FizzBuzz.scala | 35 -- .../algorithms/FizzBuzzPatternMatching.scala | 34 -- .../soda/example/algorithms/HelloWorld.scala | 23 - .../soda/example/algorithms/Package.scala | 446 ++++++++++++++++++ .../example/algorithms/PatternMatching.scala | 82 ---- .../soda/example/algorithms/SaladMaker.scala | 25 - .../ScalaReservedWordEscaping.scala | 45 -- .../soda/example/algorithms/SortExample.scala | 224 --------- .../soda/example/algorithms/SwapExample.scala | 50 -- .../ethicalissues/fairness/Fairness.scala | 54 --- .../ethicalissues/fairness/Package.scala | 48 ++ .../ethicalissues/pricemonitor/Package.scala | 207 ++++++++ .../pricemonitor/PriceMonitor.scala | 60 --- .../pricemonitor/Requirement1Monitor.scala | 57 --- .../pricemonitor/Requirement2Monitor.scala | 43 -- .../pricemonitor/Requirement3Monitor.scala | 79 ---- .../example/forcoq/algorithms/Package.scala | 45 ++ .../forcoq/algorithms/RecursionForCoq.scala | 53 --- .../scala/soda/example/forcoq/lib/List.scala | 75 --- .../scala/soda/example/forcoq/lib/Nat.scala | 95 ---- .../soda/example/forcoq/lib/Package.scala | 154 ++++++ .../forcoq/mathematics/FactorialForCoq.scala | 29 -- .../mathematics/FiboExampleInSodaForCoq.scala | 30 -- .../example/forcoq/mathematics/Package.scala | 64 +++ .../mathematics/TriangularNumberForCoq.scala | 29 -- .../example/inanutshell/InANutshell.scala | 172 ------- .../soda/example/inanutshell/Package.scala | 164 +++++++ .../mathematics/FactorialConcise.scala | 25 - .../FactorialPatternMatching.scala | 26 - .../mathematics/FactorialWithFold.scala | 22 - .../example/mathematics/FiboExample.scala | 23 - .../example/mathematics/HardProblem.scala | 157 ------ .../soda/example/mathematics/Package.scala | 290 ++++++++++++ .../soda/example/mathematics/PiIterator.scala | 91 ---- .../example/miniexample/MiniExample.scala | 37 -- .../soda/example/miniexample/Package.scala | 29 ++ .../example/algorithms/FizzBuzzSpec.scala | 50 -- .../soda/example/algorithms/Package.scala | 252 ++++++++++ .../algorithms/PatternMatchingSpec.scala | 67 --- .../example/algorithms/SaladMakerSpec.scala | 68 --- .../example/algorithms/SortExampleSpec.scala | 99 ---- .../ethicalissues/fairness/FairnessSpec.scala | 43 -- .../ethicalissues/fairness/Package.scala | 35 ++ .../ethicalissues/pricemonitor/Package.scala | 134 ++++++ .../pricemonitor/PriceMonitorSpec.scala | 142 ------ .../example/forcoq/algorithms/Package.scala | 64 +++ .../algorithms/RecursionForCoqSpec.scala | 72 --- .../soda/example/forcoq/lib/ListSpec.scala | 33 -- .../soda/example/forcoq/lib/NatSpec.scala | 49 -- .../soda/example/forcoq/lib/Package.scala | 66 +++ .../mathematics/FactorialForCoqSpec.scala | 40 -- .../FiboExampleInSodaForCoqSpec.scala | 40 -- .../example/forcoq/mathematics/Package.scala | 96 ++++ .../TriangularNumberForCoqSpec.scala | 40 -- .../example/mathematics/FactorialSpec.scala | 57 --- .../example/mathematics/FiboExampleSpec.scala | 33 -- .../example/mathematics/HardProblemSpec.scala | 84 ---- .../soda/example/mathematics/Package.scala | 173 +++++++ .../example/mathematics/PiIteratorSpec.scala | 31 -- 59 files changed, 2267 insertions(+), 2623 deletions(-) delete mode 100644 examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/HelloWorld.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/PatternMatching.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/SaladMaker.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/SortExample.scala delete mode 100644 examples/src/main/scala/soda/example/algorithms/SwapExample.scala delete mode 100644 examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala delete mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala delete mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala delete mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala delete mode 100644 examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/lib/List.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/lib/Nat.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala delete mode 100644 examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala delete mode 100644 examples/src/main/scala/soda/example/inanutshell/InANutshell.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/FiboExample.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/HardProblem.scala delete mode 100644 examples/src/main/scala/soda/example/mathematics/PiIterator.scala delete mode 100644 examples/src/main/scala/soda/example/miniexample/MiniExample.scala delete mode 100644 examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala delete mode 100644 examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala delete mode 100644 examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala delete mode 100644 examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala delete mode 100644 examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala delete mode 100644 examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala delete mode 100644 examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala delete mode 100644 examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala delete mode 100644 examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala delete mode 100644 examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala delete mode 100644 examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala deleted file mode 100644 index 377572c2..00000000 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzz.scala +++ /dev/null @@ -1,35 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait FizzBuzz -{ - - lazy val fizz = "Fizz" - - lazy val buzz = "Buzz" - - private lazy val _range = soda.lib.Range_ () - - lazy val apply : Seq [String] = - _range.apply (100) - .map ( (x : Int) => x + 1) - .map (_get_fizz_buzz_term) - - private def _get_fizz_buzz_term (n : Int) : String = - if ( _is_divisible_by (n) (15) ) fizz + buzz - else if ( _is_divisible_by (n) (3) ) fizz - else if ( _is_divisible_by (n) (5) ) buzz - else n.toString - - private def _is_divisible_by (n : Int) (k : Int) : Boolean = - n % k == 0 - -} - -case class FizzBuzz_ () extends FizzBuzz diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala deleted file mode 100644 index 01408a23..00000000 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzPatternMatching.scala +++ /dev/null @@ -1,34 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait FizzBuzzPatternMatching -{ - - lazy val fizz = "Fizz" - - lazy val buzz = "Buzz" - - private lazy val _range = soda.lib.Range_ () - - lazy val apply : Seq [String] = - _range.apply (100) - .map ( (x : Int) => x + 1) - .map (_get_fizz_buzz_term) - - private def _get_fizz_buzz_term (n : Int) : String = - Tuple2 (n % 3, n % 5) match { - case Tuple2 (0, 0) => fizz + buzz - case Tuple2 (0, x) => fizz - case Tuple2 (x, 0) => buzz - case x => n.toString - } - -} - -case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching diff --git a/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala b/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala deleted file mode 100644 index b38f51ed..00000000 --- a/examples/src/main/scala/soda/example/algorithms/HelloWorld.scala +++ /dev/null @@ -1,23 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait Main -{ - - def main (arguments : Array [String] ) : Unit = - println ("Hello world!") - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index 3c0fe0b9..c992054a 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -6,3 +6,449 @@ package soda.example.algorithms */ trait Package +trait FizzBuzzPatternMatching +{ + + lazy val fizz = "Fizz" + + lazy val buzz = "Buzz" + + private lazy val _range = soda.lib.Range_ () + + lazy val apply : Seq [String] = + _range.apply (100) + .map ( (x : Int) => x + 1) + .map (_get_fizz_buzz_term) + + private def _get_fizz_buzz_term (n : Int) : String = + Tuple2 (n % 3, n % 5) match { + case Tuple2 (0, 0) => fizz + buzz + case Tuple2 (0, x) => fizz + case Tuple2 (x, 0) => buzz + case x => n.toString + } + +} + +case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching +trait SaladMaker +{ + + def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) + ) salad_so_far + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) + +} + +case class SaladMaker_ () extends SaladMaker +trait ScalaReservedWordEscaping +{ + + private lazy val __soda__var = "var" + + private lazy val __soda__val = 1 + + private def __soda__def [A, B] (key : A) (value : B) : MyPair [A, B] = MyPair_ (key, value) + + private def __soda__while [A, B] (seq : Seq [A] ) (cond : A => Boolean) (funct : A => B) : Seq [B] = + seq.takeWhile (cond).map (funct) + + private lazy val __soda__protected = "protected" + + private lazy val __soda__private = "private" + + def f (x : Int) (y : Int) : Int = x + y + + lazy val cons : Int => Int => Int = + x => + y => + f (x) (y) + +} + +case class ScalaReservedWordEscaping_ () extends ScalaReservedWordEscaping + +trait MyPair [A, B] +{ + + def key : A + def value : B + +} + +case class MyPair_ [A, B] (key : A, value : B) extends MyPair [A, B] +trait Parameter +{ + + def name : String + +} + +case class Parameter_ (name : String) extends Parameter + +trait PatternMatching +{ + + def get_value (p : Parameter) : Int = + p match { + case Singleton_ (x) => x + case Pair_ (x, y) => (x + y) / 2 + case Triplet_ (x, y, z) => (x + y + z) / 3 + case x => 0 + } + + def get_type_name (p : Parameter) : String = + p match { + case Singleton_ (x) => (Singleton_ (x) ).name + "(x)" + case Pair_ (x, y) => (Pair_ (x, y) ).name + "(x, y)" + case Triplet_ (x, y, z) => (Triplet_ (x, y, z) ).name + "(x, y, z)" + case x => "" + } + +} + +case class PatternMatching_ () extends PatternMatching + +trait Singleton + extends + Parameter +{ + + def x : Int + + lazy val name = "singleton" + +} + +case class Singleton_ (x : Int) extends Singleton + +trait Pair + extends + Parameter +{ + + def x : Int + def y : Int + + lazy val name = "pair" + +} + +case class Pair_ (x : Int, y : Int) extends Pair + +trait Triplet + extends + Parameter +{ + + def x : Int + def y : Int + def z : Int + + lazy val name = "triplet" + +} + +case class Triplet_ (x : Int, y : Int, z : Int) extends Triplet +trait FizzBuzz +{ + + lazy val fizz = "Fizz" + + lazy val buzz = "Buzz" + + private lazy val _range = soda.lib.Range_ () + + lazy val apply : Seq [String] = + _range.apply (100) + .map ( (x : Int) => x + 1) + .map (_get_fizz_buzz_term) + + private def _get_fizz_buzz_term (n : Int) : String = + if ( _is_divisible_by (n) (15) ) fizz + buzz + else if ( _is_divisible_by (n) (3) ) fizz + else if ( _is_divisible_by (n) (5) ) buzz + else n.toString + + private def _is_divisible_by (n : Int) (k : Int) : Boolean = + n % k == 0 + +} + +case class FizzBuzz_ () extends FizzBuzz +trait SortExample +{ + + def is_sorted : Seq [Int] => Boolean + +} + +case class SortExample_ (is_sorted : Seq [Int] => Boolean) extends SortExample + +trait SortExampleWithAt + extends + SortExample +{ + + lazy val is_sorted : Seq [Int] => Boolean = + sequence => is_sorted_for (sequence) + + def is_sorted_for (sequence : Seq [Int] ) : Boolean = + sequence + .indices + .filter ( index => index > 0) + .forall ( index => sequence.apply (index - 1) <= sequence.apply (index) ) + +} + +case class SortExampleWithAt_ () extends SortExampleWithAt + +trait SortExampleWithZip + extends + SortExample +{ + + lazy val is_sorted : Seq [Int] => Boolean = + sequence => is_sorted_for (sequence) + + def is_sorted_for (sequence : Seq [Int] ) : Boolean = + sequence + .zip (sequence.tail) + .forall ( pair => (pair._1 <= pair._2) ) + +} + +case class SortExampleWithZip_ () extends SortExampleWithZip + +trait SortAlgorithmExample +{ + + def sort : Seq [Int] => Seq [Int] + +} + +case class SortAlgorithmExample_ (sort : Seq [Int] => Seq [Int]) extends SortAlgorithmExample + +trait SortAlgorithmExampleWithFold + extends + SortAlgorithmExample +{ + + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () + + lazy val sort : Seq [Int] => Seq [Int] = + sequence => sort_for (sequence) + + def sort_for (sequence : Seq [Int] ) : Seq [Int] = + if ( sequence.length < 2 + ) sequence + else _fold.apply (sequence) (_initial_value) (_next_value_function) + + private lazy val _initial_value = Seq [Int] () + + private def _next_value_function (current_sequence : Seq [Int] ) (elem : Int) : Seq [Int] = + insert_sorted (current_sequence) (elem) + + def insert_sorted (sequence : Seq [Int] ) (element : Int) : Seq [Int] = + concatenate ( + first_part = sequence.takeWhile ( x => x < element) ) ( + middle = Seq (element) ) ( + last_part = sequence.dropWhile ( x => x < element) + ) + + def concatenate (first_part : Seq [Int] ) (middle : Seq [Int] ) (last_part : Seq [Int] ) : Seq [Int] = + first_part.++ (middle.++ (last_part) ) + +} + +case class SortAlgorithmExampleWithFold_ () extends SortAlgorithmExampleWithFold + +trait ConstrainedSortAlgorithm +{ + + import soda.lib.OptionSD + import soda.lib.SomeSD_ + import soda.lib.NoneSD_ + + def sort (sequence : Seq [Int] ) : OptionSD [Seq [Int] ] = + sort_with ( SortAlgorithmExampleWithFold_ ().sort (sequence) ) + + def sort_with (sorted_sequence : Seq [Int] ) : OptionSD [Seq [Int] ] = + if ( SortExampleWithZip_ ().is_sorted (sorted_sequence) + ) SomeSD_ (sorted_sequence) + else NoneSD_ [Seq [Int] ] () + +} + +case class ConstrainedSortAlgorithm_ () extends ConstrainedSortAlgorithm + +trait SortedSequence [A <: Comparable [A] ] +{ + + def sequence : Seq [A] + def add : A => SortedSequence [A] + def invariant : Boolean + +} + +case class SortedSequence_ [A <: Comparable [A]] (sequence : Seq [A], add : A => SortedSequence [A], invariant : Boolean) extends SortedSequence [A] + +trait EmptySortedSequence [A <: Comparable [A] ] + extends + SortedSequence [A] +{ + + lazy val sequence = Seq () + + lazy val add : A => SortedSequence [A] = + element => add_for (element) + + def add_for (element : A) : SortedSequence [A] = + NonEmptySortedSequence_ (Seq (element) ) + + lazy val invariant : Boolean = true + +} + +case class EmptySortedSequence_ [A <: Comparable [A]] () extends EmptySortedSequence [A] + +trait SortedSequenceWithElements [A <: Comparable [A] ] + extends + SortedSequence [A] +{ + + def sequence : Seq [A] + def add : A => SortedSequence [A] + def invariant : Boolean + +} + +case class SortedSequenceWithElements_ [A <: Comparable [A]] (sequence : Seq [A], add : A => SortedSequence [A], invariant : Boolean) extends SortedSequenceWithElements [A] + +trait NonEmptySortedSequence [A <: Comparable [A] ] + extends + SortedSequenceWithElements [A] +{ + + def sequence : Seq [A] + + lazy val aux = NonEmptySortedSequenceAux_ [A] () + + lazy val add : A => SortedSequence [A] = + element => add_for (element) + + def add_for (element : A) : SortedSequence [A] = + NonEmptySortedSequence_ (aux.insert_sorted (sequence) (element) ) + + lazy val invariant : Boolean = aux.is_sorted (sequence) + +} + +case class NonEmptySortedSequence_ [A <: Comparable [A]] (sequence : Seq [A]) extends NonEmptySortedSequence [A] + +trait NonEmptySortedSequenceAux [A <: Comparable [A] ] +{ + + def is_less_than (x : A) (y : A) : Boolean = + x.compareTo (y) < 0 + + def is_sorted (other_sequence : Seq [A] ) : Boolean = + other_sequence + .zip (other_sequence.tail) + .forall ( pair => is_less_than (pair._1) (pair._2) ) + + def insert_sorted (original_sequence : Seq [A] ) (element : A) : Seq [A] = + concatenate ( + first_part = original_sequence.takeWhile ( x => is_less_than (x) (element) ) ) ( + middle = Seq (element) ) ( + last_part = original_sequence.dropWhile ( x => is_less_than (x) (element) ) + ) + + def concatenate (first_part : Seq [A] ) (middle : Seq [A] ) (last_part : Seq [A] ) : Seq [A] = + first_part.++ (middle.++ (last_part) ) + +} + +case class NonEmptySortedSequenceAux_ [A <: Comparable [A]] () extends NonEmptySortedSequenceAux [A] + +trait SortedSequenceBuilder [A <: Comparable [A] ] +{ + + import soda.lib.Fold_ + + private lazy val _fold = Fold_ () + + def build (sequence : Seq [A] ) : SortedSequence [A] = + _fold.apply (sequence) (_initial_value) (_next_value_function) + + private lazy val _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () + + private def _next_value_function (sorted_sequence : SortedSequence [A] ) (element : A) : SortedSequence [A] = + sorted_sequence.add (element) + +} + +case class SortedSequenceBuilder_ [A <: Comparable [A]] () extends SortedSequenceBuilder [A] +trait PairExample +{ + + def left : Int + def right : Int + +} + +case class PairExample_ (left : Int, right : Int) extends PairExample + +trait SwapExample +{ + + def left (pair : PairExample) : Int = + pair match { + case (PairExample_ (x , y) ) => x + } + + def right (pair : PairExample) : Int = + pair match { + case (PairExample_ (x , y) ) => y + } + + def swap (pair : PairExample) : PairExample = + PairExample_ (right (pair) , left (pair) ) + +/* theorem + swap_of_swap : forall (pair : PairExample) , (swap (swap (pair) ) ) = pair +*/ + +/* proof + intros p. + destruct p. + compute. + destruct x. + apply eq_refl. +*/ + +} + +case class SwapExample_ () extends SwapExample +trait Main +{ + + def main (arguments : Array [String] ) : Unit = + println ("Hello world!") + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main diff --git a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala b/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala deleted file mode 100644 index 872f4ba9..00000000 --- a/examples/src/main/scala/soda/example/algorithms/PatternMatching.scala +++ /dev/null @@ -1,82 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait Parameter -{ - - def name : String - -} - -case class Parameter_ (name : String) extends Parameter - -trait PatternMatching -{ - - def get_value (p : Parameter) : Int = - p match { - case Singleton_ (x) => x - case Pair_ (x, y) => (x + y) / 2 - case Triplet_ (x, y, z) => (x + y + z) / 3 - case x => 0 - } - - def get_type_name (p : Parameter) : String = - p match { - case Singleton_ (x) => (Singleton_ (x) ).name + "(x)" - case Pair_ (x, y) => (Pair_ (x, y) ).name + "(x, y)" - case Triplet_ (x, y, z) => (Triplet_ (x, y, z) ).name + "(x, y, z)" - case x => "" - } - -} - -case class PatternMatching_ () extends PatternMatching - -trait Singleton - extends - Parameter -{ - - def x : Int - - lazy val name = "singleton" - -} - -case class Singleton_ (x : Int) extends Singleton - -trait Pair - extends - Parameter -{ - - def x : Int - def y : Int - - lazy val name = "pair" - -} - -case class Pair_ (x : Int, y : Int) extends Pair - -trait Triplet - extends - Parameter -{ - - def x : Int - def y : Int - def z : Int - - lazy val name = "triplet" - -} - -case class Triplet_ (x : Int, y : Int, z : Int) extends Triplet diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala b/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala deleted file mode 100644 index 69f79af0..00000000 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.scala +++ /dev/null @@ -1,25 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait SaladMaker -{ - - def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) - ) salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - -} - -case class SaladMaker_ () extends SaladMaker diff --git a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala b/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala deleted file mode 100644 index 5c283b27..00000000 --- a/examples/src/main/scala/soda/example/algorithms/ScalaReservedWordEscaping.scala +++ /dev/null @@ -1,45 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait ScalaReservedWordEscaping -{ - - private lazy val __soda__var = "var" - - private lazy val __soda__val = 1 - - private def __soda__def [A, B] (key : A) (value : B) : MyPair [A, B] = MyPair_ (key, value) - - private def __soda__while [A, B] (seq : Seq [A] ) (cond : A => Boolean) (funct : A => B) : Seq [B] = - seq.takeWhile (cond).map (funct) - - private lazy val __soda__protected = "protected" - - private lazy val __soda__private = "private" - - def f (x : Int) (y : Int) : Int = x + y - - lazy val cons : Int => Int => Int = - x => - y => - f (x) (y) - -} - -case class ScalaReservedWordEscaping_ () extends ScalaReservedWordEscaping - -trait MyPair [A, B] -{ - - def key : A - def value : B - -} - -case class MyPair_ [A, B] (key : A, value : B) extends MyPair [A, B] diff --git a/examples/src/main/scala/soda/example/algorithms/SortExample.scala b/examples/src/main/scala/soda/example/algorithms/SortExample.scala deleted file mode 100644 index 9dfc3b55..00000000 --- a/examples/src/main/scala/soda/example/algorithms/SortExample.scala +++ /dev/null @@ -1,224 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait SortExample -{ - - def is_sorted : Seq [Int] => Boolean - -} - -case class SortExample_ (is_sorted : Seq [Int] => Boolean) extends SortExample - -trait SortExampleWithAt - extends - SortExample -{ - - lazy val is_sorted : Seq [Int] => Boolean = - sequence => is_sorted_for (sequence) - - def is_sorted_for (sequence : Seq [Int] ) : Boolean = - sequence - .indices - .filter ( index => index > 0) - .forall ( index => sequence.apply (index - 1) <= sequence.apply (index) ) - -} - -case class SortExampleWithAt_ () extends SortExampleWithAt - -trait SortExampleWithZip - extends - SortExample -{ - - lazy val is_sorted : Seq [Int] => Boolean = - sequence => is_sorted_for (sequence) - - def is_sorted_for (sequence : Seq [Int] ) : Boolean = - sequence - .zip (sequence.tail) - .forall ( pair => (pair._1 <= pair._2) ) - -} - -case class SortExampleWithZip_ () extends SortExampleWithZip - -trait SortAlgorithmExample -{ - - def sort : Seq [Int] => Seq [Int] - -} - -case class SortAlgorithmExample_ (sort : Seq [Int] => Seq [Int]) extends SortAlgorithmExample - -trait SortAlgorithmExampleWithFold - extends - SortAlgorithmExample -{ - - import soda.lib.Fold_ - - private lazy val _fold = Fold_ () - - lazy val sort : Seq [Int] => Seq [Int] = - sequence => sort_for (sequence) - - def sort_for (sequence : Seq [Int] ) : Seq [Int] = - if ( sequence.length < 2 - ) sequence - else _fold.apply (sequence) (_initial_value) (_next_value_function) - - private lazy val _initial_value = Seq [Int] () - - private def _next_value_function (current_sequence : Seq [Int] ) (elem : Int) : Seq [Int] = - insert_sorted (current_sequence) (elem) - - def insert_sorted (sequence : Seq [Int] ) (element : Int) : Seq [Int] = - concatenate ( - first_part = sequence.takeWhile ( x => x < element) ) ( - middle = Seq (element) ) ( - last_part = sequence.dropWhile ( x => x < element) - ) - - def concatenate (first_part : Seq [Int] ) (middle : Seq [Int] ) (last_part : Seq [Int] ) : Seq [Int] = - first_part.++ (middle.++ (last_part) ) - -} - -case class SortAlgorithmExampleWithFold_ () extends SortAlgorithmExampleWithFold - -trait ConstrainedSortAlgorithm -{ - - import soda.lib.OptionSD - import soda.lib.SomeSD_ - import soda.lib.NoneSD_ - - def sort (sequence : Seq [Int] ) : OptionSD [Seq [Int] ] = - sort_with ( SortAlgorithmExampleWithFold_ ().sort (sequence) ) - - def sort_with (sorted_sequence : Seq [Int] ) : OptionSD [Seq [Int] ] = - if ( SortExampleWithZip_ ().is_sorted (sorted_sequence) - ) SomeSD_ (sorted_sequence) - else NoneSD_ [Seq [Int] ] () - -} - -case class ConstrainedSortAlgorithm_ () extends ConstrainedSortAlgorithm - -trait SortedSequence [A <: Comparable [A] ] -{ - - def sequence : Seq [A] - def add : A => SortedSequence [A] - def invariant : Boolean - -} - -case class SortedSequence_ [A <: Comparable [A]] (sequence : Seq [A], add : A => SortedSequence [A], invariant : Boolean) extends SortedSequence [A] - -trait EmptySortedSequence [A <: Comparable [A] ] - extends - SortedSequence [A] -{ - - lazy val sequence = Seq () - - lazy val add : A => SortedSequence [A] = - element => add_for (element) - - def add_for (element : A) : SortedSequence [A] = - NonEmptySortedSequence_ (Seq (element) ) - - lazy val invariant : Boolean = true - -} - -case class EmptySortedSequence_ [A <: Comparable [A]] () extends EmptySortedSequence [A] - -trait SortedSequenceWithElements [A <: Comparable [A] ] - extends - SortedSequence [A] -{ - - def sequence : Seq [A] - def add : A => SortedSequence [A] - def invariant : Boolean - -} - -case class SortedSequenceWithElements_ [A <: Comparable [A]] (sequence : Seq [A], add : A => SortedSequence [A], invariant : Boolean) extends SortedSequenceWithElements [A] - -trait NonEmptySortedSequence [A <: Comparable [A] ] - extends - SortedSequenceWithElements [A] -{ - - def sequence : Seq [A] - - lazy val aux = NonEmptySortedSequenceAux_ [A] () - - lazy val add : A => SortedSequence [A] = - element => add_for (element) - - def add_for (element : A) : SortedSequence [A] = - NonEmptySortedSequence_ (aux.insert_sorted (sequence) (element) ) - - lazy val invariant : Boolean = aux.is_sorted (sequence) - -} - -case class NonEmptySortedSequence_ [A <: Comparable [A]] (sequence : Seq [A]) extends NonEmptySortedSequence [A] - -trait NonEmptySortedSequenceAux [A <: Comparable [A] ] -{ - - def is_less_than (x : A) (y : A) : Boolean = - x.compareTo (y) < 0 - - def is_sorted (other_sequence : Seq [A] ) : Boolean = - other_sequence - .zip (other_sequence.tail) - .forall ( pair => is_less_than (pair._1) (pair._2) ) - - def insert_sorted (original_sequence : Seq [A] ) (element : A) : Seq [A] = - concatenate ( - first_part = original_sequence.takeWhile ( x => is_less_than (x) (element) ) ) ( - middle = Seq (element) ) ( - last_part = original_sequence.dropWhile ( x => is_less_than (x) (element) ) - ) - - def concatenate (first_part : Seq [A] ) (middle : Seq [A] ) (last_part : Seq [A] ) : Seq [A] = - first_part.++ (middle.++ (last_part) ) - -} - -case class NonEmptySortedSequenceAux_ [A <: Comparable [A]] () extends NonEmptySortedSequenceAux [A] - -trait SortedSequenceBuilder [A <: Comparable [A] ] -{ - - import soda.lib.Fold_ - - private lazy val _fold = Fold_ () - - def build (sequence : Seq [A] ) : SortedSequence [A] = - _fold.apply (sequence) (_initial_value) (_next_value_function) - - private lazy val _initial_value : SortedSequence [A] = EmptySortedSequence_ [A] () - - private def _next_value_function (sorted_sequence : SortedSequence [A] ) (element : A) : SortedSequence [A] = - sorted_sequence.add (element) - -} - -case class SortedSequenceBuilder_ [A <: Comparable [A]] () extends SortedSequenceBuilder [A] diff --git a/examples/src/main/scala/soda/example/algorithms/SwapExample.scala b/examples/src/main/scala/soda/example/algorithms/SwapExample.scala deleted file mode 100644 index a450ec58..00000000 --- a/examples/src/main/scala/soda/example/algorithms/SwapExample.scala +++ /dev/null @@ -1,50 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains examples in Soda. - * These examples focus on simple algorithms. - */ - - - -trait PairExample -{ - - def left : Int - def right : Int - -} - -case class PairExample_ (left : Int, right : Int) extends PairExample - -trait SwapExample -{ - - def left (pair : PairExample) : Int = - pair match { - case (PairExample_ (x , y) ) => x - } - - def right (pair : PairExample) : Int = - pair match { - case (PairExample_ (x , y) ) => y - } - - def swap (pair : PairExample) : PairExample = - PairExample_ (right (pair) , left (pair) ) - -/* theorem - swap_of_swap : forall (pair : PairExample) , (swap (swap (pair) ) ) = pair -*/ - -/* proof - intros p. - destruct p. - compute. - destruct x. - apply eq_refl. -*/ - -} - -case class SwapExample_ () extends SwapExample diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala deleted file mode 100644 index 04e7a018..00000000 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.scala +++ /dev/null @@ -1,54 +0,0 @@ -package soda.example.ethicalissues.fairness - -/* - * This package contains examples about ethical issues. - */ - - - -trait Applicant -{ - - def background_score : Double - -} - -case class Applicant_ (background_score : Double) extends Applicant - -trait AbstractFairness -{ - - def score_difference_tolerance : Double - def ranking_difference_tolerance : Double - def rank : Applicant => Double - -} - -case class AbstractFairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends AbstractFairness - -trait Fairness - extends - AbstractFairness -{ - - def score_difference_tolerance : Double - def ranking_difference_tolerance : Double - def rank : Applicant => Double - - def is_fair (alice : Applicant) (bob : Applicant) = - if ( have_similar_score (alice.background_score) (bob.background_score) - ) have_similar_ranking (rank (alice) ) (rank (bob)) - else true - - def have_similar_score (score1 : Double) (score2 : Double) = - difference_between (score1) (score2) < score_difference_tolerance - - def have_similar_ranking (result1 : Double) (result2 : Double) = - difference_between (result1) (result2) < ranking_difference_tolerance - - def difference_between (value : Double) (another_value : Double) = - Math.abs (value - another_value) - -} - -case class Fairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends Fairness diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala index 15b45e13..1d7527ab 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala @@ -5,3 +5,51 @@ package soda.example.ethicalissues.fairness */ trait Package + + +trait Applicant +{ + + def background_score : Double + +} + +case class Applicant_ (background_score : Double) extends Applicant + +trait AbstractFairness +{ + + def score_difference_tolerance : Double + def ranking_difference_tolerance : Double + def rank : Applicant => Double + +} + +case class AbstractFairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends AbstractFairness + +trait Fairness + extends + AbstractFairness +{ + + def score_difference_tolerance : Double + def ranking_difference_tolerance : Double + def rank : Applicant => Double + + def is_fair (alice : Applicant) (bob : Applicant) = + if ( have_similar_score (alice.background_score) (bob.background_score) + ) have_similar_ranking (rank (alice) ) (rank (bob)) + else true + + def have_similar_score (score1 : Double) (score2 : Double) = + difference_between (score1) (score2) < score_difference_tolerance + + def have_similar_ranking (result1 : Double) (result2 : Double) = + difference_between (result1) (result2) < ranking_difference_tolerance + + def difference_between (value : Double) (another_value : Double) = + Math.abs (value - another_value) + +} + +case class Fairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends Fairness diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala index 762e48dd..33a35f78 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -5,3 +5,210 @@ package soda.example.ethicalissues.pricemonitor */ trait Package +trait Report3 +{ + + def compliant : Boolean + def price_of_flight : Int + def price_of_flight_by_segments : Int + +} + +case class Report3_ (compliant : Boolean, price_of_flight : Int, price_of_flight_by_segments : Int) extends Report3 + +trait Requirement3Monitor + extends + RequirementMonitor +{ + + def pricing_agent : PricingAgent + + def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report3 = + get_report_with ( + get_price (customer) (flight) (date_in_days) ) ( + get_price_of_flight_by_segments (customer) (flight) (date_in_days) + ) + + def get_report_with (price_of_flight : Int) (price_of_flight_by_segments : Int) : Report3 = + Report3_ (price_of_flight <= price_of_flight_by_segments, price_of_flight, price_of_flight_by_segments) + + def get_price_of_flight_by_segments (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + sum_prices (get_prices_of_segments (customer) (SegmentsForFlight_ (flight).segments) (date_in_days) ) + + def get_prices_of_segments (customer : Customer) (segments : Seq [Segment] ) (date_in_days : Int) : Seq [Int] = + segments.map ( segment => get_price (customer) (segment) (date_in_days) ) + + def sum_prices (prices : Seq [Int] ) : Int = + prices.sum + +} + +case class Requirement3Monitor_ (pricing_agent : PricingAgent) extends Requirement3Monitor + +trait Segment + extends + Flight +{ + + def start_airport : String + def end_airport : String + + lazy val intermediate_airports = Seq [String] () + +} + +case class Segment_ (start_airport : String, end_airport : String) extends Segment + +trait SegmentsForFlight +{ + + def flight : Flight + + lazy val segments : Seq [Segment] = + rec_segments_multi (flight.start_airport) (flight.intermediate_airports) (flight.end_airport) + + def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = + intermediate_stops match { + case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x => Nil.+: (Segment_ (first_airport, last_airport) ) + } + +} + +case class SegmentsForFlight_ (flight : Flight) extends SegmentsForFlight +trait Report2 +{ + + def compliant : Boolean + def old_price : Int + def new_price : Int + +} + +case class Report2_ (compliant : Boolean, old_price : Int, new_price : Int) extends Report2 + +trait Requirement2Monitor + extends + RequirementMonitor +{ + + def pricing_agent : PricingAgent + + lazy val acceptable_increase = 1.25 + + def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report2 = + get_report_with ( + old_price = get_price (customer) (flight) (get_a_year_before (date_in_days) ) ) ( + new_price = get_price (customer) (flight) (date_in_days) + ) + + def get_report_with (old_price : Int) (new_price : Int) : Report2 = + Report2_ (new_price <= old_price * acceptable_increase, old_price, new_price) + + def get_a_year_before (date_in_days : Int) : Int = + date_in_days - 365 + +} + +case class Requirement2Monitor_ (pricing_agent : PricingAgent) extends Requirement2Monitor +trait Report1 +{ + + def compliant : Boolean + def price1 : Int + def price2 : Int + def similarity : Double + +} + +case class Report1_ (compliant : Boolean, price1 : Int, price2 : Int, similarity : Double) extends Report1 + +trait Requirement1Monitor + extends + RequirementMonitor +{ + + def pricing_agent : PricingAgent + + lazy val minimum_similarity = 0.95 + + def get_report (c1 : Customer) (c2 : Customer) (flight : Flight) (date : Int) : Report1 = + get_report_with ( + price1 = get_price (c1) (flight) (date) ) ( + price2 = get_price (c2) (flight) (date) + ) + + def get_report_with (price1 : Int) (price2 : Int) : Report1 = + get_report_with_similarity (price1) (price2) (get_similarity (price1) (price2) ) + + def get_report_with_similarity (price1 : Int) (price2 : Int) (similarity : Double) : Report1 = + Report1_ (minimum_similarity <= similarity, price1, price2, similarity) + + def get_similarity (x : Int) (y : Int) : Double = + 1.0 * (min (x) (y) ) / (max (x) (y) ) + + def min (x : Int) (y : Int) : Int = + if ( x < y + ) x + else y + + def max (x : Int) (y : Int) : Int = + if ( x < y + ) y + else x + +} + +case class Requirement1Monitor_ (pricing_agent : PricingAgent) extends Requirement1Monitor +trait Customer +{ + + def name : String + def ip_address : String + +} + +case class Customer_ (name : String, ip_address : String) extends Customer + +trait PricingAgent +{ + + import java.util.Date + + /** get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int */ + def abs_get_price : Customer => Flight => Int => Int + + def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + abs_get_price (customer) (flight) (date_in_days) + + lazy val milliseconds_per_day : Long = 24 * 60 * 60 * 1000 + + def get_days_for (date : Date) : Int = + (date.getTime / milliseconds_per_day).toInt + +} + +case class PricingAgent_ (abs_get_price : Customer => Flight => Int => Int) extends PricingAgent + +trait Flight +{ + + def start_airport : String + def intermediate_airports : Seq [String] + def end_airport : String + +} + +case class Flight_ (start_airport : String, intermediate_airports : Seq [String], end_airport : String) extends Flight + +trait RequirementMonitor +{ + + def pricing_agent : PricingAgent + + def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + pricing_agent.get_price (customer) (flight) (date_in_days) + +} + +case class RequirementMonitor_ (pricing_agent : PricingAgent) extends RequirementMonitor diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala deleted file mode 100644 index deac457e..00000000 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ /dev/null @@ -1,60 +0,0 @@ -package soda.example.ethicalissues.pricemonitor - -/* - * This package contains example classes for a price monitor. - */ - - - -trait Customer -{ - - def name : String - def ip_address : String - -} - -case class Customer_ (name : String, ip_address : String) extends Customer - -trait PricingAgent -{ - - import java.util.Date - - /** get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int */ - def abs_get_price : Customer => Flight => Int => Int - - def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - abs_get_price (customer) (flight) (date_in_days) - - lazy val milliseconds_per_day : Long = 24 * 60 * 60 * 1000 - - def get_days_for (date : Date) : Int = - (date.getTime / milliseconds_per_day).toInt - -} - -case class PricingAgent_ (abs_get_price : Customer => Flight => Int => Int) extends PricingAgent - -trait Flight -{ - - def start_airport : String - def intermediate_airports : Seq [String] - def end_airport : String - -} - -case class Flight_ (start_airport : String, intermediate_airports : Seq [String], end_airport : String) extends Flight - -trait RequirementMonitor -{ - - def pricing_agent : PricingAgent - - def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - pricing_agent.get_price (customer) (flight) (date_in_days) - -} - -case class RequirementMonitor_ (pricing_agent : PricingAgent) extends RequirementMonitor diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala deleted file mode 100644 index ffad1b75..00000000 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ /dev/null @@ -1,57 +0,0 @@ -package soda.example.ethicalissues.pricemonitor - -/* - * This package contains example classes for a price monitor. - */ - - - -trait Report1 -{ - - def compliant : Boolean - def price1 : Int - def price2 : Int - def similarity : Double - -} - -case class Report1_ (compliant : Boolean, price1 : Int, price2 : Int, similarity : Double) extends Report1 - -trait Requirement1Monitor - extends - RequirementMonitor -{ - - def pricing_agent : PricingAgent - - lazy val minimum_similarity = 0.95 - - def get_report (c1 : Customer) (c2 : Customer) (flight : Flight) (date : Int) : Report1 = - get_report_with ( - price1 = get_price (c1) (flight) (date) ) ( - price2 = get_price (c2) (flight) (date) - ) - - def get_report_with (price1 : Int) (price2 : Int) : Report1 = - get_report_with_similarity (price1) (price2) (get_similarity (price1) (price2) ) - - def get_report_with_similarity (price1 : Int) (price2 : Int) (similarity : Double) : Report1 = - Report1_ (minimum_similarity <= similarity, price1, price2, similarity) - - def get_similarity (x : Int) (y : Int) : Double = - 1.0 * (min (x) (y) ) / (max (x) (y) ) - - def min (x : Int) (y : Int) : Int = - if ( x < y - ) x - else y - - def max (x : Int) (y : Int) : Int = - if ( x < y - ) y - else x - -} - -case class Requirement1Monitor_ (pricing_agent : PricingAgent) extends Requirement1Monitor diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala deleted file mode 100644 index e6cebfff..00000000 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ /dev/null @@ -1,43 +0,0 @@ -package soda.example.ethicalissues.pricemonitor - -/* - * This package contains example classes for a price monitor. - */ - - - -trait Report2 -{ - - def compliant : Boolean - def old_price : Int - def new_price : Int - -} - -case class Report2_ (compliant : Boolean, old_price : Int, new_price : Int) extends Report2 - -trait Requirement2Monitor - extends - RequirementMonitor -{ - - def pricing_agent : PricingAgent - - lazy val acceptable_increase = 1.25 - - def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report2 = - get_report_with ( - old_price = get_price (customer) (flight) (get_a_year_before (date_in_days) ) ) ( - new_price = get_price (customer) (flight) (date_in_days) - ) - - def get_report_with (old_price : Int) (new_price : Int) : Report2 = - Report2_ (new_price <= old_price * acceptable_increase, old_price, new_price) - - def get_a_year_before (date_in_days : Int) : Int = - date_in_days - 365 - -} - -case class Requirement2Monitor_ (pricing_agent : PricingAgent) extends Requirement2Monitor diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala deleted file mode 100644 index ccdd129d..00000000 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ /dev/null @@ -1,79 +0,0 @@ -package soda.example.ethicalissues.pricemonitor - -/* - * This package contains example classes for a price monitor. - */ - - - -trait Report3 -{ - - def compliant : Boolean - def price_of_flight : Int - def price_of_flight_by_segments : Int - -} - -case class Report3_ (compliant : Boolean, price_of_flight : Int, price_of_flight_by_segments : Int) extends Report3 - -trait Requirement3Monitor - extends - RequirementMonitor -{ - - def pricing_agent : PricingAgent - - def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report3 = - get_report_with ( - get_price (customer) (flight) (date_in_days) ) ( - get_price_of_flight_by_segments (customer) (flight) (date_in_days) - ) - - def get_report_with (price_of_flight : Int) (price_of_flight_by_segments : Int) : Report3 = - Report3_ (price_of_flight <= price_of_flight_by_segments, price_of_flight, price_of_flight_by_segments) - - def get_price_of_flight_by_segments (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - sum_prices (get_prices_of_segments (customer) (SegmentsForFlight_ (flight).segments) (date_in_days) ) - - def get_prices_of_segments (customer : Customer) (segments : Seq [Segment] ) (date_in_days : Int) : Seq [Int] = - segments.map ( segment => get_price (customer) (segment) (date_in_days) ) - - def sum_prices (prices : Seq [Int] ) : Int = - prices.sum - -} - -case class Requirement3Monitor_ (pricing_agent : PricingAgent) extends Requirement3Monitor - -trait Segment - extends - Flight -{ - - def start_airport : String - def end_airport : String - - lazy val intermediate_airports = Seq [String] () - -} - -case class Segment_ (start_airport : String, end_airport : String) extends Segment - -trait SegmentsForFlight -{ - - def flight : Flight - - lazy val segments : Seq [Segment] = - rec_segments_multi (flight.start_airport) (flight.intermediate_airports) (flight.end_airport) - - def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = - intermediate_stops match { - case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) - case x => Nil.+: (Segment_ (first_airport, last_airport) ) - } - -} - -case class SegmentsForFlight_ (flight : Flight) extends SegmentsForFlight diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala index 98b0ee3f..4c908703 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala @@ -5,3 +5,48 @@ package soda.example.forcoq.algorithms */ trait Package +/** + * This class contains tail recursive auxiliary functions. + */ + +trait RecursionForCoq +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + sequence match { + case (head) :: (tail) => + if ( ( ! (condition (current_value) (head) ) ) + ) current_value + else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) + case x => current_value + } + + def fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = + sequence match { + case (head) :: (tail) => _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) + case x => current_value + } + + def fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _tailrec_fold3 (sequence) (initial_value) (next_value_function) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = + if ( n <= 0 + ) sequence + else _tailrec_range (n - 1) (sequence .+: (n - 1)) + + def range (length : Int) : Seq [Int] = + _tailrec_range (length) ( Nil ) + +} + +case class RecursionForCoq_ () extends RecursionForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala deleted file mode 100644 index a316a4dd..00000000 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/RecursionForCoq.scala +++ /dev/null @@ -1,53 +0,0 @@ -package soda.example.forcoq.algorithms - -/* - * This package contains examples using recursion for Coq. - */ - - - -/** - * This class contains tail recursive auxiliary functions. - */ - -trait RecursionForCoq -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold4 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - sequence match { - case (head) :: (tail) => - if ( ( ! (condition (current_value) (head) ) ) - ) current_value - else _tailrec_fold4 (tail) (next_value_function (current_value) (head)) (next_value_function) (condition) - case x => current_value - } - - def fold4 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold4 (sequence) (initial_value) (next_value_function) (condition) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold3 [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = - sequence match { - case (head) :: (tail) => _tailrec_fold3 (tail) (next_value_function (current_value) (head)) (next_value_function) - case x => current_value - } - - def fold3 [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _tailrec_fold3 (sequence) (initial_value) (next_value_function) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence .+: (n - 1)) - - def range (length : Int) : Seq [Int] = - _tailrec_range (length) ( Nil ) - -} - -case class RecursionForCoq_ () extends RecursionForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/lib/List.scala b/examples/src/main/scala/soda/example/forcoq/lib/List.scala deleted file mode 100644 index 035debed..00000000 --- a/examples/src/main/scala/soda/example/forcoq/lib/List.scala +++ /dev/null @@ -1,75 +0,0 @@ -package soda.example.forcoq.lib - -/* - * This package contains helper classes that could be needed for a translation to Coq. - */ - - - -trait list [A] -{ - -} - -case class list_ [A] () extends list [A] - -trait nil [A] - extends - list [A] -{ - -} - -case class nil_ [A] () extends nil [A] - -trait cons [A] - extends - list [A] -{ - - def e : A - def s : list [A] - -} - -case class cons_ [A] (e : A, s : list [A]) extends cons [A] - -trait SeqList -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = - a match { - case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) - case x => b - } - - def reverse [A] (s : list [A] ) : list [A] = - _tailrec_reverse [A] (s) (nil_ [A] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = - a match { - case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) - case x => b - } - - def from_Seq [A] (a : Seq [A] ) : list [A] = - reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = - a match { - case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) - case x => b - } - - def to_Seq [A] (a : list [A] ) : Seq [A] = - (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse - -} - -case class SeqList_ () extends SeqList diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala b/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala deleted file mode 100644 index c71bdae1..00000000 --- a/examples/src/main/scala/soda/example/forcoq/lib/Nat.scala +++ /dev/null @@ -1,95 +0,0 @@ -package soda.example.forcoq.lib - -/* - * This package contains helper classes that could be needed for a translation to Coq. - */ - - - -trait nat -{ - - def add : nat => nat - def mul : nat => nat - -} - -case class nat_ (add : nat => nat, mul : nat => nat) extends nat - -trait O - extends - nat -{ - - lazy val add : nat => nat = - a => add_for (a) - - def add_for (a : nat) : nat = - a - - lazy val mul : nat => nat = - a => mul_for (a) - - def mul_for (a : nat) : nat = - this - -} - -case class O_ () extends O - -trait S - extends - nat -{ - - def k : nat - - lazy val t = IntNat_ () - - lazy val add : nat => nat = - a => add_for (a) - - def add_for (a : nat) : nat = - t.from_non_negative( (t.to_Int (k) + 1) + t.to_Int (a) ) - - lazy val mul : nat => nat = - a => mul_for (a) - - def mul_for (a : nat) : nat = - t.from_non_negative( (t.to_Int (k) + 1) * t.to_Int (a) ) - -} - -case class S_ (k : nat) extends S - -trait IntNat -{ - - import soda.lib.NoneSD_ - import soda.lib.OptionSD - import soda.lib.SomeSD_ - - def from_Int (a : Int) : OptionSD [nat] = - if ( a < 0 - ) NoneSD_ [nat] () - else SomeSD_ [nat] (from_non_negative (a) ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_from_non_negative (a : Int) (b : nat) : nat = - if ( a <= 0 - ) b - else _tailrec_from_non_negative (a - 1) (S_ (b) ) - - def from_non_negative (a : Int) : nat = - _tailrec_from_non_negative (a) (O_ () ) - - def to_Int (a : nat) : Int = - a match { - case S_ (k) => 1 + to_Int (k) - case x => 0 - } - -} - -case class IntNat_ () extends IntNat diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala index a64c14b6..e9120e4c 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala @@ -5,3 +5,157 @@ package soda.example.forcoq.lib */ trait Package +trait nat +{ + + def add : nat => nat + def mul : nat => nat + +} + +case class nat_ (add : nat => nat, mul : nat => nat) extends nat + +trait O + extends + nat +{ + + lazy val add : nat => nat = + a => add_for (a) + + def add_for (a : nat) : nat = + a + + lazy val mul : nat => nat = + a => mul_for (a) + + def mul_for (a : nat) : nat = + this + +} + +case class O_ () extends O + +trait S + extends + nat +{ + + def k : nat + + lazy val t = IntNat_ () + + lazy val add : nat => nat = + a => add_for (a) + + def add_for (a : nat) : nat = + t.from_non_negative( (t.to_Int (k) + 1) + t.to_Int (a) ) + + lazy val mul : nat => nat = + a => mul_for (a) + + def mul_for (a : nat) : nat = + t.from_non_negative( (t.to_Int (k) + 1) * t.to_Int (a) ) + +} + +case class S_ (k : nat) extends S + +trait IntNat +{ + + import soda.lib.NoneSD_ + import soda.lib.OptionSD + import soda.lib.SomeSD_ + + def from_Int (a : Int) : OptionSD [nat] = + if ( a < 0 + ) NoneSD_ [nat] () + else SomeSD_ [nat] (from_non_negative (a) ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_from_non_negative (a : Int) (b : nat) : nat = + if ( a <= 0 + ) b + else _tailrec_from_non_negative (a - 1) (S_ (b) ) + + def from_non_negative (a : Int) : nat = + _tailrec_from_non_negative (a) (O_ () ) + + def to_Int (a : nat) : Int = + a match { + case S_ (k) => 1 + to_Int (k) + case x => 0 + } + +} + +case class IntNat_ () extends IntNat +trait list [A] +{ + +} + +case class list_ [A] () extends list [A] + +trait nil [A] + extends + list [A] +{ + +} + +case class nil_ [A] () extends nil [A] + +trait cons [A] + extends + list [A] +{ + + def e : A + def s : list [A] + +} + +case class cons_ [A] (e : A, s : list [A]) extends cons [A] + +trait SeqList +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = + a match { + case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) + case x => b + } + + def reverse [A] (s : list [A] ) : list [A] = + _tailrec_reverse [A] (s) (nil_ [A] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = + a match { + case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) + case x => b + } + + def from_Seq [A] (a : Seq [A] ) : list [A] = + reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = + a match { + case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) + case x => b + } + + def to_Seq [A] (a : list [A] ) : Seq [A] = + (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse + +} + +case class SeqList_ () extends SeqList diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala deleted file mode 100644 index 9bb2d636..00000000 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FactorialForCoq.scala +++ /dev/null @@ -1,29 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains examples of some mathematical functions that can be translated to Coq. - */ - - - -trait FactorialForCoq -{ - - import soda.example.forcoq.lib.O_ - import soda.example.forcoq.lib.S_ - import soda.example.forcoq.lib.nat - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_factorial (m : nat) (product : nat) : nat = - m match { - case S_ (k) => _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) - case x => product - } - - def get_factorial (n : nat) : nat = - _tailrec_get_factorial (n) (S_ ( O_ () ) ) - -} - -case class FactorialForCoq_ () extends FactorialForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala deleted file mode 100644 index 46fc08d2..00000000 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala +++ /dev/null @@ -1,30 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains examples of some mathematical functions that can be translated to Coq. - */ - - - -trait FiboExampleInSodaForCoq -{ - - import soda.example.forcoq.lib.O_ - import soda.example.forcoq.lib.S_ - import soda.example.forcoq.lib.nat - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = - m match { - case S_ (O_ () ) => b - case S_ (k) => _tailrec_fib (k) (b) (a .add (b) ) - case x => a - } - - def fib (n : nat) = - _tailrec_fib (n) (O_ () ) ( S_ (O_ () ) ) - -} - -case class FiboExampleInSodaForCoq_ () extends FiboExampleInSodaForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala index 1210b73d..dae949f8 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala @@ -5,3 +5,67 @@ package soda.example.forcoq.mathematics */ trait Package +trait TriangularNumberForCoq +{ + + import soda.example.forcoq.lib.O_ + import soda.example.forcoq.lib.S_ + import soda.example.forcoq.lib.nat + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_number (m : nat) (acc : nat) : nat = + m match { + case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x => acc + } + + def get_number (n : nat) : nat = + _tailrec_get_number (n) ( O_ () ) + +} + +case class TriangularNumberForCoq_ () extends TriangularNumberForCoq +trait FactorialForCoq +{ + + import soda.example.forcoq.lib.O_ + import soda.example.forcoq.lib.S_ + import soda.example.forcoq.lib.nat + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_factorial (m : nat) (product : nat) : nat = + m match { + case S_ (k) => _tailrec_get_factorial (k) (product .mul ( S_ (k) ) ) + case x => product + } + + def get_factorial (n : nat) : nat = + _tailrec_get_factorial (n) (S_ ( O_ () ) ) + +} + +case class FactorialForCoq_ () extends FactorialForCoq +trait FiboExampleInSodaForCoq +{ + + import soda.example.forcoq.lib.O_ + import soda.example.forcoq.lib.S_ + import soda.example.forcoq.lib.nat + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fib (m : nat) (a : nat) (b : nat) : nat = + m match { + case S_ (O_ () ) => b + case S_ (k) => _tailrec_fib (k) (b) (a .add (b) ) + case x => a + } + + def fib (n : nat) = + _tailrec_fib (n) (O_ () ) ( S_ (O_ () ) ) + +} + +case class FiboExampleInSodaForCoq_ () extends FiboExampleInSodaForCoq diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala deleted file mode 100644 index 1dc51da3..00000000 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ /dev/null @@ -1,29 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains examples of some mathematical functions that can be translated to Coq. - */ - - - -trait TriangularNumberForCoq -{ - - import soda.example.forcoq.lib.O_ - import soda.example.forcoq.lib.S_ - import soda.example.forcoq.lib.nat - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_number (m : nat) (acc : nat) : nat = - m match { - case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) - case x => acc - } - - def get_number (n : nat) : nat = - _tailrec_get_number (n) ( O_ () ) - -} - -case class TriangularNumberForCoq_ () extends TriangularNumberForCoq diff --git a/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala b/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala deleted file mode 100644 index c301c084..00000000 --- a/examples/src/main/scala/soda/example/inanutshell/InANutshell.scala +++ /dev/null @@ -1,172 +0,0 @@ -package soda.example.inanutshell - -/* - * This package explains Soda in a nutshell. - */ - - - -trait InANutshell -{ - - def f (x : Int) : Int = x + 16 - - lazy val value = f (numbers) - - lazy val numbers = 1 + 2 + 4 + 8 - - def h0 (x : Int) (y : Int) : Int = - x + y - - def h1 (x : Int) (y : Int) : Int = - x - y - - def h2 (x : Int) (y : Int) : Int = - (h0 (x) (y) ) * (h1 (x) (y) ) - - def is_greater_than (a : Int) (b : Int) : Boolean = - a > b - - def max (a : Int) (b : Int) : Int = - if ( a > b - ) a - else b - -} - -case class InANutshell_ () extends InANutshell - -trait MaxAndMin -{ - - def max (a : Int) (b : Int) : Int = - if ( a > b - ) a - else b - - def min (a : Int) (b : Int) : Int = - if ( a < b - ) a - else b - -} - -case class MaxAndMin_ () extends MaxAndMin - -trait MinMaxPair -{ - - def min : Int - def max : Int - -} - -case class MinMaxPair_ (min : Int, max : Int) extends MinMaxPair - -trait Indexable -{ - - def index : Int - -} - -case class Indexable_ (index : Int) extends Indexable - -trait Example - extends Indexable -{ - - def index : Int - - def min_max (a : Int) (b : Int) : MinMaxPair = - MinMaxPair_ ( - min = MaxAndMin_ ().min (a) (b), - max = MaxAndMin_ ().max (a) (b) - ) - -} - -case class Example_ (index : Int) extends Example - -trait Comparable -{ - - def is_greater_than : Comparable => Boolean - -} - -case class Comparable_ (is_greater_than : Comparable => Boolean) extends Comparable - -trait ComparableMax [A <: Comparable] -{ - - def max (a : A) (b : A) : A = - if ( a.is_greater_than (b) - ) a - else b - -} - -case class ComparableMax_ [A <: Comparable] () extends ComparableMax [A] - -trait WithInstance -{ - - def instance_parameter : Int - -} - -case class WithInstance_ (instance_parameter : Int) extends WithInstance - -trait MyClass - extends - WithInstance -{ - - def instance_parameter : Int - - lazy val class_constant : Int = 1 - - def another_function (x : Int) : Int = 2 * x - -} - -case class MyClass_ (instance_parameter : Int) extends MyClass - -trait TimeOfToday -{ - - import java.util.Date - - lazy val get_time : Date = new Date () - -} - -case class TimeOfToday_ () extends TimeOfToday - -trait Main -{ - - def main (arguments : Array [String] ) : Unit = - println ("Hello world!") - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main - -trait PersonName -{ - - def name : String - - override - lazy val toString = name - -} - -case class PersonName_ (name : String) extends PersonName diff --git a/examples/src/main/scala/soda/example/inanutshell/Package.scala b/examples/src/main/scala/soda/example/inanutshell/Package.scala index 602fc024..32eaee22 100644 --- a/examples/src/main/scala/soda/example/inanutshell/Package.scala +++ b/examples/src/main/scala/soda/example/inanutshell/Package.scala @@ -5,3 +5,167 @@ package soda.example.inanutshell */ trait Package +trait InANutshell +{ + + def f (x : Int) : Int = x + 16 + + lazy val value = f (numbers) + + lazy val numbers = 1 + 2 + 4 + 8 + + def h0 (x : Int) (y : Int) : Int = + x + y + + def h1 (x : Int) (y : Int) : Int = + x - y + + def h2 (x : Int) (y : Int) : Int = + (h0 (x) (y) ) * (h1 (x) (y) ) + + def is_greater_than (a : Int) (b : Int) : Boolean = + a > b + + def max (a : Int) (b : Int) : Int = + if ( a > b + ) a + else b + +} + +case class InANutshell_ () extends InANutshell + +trait MaxAndMin +{ + + def max (a : Int) (b : Int) : Int = + if ( a > b + ) a + else b + + def min (a : Int) (b : Int) : Int = + if ( a < b + ) a + else b + +} + +case class MaxAndMin_ () extends MaxAndMin + +trait MinMaxPair +{ + + def min : Int + def max : Int + +} + +case class MinMaxPair_ (min : Int, max : Int) extends MinMaxPair + +trait Indexable +{ + + def index : Int + +} + +case class Indexable_ (index : Int) extends Indexable + +trait Example + extends Indexable +{ + + def index : Int + + def min_max (a : Int) (b : Int) : MinMaxPair = + MinMaxPair_ ( + min = MaxAndMin_ ().min (a) (b), + max = MaxAndMin_ ().max (a) (b) + ) + +} + +case class Example_ (index : Int) extends Example + +trait Comparable +{ + + def is_greater_than : Comparable => Boolean + +} + +case class Comparable_ (is_greater_than : Comparable => Boolean) extends Comparable + +trait ComparableMax [A <: Comparable] +{ + + def max (a : A) (b : A) : A = + if ( a.is_greater_than (b) + ) a + else b + +} + +case class ComparableMax_ [A <: Comparable] () extends ComparableMax [A] + +trait WithInstance +{ + + def instance_parameter : Int + +} + +case class WithInstance_ (instance_parameter : Int) extends WithInstance + +trait MyClass + extends + WithInstance +{ + + def instance_parameter : Int + + lazy val class_constant : Int = 1 + + def another_function (x : Int) : Int = 2 * x + +} + +case class MyClass_ (instance_parameter : Int) extends MyClass + +trait TimeOfToday +{ + + import java.util.Date + + lazy val get_time : Date = new Date () + +} + +case class TimeOfToday_ () extends TimeOfToday + +trait Main +{ + + def main (arguments : Array [String] ) : Unit = + println ("Hello world!") + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main + +trait PersonName +{ + + def name : String + + override + lazy val toString = name + +} + +case class PersonName_ (name : String) extends PersonName diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala b/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala deleted file mode 100644 index aa9aeda1..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FactorialConcise.scala +++ /dev/null @@ -1,25 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait FactorialConcise -{ - - def apply (n : Int) : Int = - _tailrec_get_factorial (n) (1) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_factorial (n : Int) (product : Int) : Int = - if ( n == 0 - ) product - else _tailrec_get_factorial (n - 1) (n * product) - -} - -case class FactorialConcise_ () extends FactorialConcise diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala b/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala deleted file mode 100644 index f8132c50..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FactorialPatternMatching.scala +++ /dev/null @@ -1,26 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait FactorialPatternMatching -{ - - def apply (n : Int) : Int = - _tailrec_get_factorial (n) (1) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_factorial (n : Int) (product : Int) : Int = - n match { - case 0 => product - case x => _tailrec_get_factorial (x - 1) (x * product) - } - -} - -case class FactorialPatternMatching_ () extends FactorialPatternMatching diff --git a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala b/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala deleted file mode 100644 index e0e2350a..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FactorialWithFold.scala +++ /dev/null @@ -1,22 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait FactorialWithFold -{ - - private lazy val _fold = soda.lib.Fold_ () - - private lazy val _range = soda.lib.Range_ () - - def apply (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) - -} - -case class FactorialWithFold_ () extends FactorialWithFold diff --git a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala b/examples/src/main/scala/soda/example/mathematics/FiboExample.scala deleted file mode 100644 index b4ee750f..00000000 --- a/examples/src/main/scala/soda/example/mathematics/FiboExample.scala +++ /dev/null @@ -1,23 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait FiboExampleInSoda -{ - - def apply (n : Int) = - _rec (n) (0) (1) - - private def _rec (m : Int) (a : Int) (b : Int) : Int = - if ( m == 0 ) a - else if ( m == 1 ) b - else _rec (m - 1) (b) (a + b) - -} - -case class FiboExampleInSoda_ () extends FiboExampleInSoda diff --git a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala b/examples/src/main/scala/soda/example/mathematics/HardProblem.scala deleted file mode 100644 index 5cb88354..00000000 --- a/examples/src/main/scala/soda/example/mathematics/HardProblem.scala +++ /dev/null @@ -1,157 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait InputPair [A, B] -{ - - def value : A - def memoized_values : Map [A, B] - -} - -case class InputPair_ [A, B] (value : A, memoized_values : Map [A, B]) extends InputPair [A, B] - -trait OutputPair [A, B] -{ - - def value : B - def memoized_values : Map [A, B] - -} - -case class OutputPair_ [A, B] (value : B, memoized_values : Map [A, B]) extends OutputPair [A, B] - -trait MemoizableFunction [A, B] -{ - - /** compute (input : InputPair [A, B] ) : OutputPair [A, B] */ - def abs_compute : InputPair [A, B] => OutputPair [A, B] - - def compute (input : InputPair [A, B] ) : OutputPair [A, B] = - abs_compute (input) - -} - -case class MemoizableFunction_ [A, B] (abs_compute : InputPair [A, B] => OutputPair [A, B]) extends MemoizableFunction [A, B] - -trait MainFunction [A, B] -{ - - def main_function : InputPair [A, B] => OutputPair [A, B] - -} - -case class MainFunction_ [A, B] (main_function : InputPair [A, B] => OutputPair [A, B]) extends MainFunction [A, B] - -trait Memoizer [A, B] - extends - MemoizableFunction [A, B] - with MainFunction [A, B] -{ - - def main_function : InputPair [A, B] => OutputPair [A, B] - - lazy val abs_compute : InputPair [A, B] => OutputPair [A, B] = - input => - compute_for (input) - - def compute_for (input : InputPair [A, B] ) : OutputPair [A, B] = - _compute_with (input.memoized_values.get (input.value) ) (input) - - private def _compute_with (maybe_res : Option [B] ) (input : InputPair [A, B] ) : OutputPair [A, B] = - if ( maybe_res.isEmpty - ) compute_and_update (input) - else OutputPair_ (maybe_res.get, input.memoized_values) - - def compute_and_update (input : InputPair [A, B] ) : OutputPair [A, B] = - _compute_and_update_with (input.value) (main_function (input) ) - - private def _compute_and_update_with (input_value : A) (output : OutputPair [A, B] ) : OutputPair [A, B] = - _add_element (output, Tuple2 (input_value, output.value) ) - - private def _add_element (output : OutputPair [A, B], new_pair : Tuple2 [A, B] ) : OutputPair [A, B] = - OutputPair_ (output.value, output.memoized_values + new_pair) - -} - -case class Memoizer_ [A, B] (main_function : InputPair [A, B] => OutputPair [A, B]) extends Memoizer [A, B] - -trait HardProblem - extends - MemoizableFunction [Int, Int] -{ - - lazy val memoizer = Memoizer_ [Int, Int] (main_function) - - def is_even (n : Int) : Boolean = - n % 2 == 0 - - def one_step (n : Int) : Int = - if ( is_even (n) - ) n / 2 - else 3 * n + 1 - - lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = - input => - if ( input.value == 1 - ) OutputPair_ (0, input.memoized_values) - else _plus_one (compute (InputPair_ (one_step (input.value), input.memoized_values) ) ) - - private def _plus_one (pair : OutputPair [Int, Int] ) : OutputPair [Int, Int] = - OutputPair_ (1 + pair.value, pair.memoized_values) - - lazy val abs_compute : InputPair [Int, Int] => OutputPair [Int, Int] = - input => - compute_for (input) - - def compute_for (input : InputPair [Int, Int] ) : OutputPair [Int, Int] = - memoizer.compute (input) - -} - -case class HardProblem_ () extends HardProblem - -trait MemoizedFibonacci - extends - MemoizableFunction [Int, Int] -{ - - lazy val memoizer = Memoizer_ [Int, Int] (main_function) - - lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = - input => - main_function_for (input) - - def main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = - if ( (input.value == 0) || (input.value == 1) - ) OutputPair_ (input.value, input.memoized_values ) - else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) - - private def _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = - _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) - - private def _compute_and_update_2 (first_value : Int) (second_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = - _compute_and_update_3 (_get_next_fibo (first_value) (second_tuple.value) ) (second_tuple.memoized_values) (n) - - private def _compute_and_update_3 (res : Int) (second_map : Map [Int, Int] ) (n : Int) : OutputPair [Int, Int] = - OutputPair_ (res, second_map + Tuple2 (n, res) ) - - private def _get_next_fibo (a : Int) (b : Int) : Int = - a + b - - lazy val abs_compute : InputPair [Int, Int] => OutputPair [Int, Int] = - input => - compute_for (input) - - def compute_for (input : InputPair [Int, Int] ) : OutputPair [Int, Int] = - memoizer.compute (input) - -} - -case class MemoizedFibonacci_ () extends MemoizedFibonacci diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index 5bdefb97..c5449479 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -6,3 +6,293 @@ package soda.example.mathematics */ trait Package +trait FactorialConcise +{ + + def apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_factorial (n : Int) (product : Int) : Int = + if ( n == 0 + ) product + else _tailrec_get_factorial (n - 1) (n * product) + +} + +case class FactorialConcise_ () extends FactorialConcise +trait Status +{ + + def r : BigInt + def n : Int + def q : BigInt + def t : BigInt + def l : Int + def k : Int + + override + lazy val toString = " r=" + r + " n=" + n + " q=" + q + " t=" + t + " l=" + l + " k=" + k + +} + +case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : Int) extends Status + +trait PiIterator +{ + + def apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + + private lazy val _initial_status = + Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_compute_new_status (s : Status) : Status = + if ( (4 * s.q + s.r - s.t) < (s.n * s.t) + ) s + else + _tailrec_compute_new_status ( + Status_ ( + r = (2 * s.q + s.r) * s.l, + n = ( (s.q * (7 * s.k) + 2 + (s.r * s.l) ) / (s.t * s.l) ).toInt, + q = s.q * s.k, + t = s.t * s.l, + l = s.l + 2, + k = s.k + 1 + ) + ) + + private def _compute_new_status (s : Status) : Status = + _tailrec_compute_new_status (s) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_take (n : Int) (rev_seq : Seq [Int] ) (s : Status) (t : IntAndStatus) : Seq [Int] = + if ( n == 0 + ) rev_seq.reverse + else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) + + private def _get_next (s : Status) : IntAndStatus = + _get_next_with_new_status (_compute_new_status (s) ) + + private def _get_next_with_new_status (s : Status) : IntAndStatus = + IntAndStatus_ ( + s.n, + Status_ ( + r = 10 * (s.r - s.n * s.t), + n = ( ( (10 * (3 * s.q + s.r) ) / s.t) - (10 * s.n) ).toInt, + q = s.q * 10, + t = s.t, + l = s.l, + k = s.k + ) + ) + +} + +case class PiIterator_ () extends PiIterator + +trait IntAndStatus +{ + + def digit : Int + def new_status : Status + +} + +case class IntAndStatus_ (digit : Int, new_status : Status) extends IntAndStatus +trait InputPair [A, B] +{ + + def value : A + def memoized_values : Map [A, B] + +} + +case class InputPair_ [A, B] (value : A, memoized_values : Map [A, B]) extends InputPair [A, B] + +trait OutputPair [A, B] +{ + + def value : B + def memoized_values : Map [A, B] + +} + +case class OutputPair_ [A, B] (value : B, memoized_values : Map [A, B]) extends OutputPair [A, B] + +trait MemoizableFunction [A, B] +{ + + /** compute (input : InputPair [A, B] ) : OutputPair [A, B] */ + def abs_compute : InputPair [A, B] => OutputPair [A, B] + + def compute (input : InputPair [A, B] ) : OutputPair [A, B] = + abs_compute (input) + +} + +case class MemoizableFunction_ [A, B] (abs_compute : InputPair [A, B] => OutputPair [A, B]) extends MemoizableFunction [A, B] + +trait MainFunction [A, B] +{ + + def main_function : InputPair [A, B] => OutputPair [A, B] + +} + +case class MainFunction_ [A, B] (main_function : InputPair [A, B] => OutputPair [A, B]) extends MainFunction [A, B] + +trait Memoizer [A, B] + extends + MemoizableFunction [A, B] + with MainFunction [A, B] +{ + + def main_function : InputPair [A, B] => OutputPair [A, B] + + lazy val abs_compute : InputPair [A, B] => OutputPair [A, B] = + input => + compute_for (input) + + def compute_for (input : InputPair [A, B] ) : OutputPair [A, B] = + _compute_with (input.memoized_values.get (input.value) ) (input) + + private def _compute_with (maybe_res : Option [B] ) (input : InputPair [A, B] ) : OutputPair [A, B] = + if ( maybe_res.isEmpty + ) compute_and_update (input) + else OutputPair_ (maybe_res.get, input.memoized_values) + + def compute_and_update (input : InputPair [A, B] ) : OutputPair [A, B] = + _compute_and_update_with (input.value) (main_function (input) ) + + private def _compute_and_update_with (input_value : A) (output : OutputPair [A, B] ) : OutputPair [A, B] = + _add_element (output, Tuple2 (input_value, output.value) ) + + private def _add_element (output : OutputPair [A, B], new_pair : Tuple2 [A, B] ) : OutputPair [A, B] = + OutputPair_ (output.value, output.memoized_values + new_pair) + +} + +case class Memoizer_ [A, B] (main_function : InputPair [A, B] => OutputPair [A, B]) extends Memoizer [A, B] + +trait HardProblem + extends + MemoizableFunction [Int, Int] +{ + + lazy val memoizer = Memoizer_ [Int, Int] (main_function) + + def is_even (n : Int) : Boolean = + n % 2 == 0 + + def one_step (n : Int) : Int = + if ( is_even (n) + ) n / 2 + else 3 * n + 1 + + lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = + input => + if ( input.value == 1 + ) OutputPair_ (0, input.memoized_values) + else _plus_one (compute (InputPair_ (one_step (input.value), input.memoized_values) ) ) + + private def _plus_one (pair : OutputPair [Int, Int] ) : OutputPair [Int, Int] = + OutputPair_ (1 + pair.value, pair.memoized_values) + + lazy val abs_compute : InputPair [Int, Int] => OutputPair [Int, Int] = + input => + compute_for (input) + + def compute_for (input : InputPair [Int, Int] ) : OutputPair [Int, Int] = + memoizer.compute (input) + +} + +case class HardProblem_ () extends HardProblem + +trait MemoizedFibonacci + extends + MemoizableFunction [Int, Int] +{ + + lazy val memoizer = Memoizer_ [Int, Int] (main_function) + + lazy val main_function : InputPair [Int, Int] => OutputPair [Int, Int] = + input => + main_function_for (input) + + def main_function_for (input : InputPair [Int, Int] ): OutputPair [Int, Int] = + if ( (input.value == 0) || (input.value == 1) + ) OutputPair_ (input.value, input.memoized_values ) + else _compute_and_update_1 (compute (InputPair_ (input.value - 2, input.memoized_values ) ) ) (input.value) + + private def _compute_and_update_1 (first_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = + _compute_and_update_2 (first_tuple.value) (compute (InputPair_ (n - 1, first_tuple.memoized_values) ) ) (n) + + private def _compute_and_update_2 (first_value : Int) (second_tuple : OutputPair [Int, Int] ) (n : Int ) : OutputPair [Int, Int] = + _compute_and_update_3 (_get_next_fibo (first_value) (second_tuple.value) ) (second_tuple.memoized_values) (n) + + private def _compute_and_update_3 (res : Int) (second_map : Map [Int, Int] ) (n : Int) : OutputPair [Int, Int] = + OutputPair_ (res, second_map + Tuple2 (n, res) ) + + private def _get_next_fibo (a : Int) (b : Int) : Int = + a + b + + lazy val abs_compute : InputPair [Int, Int] => OutputPair [Int, Int] = + input => + compute_for (input) + + def compute_for (input : InputPair [Int, Int] ) : OutputPair [Int, Int] = + memoizer.compute (input) + +} + +case class MemoizedFibonacci_ () extends MemoizedFibonacci +trait FactorialWithFold +{ + + private lazy val _fold = soda.lib.Fold_ () + + private lazy val _range = soda.lib.Range_ () + + def apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) + +} + +case class FactorialWithFold_ () extends FactorialWithFold +trait FiboExampleInSoda +{ + + def apply (n : Int) = + _rec (n) (0) (1) + + private def _rec (m : Int) (a : Int) (b : Int) : Int = + if ( m == 0 ) a + else if ( m == 1 ) b + else _rec (m - 1) (b) (a + b) + +} + +case class FiboExampleInSoda_ () extends FiboExampleInSoda +trait FactorialPatternMatching +{ + + def apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_factorial (n : Int) (product : Int) : Int = + n match { + case 0 => product + case x => _tailrec_get_factorial (x - 1) (x * product) + } + +} + +case class FactorialPatternMatching_ () extends FactorialPatternMatching diff --git a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala b/examples/src/main/scala/soda/example/mathematics/PiIterator.scala deleted file mode 100644 index f6aad5df..00000000 --- a/examples/src/main/scala/soda/example/mathematics/PiIterator.scala +++ /dev/null @@ -1,91 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains examples in Soda. - * These examples use mathematical properties. - */ - - - -trait Status -{ - - def r : BigInt - def n : Int - def q : BigInt - def t : BigInt - def l : Int - def k : Int - - override - lazy val toString = " r=" + r + " n=" + n + " q=" + q + " t=" + t + " l=" + l + " k=" + k - -} - -case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : Int) extends Status - -trait PiIterator -{ - - def apply (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) - - private lazy val _initial_status = - Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_compute_new_status (s : Status) : Status = - if ( (4 * s.q + s.r - s.t) < (s.n * s.t) - ) s - else - _tailrec_compute_new_status ( - Status_ ( - r = (2 * s.q + s.r) * s.l, - n = ( (s.q * (7 * s.k) + 2 + (s.r * s.l) ) / (s.t * s.l) ).toInt, - q = s.q * s.k, - t = s.t * s.l, - l = s.l + 2, - k = s.k + 1 - ) - ) - - private def _compute_new_status (s : Status) : Status = - _tailrec_compute_new_status (s) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_take (n : Int) (rev_seq : Seq [Int] ) (s : Status) (t : IntAndStatus) : Seq [Int] = - if ( n == 0 - ) rev_seq.reverse - else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) - - private def _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (_compute_new_status (s) ) - - private def _get_next_with_new_status (s : Status) : IntAndStatus = - IntAndStatus_ ( - s.n, - Status_ ( - r = 10 * (s.r - s.n * s.t), - n = ( ( (10 * (3 * s.q + s.r) ) / s.t) - (10 * s.n) ).toInt, - q = s.q * 10, - t = s.t, - l = s.l, - k = s.k - ) - ) - -} - -case class PiIterator_ () extends PiIterator - -trait IntAndStatus -{ - - def digit : Int - def new_status : Status - -} - -case class IntAndStatus_ (digit : Int, new_status : Status) extends IntAndStatus diff --git a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala b/examples/src/main/scala/soda/example/miniexample/MiniExample.scala deleted file mode 100644 index 1b1466a5..00000000 --- a/examples/src/main/scala/soda/example/miniexample/MiniExample.scala +++ /dev/null @@ -1,37 +0,0 @@ -package soda.example.miniexample - -/* - * This package contains mini-examples. - */ - - - -trait MiniExample -{ - - import soda.lib.Range_ - - private lazy val _range = Range_ () - - def run () : Seq [Unit] = - _range.apply (50) - .map ( x => print (" " + (2 * x + 1) ) ) - -} - -case class MiniExample_ () extends MiniExample - -trait Main -{ - - def main (arguments : Array [String] ) : Unit = - MiniExample_ ().run () - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main diff --git a/examples/src/main/scala/soda/example/miniexample/Package.scala b/examples/src/main/scala/soda/example/miniexample/Package.scala index a29edeb4..40a43845 100644 --- a/examples/src/main/scala/soda/example/miniexample/Package.scala +++ b/examples/src/main/scala/soda/example/miniexample/Package.scala @@ -5,3 +5,32 @@ package soda.example.miniexample */ trait Package +trait MiniExample +{ + + import soda.lib.Range_ + + private lazy val _range = Range_ () + + def run () : Seq [Unit] = + _range.apply (50) + .map ( x => print (" " + (2 * x + 1) ) ) + +} + +case class MiniExample_ () extends MiniExample + +trait Main +{ + + def main (arguments : Array [String] ) : Unit = + MiniExample_ ().run () + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main diff --git a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala b/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala deleted file mode 100644 index 3fb26ad7..00000000 --- a/examples/src/test/scala/soda/example/algorithms/FizzBuzzSpec.scala +++ /dev/null @@ -1,50 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains tests for examples of simple algorithms. - */ - - - -case class FizzBuzzSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val expected_result = Seq ( - "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", - "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", - "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", - "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", - "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", - "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", - "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", - "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", - "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", - "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" - ) - - private lazy val _fizz_buzz = FizzBuzz_ () - - private lazy val _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () - - test ("first elements of FizzBuzz") ( - check ( - obtained = _fizz_buzz.apply - ) ( - expected = expected_result - ) - ) - - test ("first elements of FizzBuzz with pattern matching") ( - check ( - obtained = _fizz_buzz_pattern_matching.apply - ) ( - expected = expected_result - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/algorithms/Package.scala b/examples/src/test/scala/soda/example/algorithms/Package.scala index 77995fd6..9fc61a74 100644 --- a/examples/src/test/scala/soda/example/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/algorithms/Package.scala @@ -5,3 +5,255 @@ package soda.example.algorithms */ trait Package +case class SortExampleSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.lib.SomeSD_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val sorted_sequence = Seq (1, 3, 5, 5, 8, 9) + + lazy val unsorted_sequence = Seq (1, 3, 5, 4, 8, 9) + + test ("test sorted sequence with at") ( + check ( + obtained = SortExampleWithAt_ ().is_sorted (sorted_sequence) + ) ( + expected = true + ) + ) + + test ("test unsorted sequence with at") ( + check ( + obtained = SortExampleWithAt_ ().is_sorted (unsorted_sequence) + ) ( + expected = false + ) + ) + + test ("test sorted sequence with zip") ( + check ( + obtained = SortExampleWithZip_ ().is_sorted (sorted_sequence) + ) ( + expected = true + ) + ) + + test ("test unsorted sequence with zip") ( + check ( + obtained = SortExampleWithZip_ ().is_sorted (unsorted_sequence) + ) ( + expected = false + ) + ) + + test ("insert sorted simple") ( + check ( + obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 6, 8, 9) ) (5) + ) ( + expected = Seq (1, 2, 3, 5, 6, 8, 9) + ) + ) + + test ("insert sorted with repetition") ( + check ( + obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 5, 6, 8, 9) ) (5) + ) ( + expected = Seq (1, 2, 3, 5, 5, 6, 8, 9) + ) + ) + + test ("sort unsorted sequence") ( + check ( + obtained = SortAlgorithmExampleWithFold_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) + ) ( + expected = Seq (1, 3, 4, 5, 8 ,9) + ) + ) + + test ("sort unsorted sequence applying constraints to verify correctness") ( + check ( + obtained = ConstrainedSortAlgorithm_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) + ) ( + expected = SomeSD_ (Seq (1, 3, 4, 5, 8 ,9) ) + ) + ) + + test ("sort unsorted sequence with SortedSequenceBuilder") ( + check ( + obtained = + SortedSequenceBuilder_ [Integer] () + .build ( Seq (3, 5, 1, 9, 8, 4).map ( x => Integer.valueOf (x) ) ) + .sequence + .map ( x => x.intValue) + ) ( + expected = Seq (1, 3, 4, 5, 8 ,9) + ) + ) + +} +case class PatternMatchingSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = PatternMatching_ () + + test ("get value and name of singleton - 1") ( + check ( + obtained = instance.get_value (Singleton_ (5) ) + ) ( + expected = 5 + ) + ) + + test ("get value and name of singleton - 2") ( + check ( + obtained = instance.get_type_name (Singleton_ (5) ) + ) ( + expected = "singleton(x)" + ) + ) + + test ("get value and name of pair - 1") ( + check ( + obtained = instance.get_value (Pair_ (10, 100) ) + ) ( + expected = 55 + ) + ) + + test ("get value and name of pair - 2") ( + check ( + obtained = instance.get_type_name (Pair_ (10, 100) ) + ) ( + expected = "pair(x, y)" + ) + ) + + test ("get value and name of triplet - 1") ( + check ( + obtained = instance.get_value (Triplet_ (9, 100, 890) ) + ) ( + expected = 333 + ) + ) + + test ("get value and name of triplet - 2") ( + check ( + obtained = instance.get_type_name (Triplet_ (9, 100, 890) ) + ) ( + expected = "triplet(x, y, z)" + ) + ) + +} +trait SaladIngredient + extends + soda.lib.EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class SaladIngredient_ (ordinal : Int, name : String) extends SaladIngredient + +trait SaladIngredientConstant +{ + + lazy val tomato = SaladIngredient_ (1, "tomato") + + lazy val lettuce = SaladIngredient_ (2, "lettuce") + + lazy val sunflower_seeds = SaladIngredient_ (3, "sunflower seeds") + + lazy val olive_oil = SaladIngredient_ (4, "olive_oil") + + lazy val SaladIngredient_values = Seq (tomato, lettuce, sunflower_seeds, olive_oil) + +} + +case class SaladIngredientConstant_ () extends SaladIngredientConstant + +case class SaladMakerSpec () + extends + org.scalatest.funsuite.AnyFunSuite + with SaladIngredientConstant +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + def add_next_ingredient (salad_so_far : Seq [SaladIngredient] ) (ingredient : SaladIngredient) : Seq [SaladIngredient] = + salad_so_far.+: (ingredient) + + def has_salad_at_most_2_ingredients (salad_so_far : Seq [SaladIngredient] ) (next_ingredient : SaladIngredient) : Boolean = + salad_so_far.length < 3 + + private lazy val _salad_maker = SaladMaker_ () + + test ("salad maker") ( + check ( + obtained = _salad_maker.apply ( + list_of_ingredients = SaladIngredient_values) ( + initial_bowl = Seq [SaladIngredient] () ) ( + next_ingredient_function = add_next_ingredient) ( + condition_to_continue = has_salad_at_most_2_ingredients + ) + ) ( + expected = Seq (sunflower_seeds, lettuce, tomato) + ) + ) + +} +case class FizzBuzzSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val expected_result = Seq ( + "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", + "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", + "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", + "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", + "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", + "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", + "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", + "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", + "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", + "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" + ) + + private lazy val _fizz_buzz = FizzBuzz_ () + + private lazy val _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () + + test ("first elements of FizzBuzz") ( + check ( + obtained = _fizz_buzz.apply + ) ( + expected = expected_result + ) + ) + + test ("first elements of FizzBuzz with pattern matching") ( + check ( + obtained = _fizz_buzz_pattern_matching.apply + ) ( + expected = expected_result + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala b/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala deleted file mode 100644 index f2e1fef1..00000000 --- a/examples/src/test/scala/soda/example/algorithms/PatternMatchingSpec.scala +++ /dev/null @@ -1,67 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains tests for examples of simple algorithms. - */ - - - -case class PatternMatchingSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = PatternMatching_ () - - test ("get value and name of singleton - 1") ( - check ( - obtained = instance.get_value (Singleton_ (5) ) - ) ( - expected = 5 - ) - ) - - test ("get value and name of singleton - 2") ( - check ( - obtained = instance.get_type_name (Singleton_ (5) ) - ) ( - expected = "singleton(x)" - ) - ) - - test ("get value and name of pair - 1") ( - check ( - obtained = instance.get_value (Pair_ (10, 100) ) - ) ( - expected = 55 - ) - ) - - test ("get value and name of pair - 2") ( - check ( - obtained = instance.get_type_name (Pair_ (10, 100) ) - ) ( - expected = "pair(x, y)" - ) - ) - - test ("get value and name of triplet - 1") ( - check ( - obtained = instance.get_value (Triplet_ (9, 100, 890) ) - ) ( - expected = 333 - ) - ) - - test ("get value and name of triplet - 2") ( - check ( - obtained = instance.get_type_name (Triplet_ (9, 100, 890) ) - ) ( - expected = "triplet(x, y, z)" - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala b/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala deleted file mode 100644 index 603f7fba..00000000 --- a/examples/src/test/scala/soda/example/algorithms/SaladMakerSpec.scala +++ /dev/null @@ -1,68 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains tests for examples of simple algorithms. - */ - - - -trait SaladIngredient - extends - soda.lib.EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class SaladIngredient_ (ordinal : Int, name : String) extends SaladIngredient - -trait SaladIngredientConstant -{ - - lazy val tomato = SaladIngredient_ (1, "tomato") - - lazy val lettuce = SaladIngredient_ (2, "lettuce") - - lazy val sunflower_seeds = SaladIngredient_ (3, "sunflower seeds") - - lazy val olive_oil = SaladIngredient_ (4, "olive_oil") - - lazy val SaladIngredient_values = Seq (tomato, lettuce, sunflower_seeds, olive_oil) - -} - -case class SaladIngredientConstant_ () extends SaladIngredientConstant - -case class SaladMakerSpec () - extends - org.scalatest.funsuite.AnyFunSuite - with SaladIngredientConstant -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - def add_next_ingredient (salad_so_far : Seq [SaladIngredient] ) (ingredient : SaladIngredient) : Seq [SaladIngredient] = - salad_so_far.+: (ingredient) - - def has_salad_at_most_2_ingredients (salad_so_far : Seq [SaladIngredient] ) (next_ingredient : SaladIngredient) : Boolean = - salad_so_far.length < 3 - - private lazy val _salad_maker = SaladMaker_ () - - test ("salad maker") ( - check ( - obtained = _salad_maker.apply ( - list_of_ingredients = SaladIngredient_values) ( - initial_bowl = Seq [SaladIngredient] () ) ( - next_ingredient_function = add_next_ingredient) ( - condition_to_continue = has_salad_at_most_2_ingredients - ) - ) ( - expected = Seq (sunflower_seeds, lettuce, tomato) - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala b/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala deleted file mode 100644 index e6b166d6..00000000 --- a/examples/src/test/scala/soda/example/algorithms/SortExampleSpec.scala +++ /dev/null @@ -1,99 +0,0 @@ -package soda.example.algorithms - -/* - * This package contains tests for examples of simple algorithms. - */ - - - -case class SortExampleSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.lib.SomeSD_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val sorted_sequence = Seq (1, 3, 5, 5, 8, 9) - - lazy val unsorted_sequence = Seq (1, 3, 5, 4, 8, 9) - - test ("test sorted sequence with at") ( - check ( - obtained = SortExampleWithAt_ ().is_sorted (sorted_sequence) - ) ( - expected = true - ) - ) - - test ("test unsorted sequence with at") ( - check ( - obtained = SortExampleWithAt_ ().is_sorted (unsorted_sequence) - ) ( - expected = false - ) - ) - - test ("test sorted sequence with zip") ( - check ( - obtained = SortExampleWithZip_ ().is_sorted (sorted_sequence) - ) ( - expected = true - ) - ) - - test ("test unsorted sequence with zip") ( - check ( - obtained = SortExampleWithZip_ ().is_sorted (unsorted_sequence) - ) ( - expected = false - ) - ) - - test ("insert sorted simple") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 6, 8, 9) ) (5) - ) ( - expected = Seq (1, 2, 3, 5, 6, 8, 9) - ) - ) - - test ("insert sorted with repetition") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 5, 6, 8, 9) ) (5) - ) ( - expected = Seq (1, 2, 3, 5, 5, 6, 8, 9) - ) - ) - - test ("sort unsorted sequence") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) - ) ( - expected = Seq (1, 3, 4, 5, 8 ,9) - ) - ) - - test ("sort unsorted sequence applying constraints to verify correctness") ( - check ( - obtained = ConstrainedSortAlgorithm_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) - ) ( - expected = SomeSD_ (Seq (1, 3, 4, 5, 8 ,9) ) - ) - ) - - test ("sort unsorted sequence with SortedSequenceBuilder") ( - check ( - obtained = - SortedSequenceBuilder_ [Integer] () - .build ( Seq (3, 5, 1, 9, 8, 4).map ( x => Integer.valueOf (x) ) ) - .sequence - .map ( x => x.intValue) - ) ( - expected = Seq (1, 3, 4, 5, 8 ,9) - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala deleted file mode 100644 index 243c566e..00000000 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/FairnessSpec.scala +++ /dev/null @@ -1,43 +0,0 @@ -package soda.example.ethicalissues.fairness - -/* - * This package contains tests for examples about ethical issues. - */ - - - -case class FairnessSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val rank_1 : Applicant => Double = - applicant => - applicant.background_score * 2 - - lazy val rank_2 : Applicant => Double = - applicant => - (1 - applicant.background_score) * 2 - - test ("simple test for fairness (true)") ( - check ( - obtained = Fairness_ (score_difference_tolerance = 2, ranking_difference_tolerance = 5, rank_1) - .is_fair (Applicant_ (78) ) (Applicant_ (77) ) - ) ( - expected = true - ) - ) - - test ("simple test for fairness (false)") ( - check ( - Fairness_ (score_difference_tolerance = 2, ranking_difference_tolerance = 1, rank_2) - .is_fair (Applicant_ (78) ) (Applicant_ (77) ) - ) ( - expected = false - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala index 16be32bd..b046dc23 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala @@ -5,3 +5,38 @@ package soda.example.ethicalissues.fairness */ trait Package +case class FairnessSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val rank_1 : Applicant => Double = + applicant => + applicant.background_score * 2 + + lazy val rank_2 : Applicant => Double = + applicant => + (1 - applicant.background_score) * 2 + + test ("simple test for fairness (true)") ( + check ( + obtained = Fairness_ (score_difference_tolerance = 2, ranking_difference_tolerance = 5, rank_1) + .is_fair (Applicant_ (78) ) (Applicant_ (77) ) + ) ( + expected = true + ) + ) + + test ("simple test for fairness (false)") ( + check ( + Fairness_ (score_difference_tolerance = 2, ranking_difference_tolerance = 1, rank_2) + .is_fair (Applicant_ (78) ) (Applicant_ (77) ) + ) ( + expected = false + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala index d480d4ac..491cecb9 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -5,3 +5,137 @@ package soda.example.ethicalissues.pricemonitor */ trait Package +trait UnfairPricingAgent + extends + PricingAgent +{ + + lazy val abs_get_price : Customer => Flight => Int => Int = + customer => + flight => + date => + get_price_for (customer) (flight) (date) + + def get_price_for (customer : Customer) (flight : Flight) (date : Int) : Int = + customer.name.length * (date % 100 + 100 * flight.intermediate_airports.length + 1) + +} + +case class UnfairPricingAgent_ () extends UnfairPricingAgent + +trait FairPricingAgent + extends + PricingAgent +{ + + lazy val abs_get_price : Customer => Flight => Int => Int = + customer => + flight => + date => + get_price_for (customer) (flight) (date) + + def get_price_for (customer : Customer) (flight : Flight) (date : Int) : Int = + 100 * (flight.intermediate_airports.length + 1) + +} + +case class FairPricingAgent_ () extends FairPricingAgent + +case class PriceMonitorSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import java.util.Calendar + import java.util.TimeZone + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val fair_pricing_agent = FairPricingAgent_ () + + lazy val unfair_pricing_agent = UnfairPricingAgent_ () + + lazy val customer_1 = Customer_ (name = "Jon", ip_address = "127.0.0.1") + + lazy val customer_2 = Customer_ (name = "Maria", ip_address = "192.168.1.1") + + lazy val flight_1 = Flight_ ("BER", Seq ("FRA", "ARN"), "UMU") + + lazy val date_1 = 18898 + + test ("unfair pricing agent - requirement_monitor 1") ( + check ( + obtained = Requirement1Monitor_ (unfair_pricing_agent).get_report (customer_1) (customer_2) (flight_1) (date_1) + ) ( + expected = Report1_ (false, 897, 1495, 0.6) + ) + ) + + test ("unfair pricing agent - requirement_monitor 2") ( + check ( + obtained = Requirement2Monitor_ (unfair_pricing_agent).get_report (customer_1) (flight_1) (date_1) + ) ( + expected = Report2_ (false, 702, 897) + ) + ) + + test ("unfair pricing agent - requirement_monitor 3") ( + check ( + obtained = Requirement3Monitor_ (unfair_pricing_agent).get_report (customer_1) (flight_1) (date_1) + ) ( + expected = Report3_ (false, 897, 891) + ) + ) + + test ("fair pricing agent - requirement_monitor 1") ( + check ( + obtained = Requirement1Monitor_ (fair_pricing_agent).get_report (customer_1) (customer_2) (flight_1) (date_1) + ) ( + expected = Report1_ (true, 300, 300, 1.0) + ) + ) + + test ("fair pricing agent - requirement_monitor 2") ( + check ( + obtained = Requirement2Monitor_ (fair_pricing_agent).get_report (customer_1) (flight_1) (date_1) + ) ( + expected = Report2_ (true, 300, 300) + ) + ) + + test ("fair pricing agent - requirement_monitor 3") ( + check ( + obtained = Requirement3Monitor_ (fair_pricing_agent).get_report (customer_1) (flight_1) (date_1) + ) ( + expected = Report3_ (true, 300, 300) + ) + ) + + test ("get number of days for 1970-01-01") ( + check ( + obtained = fair_pricing_agent.get_days_for (_calendar_0.getTime) + ) ( + expected = 0 + ) + ) + + private lazy val _calendar_0 = new Calendar.Builder () + .setTimeZone (TimeZone.getTimeZone ("UTC")) + .setDate (1970, 0, 1) + .build + + test ("get number of days for 2021-09-28") ( + check ( + obtained = fair_pricing_agent.get_days_for (_calendar_1.getTime) + ) ( + expected = 18898 + ) + ) + + private lazy val _calendar_1 = new Calendar.Builder () + .setTimeZone (TimeZone.getTimeZone ("UTC")) + .setDate (2021, 8, 28) + .build + +} diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala deleted file mode 100644 index 62d69b9e..00000000 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/PriceMonitorSpec.scala +++ /dev/null @@ -1,142 +0,0 @@ -package soda.example.ethicalissues.pricemonitor - -/* - * This package contains tests for example classes for a price monitor. - */ - - - -trait UnfairPricingAgent - extends - PricingAgent -{ - - lazy val abs_get_price : Customer => Flight => Int => Int = - customer => - flight => - date => - get_price_for (customer) (flight) (date) - - def get_price_for (customer : Customer) (flight : Flight) (date : Int) : Int = - customer.name.length * (date % 100 + 100 * flight.intermediate_airports.length + 1) - -} - -case class UnfairPricingAgent_ () extends UnfairPricingAgent - -trait FairPricingAgent - extends - PricingAgent -{ - - lazy val abs_get_price : Customer => Flight => Int => Int = - customer => - flight => - date => - get_price_for (customer) (flight) (date) - - def get_price_for (customer : Customer) (flight : Flight) (date : Int) : Int = - 100 * (flight.intermediate_airports.length + 1) - -} - -case class FairPricingAgent_ () extends FairPricingAgent - -case class PriceMonitorSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import java.util.Calendar - import java.util.TimeZone - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val fair_pricing_agent = FairPricingAgent_ () - - lazy val unfair_pricing_agent = UnfairPricingAgent_ () - - lazy val customer_1 = Customer_ (name = "Jon", ip_address = "127.0.0.1") - - lazy val customer_2 = Customer_ (name = "Maria", ip_address = "192.168.1.1") - - lazy val flight_1 = Flight_ ("BER", Seq ("FRA", "ARN"), "UMU") - - lazy val date_1 = 18898 - - test ("unfair pricing agent - requirement_monitor 1") ( - check ( - obtained = Requirement1Monitor_ (unfair_pricing_agent).get_report (customer_1) (customer_2) (flight_1) (date_1) - ) ( - expected = Report1_ (false, 897, 1495, 0.6) - ) - ) - - test ("unfair pricing agent - requirement_monitor 2") ( - check ( - obtained = Requirement2Monitor_ (unfair_pricing_agent).get_report (customer_1) (flight_1) (date_1) - ) ( - expected = Report2_ (false, 702, 897) - ) - ) - - test ("unfair pricing agent - requirement_monitor 3") ( - check ( - obtained = Requirement3Monitor_ (unfair_pricing_agent).get_report (customer_1) (flight_1) (date_1) - ) ( - expected = Report3_ (false, 897, 891) - ) - ) - - test ("fair pricing agent - requirement_monitor 1") ( - check ( - obtained = Requirement1Monitor_ (fair_pricing_agent).get_report (customer_1) (customer_2) (flight_1) (date_1) - ) ( - expected = Report1_ (true, 300, 300, 1.0) - ) - ) - - test ("fair pricing agent - requirement_monitor 2") ( - check ( - obtained = Requirement2Monitor_ (fair_pricing_agent).get_report (customer_1) (flight_1) (date_1) - ) ( - expected = Report2_ (true, 300, 300) - ) - ) - - test ("fair pricing agent - requirement_monitor 3") ( - check ( - obtained = Requirement3Monitor_ (fair_pricing_agent).get_report (customer_1) (flight_1) (date_1) - ) ( - expected = Report3_ (true, 300, 300) - ) - ) - - test ("get number of days for 1970-01-01") ( - check ( - obtained = fair_pricing_agent.get_days_for (_calendar_0.getTime) - ) ( - expected = 0 - ) - ) - - private lazy val _calendar_0 = new Calendar.Builder () - .setTimeZone (TimeZone.getTimeZone ("UTC")) - .setDate (1970, 0, 1) - .build - - test ("get number of days for 2021-09-28") ( - check ( - obtained = fair_pricing_agent.get_days_for (_calendar_1.getTime) - ) ( - expected = 18898 - ) - ) - - private lazy val _calendar_1 = new Calendar.Builder () - .setTimeZone (TimeZone.getTimeZone ("UTC")) - .setDate (2021, 8, 28) - .build - -} diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala index 98b0ee3f..ae4b0ff5 100644 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala @@ -5,3 +5,67 @@ package soda.example.forcoq.algorithms */ trait Package +case class RecursionForCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) + + test ("fold left while with Seq") ( + check ( + obtained = RecursionForCoq_ ().fold4 (example_seq) (_fold_left_while_initial_value) (_fold_left_while_next_value_function) (_fold_left_while_condition) + ) ( + expected = Seq ("103", "102", "101", "101", "100") + ) + ) + + private lazy val _fold_left_while_initial_value = Seq [String] () + + private lazy val _fold_left_while_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String]) => (e : Int) => s .+: ("" + (e + 100)) + + private lazy val _fold_left_while_condition : Seq [String] => Int => Boolean = + (s : Seq [String]) => (e : Int) => e < 5 + + test ("fold left with Seq") ( + check ( + obtained = RecursionForCoq_ ().fold3 (example_seq) (_fold_left_initial_value) (_fold_left_next_value_function) + ) ( + expected = Seq ("108", "105", "103", "102", "101", "101", "100") + ) + ) + + private lazy val _fold_left_initial_value = Seq [String] () + + private lazy val _fold_left_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String]) => (e : Int) => s .+: ("" + (e + 100)) + + test ("range with positive number") ( + check ( + obtained = RecursionForCoq_ ().range (8) + ) ( + expected = Seq [Int] (0, 1, 2, 3, 4, 5, 6, 7) + ) + ) + + test ("range with zero size") ( + check ( + obtained = RecursionForCoq_ ().range (-1) + ) ( + expected = Seq [Int] () + ) + ) + + test ("range with negative number") ( + check ( + obtained = RecursionForCoq_ ().range (-1) + ) ( + expected = Seq [Int] () + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala deleted file mode 100644 index 36584836..00000000 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/RecursionForCoqSpec.scala +++ /dev/null @@ -1,72 +0,0 @@ -package soda.example.forcoq.algorithms - -/* - * This package contains examples using recursion for Coq. - */ - - - -case class RecursionForCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) - - test ("fold left while with Seq") ( - check ( - obtained = RecursionForCoq_ ().fold4 (example_seq) (_fold_left_while_initial_value) (_fold_left_while_next_value_function) (_fold_left_while_condition) - ) ( - expected = Seq ("103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold_left_while_initial_value = Seq [String] () - - private lazy val _fold_left_while_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String]) => (e : Int) => s .+: ("" + (e + 100)) - - private lazy val _fold_left_while_condition : Seq [String] => Int => Boolean = - (s : Seq [String]) => (e : Int) => e < 5 - - test ("fold left with Seq") ( - check ( - obtained = RecursionForCoq_ ().fold3 (example_seq) (_fold_left_initial_value) (_fold_left_next_value_function) - ) ( - expected = Seq ("108", "105", "103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold_left_initial_value = Seq [String] () - - private lazy val _fold_left_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String]) => (e : Int) => s .+: ("" + (e + 100)) - - test ("range with positive number") ( - check ( - obtained = RecursionForCoq_ ().range (8) - ) ( - expected = Seq [Int] (0, 1, 2, 3, 4, 5, 6, 7) - ) - ) - - test ("range with zero size") ( - check ( - obtained = RecursionForCoq_ ().range (-1) - ) ( - expected = Seq [Int] () - ) - ) - - test ("range with negative number") ( - check ( - obtained = RecursionForCoq_ ().range (-1) - ) ( - expected = Seq [Int] () - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala b/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala deleted file mode 100644 index 5b67a6eb..00000000 --- a/examples/src/test/scala/soda/example/forcoq/lib/ListSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package soda.example.forcoq.lib - -/* - * This package contains tests for helper classes that could be needed for a translation to Coq. - */ - - - -case class ListSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("list from Seq") ( - check ( - obtained = SeqList_ ().from_Seq ( Seq [Int] (0, 1, 1, 2, 3, 5) ) - ) ( - expected = (cons_ (0, cons_ (1, cons_ (1, cons_ (2, cons_ (3, cons_ (5, nil_ [Int] () ) ) ) ) ) ) ) - ) - ) - - test ("list to Seq") ( - check ( - obtained = SeqList_ ().to_Seq ( (cons_ (1, cons_ (2, cons_ (4, cons_ (8, cons_ (16, nil_ [Int] () ) ) ) ) ) ) ) - ) ( - expected = Seq [Int] (1, 2, 4, 8, 16) - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala b/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala deleted file mode 100644 index e7824aa2..00000000 --- a/examples/src/test/scala/soda/example/forcoq/lib/NatSpec.scala +++ /dev/null @@ -1,49 +0,0 @@ -package soda.example.forcoq.lib - -/* - * This package contains tests for helper classes that could be needed for a translation to Coq. - */ - - - -case class NatSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("IntNat from non negative") ( - check ( - obtained = IntNat_ ().from_non_negative (8) - ) ( - expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) - ) - ) - - test ("IntNat to Int") ( - check ( - obtained = IntNat_ ().to_Int ( S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) - ) ( - expected = 5 - ) - ) - - test ("Nat add") ( - check ( - obtained = S_ (S_ (S_ (O_ ( ) ) ) ).add (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) - ) ( - expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) - ) - ) - - test ("Nat mul") ( - check ( - obtained = S_ (S_ (S_ (O_ ( ) ) ) ).mul (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) - ) ( - expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) ) ) ) ) - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala index 641afbae..8d6a3106 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala @@ -5,3 +5,69 @@ package soda.example.forcoq.lib */ trait Package +case class ListSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("list from Seq") ( + check ( + obtained = SeqList_ ().from_Seq ( Seq [Int] (0, 1, 1, 2, 3, 5) ) + ) ( + expected = (cons_ (0, cons_ (1, cons_ (1, cons_ (2, cons_ (3, cons_ (5, nil_ [Int] () ) ) ) ) ) ) ) + ) + ) + + test ("list to Seq") ( + check ( + obtained = SeqList_ ().to_Seq ( (cons_ (1, cons_ (2, cons_ (4, cons_ (8, cons_ (16, nil_ [Int] () ) ) ) ) ) ) ) + ) ( + expected = Seq [Int] (1, 2, 4, 8, 16) + ) + ) + +} +case class NatSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("IntNat from non negative") ( + check ( + obtained = IntNat_ ().from_non_negative (8) + ) ( + expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) + ) + ) + + test ("IntNat to Int") ( + check ( + obtained = IntNat_ ().to_Int ( S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) + ) ( + expected = 5 + ) + ) + + test ("Nat add") ( + check ( + obtained = S_ (S_ (S_ (O_ ( ) ) ) ).add (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) + ) ( + expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) + ) + ) + + test ("Nat mul") ( + check ( + obtained = S_ (S_ (S_ (O_ ( ) ) ) ).mul (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) + ) ( + expected = S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (S_ (O_ ( ) ) ) ) ) ) ) ) ) ) ) ) ) + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala deleted file mode 100644 index a486a85a..00000000 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FactorialForCoqSpec.scala +++ /dev/null @@ -1,40 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains tests for examples of some mathematical functions that can be translated to Coq. - */ - - - -case class FactorialForCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.example.forcoq.lib.IntNat_ - import soda.example.forcoq.lib.nat - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val factorial_values : Seq [ Tuple2 [Int, Int] ] = Seq ( - (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720) - ) - - lazy val factorial_values_with_nat : Seq [ Tuple2 [nat, nat] ] = - factorial_values - .map ( pair => - Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) - ) - - test ("should test the factorial function for Coq") ( - check ( - obtained = factorial_values_with_nat - .map ( pair => pair._1) - .map ( n => Tuple2 (n, FactorialForCoq_ ().get_factorial (n) ) ) - ) ( - expected = factorial_values_with_nat - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala deleted file mode 100644 index daaaefb9..00000000 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/FiboExampleInSodaForCoqSpec.scala +++ /dev/null @@ -1,40 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains tests for examples of some mathematical functions that can be translated to Coq. - */ - - - -case class FiboExampleInSodaForCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.example.forcoq.lib.IntNat_ - import soda.example.forcoq.lib.nat - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val fibonacci_values : Seq [ Tuple2 [Int, Int] ] = Seq ( - (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) - ) - - lazy val fibonacci_values_with_nat : Seq [ Tuple2 [nat, nat] ] = - fibonacci_values - .map ( pair => - Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) - ) - - test ("should test the fibonacci function for Coq") ( - check ( - obtained = fibonacci_values_with_nat - .map ( pair => pair._1) - .map ( n => Tuple2 (n, FiboExampleInSodaForCoq_ ().fib (n) ) ) - ) ( - expected = fibonacci_values_with_nat - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala index bc586482..d3c9aed9 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala @@ -5,3 +5,99 @@ package soda.example.forcoq.mathematics */ trait Package +case class FactorialForCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.example.forcoq.lib.IntNat_ + import soda.example.forcoq.lib.nat + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val factorial_values : Seq [ Tuple2 [Int, Int] ] = Seq ( + (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720) + ) + + lazy val factorial_values_with_nat : Seq [ Tuple2 [nat, nat] ] = + factorial_values + .map ( pair => + Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) + ) + + test ("should test the factorial function for Coq") ( + check ( + obtained = factorial_values_with_nat + .map ( pair => pair._1) + .map ( n => Tuple2 (n, FactorialForCoq_ ().get_factorial (n) ) ) + ) ( + expected = factorial_values_with_nat + ) + ) + +} +case class TriangularNumberForCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.example.forcoq.lib.IntNat_ + import soda.example.forcoq.lib.nat + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val triangular_number_values : Seq [ Tuple2 [Int, Int] ] = Seq ( + (0, 0), (1, 1), (2, 3), (3, 6), (4, 10), (5, 15), (6, 21) + ) + + lazy val triangular_number_with_nat : Seq [ Tuple2 [nat, nat] ] = + triangular_number_values + .map ( pair => + Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) + ) + + test ("should test the triangular for Coq") ( + check ( + obtained = triangular_number_with_nat + .map ( pair => pair._1) + .map ( n => Tuple2 (n, TriangularNumberForCoq_ ().get_number (n) ) ) + ) ( + expected = triangular_number_with_nat + ) + ) + +} +case class FiboExampleInSodaForCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.example.forcoq.lib.IntNat_ + import soda.example.forcoq.lib.nat + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val fibonacci_values : Seq [ Tuple2 [Int, Int] ] = Seq ( + (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) + ) + + lazy val fibonacci_values_with_nat : Seq [ Tuple2 [nat, nat] ] = + fibonacci_values + .map ( pair => + Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) + ) + + test ("should test the fibonacci function for Coq") ( + check ( + obtained = fibonacci_values_with_nat + .map ( pair => pair._1) + .map ( n => Tuple2 (n, FiboExampleInSodaForCoq_ ().fib (n) ) ) + ) ( + expected = fibonacci_values_with_nat + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala deleted file mode 100644 index 68332b62..00000000 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/TriangularNumberForCoqSpec.scala +++ /dev/null @@ -1,40 +0,0 @@ -package soda.example.forcoq.mathematics - -/* - * This package contains tests for examples of some mathematical functions that can be translated to Coq. - */ - - - -case class TriangularNumberForCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.example.forcoq.lib.IntNat_ - import soda.example.forcoq.lib.nat - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val triangular_number_values : Seq [ Tuple2 [Int, Int] ] = Seq ( - (0, 0), (1, 1), (2, 3), (3, 6), (4, 10), (5, 15), (6, 21) - ) - - lazy val triangular_number_with_nat : Seq [ Tuple2 [nat, nat] ] = - triangular_number_values - .map ( pair => - Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) - ) - - test ("should test the triangular for Coq") ( - check ( - obtained = triangular_number_with_nat - .map ( pair => pair._1) - .map ( n => Tuple2 (n, TriangularNumberForCoq_ ().get_number (n) ) ) - ) ( - expected = triangular_number_with_nat - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala b/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala deleted file mode 100644 index 798e9840..00000000 --- a/examples/src/test/scala/soda/example/mathematics/FactorialSpec.scala +++ /dev/null @@ -1,57 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains tests for examples in Soda that use mathematical properties. - */ - - - -case class FactorialSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val factorial_values = Seq ( - (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720), (7, 5040), (8, 40320), (9, 362880), (10, 3628800) - ) - - private lazy val _factorial_concise = FactorialConcise_ () - - private lazy val _factorial_patten_matching = FactorialPatternMatching_ () - - private lazy val _factorial_with_fold = FactorialWithFold_ () - - test ("should test the factorial - concise version") ( - check ( - obtained = factorial_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, _factorial_concise.apply (n) ) ) - ) ( - expected = factorial_values - ) - ) - - test ("should test the factorial - with pattern matching") ( - check ( - obtained = factorial_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, _factorial_patten_matching.apply (n) ) ) - ) ( - expected = factorial_values - ) - ) - - test ("should test the factorial - with fold") ( - check ( - obtained = factorial_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, _factorial_with_fold.apply (n) ) ) - ) ( - expected = factorial_values - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala b/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala deleted file mode 100644 index 7f982269..00000000 --- a/examples/src/test/scala/soda/example/mathematics/FiboExampleSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains tests for examples in Soda that use mathematical properties. - */ - - - -case class FiboExampleSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val fibonacci_values = Seq ( - (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) - ) - - private lazy val _fibo_example_in_soda = FiboExampleInSoda_ () - - test ("should test the fibonacci function") ( - check ( - obtained = fibonacci_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) - ) ( - expected = fibonacci_values - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala b/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala deleted file mode 100644 index de5a3cde..00000000 --- a/examples/src/test/scala/soda/example/mathematics/HardProblemSpec.scala +++ /dev/null @@ -1,84 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains tests for examples in Soda that use mathematical properties. - */ - - - -case class HardProblemSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val empty_map = Map [Int, Int] () - - lazy val instance = HardProblem_ () - - test ("hard problem 9") ( - check ( - obtained = instance.compute (InputPair_ (9, empty_map) ) - ) ( - expected = OutputPair_ (19, Seq ( (9, 19), (28, 18), (14, 17), (7, 16), (22, 15), - (11, 14), (34, 13), (17, 12), (52, 11), (26, 10), - (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("hard problem 12") ( - check ( - obtained = instance.compute (InputPair_ (12, empty_map) ) - ) ( - expected = OutputPair_ (9, Seq ( (12, 9), (6, 8), (3, 7), (10, 6), (5, 5), - (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("hard problem 13") ( - check ( - obtained = instance.compute (InputPair_ (13, empty_map) ) - ) ( - expected = OutputPair_ (9, Seq ( (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), - (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("hard problem 14") ( - check ( - obtained = instance.compute (InputPair_ (14, empty_map) ) - ) ( - expected = OutputPair_ (17, Seq ( (14, 17), (7, 16), (22, 15), (11, 14), (34, 13), (17, 12), (52, 11), (26, 10), - (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("hard problem 16") ( - check ( - obtained = instance.compute (InputPair_ (16, empty_map) ) - ) ( - expected = OutputPair_ (4, Seq ( (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("hard problem 20") ( - check ( - obtained = instance.compute (InputPair_ (20, empty_map) ) - ) ( - expected = OutputPair_ (7, Seq ( (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) - ) - ) - - test ("memoized fibonacci 20") ( - check ( - obtained = MemoizedFibonacci_ ().compute (InputPair_ (20, empty_map) ) - ) ( - expected = OutputPair_ (6765, Seq ( (20, 6765), (19, 4181), (18, 2584), (17, 1597), (16, 987), (15, 610), (14, 377), - (13, 233), (12, 144), (11, 89), (10, 55), (9, 34), (8, 21), (7, 13), - (6, 8), (5, 5), (4, 3), (3, 2), (2, 1), (1, 1), (0, 0) ).toMap) - ) - ) - -} diff --git a/examples/src/test/scala/soda/example/mathematics/Package.scala b/examples/src/test/scala/soda/example/mathematics/Package.scala index bdc89132..763680b2 100644 --- a/examples/src/test/scala/soda/example/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/mathematics/Package.scala @@ -5,3 +5,176 @@ package soda.example.mathematics */ trait Package +case class PiIteratorSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" + + private lazy val _pi_iterator = PiIterator_ () + + lazy val pi_sequence = _pi_iterator.apply (128) + + test ("first digits of Pi") ( + check ( + obtained = "" + pi_sequence.head + "." + pi_sequence.tail.mkString ("") + ) ( + expected = pi_start + ) + ) + +} +case class FiboExampleSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val fibonacci_values = Seq ( + (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) + ) + + private lazy val _fibo_example_in_soda = FiboExampleInSoda_ () + + test ("should test the fibonacci function") ( + check ( + obtained = fibonacci_values + .map ( pair => pair._1) + .map ( n => Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) + ) ( + expected = fibonacci_values + ) + ) + +} +case class FactorialSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val factorial_values = Seq ( + (0, 1), (1, 1), (2, 2), (3, 6), (4, 24), (5, 120), (6, 720), (7, 5040), (8, 40320), (9, 362880), (10, 3628800) + ) + + private lazy val _factorial_concise = FactorialConcise_ () + + private lazy val _factorial_patten_matching = FactorialPatternMatching_ () + + private lazy val _factorial_with_fold = FactorialWithFold_ () + + test ("should test the factorial - concise version") ( + check ( + obtained = factorial_values + .map ( pair => pair._1) + .map ( n => Tuple2 (n, _factorial_concise.apply (n) ) ) + ) ( + expected = factorial_values + ) + ) + + test ("should test the factorial - with pattern matching") ( + check ( + obtained = factorial_values + .map ( pair => pair._1) + .map ( n => Tuple2 (n, _factorial_patten_matching.apply (n) ) ) + ) ( + expected = factorial_values + ) + ) + + test ("should test the factorial - with fold") ( + check ( + obtained = factorial_values + .map ( pair => pair._1) + .map ( n => Tuple2 (n, _factorial_with_fold.apply (n) ) ) + ) ( + expected = factorial_values + ) + ) + +} +case class HardProblemSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val empty_map = Map [Int, Int] () + + lazy val instance = HardProblem_ () + + test ("hard problem 9") ( + check ( + obtained = instance.compute (InputPair_ (9, empty_map) ) + ) ( + expected = OutputPair_ (19, Seq ( (9, 19), (28, 18), (14, 17), (7, 16), (22, 15), + (11, 14), (34, 13), (17, 12), (52, 11), (26, 10), + (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("hard problem 12") ( + check ( + obtained = instance.compute (InputPair_ (12, empty_map) ) + ) ( + expected = OutputPair_ (9, Seq ( (12, 9), (6, 8), (3, 7), (10, 6), (5, 5), + (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("hard problem 13") ( + check ( + obtained = instance.compute (InputPair_ (13, empty_map) ) + ) ( + expected = OutputPair_ (9, Seq ( (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), + (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("hard problem 14") ( + check ( + obtained = instance.compute (InputPair_ (14, empty_map) ) + ) ( + expected = OutputPair_ (17, Seq ( (14, 17), (7, 16), (22, 15), (11, 14), (34, 13), (17, 12), (52, 11), (26, 10), + (13, 9), (40, 8), (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("hard problem 16") ( + check ( + obtained = instance.compute (InputPair_ (16, empty_map) ) + ) ( + expected = OutputPair_ (4, Seq ( (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("hard problem 20") ( + check ( + obtained = instance.compute (InputPair_ (20, empty_map) ) + ) ( + expected = OutputPair_ (7, Seq ( (20, 7), (10, 6), (5, 5), (16, 4), (8, 3), (4, 2), (2, 1), (1, 0) ).toMap) + ) + ) + + test ("memoized fibonacci 20") ( + check ( + obtained = MemoizedFibonacci_ ().compute (InputPair_ (20, empty_map) ) + ) ( + expected = OutputPair_ (6765, Seq ( (20, 6765), (19, 4181), (18, 2584), (17, 1597), (16, 987), (15, 610), (14, 377), + (13, 233), (12, 144), (11, 89), (10, 55), (9, 34), (8, 21), (7, 13), + (6, 8), (5, 5), (4, 3), (3, 2), (2, 1), (1, 1), (0, 0) ).toMap) + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala b/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala deleted file mode 100644 index 0eae2a80..00000000 --- a/examples/src/test/scala/soda/example/mathematics/PiIteratorSpec.scala +++ /dev/null @@ -1,31 +0,0 @@ -package soda.example.mathematics - -/* - * This package contains tests for examples in Soda that use mathematical properties. - */ - - - -case class PiIteratorSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" - - private lazy val _pi_iterator = PiIterator_ () - - lazy val pi_sequence = _pi_iterator.apply (128) - - test ("first digits of Pi") ( - check ( - obtained = "" + pi_sequence.head + "." + pi_sequence.tail.mkString ("") - ) ( - expected = pi_start - ) - ) - -} From e936b1fd99d8b2519d5f63f2e332cd3e928aabd5 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 21:00:32 +0100 Subject: [PATCH 51/71] Replace Scala files by Package.scala in library --- .../src/main/scala/soda/collection/MSeq.scala | 86 --- .../src/main/scala/soda/collection/Min.scala | 426 ------------- .../main/scala/soda/collection/Package.scala | 492 +++++++++++++++ .../soda/collection/example/ListExample.scala | 100 --- .../scala/soda/collection/example/Main.scala | 52 -- .../soda/collection/example/Package.scala | 136 ++++ .../test/scala/soda/collection/MinSpec.scala | 592 ------------------ .../test/scala/soda/collection/Package.scala | 584 +++++++++++++++++ .../collection/example/ListExampleSpec.scala | 193 ------ .../soda/collection/example/Package.scala | 185 ++++++ 10 files changed, 1397 insertions(+), 1449 deletions(-) delete mode 100644 library/src/main/scala/soda/collection/MSeq.scala delete mode 100644 library/src/main/scala/soda/collection/Min.scala delete mode 100644 library/src/main/scala/soda/collection/example/ListExample.scala delete mode 100644 library/src/main/scala/soda/collection/example/Main.scala delete mode 100644 library/src/test/scala/soda/collection/MinSpec.scala delete mode 100644 library/src/test/scala/soda/collection/example/ListExampleSpec.scala diff --git a/library/src/main/scala/soda/collection/MSeq.scala b/library/src/main/scala/soda/collection/MSeq.scala deleted file mode 100644 index 45eeafb5..00000000 --- a/library/src/main/scala/soda/collection/MSeq.scala +++ /dev/null @@ -1,86 +0,0 @@ -package soda.collection - -/* - * This package contains examples for Soda. - * They can be used as libraries, but their main purpose is - * to show possible implementations of functions for list manipulation. - */ - - - -trait MSeq [A] -{ - - def isEmpty : Boolean - - def opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] => B) : B = - this match { - case NESeq_ (head, tail) => ifNonEmpty (NESeq_ (head, tail) ) - case x => ifEmpty - } - -} - -case class MSeq_ [A] (isEmpty : Boolean) extends MSeq [A] - -trait MSeqRec [A] -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - sequence match { - case NESeq_ (head, tail) => - if ( ! condition (current_value) (head) - ) current_value - else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) - case x => current_value - } - - def fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) - -} - -case class MSeqRec_ [A] () extends MSeqRec [A] - -trait ESeq [A] - extends - MSeq [A] -{ - - lazy val isEmpty = true - -} - -case class ESeq_ [A] () extends ESeq [A] - -trait NEMSeq [A] - extends - MSeq [A] -{ - - def head0 : A - def tail0 : MSeq [A] - - lazy val isEmpty = false - -} - -case class NEMSeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NEMSeq [A] - -trait NESeq [A] - extends - NEMSeq [A] -{ - - def head0 : A - def tail0 : MSeq [A] - - lazy val head : A = head0 - - lazy val tail : MSeq [A] = tail0 - -} - -case class NESeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NESeq [A] diff --git a/library/src/main/scala/soda/collection/Min.scala b/library/src/main/scala/soda/collection/Min.scala deleted file mode 100644 index c5f7462d..00000000 --- a/library/src/main/scala/soda/collection/Min.scala +++ /dev/null @@ -1,426 +0,0 @@ -package soda.collection - -/* - * This package contains examples for Soda. - * They can be used as libraries, but their main purpose is - * to show possible implementations of functions for list manipulation. - */ - - - -trait MSeqTranslator [A] -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_foldLeftSeq [B] (sequence : Seq [A] ) (current_value : B) (next_value : B => A => B) : B = - if ( sequence.isEmpty - ) current_value - else _tailrec_foldLeftSeq (sequence.tail) (next_value (current_value) (sequence.head) ) (next_value) - - def foldLeftSeq [B] (sequence : Seq [A] ) (initial_value : B) (next_value : B => A => B) : B = - _tailrec_foldLeftSeq (sequence) (initial_value) (next_value) - - def asMSeq (seq : Seq [A] ) : MSeq [A] = - Min_ ().reverse (foldLeftSeq [MSeq [A] ] (seq) (_asMSeq_initial_value) (_asMSeq_next_value) ) - - private lazy val _asMSeq_initial_value : MSeq [A] = Min_ ().empty - - private def _asMSeq_next_value (acc : MSeq [A] ) (elem : A) : MSeq [A] = - Min_ ().prepended (acc) (elem) - - def asSeq (mseq : MSeq [A] ) : Seq [A] = - (Min_ ().foldLeft (mseq) (_asSeq_initial_value) (_asSeq_next_value) ).reverse - - private lazy val _asSeq_initial_value : Seq [A] = Seq () - - private def _asSeq_next_value (acc : Seq [A] ) (elem : A) : Seq [A] = - acc.+: (elem) - -} - -case class MSeqTranslator_ [A] () extends MSeqTranslator [A] - -trait MSeqPair [A] -{ - - def left : MSeq [A] - def right : MSeq [A] - -} - -case class MSeqPair_ [A] (left : MSeq [A], right : MSeq [A]) extends MSeqPair [A] - -trait Min [A] -{ - - import soda.lib.NoneSD_ - import soda.lib.OptionSD - import soda.lib.SomeSD_ - - lazy val empty : ESeq [A] = ESeq_ () - - def prepended (s : MSeq [A] ) (e : A) : NESeq [A] = - NESeq_ (e, s) - - def head (s : NESeq [A] ) : A = - s.head - - def tail (s : NESeq [A] ) : MSeq [A] = - s.tail - - def nonEmpty (s : MSeq [A] ) : Boolean = - ! isEmpty (s) - - def isEmpty (s : MSeq [A] ) : Boolean = - s.isEmpty - - /* */ - - def foldLeftWhile [B] (s : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = - MSeqRec_ [A] ().fold_while [B] (s) (initial_value) (next_value) (condition) - - def foldLeft [B] (s : MSeq [A] ) (initial_value : B) (next_value : B => A => B) : B = - foldLeftWhile (s) (initial_value) (next_value) ( (acc : B) => (elem : A) => true) - - def reverse (s : MSeq [A] ) : MSeq [A] = - s.opt [MSeq [A] ] ( - ifEmpty = empty) ( - ifNonEmpty = neseq => reverseNonEmpty (neseq) - ) - - def reverseNonEmpty (s : NESeq [A] ) : NESeq [A] = - foldLeft (s.tail) (_reverseNonEmpty_initial_value (s) ) (_reverseNonEmpty_next_value) - - private def _reverseNonEmpty_initial_value (s : NESeq [A] ) : NESeq [A] = prepended (empty) (s.head) - - private def _reverseNonEmpty_next_value (acc : MSeq [A] ) (elem : A) : NESeq [A] = prepended (acc) (elem) - - def length (s : MSeq [A] ) : Int = - foldLeft (s) (_length_initial_value) (_length_next_value) - - private lazy val _length_initial_value : Int = 0 - - private def _length_next_value (acc : Int) (elem : A) : Int = - acc + 1 - - def indexOf (s : MSeq [A] ) (e : A) : Int = - (foldLeftWhile (s) (_indexOf_initial_value (e) ) (_indexOf_next_value) (_indexOf_condition) ).position - - private def _indexOf_initial_value (element : A) : IndexFoldTuple [A] = IndexFoldTuple_ [A] (0, -1, element) - - private def _indexOf_next_value (tuple : IndexFoldTuple [A] ) (current_element : A) : IndexFoldTuple [A] = - IndexFoldTuple_ [A] ( - tuple.index + 1, - _get_index_if_element_found (tuple) (current_element) , - tuple.element - ) - - private def _get_index_if_element_found (tuple : IndexFoldTuple [A] ) (current_element : A) : Int = - if ( current_element == tuple.element - ) tuple.index - else tuple.position - - private def _indexOf_condition (tuple : IndexFoldTuple [A] ) (elem : A) : Boolean = - tuple.position == -1 - - def contains (s : MSeq [A] ) (e : A) : Boolean = - (foldLeftWhile (s) (_contains_initial_value (e) ) (_contains_next_value) (_contains_condition) ).contained - - private def _contains_initial_value (element : A) : ContainsFoldTuple [A] = - ContainsFoldTuple_ (false, element) - - private def _contains_next_value (tuple : ContainsFoldTuple [A] ) (elem : A) : ContainsFoldTuple [A] = - ContainsFoldTuple_ (elem == tuple.element, tuple.element) - - private def _contains_condition (tuple : ContainsFoldTuple [A] ) (elem : A) : Boolean = - ! tuple.contained - - def at (s : MSeq [A] ) (n : Int) : OptionSD [A] = - s.opt [OptionSD [A] ] ( - ifEmpty = NoneSD_ [A] () ) ( - ifNonEmpty = ( neseq => _retrieve_if_in_range (neseq) (n) ) - ) - - private def _retrieve_if_in_range (xs : NESeq [A] ) (n : Int) : OptionSD [A] = - if ( n < 0 || n >= length (xs) - ) NoneSD_ [A] () - else SomeSD_ [A] (_atNonEmpty (xs) (n) ) - - private def _atNonEmpty (xs : NESeq [A] ) (n : Int) : A = - (foldLeftWhile (xs) (_atNonEmpty_initial_value (xs) (n) ) (_atNonEmpty_next_value) (_atNonEmpty_condition) ).elem - - private def _atNonEmpty_initial_value (xs : NESeq [A] ) (position : Int ) : AtFoldTuple [A] = - AtFoldTuple_ [A] (xs.head, -1, position) - - private def _atNonEmpty_next_value (tuple : AtFoldTuple [A] ) (elem : A) : AtFoldTuple [A] = - AtFoldTuple_ [A] (elem, tuple.index + 1, tuple.position) - - private def _atNonEmpty_condition (tuple : AtFoldTuple [A] ) (elem : A) : Boolean = - tuple.index < tuple.position - - /* */ - - def take (s : MSeq [A] ) (n : Int) : MSeq [A] = - reverse ( (foldLeftWhile (s) (_take_initial_value (n) ) (_take_next_value) (_take_condition) ).seq ) - - private def _take_initial_value (length : Int ) : TakeDropFoldTuple [A] = TakeDropFoldTuple_ [A] (empty, 0, length) - - private def _take_next_value (tuple : TakeDropFoldTuple [A] ) (elem : A) : TakeDropFoldTuple [A] = - TakeDropFoldTuple_ [A] (prepended (tuple.seq) (elem), tuple.index + 1, tuple.length) - - private def _take_condition (tuple : TakeDropFoldTuple [A] ) (elem : A) : Boolean = tuple.index < tuple.length - - def drop (s : MSeq [A] ) (n : Int) : MSeq [A] = - (foldLeftWhile (s) (_drop_initial_value (s) (n) ) (_drop_next_value) (_drop_condition) ).seq - - private def _drop_initial_value (s : MSeq [A] ) (length : Int) : TakeDropFoldTuple [A] = TakeDropFoldTuple_ [A] (s, 0, length) - - private def _drop_next_value (tuple : TakeDropFoldTuple [A] ) (elem : A) : TakeDropFoldTuple [A] = - tuple.seq.opt ( - ifEmpty = TakeDropFoldTuple_ [A] (tuple.seq, tuple.index + 1, tuple.length) ) ( - ifNonEmpty = neseq => TakeDropFoldTuple_ [A] (neseq.tail, tuple.index + 1, tuple.length) - ) - - private def _drop_condition (tuple : TakeDropFoldTuple [A] ) (elem : A) : Boolean = - tuple.index < tuple.length - - def takeWhile (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = - reverse ( (spanRevRec (s) (p) ).left) - - def dropWhile (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = - (spanRevRec (s) (p) ).right - - def splitAt (s : MSeq [A] ) (n : Int) : MSeqPair [A] = - MSeqPair_ (take (s) (n), drop (s) (n) ) - - def span (s : MSeq [A] ) (p : A => Boolean) : MSeqPair [A] = - _span_with (s) (p) (spanRevRec (s) (p) ) - - private def _span_with (s : MSeq [A] ) (p : A => Boolean) (pair : MSeqPair [A] ) : MSeqPair [A] = - MSeqPair_ (reverse (pair.left), pair.right) - - /* */ - - def appended (s : MSeq [A] ) (e : A) : MSeq [A] = - reverse (prepended (reverse (s) ) (e) ) - - def last (s : NESeq [A] ) : A = - reverseNonEmpty (s).head - - def concat (s0 : MSeq [A] ) (s1 : MSeq [A] ) : MSeq [A] = - foldLeft (reverse (s0) ) (_concat_initial_value (s1) ) (_concat_next_value) - - private def _concat_initial_value (s1 : MSeq [A] ) : MSeq [A] = s1 - - private def _concat_next_value (acc : MSeq [A] ) (elem : A) : MSeq [A] = prepended (acc) (elem) - - def slice (s : MSeq [A] ) (from : Int) (until : Int) : MSeq [A] = take (drop (s) (from) ) (until - from) - - /* */ - - def forall (s : MSeq [A] ) (p : A => Boolean) : Boolean = - (foldLeftWhile (s) (_forall_initial_value (p) ) (_forall_next_value) (_forall_condition) ).status - - private def _forall_initial_value (condition : A => Boolean ) : ForallExistsFoldTuple [A] = ForallExistsFoldTuple_ (true, condition) - - private def _forall_next_value (tuple : ForallExistsFoldTuple [A] ) (elem : A) : ForallExistsFoldTuple [A] = - ForallExistsFoldTuple_ (tuple.status && tuple.condition (elem), tuple.condition) - - private def _forall_condition (tuple : ForallExistsFoldTuple [A] ) (elem : A) : Boolean = - tuple.status - - def exists (s : MSeq [A] ) (p : A => Boolean ) : Boolean = - (foldLeftWhile (s) (_exists_initial_value (p) ) (_exists_next_value) (_exists_condition) ).status - - private def _exists_initial_value (condition : A => Boolean ) : ForallExistsFoldTuple [A] = ForallExistsFoldTuple_ (false, condition) - - private def _exists_next_value (tuple : ForallExistsFoldTuple [A] ) (elem : A) : ForallExistsFoldTuple [A] = - ForallExistsFoldTuple_ (tuple.status || tuple.condition (elem), tuple.condition) - - private def _exists_condition (tuple : ForallExistsFoldTuple [A] ) (elem : A) : Boolean = - ! tuple.status - - def find (s : MSeq [A] ) (p : A => Boolean) : OptionSD [A] = - (foldLeftWhile (s) (_find_initial_value (p) ) (_find_next_value) (_find_condition) ).maybe_element - - private def _find_initial_value (condition : A => Boolean) : FindFoldTuple [A] = - FindFoldTuple_ (NoneSD_ [A] (), condition) - - private def _find_next_value (tuple : FindFoldTuple [A] ) (elem : A) : FindFoldTuple [A] = - if ( tuple.condition (elem) - ) FindFoldTuple_ (SomeSD_ [A] (elem), tuple.condition) - else FindFoldTuple_ (NoneSD_ [A] (), tuple.condition) - - private def _find_condition (tuple : FindFoldTuple [A] ) (elem : A) : Boolean = - tuple.maybe_element.isEmpty - - def filter (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = - reverse ( (foldLeft (s) (_filter_initial_value (p) ) (_filter_next_value) ).sequence ) - - private def _filter_initial_value (condition : A => Boolean) : FilterFoldTuple [A] = - FilterFoldTuple_ (empty, condition) - - private def _filter_next_value (tuple : FilterFoldTuple [A] ) (elem : A) : FilterFoldTuple [A] = - FilterFoldTuple_ ( - _prepend_when_condition (tuple) (elem) , - tuple.condition - ) - - private def _prepend_when_condition (tuple : FilterFoldTuple [A] ) (elem : A) : MSeq [A] = - if ( tuple.condition (elem) - ) prepended (tuple.sequence) (elem) - else tuple.sequence - - def map0 (s : MSeq [A] ) (f : A => A) : MSeq [A] = - reverse ( (foldLeft (s) (_map0_initial_value (f) ) (_map0_next_value) ).sequence) - - private def _map0_initial_value (mapping : A => A) : Map0FoldTuple [A] = - Map0FoldTuple_ (empty, mapping) - - private def _map0_next_value (tuple : Map0FoldTuple [A] ) (elem : A) : Map0FoldTuple [A] = - Map0FoldTuple_ (prepended (tuple.sequence) (tuple.mapping (elem) ), tuple.mapping) - - /** - *
-   * def foldLeft [B] (z : B) (op : (B, A) -> B) : B =
-   * . var result = z
-   * . it = iterator
-   * . while (it.hasNext) {
-   * . . result = op (result, it.next () )
-   * . }
-   * . result
-   * end
-   * 
- */ - def foldLeft0 (mseq : MSeq [A] ) : MSeq [A] => (MSeq [A] => A => MSeq [A] ) => MSeq [A] = - (initial_value : MSeq [A] ) => - (next_value : MSeq [A] => A => MSeq [A] ) => - foldLeft (mseq) (initial_value) (next_value) - - /* */ - - def spanRevRec (s0 : MSeq [A] ) (p : A => Boolean) : MSeqPair [A] = - _spanRevRec_for (foldLeftWhile (s0) (_spanRevRec_initial_value (s0) (p) ) (_spanRevRec_next_value) (_spanRevRec_condition) ) - - private def _spanRevRec_for (tuple: SpanRevFoldTuple [A] ) : MSeqPair [A] = - MSeqPair_ (tuple.right, tuple.left) - - private def _spanRevRec_initial_value (s0 : MSeq [A] ) (condition : A => Boolean) : SpanRevFoldTuple [A] = - SpanRevFoldTuple_ [A] (s0, empty, true, condition) - - private def _spanRevRec_next_value (tuple : SpanRevFoldTuple [A] ) (elem : A) : SpanRevFoldTuple [A] = - tuple.left.opt [SpanRevFoldTuple [A] ] ( - ifEmpty = SpanRevFoldTuple_ [A] (tuple.left, tuple.right, false, tuple.condition) ) ( - ifNonEmpty = neleft => _aux_next_value (tuple) (neleft) - ) - - private def _spanRevRec_condition (tuple : SpanRevFoldTuple [A] ) (elem : A) : Boolean = - tuple.taking - - private def _aux_next_value (tuple : SpanRevFoldTuple [A] ) (neleft : NESeq [A] ) : SpanRevFoldTuple [A] = - _aux_next_value_for (tuple) (neleft) (tuple.condition (neleft.head) ) - - private def _aux_next_value_for (tuple : SpanRevFoldTuple [A] ) (neleft : NESeq [A] ) (new_taking : Boolean) : SpanRevFoldTuple [A] = - if ( new_taking - ) SpanRevFoldTuple_ [A] (neleft.tail, prepended (tuple.right) (neleft.head), new_taking, tuple.condition) - else SpanRevFoldTuple_ [A] (neleft, tuple.right, new_taking, tuple.condition) - -} - -case class Min_ [A] () extends Min [A] - -trait IndexFoldTuple [A] -{ - - def index : Int - def position : Int - def element : A - -} - -case class IndexFoldTuple_ [A] (index : Int, position : Int, element : A) extends IndexFoldTuple [A] - -trait ContainsFoldTuple [A] -{ - - def contained : Boolean - def element : A - -} - -case class ContainsFoldTuple_ [A] (contained : Boolean, element : A) extends ContainsFoldTuple [A] - -trait AtFoldTuple [A] -{ - - def elem : A - def index : Int - def position : Int - -} - -case class AtFoldTuple_ [A] (elem : A, index : Int, position : Int) extends AtFoldTuple [A] - -trait TakeDropFoldTuple [A] -{ - - def seq : MSeq [A] - def index : Int - def length : Int - -} - -case class TakeDropFoldTuple_ [A] (seq : MSeq [A], index : Int, length : Int) extends TakeDropFoldTuple [A] - -trait ForallExistsFoldTuple [A] -{ - - def status : Boolean - def condition : A => Boolean - -} - -case class ForallExistsFoldTuple_ [A] (status : Boolean, condition : A => Boolean) extends ForallExistsFoldTuple [A] - -trait FindFoldTuple [A] -{ - - def maybe_element : soda.lib.OptionSD [A] - def condition : A => Boolean - -} - -case class FindFoldTuple_ [A] (maybe_element : soda.lib.OptionSD [A], condition : A => Boolean) extends FindFoldTuple [A] - -trait FilterFoldTuple [A] -{ - - def sequence : MSeq [A] - def condition : A => Boolean - -} - -case class FilterFoldTuple_ [A] (sequence : MSeq [A], condition : A => Boolean) extends FilterFoldTuple [A] - -trait Map0FoldTuple [A] -{ - - def sequence : MSeq [A] - def mapping : A => A - -} - -case class Map0FoldTuple_ [A] (sequence : MSeq [A], mapping : A => A) extends Map0FoldTuple [A] - -trait SpanRevFoldTuple [A] -{ - - def left : MSeq [A] - def right : MSeq [A] - def taking : Boolean - def condition : A => Boolean - -} - -case class SpanRevFoldTuple_ [A] (left : MSeq [A], right : MSeq [A], taking : Boolean, condition : A => Boolean) extends SpanRevFoldTuple [A] diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index 81106915..1365dbad 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -7,3 +7,495 @@ package soda.collection */ trait Package +trait MSeqTranslator [A] +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_foldLeftSeq [B] (sequence : Seq [A] ) (current_value : B) (next_value : B => A => B) : B = + if ( sequence.isEmpty + ) current_value + else _tailrec_foldLeftSeq (sequence.tail) (next_value (current_value) (sequence.head) ) (next_value) + + def foldLeftSeq [B] (sequence : Seq [A] ) (initial_value : B) (next_value : B => A => B) : B = + _tailrec_foldLeftSeq (sequence) (initial_value) (next_value) + + def asMSeq (seq : Seq [A] ) : MSeq [A] = + Min_ ().reverse (foldLeftSeq [MSeq [A] ] (seq) (_asMSeq_initial_value) (_asMSeq_next_value) ) + + private lazy val _asMSeq_initial_value : MSeq [A] = Min_ ().empty + + private def _asMSeq_next_value (acc : MSeq [A] ) (elem : A) : MSeq [A] = + Min_ ().prepended (acc) (elem) + + def asSeq (mseq : MSeq [A] ) : Seq [A] = + (Min_ ().foldLeft (mseq) (_asSeq_initial_value) (_asSeq_next_value) ).reverse + + private lazy val _asSeq_initial_value : Seq [A] = Seq () + + private def _asSeq_next_value (acc : Seq [A] ) (elem : A) : Seq [A] = + acc.+: (elem) + +} + +case class MSeqTranslator_ [A] () extends MSeqTranslator [A] + +trait MSeqPair [A] +{ + + def left : MSeq [A] + def right : MSeq [A] + +} + +case class MSeqPair_ [A] (left : MSeq [A], right : MSeq [A]) extends MSeqPair [A] + +trait Min [A] +{ + + import soda.lib.NoneSD_ + import soda.lib.OptionSD + import soda.lib.SomeSD_ + + lazy val empty : ESeq [A] = ESeq_ () + + def prepended (s : MSeq [A] ) (e : A) : NESeq [A] = + NESeq_ (e, s) + + def head (s : NESeq [A] ) : A = + s.head + + def tail (s : NESeq [A] ) : MSeq [A] = + s.tail + + def nonEmpty (s : MSeq [A] ) : Boolean = + ! isEmpty (s) + + def isEmpty (s : MSeq [A] ) : Boolean = + s.isEmpty + + /* */ + + def foldLeftWhile [B] (s : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = + MSeqRec_ [A] ().fold_while [B] (s) (initial_value) (next_value) (condition) + + def foldLeft [B] (s : MSeq [A] ) (initial_value : B) (next_value : B => A => B) : B = + foldLeftWhile (s) (initial_value) (next_value) ( (acc : B) => (elem : A) => true) + + def reverse (s : MSeq [A] ) : MSeq [A] = + s.opt [MSeq [A] ] ( + ifEmpty = empty) ( + ifNonEmpty = neseq => reverseNonEmpty (neseq) + ) + + def reverseNonEmpty (s : NESeq [A] ) : NESeq [A] = + foldLeft (s.tail) (_reverseNonEmpty_initial_value (s) ) (_reverseNonEmpty_next_value) + + private def _reverseNonEmpty_initial_value (s : NESeq [A] ) : NESeq [A] = prepended (empty) (s.head) + + private def _reverseNonEmpty_next_value (acc : MSeq [A] ) (elem : A) : NESeq [A] = prepended (acc) (elem) + + def length (s : MSeq [A] ) : Int = + foldLeft (s) (_length_initial_value) (_length_next_value) + + private lazy val _length_initial_value : Int = 0 + + private def _length_next_value (acc : Int) (elem : A) : Int = + acc + 1 + + def indexOf (s : MSeq [A] ) (e : A) : Int = + (foldLeftWhile (s) (_indexOf_initial_value (e) ) (_indexOf_next_value) (_indexOf_condition) ).position + + private def _indexOf_initial_value (element : A) : IndexFoldTuple [A] = IndexFoldTuple_ [A] (0, -1, element) + + private def _indexOf_next_value (tuple : IndexFoldTuple [A] ) (current_element : A) : IndexFoldTuple [A] = + IndexFoldTuple_ [A] ( + tuple.index + 1, + _get_index_if_element_found (tuple) (current_element) , + tuple.element + ) + + private def _get_index_if_element_found (tuple : IndexFoldTuple [A] ) (current_element : A) : Int = + if ( current_element == tuple.element + ) tuple.index + else tuple.position + + private def _indexOf_condition (tuple : IndexFoldTuple [A] ) (elem : A) : Boolean = + tuple.position == -1 + + def contains (s : MSeq [A] ) (e : A) : Boolean = + (foldLeftWhile (s) (_contains_initial_value (e) ) (_contains_next_value) (_contains_condition) ).contained + + private def _contains_initial_value (element : A) : ContainsFoldTuple [A] = + ContainsFoldTuple_ (false, element) + + private def _contains_next_value (tuple : ContainsFoldTuple [A] ) (elem : A) : ContainsFoldTuple [A] = + ContainsFoldTuple_ (elem == tuple.element, tuple.element) + + private def _contains_condition (tuple : ContainsFoldTuple [A] ) (elem : A) : Boolean = + ! tuple.contained + + def at (s : MSeq [A] ) (n : Int) : OptionSD [A] = + s.opt [OptionSD [A] ] ( + ifEmpty = NoneSD_ [A] () ) ( + ifNonEmpty = ( neseq => _retrieve_if_in_range (neseq) (n) ) + ) + + private def _retrieve_if_in_range (xs : NESeq [A] ) (n : Int) : OptionSD [A] = + if ( n < 0 || n >= length (xs) + ) NoneSD_ [A] () + else SomeSD_ [A] (_atNonEmpty (xs) (n) ) + + private def _atNonEmpty (xs : NESeq [A] ) (n : Int) : A = + (foldLeftWhile (xs) (_atNonEmpty_initial_value (xs) (n) ) (_atNonEmpty_next_value) (_atNonEmpty_condition) ).elem + + private def _atNonEmpty_initial_value (xs : NESeq [A] ) (position : Int ) : AtFoldTuple [A] = + AtFoldTuple_ [A] (xs.head, -1, position) + + private def _atNonEmpty_next_value (tuple : AtFoldTuple [A] ) (elem : A) : AtFoldTuple [A] = + AtFoldTuple_ [A] (elem, tuple.index + 1, tuple.position) + + private def _atNonEmpty_condition (tuple : AtFoldTuple [A] ) (elem : A) : Boolean = + tuple.index < tuple.position + + /* */ + + def take (s : MSeq [A] ) (n : Int) : MSeq [A] = + reverse ( (foldLeftWhile (s) (_take_initial_value (n) ) (_take_next_value) (_take_condition) ).seq ) + + private def _take_initial_value (length : Int ) : TakeDropFoldTuple [A] = TakeDropFoldTuple_ [A] (empty, 0, length) + + private def _take_next_value (tuple : TakeDropFoldTuple [A] ) (elem : A) : TakeDropFoldTuple [A] = + TakeDropFoldTuple_ [A] (prepended (tuple.seq) (elem), tuple.index + 1, tuple.length) + + private def _take_condition (tuple : TakeDropFoldTuple [A] ) (elem : A) : Boolean = tuple.index < tuple.length + + def drop (s : MSeq [A] ) (n : Int) : MSeq [A] = + (foldLeftWhile (s) (_drop_initial_value (s) (n) ) (_drop_next_value) (_drop_condition) ).seq + + private def _drop_initial_value (s : MSeq [A] ) (length : Int) : TakeDropFoldTuple [A] = TakeDropFoldTuple_ [A] (s, 0, length) + + private def _drop_next_value (tuple : TakeDropFoldTuple [A] ) (elem : A) : TakeDropFoldTuple [A] = + tuple.seq.opt ( + ifEmpty = TakeDropFoldTuple_ [A] (tuple.seq, tuple.index + 1, tuple.length) ) ( + ifNonEmpty = neseq => TakeDropFoldTuple_ [A] (neseq.tail, tuple.index + 1, tuple.length) + ) + + private def _drop_condition (tuple : TakeDropFoldTuple [A] ) (elem : A) : Boolean = + tuple.index < tuple.length + + def takeWhile (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = + reverse ( (spanRevRec (s) (p) ).left) + + def dropWhile (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = + (spanRevRec (s) (p) ).right + + def splitAt (s : MSeq [A] ) (n : Int) : MSeqPair [A] = + MSeqPair_ (take (s) (n), drop (s) (n) ) + + def span (s : MSeq [A] ) (p : A => Boolean) : MSeqPair [A] = + _span_with (s) (p) (spanRevRec (s) (p) ) + + private def _span_with (s : MSeq [A] ) (p : A => Boolean) (pair : MSeqPair [A] ) : MSeqPair [A] = + MSeqPair_ (reverse (pair.left), pair.right) + + /* */ + + def appended (s : MSeq [A] ) (e : A) : MSeq [A] = + reverse (prepended (reverse (s) ) (e) ) + + def last (s : NESeq [A] ) : A = + reverseNonEmpty (s).head + + def concat (s0 : MSeq [A] ) (s1 : MSeq [A] ) : MSeq [A] = + foldLeft (reverse (s0) ) (_concat_initial_value (s1) ) (_concat_next_value) + + private def _concat_initial_value (s1 : MSeq [A] ) : MSeq [A] = s1 + + private def _concat_next_value (acc : MSeq [A] ) (elem : A) : MSeq [A] = prepended (acc) (elem) + + def slice (s : MSeq [A] ) (from : Int) (until : Int) : MSeq [A] = take (drop (s) (from) ) (until - from) + + /* */ + + def forall (s : MSeq [A] ) (p : A => Boolean) : Boolean = + (foldLeftWhile (s) (_forall_initial_value (p) ) (_forall_next_value) (_forall_condition) ).status + + private def _forall_initial_value (condition : A => Boolean ) : ForallExistsFoldTuple [A] = ForallExistsFoldTuple_ (true, condition) + + private def _forall_next_value (tuple : ForallExistsFoldTuple [A] ) (elem : A) : ForallExistsFoldTuple [A] = + ForallExistsFoldTuple_ (tuple.status && tuple.condition (elem), tuple.condition) + + private def _forall_condition (tuple : ForallExistsFoldTuple [A] ) (elem : A) : Boolean = + tuple.status + + def exists (s : MSeq [A] ) (p : A => Boolean ) : Boolean = + (foldLeftWhile (s) (_exists_initial_value (p) ) (_exists_next_value) (_exists_condition) ).status + + private def _exists_initial_value (condition : A => Boolean ) : ForallExistsFoldTuple [A] = ForallExistsFoldTuple_ (false, condition) + + private def _exists_next_value (tuple : ForallExistsFoldTuple [A] ) (elem : A) : ForallExistsFoldTuple [A] = + ForallExistsFoldTuple_ (tuple.status || tuple.condition (elem), tuple.condition) + + private def _exists_condition (tuple : ForallExistsFoldTuple [A] ) (elem : A) : Boolean = + ! tuple.status + + def find (s : MSeq [A] ) (p : A => Boolean) : OptionSD [A] = + (foldLeftWhile (s) (_find_initial_value (p) ) (_find_next_value) (_find_condition) ).maybe_element + + private def _find_initial_value (condition : A => Boolean) : FindFoldTuple [A] = + FindFoldTuple_ (NoneSD_ [A] (), condition) + + private def _find_next_value (tuple : FindFoldTuple [A] ) (elem : A) : FindFoldTuple [A] = + if ( tuple.condition (elem) + ) FindFoldTuple_ (SomeSD_ [A] (elem), tuple.condition) + else FindFoldTuple_ (NoneSD_ [A] (), tuple.condition) + + private def _find_condition (tuple : FindFoldTuple [A] ) (elem : A) : Boolean = + tuple.maybe_element.isEmpty + + def filter (s : MSeq [A] ) (p : A => Boolean) : MSeq [A] = + reverse ( (foldLeft (s) (_filter_initial_value (p) ) (_filter_next_value) ).sequence ) + + private def _filter_initial_value (condition : A => Boolean) : FilterFoldTuple [A] = + FilterFoldTuple_ (empty, condition) + + private def _filter_next_value (tuple : FilterFoldTuple [A] ) (elem : A) : FilterFoldTuple [A] = + FilterFoldTuple_ ( + _prepend_when_condition (tuple) (elem) , + tuple.condition + ) + + private def _prepend_when_condition (tuple : FilterFoldTuple [A] ) (elem : A) : MSeq [A] = + if ( tuple.condition (elem) + ) prepended (tuple.sequence) (elem) + else tuple.sequence + + def map0 (s : MSeq [A] ) (f : A => A) : MSeq [A] = + reverse ( (foldLeft (s) (_map0_initial_value (f) ) (_map0_next_value) ).sequence) + + private def _map0_initial_value (mapping : A => A) : Map0FoldTuple [A] = + Map0FoldTuple_ (empty, mapping) + + private def _map0_next_value (tuple : Map0FoldTuple [A] ) (elem : A) : Map0FoldTuple [A] = + Map0FoldTuple_ (prepended (tuple.sequence) (tuple.mapping (elem) ), tuple.mapping) + + /** + *
+   * def foldLeft [B] (z : B) (op : (B, A) -> B) : B =
+   * . var result = z
+   * . it = iterator
+   * . while (it.hasNext) {
+   * . . result = op (result, it.next () )
+   * . }
+   * . result
+   * end
+   * 
+ */ + def foldLeft0 (mseq : MSeq [A] ) : MSeq [A] => (MSeq [A] => A => MSeq [A] ) => MSeq [A] = + (initial_value : MSeq [A] ) => + (next_value : MSeq [A] => A => MSeq [A] ) => + foldLeft (mseq) (initial_value) (next_value) + + /* */ + + def spanRevRec (s0 : MSeq [A] ) (p : A => Boolean) : MSeqPair [A] = + _spanRevRec_for (foldLeftWhile (s0) (_spanRevRec_initial_value (s0) (p) ) (_spanRevRec_next_value) (_spanRevRec_condition) ) + + private def _spanRevRec_for (tuple: SpanRevFoldTuple [A] ) : MSeqPair [A] = + MSeqPair_ (tuple.right, tuple.left) + + private def _spanRevRec_initial_value (s0 : MSeq [A] ) (condition : A => Boolean) : SpanRevFoldTuple [A] = + SpanRevFoldTuple_ [A] (s0, empty, true, condition) + + private def _spanRevRec_next_value (tuple : SpanRevFoldTuple [A] ) (elem : A) : SpanRevFoldTuple [A] = + tuple.left.opt [SpanRevFoldTuple [A] ] ( + ifEmpty = SpanRevFoldTuple_ [A] (tuple.left, tuple.right, false, tuple.condition) ) ( + ifNonEmpty = neleft => _aux_next_value (tuple) (neleft) + ) + + private def _spanRevRec_condition (tuple : SpanRevFoldTuple [A] ) (elem : A) : Boolean = + tuple.taking + + private def _aux_next_value (tuple : SpanRevFoldTuple [A] ) (neleft : NESeq [A] ) : SpanRevFoldTuple [A] = + _aux_next_value_for (tuple) (neleft) (tuple.condition (neleft.head) ) + + private def _aux_next_value_for (tuple : SpanRevFoldTuple [A] ) (neleft : NESeq [A] ) (new_taking : Boolean) : SpanRevFoldTuple [A] = + if ( new_taking + ) SpanRevFoldTuple_ [A] (neleft.tail, prepended (tuple.right) (neleft.head), new_taking, tuple.condition) + else SpanRevFoldTuple_ [A] (neleft, tuple.right, new_taking, tuple.condition) + +} + +case class Min_ [A] () extends Min [A] + +trait IndexFoldTuple [A] +{ + + def index : Int + def position : Int + def element : A + +} + +case class IndexFoldTuple_ [A] (index : Int, position : Int, element : A) extends IndexFoldTuple [A] + +trait ContainsFoldTuple [A] +{ + + def contained : Boolean + def element : A + +} + +case class ContainsFoldTuple_ [A] (contained : Boolean, element : A) extends ContainsFoldTuple [A] + +trait AtFoldTuple [A] +{ + + def elem : A + def index : Int + def position : Int + +} + +case class AtFoldTuple_ [A] (elem : A, index : Int, position : Int) extends AtFoldTuple [A] + +trait TakeDropFoldTuple [A] +{ + + def seq : MSeq [A] + def index : Int + def length : Int + +} + +case class TakeDropFoldTuple_ [A] (seq : MSeq [A], index : Int, length : Int) extends TakeDropFoldTuple [A] + +trait ForallExistsFoldTuple [A] +{ + + def status : Boolean + def condition : A => Boolean + +} + +case class ForallExistsFoldTuple_ [A] (status : Boolean, condition : A => Boolean) extends ForallExistsFoldTuple [A] + +trait FindFoldTuple [A] +{ + + def maybe_element : soda.lib.OptionSD [A] + def condition : A => Boolean + +} + +case class FindFoldTuple_ [A] (maybe_element : soda.lib.OptionSD [A], condition : A => Boolean) extends FindFoldTuple [A] + +trait FilterFoldTuple [A] +{ + + def sequence : MSeq [A] + def condition : A => Boolean + +} + +case class FilterFoldTuple_ [A] (sequence : MSeq [A], condition : A => Boolean) extends FilterFoldTuple [A] + +trait Map0FoldTuple [A] +{ + + def sequence : MSeq [A] + def mapping : A => A + +} + +case class Map0FoldTuple_ [A] (sequence : MSeq [A], mapping : A => A) extends Map0FoldTuple [A] + +trait SpanRevFoldTuple [A] +{ + + def left : MSeq [A] + def right : MSeq [A] + def taking : Boolean + def condition : A => Boolean + +} + +case class SpanRevFoldTuple_ [A] (left : MSeq [A], right : MSeq [A], taking : Boolean, condition : A => Boolean) extends SpanRevFoldTuple [A] +trait MSeq [A] +{ + + def isEmpty : Boolean + + def opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] => B) : B = + this match { + case NESeq_ (head, tail) => ifNonEmpty (NESeq_ (head, tail) ) + case x => ifEmpty + } + +} + +case class MSeq_ [A] (isEmpty : Boolean) extends MSeq [A] + +trait MSeqRec [A] +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + sequence match { + case NESeq_ (head, tail) => + if ( ! condition (current_value) (head) + ) current_value + else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) + case x => current_value + } + + def fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) + +} + +case class MSeqRec_ [A] () extends MSeqRec [A] + +trait ESeq [A] + extends + MSeq [A] +{ + + lazy val isEmpty = true + +} + +case class ESeq_ [A] () extends ESeq [A] + +trait NEMSeq [A] + extends + MSeq [A] +{ + + def head0 : A + def tail0 : MSeq [A] + + lazy val isEmpty = false + +} + +case class NEMSeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NEMSeq [A] + +trait NESeq [A] + extends + NEMSeq [A] +{ + + def head0 : A + def tail0 : MSeq [A] + + lazy val head : A = head0 + + lazy val tail : MSeq [A] = tail0 + +} + +case class NESeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NESeq [A] diff --git a/library/src/main/scala/soda/collection/example/ListExample.scala b/library/src/main/scala/soda/collection/example/ListExample.scala deleted file mode 100644 index a52f4ec8..00000000 --- a/library/src/main/scala/soda/collection/example/ListExample.scala +++ /dev/null @@ -1,100 +0,0 @@ -package soda.collection.example - -/* - * This package contains examples for Soda. - */ - - - -trait Pair [A] -{ - - def name : String - def result : A - -} - -case class Pair_ [A] (name : String, result : A) extends Pair [A] - -trait ListExample -{ - - lazy val a : Seq [Char] = Seq ('A', 'B', 'C', 'D', 'E', 'F') - - lazy val b : Seq [Int] = Seq (10, 20, 30, 40, 50, 60) - - lazy val a_example : Pair [Seq [Char] ] = - Pair_("a", a) - - lazy val b_example : Pair [Seq [Int] ] = - Pair_("b", b) - - lazy val take_example : Pair [Seq [Char] ] = - Pair_("a.take(3)", a.take (3) ) - - lazy val takeRight_example : Pair [Seq [Char] ] = - Pair_("a.takeRight(3)", a.takeRight (3) ) - - lazy val takeWhile_example : Pair [Seq [Char] ] = - Pair_("a.takeWhile( lambda x --> not (x == 'E'))", a.takeWhile ( x => ! (x == 'E') ) ) - - lazy val drop_example : Pair [Seq [Char] ] = - Pair_("a.drop(2)", a.drop (2)) - - lazy val dropRight_example : Pair [Seq [Char] ] = - Pair_("a.dropRight(2)", a.dropRight (2)) - - lazy val dropWhile_example : Pair [Seq [Char] ] = - Pair_("a.dropWhile( lambda x --> not (x == 'E'))", a.dropWhile ( x => ! (x == 'E') ) ) - - lazy val splitAt_example : Pair [(Seq [Char], Seq [Char] ) ] = - Pair_("a.splitAt(3)", a.splitAt (3) ) - - lazy val indices_example : Pair [Range] = - Pair_("a.indices", a.indices) - - lazy val zipWithIndex_example : Pair [Seq [ Tuple2 [Char, Int] ] ] = - Pair_("a.zipWithIndex", a.zipWithIndex) - - lazy val zip_example : Pair [Seq [ Tuple2 [Char, Int] ] ] = - Pair_("a.zip(b)", a.zip (b)) - - lazy val reverse_example : Pair [Seq [Char] ] = - Pair_("a.reverse", a.reverse) - - /** - * A mnemonic for `+:` vs. `:+` is that the COLon goes on the COLlection side. - */ - lazy val prepended_example : Pair [Seq [Char] ] = - Pair_("a.+:('X')", (a.+: ('X') ) ) - - /** - * A mnemonic for `+:` vs. `:+` is that the COLon goes on the COLlection side. - */ - lazy val appended_example : Pair [Seq [Char] ] = - Pair_("a.:+('X')", (a.:+ ('X') ) ) - - lazy val concat_example : Pair [Seq [Int] ] = - Pair_("a.map(_.toInt).++(b)", a.map (_.toInt).++ (b) ) - - lazy val span_example : Pair [(Seq [Char], Seq [Char])] = - Pair_("a.span( lambda x --> not (x == 'D'))", a.span ( x => ! (x == 'D') ) ) - - lazy val map_example : Pair [Seq [Int] ] = - Pair_("a.map( lambda x --> x.toInt)", a.map ( x => x.toInt) ) - - lazy val filter_example : Pair [Seq [Char] ] = - Pair_("a.filter( lambda x --> x.toInt % 2 == 0)", a.filter ( x => x.toInt % 2 == 0) ) - - lazy val fold_example : Pair [Int] = - Pair_("b.fold(0)( lambda (a, b) --> a + b)", b.fold (0)( (a, b) => a + b) ) - - lazy val foldLeft_example : Pair [Seq [Char] ] = - Pair_("a.foldLeft(Seq('*'))( lambda (list, elem) --> \"(\" + list + \" :+ \" + elem + \")\")", a.foldLeft (Seq ('*') )( (list, elem) => "(" + list + " :+ " + elem + ")") ) - - lazy val foldRight_example : Pair [Seq [Char] ] = - Pair_("a.foldRight(Seq('*'))( lambda (elem, list) --> \"(\" + elem + \" +: \" + list + \")\")", a.foldRight (Seq ('*') )( (elem, list) => "(" + elem + " +: " + list + ")") ) - -} - -case class ListExample_ () extends ListExample diff --git a/library/src/main/scala/soda/collection/example/Main.scala b/library/src/main/scala/soda/collection/example/Main.scala deleted file mode 100644 index 12f8e13f..00000000 --- a/library/src/main/scala/soda/collection/example/Main.scala +++ /dev/null @@ -1,52 +0,0 @@ -package soda.collection.example - -/* - * This package contains examples for Soda. - */ - - - -trait Main -{ - - lazy val e = ListExample_ () - - lazy val all_examples = - Seq ( - e.a_example, - e.b_example, - e.take_example, - e.takeRight_example, - e.takeWhile_example, - e.drop_example, - e.dropRight_example, - e.dropWhile_example, - e.splitAt_example, - e.indices_example, - e.zipWithIndex_example, - e.zip_example, - e.reverse_example, - e.prepended_example, - e.appended_example, - e.concat_example, - e.span_example, - e.map_example, - e.filter_example, - e.fold_example, - e.foldLeft_example, - e.foldRight_example - ) - .map ( pair => pair.name + " = " + pair.result.toString) - .mkString ("\n") - - def main (arguments : Array [String] ) : Unit = - println (all_examples) - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala index 0a7c55d6..bf587d7b 100644 --- a/library/src/main/scala/soda/collection/example/Package.scala +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -5,3 +5,139 @@ package soda.collection.example */ trait Package +trait Main +{ + + lazy val e = ListExample_ () + + lazy val all_examples = + Seq ( + e.a_example, + e.b_example, + e.take_example, + e.takeRight_example, + e.takeWhile_example, + e.drop_example, + e.dropRight_example, + e.dropWhile_example, + e.splitAt_example, + e.indices_example, + e.zipWithIndex_example, + e.zip_example, + e.reverse_example, + e.prepended_example, + e.appended_example, + e.concat_example, + e.span_example, + e.map_example, + e.filter_example, + e.fold_example, + e.foldLeft_example, + e.foldRight_example + ) + .map ( pair => pair.name + " = " + pair.result.toString) + .mkString ("\n") + + def main (arguments : Array [String] ) : Unit = + println (all_examples) + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main +trait Pair [A] +{ + + def name : String + def result : A + +} + +case class Pair_ [A] (name : String, result : A) extends Pair [A] + +trait ListExample +{ + + lazy val a : Seq [Char] = Seq ('A', 'B', 'C', 'D', 'E', 'F') + + lazy val b : Seq [Int] = Seq (10, 20, 30, 40, 50, 60) + + lazy val a_example : Pair [Seq [Char] ] = + Pair_("a", a) + + lazy val b_example : Pair [Seq [Int] ] = + Pair_("b", b) + + lazy val take_example : Pair [Seq [Char] ] = + Pair_("a.take(3)", a.take (3) ) + + lazy val takeRight_example : Pair [Seq [Char] ] = + Pair_("a.takeRight(3)", a.takeRight (3) ) + + lazy val takeWhile_example : Pair [Seq [Char] ] = + Pair_("a.takeWhile( lambda x --> not (x == 'E'))", a.takeWhile ( x => ! (x == 'E') ) ) + + lazy val drop_example : Pair [Seq [Char] ] = + Pair_("a.drop(2)", a.drop (2)) + + lazy val dropRight_example : Pair [Seq [Char] ] = + Pair_("a.dropRight(2)", a.dropRight (2)) + + lazy val dropWhile_example : Pair [Seq [Char] ] = + Pair_("a.dropWhile( lambda x --> not (x == 'E'))", a.dropWhile ( x => ! (x == 'E') ) ) + + lazy val splitAt_example : Pair [(Seq [Char], Seq [Char] ) ] = + Pair_("a.splitAt(3)", a.splitAt (3) ) + + lazy val indices_example : Pair [Range] = + Pair_("a.indices", a.indices) + + lazy val zipWithIndex_example : Pair [Seq [ Tuple2 [Char, Int] ] ] = + Pair_("a.zipWithIndex", a.zipWithIndex) + + lazy val zip_example : Pair [Seq [ Tuple2 [Char, Int] ] ] = + Pair_("a.zip(b)", a.zip (b)) + + lazy val reverse_example : Pair [Seq [Char] ] = + Pair_("a.reverse", a.reverse) + + /** + * A mnemonic for `+:` vs. `:+` is that the COLon goes on the COLlection side. + */ + lazy val prepended_example : Pair [Seq [Char] ] = + Pair_("a.+:('X')", (a.+: ('X') ) ) + + /** + * A mnemonic for `+:` vs. `:+` is that the COLon goes on the COLlection side. + */ + lazy val appended_example : Pair [Seq [Char] ] = + Pair_("a.:+('X')", (a.:+ ('X') ) ) + + lazy val concat_example : Pair [Seq [Int] ] = + Pair_("a.map(_.toInt).++(b)", a.map (_.toInt).++ (b) ) + + lazy val span_example : Pair [(Seq [Char], Seq [Char])] = + Pair_("a.span( lambda x --> not (x == 'D'))", a.span ( x => ! (x == 'D') ) ) + + lazy val map_example : Pair [Seq [Int] ] = + Pair_("a.map( lambda x --> x.toInt)", a.map ( x => x.toInt) ) + + lazy val filter_example : Pair [Seq [Char] ] = + Pair_("a.filter( lambda x --> x.toInt % 2 == 0)", a.filter ( x => x.toInt % 2 == 0) ) + + lazy val fold_example : Pair [Int] = + Pair_("b.fold(0)( lambda (a, b) --> a + b)", b.fold (0)( (a, b) => a + b) ) + + lazy val foldLeft_example : Pair [Seq [Char] ] = + Pair_("a.foldLeft(Seq('*'))( lambda (list, elem) --> \"(\" + list + \" :+ \" + elem + \")\")", a.foldLeft (Seq ('*') )( (list, elem) => "(" + list + " :+ " + elem + ")") ) + + lazy val foldRight_example : Pair [Seq [Char] ] = + Pair_("a.foldRight(Seq('*'))( lambda (elem, list) --> \"(\" + elem + \" +: \" + list + \")\")", a.foldRight (Seq ('*') )( (elem, list) => "(" + elem + " +: " + list + ")") ) + +} + +case class ListExample_ () extends ListExample diff --git a/library/src/test/scala/soda/collection/MinSpec.scala b/library/src/test/scala/soda/collection/MinSpec.scala deleted file mode 100644 index 5397ccfd..00000000 --- a/library/src/test/scala/soda/collection/MinSpec.scala +++ /dev/null @@ -1,592 +0,0 @@ -package soda.collection - -/* - * This package contains tests for examples for Soda. - */ - - - -case class MinSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.lib.NoneSD_ - import soda.lib.Fold_ - import soda.lib.SomeSD_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val empty : ESeq [Int] = ESeq_ [Int] () - - lazy val exampleSeq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) - - lazy val revExampleSeq : Seq [Int] = exampleSeq.reverse - - def prepend_elem (list : MSeq [Int]) (elem : Int) : NESeq [Int] = Min_ ().prepended (list) (elem) - - private lazy val _fold = Fold_ () - - private lazy val _initial_value : NESeq [Int] = NESeq_ [Int] (revExampleSeq.head, ESeq_ [Int] () ) - - lazy val example : NESeq [Int] = - _fold.apply (revExampleSeq.tail) (_initial_value) (prepend_elem) - - test ("prepended") ( - check ( - obtained = _prepended_sequence - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq [Int] (1, 0, 1, 1, 2, 3, 5, 8) ) - ) - ) - - private lazy val _prepended_sequence : MSeq [Int] = Min_ ().prepended (example) (1) - - test ("head") ( - check ( - obtained = Min_ ().head (example) - ) ( - expected = 0 - ) - ) - - test ("tail") ( - check ( - obtained = Min_ ().tail (example) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (1, 1, 2, 3, 5, 8) ) - ) - ) - - test ("reverse") ( - check ( - obtained = Min_ ().reverse (example) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (8, 5, 3, 2, 1, 1, 0) ) - ) - ) - - test ("length") ( - check ( - obtained = Min_ ().length (example) - ) ( - expected = 7 - ) - ) - - test ("indexOf something found") ( - check ( - obtained = Min_ ().indexOf (example) (8) - ) ( - expected = 6 - ) - ) - - test ("indexOf something not found") ( - check ( - obtained = Min_ ().indexOf (example) (7) - ) ( - expected = -1 - ) - ) - - test ("contains something found") ( - check ( - obtained = Min_ ().contains (example) (8) - ) ( - expected = true - ) - ) - - test ("contains something not found") ( - check ( - obtained = Min_ ().contains (example) (7) - ) ( - expected = false - ) - ) - - test ("at") ( - check ( - obtained = Min_ ().at (example) (4) - ) ( - expected = SomeSD_ (3) - ) - ) - - test ("take with Seq 0") ( - check ( - obtained = exampleSeq.take (5) - ) ( - expected = Seq (0, 1, 1, 2, 3) - ) - ) - - test ("take with Seq 1") ( - check ( - obtained = exampleSeq.take (-100) - ) ( - expected = Seq () - ) - ) - - test ("take with Seq 2") ( - check ( - obtained = exampleSeq.take (100) - ) ( - expected = exampleSeq - ) - ) - - test ("take 0") ( - check ( - obtained = Min_ ().take (example) (5) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3) ) - ) - ) - - test ("take 1") ( - check ( - obtained = Min_ ().take (example) (-100) - ) ( - expected = empty - ) - ) - - test ("take 2") ( - check ( - obtained = Min_ ().take (example) (100) - ) ( - expected = example - ) - ) - - test ("drop with Seq 0") ( - check ( - obtained = exampleSeq.drop (3) - ) ( - expected = Seq (2, 3, 5, 8) - ) - ) - - test ("drop with Seq 1") ( - check ( - obtained = exampleSeq.drop (-100) - ) ( - expected = exampleSeq - ) - ) - - test ("drop with Seq 2") ( - check ( - obtained = exampleSeq.drop (100) - ) ( - expected = Seq () - ) - ) - - test ("drop 0") ( - check ( - obtained = Min_ ().drop (example) (3) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (2, 3, 5, 8) ) - ) - ) - - test ("drop 1") ( - check ( - obtained = Min_ ().drop (example) (-100) - ) ( - expected = example - ) - ) - - test ("drop 2") ( - check ( - obtained = Min_ ().drop (example) (100) - ) ( - expected = empty - ) - ) - - test ("takeWhile with Seq") ( - check ( - obtained = exampleSeq.takeWhile ( e => ! (e == 3) ) - ) ( - expected = Seq (0, 1, 1, 2) - ) - ) - - test ("takeWhile") ( - check ( - obtained = Min_ ().takeWhile (example) ( e => ! (e == 3) ) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2) ) - ) - ) - - test ("dropWhile with Seq") ( - check ( - obtained = exampleSeq.dropWhile ( e => ! (e == 3) ) - ) ( - expected = Seq (3, 5, 8) - ) - ) - - test ("dropWhile") ( - check ( - obtained = Min_ ().dropWhile (example) ( e => ! (e == 3) ) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (3, 5, 8) ) - ) - ) - - test ("splitAt with Seq") ( - check ( - obtained = exampleSeq.splitAt (3) - ) ( - expected = Tuple2 (Seq (0, 1, 1), Seq (2, 3, 5, 8) ) - ) - ) - - test ("splitAt") ( - check ( - obtained = Min_ ().splitAt (example) (3) - ) ( - expected = MSeqPair_ (MSeqTranslator_ ().asMSeq (Seq (0, 1, 1) ), MSeqTranslator_ ().asMSeq (Seq (2, 3, 5, 8) ) ) - ) - ) - - test ("span with Seq") ( - check ( - obtained = exampleSeq.span ( x => ! (x == 5) ) - ) ( - expected = Tuple2 (Seq (0, 1, 1, 2, 3), Seq (5, 8) ) - ) - ) - - test ("span") ( - check ( - obtained = Min_ ().span (example) ( (x : Int) => ! (x == 5) ) - ) ( - expected = MSeqPair_ (MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3) ), MSeqTranslator_ ().asMSeq (Seq (5, 8) ) ) - ) - ) - - test ("append") ( - check ( - obtained = Min_ ().appended (example) (13) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3, 5, 8, 13) ) - ) - ) - - test ("last") ( - check ( - obtained = Min_ ().last (example) - ) ( - expected = 8 - ) - ) - - test ("concat") ( - check ( - obtained = Min_ ().concat (example) (MSeqTranslator_ ().asMSeq (Seq (13, 21, 34, 55) ) ) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55) ) - ) - ) - - test ("slice with Seq 0") ( - check ( - obtained = exampleSeq.slice (2, 5) - ) ( - expected = Seq (1, 2, 3) - ) - ) - - test ("slice with Seq 1") ( - check ( - obtained = exampleSeq.slice (5, 2) - ) ( - expected = Seq () - ) - ) - - test ("slice with Seq 2") ( - check ( - obtained = exampleSeq.slice (3, 3) - ) ( - expected = Seq () - ) - ) - - test ("slice with Seq 3") ( - check ( - obtained = exampleSeq.slice (100, 5) - ) ( - expected = Seq () - ) - ) - - test ("slice with Seq 4") ( - check ( - obtained = exampleSeq.slice (100, 200) - ) ( - expected = Seq () - ) - ) - - test ("slice with Seq 5") ( - check ( - obtained = exampleSeq.slice (-100, 200) - ) ( - expected = exampleSeq - ) - ) - - test ("slice 0") ( - check ( - obtained = Min_ ().slice (example) (2) (5) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (1, 2, 3) ) - ) - ) - - test ("slice 1") ( - check ( - obtained = Min_ ().slice (example) (5) (2) - ) ( - expected = empty - ) - ) - - test ("slice 2") ( - check ( - obtained = Min_ ().slice (example) (3) (3) - ) ( - expected = empty - ) - ) - - test ("slice 3") ( - check ( - obtained = Min_ ().slice (example) (100) (5) - ) ( - expected = empty - ) - ) - - test ("slice 4") ( - check ( - obtained = Min_ ().slice (example) (100) (200) - ) ( - expected = empty - ) - ) - - test ("slice 5") ( - check ( - obtained = Min_ ().slice (example) (-100) (200) - ) ( - expected = example - ) - ) - - test ("forall with Seq 0") ( - check ( - obtained = exampleSeq.forall ( x => ! (x == 7) ) - ) ( - expected = true - ) - ) - - test ("forall with Seq 1") ( - check ( - obtained = exampleSeq.forall ( x => x < 7) - ) ( - expected = false - ) - ) - - test ("forall with Seq 2") ( - check ( - obtained = Seq ().forall ( x => x == 7) - ) ( - expected = true - ) - ) - - test ("forall 0") ( - check ( - obtained = Min_ ().forall (example) ( x => ! (x == 7) ) - ) ( - expected = true - ) - ) - - test ("forall 1") ( - check ( - obtained = Min_ ().forall (example) ( x => x < 7) - ) ( - expected = false - ) - ) - - test ("forall 2") ( - check ( - obtained = Min_ ().forall (empty) ( x => x == 7) - ) ( - expected = true - ) - ) - - test ("exists with Seq 0") ( - check ( - obtained = exampleSeq.exists ( x => x == 8) - ) ( - expected = true - ) - ) - - test ("exists with Seq 1") ( - check ( - obtained = exampleSeq.exists ( x => x == 7) - ) ( - expected = false - ) - ) - - test ("exists with Seq 2") ( - check ( - obtained = Seq ().exists ( x => x == 7) - ) ( - expected = false - ) - ) - - test ("exists 0") ( - check ( - obtained = Min_ ().exists (example) ( x => x == 8) - ) ( - expected = true - ) - ) - - test ("exists 1") ( - check ( - obtained = Min_ ().exists (example) ( x => x == 7) - ) ( - expected = false - ) - ) - - test ("exists 2") ( - check ( - obtained = Min_ ().exists (empty) ( x => x == 7) - ) ( - expected = false - ) - ) - - test ("find with Seq 0") ( - check ( - obtained = exampleSeq.find ( x => ! (x == 7) ) - ) ( - expected = Some (0) - ) - ) - - test ("find with Seq 1") ( - check ( - obtained = exampleSeq.find ( x => x == 8) - ) ( - expected = Some (8) - ) - ) - - test ("find with Seq 2") ( - check ( - obtained = Seq ().find ( x => x == 7) - ) ( - expected = None - ) - ) - - test ("find 0") ( - check ( - obtained = Min_ ().find (example) ( x => ! (x == 7) ) - ) ( - expected = SomeSD_ (0) - ) - ) - - test ("find 1") ( - check ( - obtained = Min_ ().find (example) ( x => x == 8) - ) ( - expected = SomeSD_ (8) - ) - ) - - test ("find 2") ( - check ( - obtained = Min_ ().find (empty) ( x => x == 7) - ) ( - expected = NoneSD_ () - ) - ) - - test ("filter with Seq") ( - check ( - obtained = exampleSeq.filter ( x => x % 3 == 0) - ) ( - expected = Seq (0, 3) - ) - ) - - test ("filter") ( - check ( - obtained = Min_ ().filter (example) ( x => x % 3 == 0) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (0, 3) ) - ) - ) - - test ("map with Seq") ( - check ( - obtained = exampleSeq.map ( x => x + 100) - ) ( - expected = Seq (100, 101, 101, 102, 103, 105, 108) - ) - ) - - test ("map in the same type") ( - check ( - obtained = Min_ ().map0 (example) ( x => x + 100) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (100, 101, 101, 102, 103, 105, 108) ) - ) - ) - - test ("foldLeft with Seq") ( - check ( - obtained = exampleSeq.foldLeft (Seq [Int] () ) ( (s : Seq [Int], e : Int) => s.+: ( (e + 100) ) ) - ) ( - expected = Seq (108, 105, 103, 102, 101, 101, 100) - ) - ) - - test ("foldLeft in the same type") ( - check ( - obtained = Min_ ().foldLeft0 (example) (Min_ ().empty) ( - (s : MSeq [Int] ) => (e : Int) => Min_ ().prepended (s) (e + 100) - ) - ) ( - expected = MSeqTranslator_ ().asMSeq (Seq (108, 105, 103, 102, 101, 101, 100) ) - ) - ) - -} diff --git a/library/src/test/scala/soda/collection/Package.scala b/library/src/test/scala/soda/collection/Package.scala index 9b10c7e6..59780e63 100644 --- a/library/src/test/scala/soda/collection/Package.scala +++ b/library/src/test/scala/soda/collection/Package.scala @@ -5,3 +5,587 @@ package soda.collection */ trait Package +case class MinSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.lib.NoneSD_ + import soda.lib.Fold_ + import soda.lib.SomeSD_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val empty : ESeq [Int] = ESeq_ [Int] () + + lazy val exampleSeq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) + + lazy val revExampleSeq : Seq [Int] = exampleSeq.reverse + + def prepend_elem (list : MSeq [Int]) (elem : Int) : NESeq [Int] = Min_ ().prepended (list) (elem) + + private lazy val _fold = Fold_ () + + private lazy val _initial_value : NESeq [Int] = NESeq_ [Int] (revExampleSeq.head, ESeq_ [Int] () ) + + lazy val example : NESeq [Int] = + _fold.apply (revExampleSeq.tail) (_initial_value) (prepend_elem) + + test ("prepended") ( + check ( + obtained = _prepended_sequence + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq [Int] (1, 0, 1, 1, 2, 3, 5, 8) ) + ) + ) + + private lazy val _prepended_sequence : MSeq [Int] = Min_ ().prepended (example) (1) + + test ("head") ( + check ( + obtained = Min_ ().head (example) + ) ( + expected = 0 + ) + ) + + test ("tail") ( + check ( + obtained = Min_ ().tail (example) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (1, 1, 2, 3, 5, 8) ) + ) + ) + + test ("reverse") ( + check ( + obtained = Min_ ().reverse (example) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (8, 5, 3, 2, 1, 1, 0) ) + ) + ) + + test ("length") ( + check ( + obtained = Min_ ().length (example) + ) ( + expected = 7 + ) + ) + + test ("indexOf something found") ( + check ( + obtained = Min_ ().indexOf (example) (8) + ) ( + expected = 6 + ) + ) + + test ("indexOf something not found") ( + check ( + obtained = Min_ ().indexOf (example) (7) + ) ( + expected = -1 + ) + ) + + test ("contains something found") ( + check ( + obtained = Min_ ().contains (example) (8) + ) ( + expected = true + ) + ) + + test ("contains something not found") ( + check ( + obtained = Min_ ().contains (example) (7) + ) ( + expected = false + ) + ) + + test ("at") ( + check ( + obtained = Min_ ().at (example) (4) + ) ( + expected = SomeSD_ (3) + ) + ) + + test ("take with Seq 0") ( + check ( + obtained = exampleSeq.take (5) + ) ( + expected = Seq (0, 1, 1, 2, 3) + ) + ) + + test ("take with Seq 1") ( + check ( + obtained = exampleSeq.take (-100) + ) ( + expected = Seq () + ) + ) + + test ("take with Seq 2") ( + check ( + obtained = exampleSeq.take (100) + ) ( + expected = exampleSeq + ) + ) + + test ("take 0") ( + check ( + obtained = Min_ ().take (example) (5) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3) ) + ) + ) + + test ("take 1") ( + check ( + obtained = Min_ ().take (example) (-100) + ) ( + expected = empty + ) + ) + + test ("take 2") ( + check ( + obtained = Min_ ().take (example) (100) + ) ( + expected = example + ) + ) + + test ("drop with Seq 0") ( + check ( + obtained = exampleSeq.drop (3) + ) ( + expected = Seq (2, 3, 5, 8) + ) + ) + + test ("drop with Seq 1") ( + check ( + obtained = exampleSeq.drop (-100) + ) ( + expected = exampleSeq + ) + ) + + test ("drop with Seq 2") ( + check ( + obtained = exampleSeq.drop (100) + ) ( + expected = Seq () + ) + ) + + test ("drop 0") ( + check ( + obtained = Min_ ().drop (example) (3) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (2, 3, 5, 8) ) + ) + ) + + test ("drop 1") ( + check ( + obtained = Min_ ().drop (example) (-100) + ) ( + expected = example + ) + ) + + test ("drop 2") ( + check ( + obtained = Min_ ().drop (example) (100) + ) ( + expected = empty + ) + ) + + test ("takeWhile with Seq") ( + check ( + obtained = exampleSeq.takeWhile ( e => ! (e == 3) ) + ) ( + expected = Seq (0, 1, 1, 2) + ) + ) + + test ("takeWhile") ( + check ( + obtained = Min_ ().takeWhile (example) ( e => ! (e == 3) ) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2) ) + ) + ) + + test ("dropWhile with Seq") ( + check ( + obtained = exampleSeq.dropWhile ( e => ! (e == 3) ) + ) ( + expected = Seq (3, 5, 8) + ) + ) + + test ("dropWhile") ( + check ( + obtained = Min_ ().dropWhile (example) ( e => ! (e == 3) ) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (3, 5, 8) ) + ) + ) + + test ("splitAt with Seq") ( + check ( + obtained = exampleSeq.splitAt (3) + ) ( + expected = Tuple2 (Seq (0, 1, 1), Seq (2, 3, 5, 8) ) + ) + ) + + test ("splitAt") ( + check ( + obtained = Min_ ().splitAt (example) (3) + ) ( + expected = MSeqPair_ (MSeqTranslator_ ().asMSeq (Seq (0, 1, 1) ), MSeqTranslator_ ().asMSeq (Seq (2, 3, 5, 8) ) ) + ) + ) + + test ("span with Seq") ( + check ( + obtained = exampleSeq.span ( x => ! (x == 5) ) + ) ( + expected = Tuple2 (Seq (0, 1, 1, 2, 3), Seq (5, 8) ) + ) + ) + + test ("span") ( + check ( + obtained = Min_ ().span (example) ( (x : Int) => ! (x == 5) ) + ) ( + expected = MSeqPair_ (MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3) ), MSeqTranslator_ ().asMSeq (Seq (5, 8) ) ) + ) + ) + + test ("append") ( + check ( + obtained = Min_ ().appended (example) (13) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3, 5, 8, 13) ) + ) + ) + + test ("last") ( + check ( + obtained = Min_ ().last (example) + ) ( + expected = 8 + ) + ) + + test ("concat") ( + check ( + obtained = Min_ ().concat (example) (MSeqTranslator_ ().asMSeq (Seq (13, 21, 34, 55) ) ) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55) ) + ) + ) + + test ("slice with Seq 0") ( + check ( + obtained = exampleSeq.slice (2, 5) + ) ( + expected = Seq (1, 2, 3) + ) + ) + + test ("slice with Seq 1") ( + check ( + obtained = exampleSeq.slice (5, 2) + ) ( + expected = Seq () + ) + ) + + test ("slice with Seq 2") ( + check ( + obtained = exampleSeq.slice (3, 3) + ) ( + expected = Seq () + ) + ) + + test ("slice with Seq 3") ( + check ( + obtained = exampleSeq.slice (100, 5) + ) ( + expected = Seq () + ) + ) + + test ("slice with Seq 4") ( + check ( + obtained = exampleSeq.slice (100, 200) + ) ( + expected = Seq () + ) + ) + + test ("slice with Seq 5") ( + check ( + obtained = exampleSeq.slice (-100, 200) + ) ( + expected = exampleSeq + ) + ) + + test ("slice 0") ( + check ( + obtained = Min_ ().slice (example) (2) (5) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (1, 2, 3) ) + ) + ) + + test ("slice 1") ( + check ( + obtained = Min_ ().slice (example) (5) (2) + ) ( + expected = empty + ) + ) + + test ("slice 2") ( + check ( + obtained = Min_ ().slice (example) (3) (3) + ) ( + expected = empty + ) + ) + + test ("slice 3") ( + check ( + obtained = Min_ ().slice (example) (100) (5) + ) ( + expected = empty + ) + ) + + test ("slice 4") ( + check ( + obtained = Min_ ().slice (example) (100) (200) + ) ( + expected = empty + ) + ) + + test ("slice 5") ( + check ( + obtained = Min_ ().slice (example) (-100) (200) + ) ( + expected = example + ) + ) + + test ("forall with Seq 0") ( + check ( + obtained = exampleSeq.forall ( x => ! (x == 7) ) + ) ( + expected = true + ) + ) + + test ("forall with Seq 1") ( + check ( + obtained = exampleSeq.forall ( x => x < 7) + ) ( + expected = false + ) + ) + + test ("forall with Seq 2") ( + check ( + obtained = Seq ().forall ( x => x == 7) + ) ( + expected = true + ) + ) + + test ("forall 0") ( + check ( + obtained = Min_ ().forall (example) ( x => ! (x == 7) ) + ) ( + expected = true + ) + ) + + test ("forall 1") ( + check ( + obtained = Min_ ().forall (example) ( x => x < 7) + ) ( + expected = false + ) + ) + + test ("forall 2") ( + check ( + obtained = Min_ ().forall (empty) ( x => x == 7) + ) ( + expected = true + ) + ) + + test ("exists with Seq 0") ( + check ( + obtained = exampleSeq.exists ( x => x == 8) + ) ( + expected = true + ) + ) + + test ("exists with Seq 1") ( + check ( + obtained = exampleSeq.exists ( x => x == 7) + ) ( + expected = false + ) + ) + + test ("exists with Seq 2") ( + check ( + obtained = Seq ().exists ( x => x == 7) + ) ( + expected = false + ) + ) + + test ("exists 0") ( + check ( + obtained = Min_ ().exists (example) ( x => x == 8) + ) ( + expected = true + ) + ) + + test ("exists 1") ( + check ( + obtained = Min_ ().exists (example) ( x => x == 7) + ) ( + expected = false + ) + ) + + test ("exists 2") ( + check ( + obtained = Min_ ().exists (empty) ( x => x == 7) + ) ( + expected = false + ) + ) + + test ("find with Seq 0") ( + check ( + obtained = exampleSeq.find ( x => ! (x == 7) ) + ) ( + expected = Some (0) + ) + ) + + test ("find with Seq 1") ( + check ( + obtained = exampleSeq.find ( x => x == 8) + ) ( + expected = Some (8) + ) + ) + + test ("find with Seq 2") ( + check ( + obtained = Seq ().find ( x => x == 7) + ) ( + expected = None + ) + ) + + test ("find 0") ( + check ( + obtained = Min_ ().find (example) ( x => ! (x == 7) ) + ) ( + expected = SomeSD_ (0) + ) + ) + + test ("find 1") ( + check ( + obtained = Min_ ().find (example) ( x => x == 8) + ) ( + expected = SomeSD_ (8) + ) + ) + + test ("find 2") ( + check ( + obtained = Min_ ().find (empty) ( x => x == 7) + ) ( + expected = NoneSD_ () + ) + ) + + test ("filter with Seq") ( + check ( + obtained = exampleSeq.filter ( x => x % 3 == 0) + ) ( + expected = Seq (0, 3) + ) + ) + + test ("filter") ( + check ( + obtained = Min_ ().filter (example) ( x => x % 3 == 0) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (0, 3) ) + ) + ) + + test ("map with Seq") ( + check ( + obtained = exampleSeq.map ( x => x + 100) + ) ( + expected = Seq (100, 101, 101, 102, 103, 105, 108) + ) + ) + + test ("map in the same type") ( + check ( + obtained = Min_ ().map0 (example) ( x => x + 100) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (100, 101, 101, 102, 103, 105, 108) ) + ) + ) + + test ("foldLeft with Seq") ( + check ( + obtained = exampleSeq.foldLeft (Seq [Int] () ) ( (s : Seq [Int], e : Int) => s.+: ( (e + 100) ) ) + ) ( + expected = Seq (108, 105, 103, 102, 101, 101, 100) + ) + ) + + test ("foldLeft in the same type") ( + check ( + obtained = Min_ ().foldLeft0 (example) (Min_ ().empty) ( + (s : MSeq [Int] ) => (e : Int) => Min_ ().prepended (s) (e + 100) + ) + ) ( + expected = MSeqTranslator_ ().asMSeq (Seq (108, 105, 103, 102, 101, 101, 100) ) + ) + ) + +} diff --git a/library/src/test/scala/soda/collection/example/ListExampleSpec.scala b/library/src/test/scala/soda/collection/example/ListExampleSpec.scala deleted file mode 100644 index c93b7f15..00000000 --- a/library/src/test/scala/soda/collection/example/ListExampleSpec.scala +++ /dev/null @@ -1,193 +0,0 @@ -package soda.collection.example - -/* - * This package contains tests for examples for Soda. - */ - - - -case class ListExampleSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should test a") ( - check ( - obtained = ListExample_ ().a_example - ) ( - expected = Pair_ ("a", List ('A', 'B', 'C', 'D', 'E', 'F')) - ) - ) - - test ("should test b") ( - check ( - obtained = ListExample_ ().b_example - ) ( - expected = Pair_ ("b", List (10, 20, 30, 40, 50, 60)) - ) - ) - - test ("should test a.take") ( - check ( - obtained = ListExample_ ().take_example - ) ( - expected = Pair_ ("a.take(3)", List ('A', 'B', 'C')) - ) - ) - - test ("should test a.takeRight") ( - check ( - obtained = ListExample_ ().takeRight_example - ) ( - expected = Pair_ ("a.takeRight(3)", List ('D', 'E', 'F')) - ) - ) - - test ("should test a.takeWhile") ( - check ( - obtained = ListExample_ ().takeWhile_example - ) ( - expected = Pair_ ("a.takeWhile( lambda x --> not (x == 'E'))", List ('A', 'B', 'C', 'D')) - ) - ) - - test ("should test a.drop") ( - check ( - obtained = ListExample_ ().drop_example - ) ( - expected = Pair_ ("a.drop(2)", List ('C', 'D', 'E', 'F')) - ) - ) - - test ("should test a.dropRight") ( - check ( - obtained = ListExample_ ().dropRight_example - ) ( - expected = Pair_ ("a.dropRight(2)", List ('A', 'B', 'C', 'D')) - ) - ) - - test ("should test a.dropWhile") ( - check ( - obtained = ListExample_ ().dropWhile_example - ) ( - expected = Pair_ ("a.dropWhile( lambda x --> not (x == 'E'))", List ('E', 'F')) - ) - ) - - test ("should test a.splitAt") ( - check ( - obtained = ListExample_ ().splitAt_example - ) ( - expected = Pair_ ("a.splitAt(3)", (List ('A', 'B', 'C'), List ('D', 'E', 'F'))) - ) - ) - - test ("should test a.indices") ( - check ( - obtained = ListExample_ ().indices_example - ) ( - expected = Pair_ ("a.indices", Range(0, 6)) - ) - ) - - test ("should test a.zipWithIndex") ( - check ( - obtained = ListExample_ ().zipWithIndex_example - ) ( - expected = Pair_ ("a.zipWithIndex", List (('A',0), ('B',1), ('C',2), ('D',3), ('E',4), ('F',5))) - ) - ) - - test ("should test a.zip") ( - check ( - obtained = ListExample_ ().zip_example - ) ( - expected = Pair_ ("a.zip(b)", List (('A', 10), ('B', 20), ('C', 30), ('D', 40), ('E', 50), ('F', 60))) - ) - ) - - test ("should test a.reverse") ( - check ( - obtained = ListExample_ ().reverse_example - ) ( - expected = Pair_ ("a.reverse", List ('F', 'E', 'D', 'C', 'B', 'A')) - ) - ) - - test ("should test a.+") ( - check ( - obtained = ListExample_ ().prepended_example - ) ( - expected = Pair_ ("a.+:('X')", List ('X', 'A', 'B', 'C', 'D', 'E', 'F')) - ) - ) - - test ("should test a.:") ( - check ( - obtained = ListExample_ ().appended_example - ) ( - expected = Pair_ ("a.:+('X')", List ('A', 'B', 'C', 'D', 'E', 'F', 'X')) - ) - ) - - test ("should test a.++") ( - check ( - obtained = ListExample_ ().concat_example - ) ( - expected = Pair_ ("a.map(_.toInt).++(b)", List (65, 66, 67, 68, 69, 70, 10, 20, 30, 40, 50, 60)) - ) - ) - - test ("should test a.span") ( - check ( - obtained = ListExample_ ().span_example - ) ( - expected = Pair_ ("a.span( lambda x --> not (x == 'D'))", (List ('A', 'B', 'C'), List ('D', 'E', 'F'))) - ) - ) - - test ("should test a.map") ( - check ( - obtained = ListExample_ ().map_example - ) ( - expected = Pair_ ("a.map( lambda x --> x.toInt)", List (65, 66, 67, 68, 69, 70)) - ) - ) - - test ("should test a.filter") ( - check ( - obtained = ListExample_ ().filter_example - ) ( - expected = Pair_ ("a.filter( lambda x --> x.toInt % 2 == 0)", List ('B', 'D', 'F')) - ) - ) - - test ("should test b.fold") ( - check ( - obtained = ListExample_ ().fold_example - ) ( - expected = Pair_ ("b.fold(0)( lambda (a, b) --> a + b)", 210) - ) - ) - - test ("should test a.foldLeft") ( - check ( - obtained = ListExample_ ().foldLeft_example - ) ( - expected = Pair_ ("a.foldLeft(Seq('*'))( lambda (list, elem) --> \"(\" + list + \" :+ \" + elem + \")\")", "((((((List(*) :+ A) :+ B) :+ C) :+ D) :+ E) :+ F)".toCharArray.toSeq) - ) - ) - - test ("should test a.foldRight") ( - check ( - obtained = ListExample_ ().foldRight_example - ) ( - expected = Pair_ ("a.foldRight(Seq('*'))( lambda (elem, list) --> \"(\" + elem + \" +: \" + list + \")\")", "(A +: (B +: (C +: (D +: (E +: (F +: List(*)))))))".toCharArray.toSeq) - ) - ) - -} diff --git a/library/src/test/scala/soda/collection/example/Package.scala b/library/src/test/scala/soda/collection/example/Package.scala index 66978c74..e40cdddb 100644 --- a/library/src/test/scala/soda/collection/example/Package.scala +++ b/library/src/test/scala/soda/collection/example/Package.scala @@ -5,3 +5,188 @@ package soda.collection.example */ trait Package +case class ListExampleSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should test a") ( + check ( + obtained = ListExample_ ().a_example + ) ( + expected = Pair_ ("a", List ('A', 'B', 'C', 'D', 'E', 'F')) + ) + ) + + test ("should test b") ( + check ( + obtained = ListExample_ ().b_example + ) ( + expected = Pair_ ("b", List (10, 20, 30, 40, 50, 60)) + ) + ) + + test ("should test a.take") ( + check ( + obtained = ListExample_ ().take_example + ) ( + expected = Pair_ ("a.take(3)", List ('A', 'B', 'C')) + ) + ) + + test ("should test a.takeRight") ( + check ( + obtained = ListExample_ ().takeRight_example + ) ( + expected = Pair_ ("a.takeRight(3)", List ('D', 'E', 'F')) + ) + ) + + test ("should test a.takeWhile") ( + check ( + obtained = ListExample_ ().takeWhile_example + ) ( + expected = Pair_ ("a.takeWhile( lambda x --> not (x == 'E'))", List ('A', 'B', 'C', 'D')) + ) + ) + + test ("should test a.drop") ( + check ( + obtained = ListExample_ ().drop_example + ) ( + expected = Pair_ ("a.drop(2)", List ('C', 'D', 'E', 'F')) + ) + ) + + test ("should test a.dropRight") ( + check ( + obtained = ListExample_ ().dropRight_example + ) ( + expected = Pair_ ("a.dropRight(2)", List ('A', 'B', 'C', 'D')) + ) + ) + + test ("should test a.dropWhile") ( + check ( + obtained = ListExample_ ().dropWhile_example + ) ( + expected = Pair_ ("a.dropWhile( lambda x --> not (x == 'E'))", List ('E', 'F')) + ) + ) + + test ("should test a.splitAt") ( + check ( + obtained = ListExample_ ().splitAt_example + ) ( + expected = Pair_ ("a.splitAt(3)", (List ('A', 'B', 'C'), List ('D', 'E', 'F'))) + ) + ) + + test ("should test a.indices") ( + check ( + obtained = ListExample_ ().indices_example + ) ( + expected = Pair_ ("a.indices", Range(0, 6)) + ) + ) + + test ("should test a.zipWithIndex") ( + check ( + obtained = ListExample_ ().zipWithIndex_example + ) ( + expected = Pair_ ("a.zipWithIndex", List (('A',0), ('B',1), ('C',2), ('D',3), ('E',4), ('F',5))) + ) + ) + + test ("should test a.zip") ( + check ( + obtained = ListExample_ ().zip_example + ) ( + expected = Pair_ ("a.zip(b)", List (('A', 10), ('B', 20), ('C', 30), ('D', 40), ('E', 50), ('F', 60))) + ) + ) + + test ("should test a.reverse") ( + check ( + obtained = ListExample_ ().reverse_example + ) ( + expected = Pair_ ("a.reverse", List ('F', 'E', 'D', 'C', 'B', 'A')) + ) + ) + + test ("should test a.+") ( + check ( + obtained = ListExample_ ().prepended_example + ) ( + expected = Pair_ ("a.+:('X')", List ('X', 'A', 'B', 'C', 'D', 'E', 'F')) + ) + ) + + test ("should test a.:") ( + check ( + obtained = ListExample_ ().appended_example + ) ( + expected = Pair_ ("a.:+('X')", List ('A', 'B', 'C', 'D', 'E', 'F', 'X')) + ) + ) + + test ("should test a.++") ( + check ( + obtained = ListExample_ ().concat_example + ) ( + expected = Pair_ ("a.map(_.toInt).++(b)", List (65, 66, 67, 68, 69, 70, 10, 20, 30, 40, 50, 60)) + ) + ) + + test ("should test a.span") ( + check ( + obtained = ListExample_ ().span_example + ) ( + expected = Pair_ ("a.span( lambda x --> not (x == 'D'))", (List ('A', 'B', 'C'), List ('D', 'E', 'F'))) + ) + ) + + test ("should test a.map") ( + check ( + obtained = ListExample_ ().map_example + ) ( + expected = Pair_ ("a.map( lambda x --> x.toInt)", List (65, 66, 67, 68, 69, 70)) + ) + ) + + test ("should test a.filter") ( + check ( + obtained = ListExample_ ().filter_example + ) ( + expected = Pair_ ("a.filter( lambda x --> x.toInt % 2 == 0)", List ('B', 'D', 'F')) + ) + ) + + test ("should test b.fold") ( + check ( + obtained = ListExample_ ().fold_example + ) ( + expected = Pair_ ("b.fold(0)( lambda (a, b) --> a + b)", 210) + ) + ) + + test ("should test a.foldLeft") ( + check ( + obtained = ListExample_ ().foldLeft_example + ) ( + expected = Pair_ ("a.foldLeft(Seq('*'))( lambda (list, elem) --> \"(\" + list + \" :+ \" + elem + \")\")", "((((((List(*) :+ A) :+ B) :+ C) :+ D) :+ E) :+ F)".toCharArray.toSeq) + ) + ) + + test ("should test a.foldRight") ( + check ( + obtained = ListExample_ ().foldRight_example + ) ( + expected = Pair_ ("a.foldRight(Seq('*'))( lambda (elem, list) --> \"(\" + elem + \" +: \" + list + \")\")", "(A +: (B +: (C +: (D +: (E +: (F +: List(*)))))))".toCharArray.toSeq) + ) + ) + +} From b2c83e88e7b943e2f93d68be8519fb49d0854040 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 21:04:53 +0100 Subject: [PATCH 52/71] Replace Scala files by Package.scala in translator --- .../lib/soda/lib/CartesianProduct.scala | 45 - .../src/main/resources/lib/soda/lib/Doc.scala | 30 - .../resources/lib/soda/lib/EnumConstant.scala | 40 - .../resources/lib/soda/lib/OptionSD.scala | 146 -- .../main/resources/lib/soda/lib/Package.scala | 359 +++++ .../resources/lib/soda/lib/Recursion.scala | 103 -- .../main/resources/lib/soda/lib/SeqSD.scala | 79 -- .../translator/documentation/Manual.scala | 344 ----- .../scala/soda/lib/CartesianProduct.scala | 45 - translator/src/main/scala/soda/lib/Doc.scala | 30 - .../main/scala/soda/lib/EnumConstant.scala | 40 - .../src/main/scala/soda/lib/OptionSD.scala | 146 -- .../src/main/scala/soda/lib/Package.scala | 360 +++++ .../src/main/scala/soda/lib/Recursion.scala | 103 -- .../src/main/scala/soda/lib/SeqSD.scala | 79 -- translator/src/main/scala/soda/lib/lib.scala | 15 - .../translator/block/AnnotatedBlock.scala | 21 - .../scala/soda/translator/block/Block.scala | 38 - .../block/BlockAnnotationEnum.scala | 70 - .../block/BlockSequenceTranslator.scala | 33 - .../translator/block/BlockTranslator.scala | 31 - .../block/BlockTranslatorPipeline.scala | 31 - .../block/ConditionalBlockTranslator.scala | 30 - .../soda/translator/block/LineProcessor.scala | 18 - .../translator/block/LineTranslator.scala | 18 - .../scala/soda/translator/block/Package.scala | 226 +++ .../soda/translator/block/PlainBlock.scala | 23 - .../soda/translator/block/Translator.scala | 23 - .../soda/translator/blocktr/Package.scala | 103 ++ .../translator/blocktr/TableTranslator.scala | 38 - .../translator/blocktr/TokenReplacement.scala | 26 - .../blocktr/TokenizedBlockTranslator.scala | 75 - .../extension/common/Extension.scala | 18 - .../translator/extension/common/Package.scala | 8 + .../soda/translator/extension/help/Help.scala | 87 -- .../translator/extension/help/Package.scala | 77 ++ .../soda/translator/extension/main/Main.scala | 61 - .../translator/extension/main/Package.scala | 50 + .../CoqClassConstructorBlockTranslator.scala | 139 -- .../CoqClassDeclarationBlockTranslator.scala | 106 -- .../tocoq/CoqClassEndBlockTranslator.scala | 74 - .../tocoq/CoqDefinitionBlockTranslator.scala | 69 - .../CoqImportDeclarationBlockTranslator.scala | 70 - ...CoqPackageDeclarationBlockTranslator.scala | 48 - .../tocoq/CoqProofBlockTranslator.scala | 59 - .../tocoq/CoqTheoremBlockTranslator.scala | 60 - .../tocoq/DefinitionLineTranslator.scala | 137 -- .../tocoq/MatchCaseBlockTranslator.scala | 94 -- .../tocoq/MicroTranslatorToCoq.scala | 63 - .../translator/extension/tocoq/Package.scala | 1148 ++++++++++++++++ .../tocoq/TranslationConstantToCoq.scala | 268 ---- .../extension/tocoq/TranslatorToCoq.scala | 91 -- .../extension/todoc/DocBlockTranslator.scala | 108 -- .../todoc/MicroTranslatorToDoc.scala | 49 - .../translator/extension/todoc/Package.scala | 332 +++++ .../todoc/TranslationConstantToDoc.scala | 119 -- .../extension/todoc/TranslatorToDoc.scala | 96 -- .../AbstractDeclarationBlockTranslator.scala | 69 - .../ClassConstructorBlockTranslator.scala | 128 -- .../ClassDeclarationBlockTranslator.scala | 118 -- .../toscala/ClassEndBlockTranslator.scala | 57 - .../FunctionDefinitionBlockTranslator.scala | 118 -- .../FunctionDefinitionLineDetector.scala | 104 -- .../ImportDeclarationBlockTranslator.scala | 67 - .../toscala/MainClassBlockTranslator.scala | 69 - .../toscala/MatchCaseBlockTranslator.scala | 88 -- .../toscala/MicroTranslatorToScala.scala | 65 - .../extension/toscala/Package.scala | 1210 +++++++++++++++++ .../TheoremAndProofBlockTranslator.scala | 58 - .../toscala/TranslationConstantToScala.scala | 243 ---- .../extension/toscala/TranslatorToScala.scala | 156 --- .../translator/io/DirectoryProcessor.scala | 69 - .../soda/translator/io/DirectoryScanner.scala | 48 - .../soda/translator/io/LibraryDeployer.scala | 44 - .../scala/soda/translator/io/Package.scala | 198 +++ .../scala/soda/translator/io/SimpleIO.scala | 81 -- .../soda/translator/parser/BlockBuilder.scala | 76 -- .../translator/parser/BlockProcessor.scala | 60 - .../soda/translator/parser/Package.scala | 388 ++++++ .../PreprocessorSequenceTranslator.scala | 117 -- .../soda/translator/parser/SodaConstant.scala | 175 --- .../AbstractDeclarationAnnotation.scala | 36 - .../parser/annotation/AnnotationFactory.scala | 76 -- .../annotation/BlockAnnotationParser.scala | 66 - .../annotation/ClassAliasAnnotation.scala | 32 - .../annotation/ClassBeginningAnnotation.scala | 63 - .../annotation/ClassEndAnnotation.scala | 28 - .../parser/annotation/CommentAnnotation.scala | 27 - .../FunctionDefinitionAnnotation.scala | 83 -- .../ImportDeclarationAnnotation.scala | 31 - .../parser/annotation/Package.scala | 444 ++++++ .../PackageDeclarationAnnotation.scala | 26 - .../annotation/ProofBlockAnnotation.scala | 27 - .../TestDeclarationAnnotation.scala | 26 - .../annotation/TheoremBlockAnnotation.scala | 27 - .../translator/replacement/CharType.scala | 90 -- .../soda/translator/replacement/Package.scala | 492 +++++++ .../replacement/ParserTransition.scala | 104 -- .../translator/replacement/Replacement.scala | 168 --- .../translator/replacement/Replacer.scala | 78 -- .../translator/replacement/Tokenizer.scala | 107 -- .../test/resources/soda/example/Package.scala | 4 + .../soda/example/otherexample/Package.scala | 4 + .../src/test/scala/soda/example/Example.scala | 3 - .../example/otherexample/OtherExample.scala | 3 - .../scala/soda/lib/CartesianProductSpec.scala | 79 -- .../src/test/scala/soda/lib/EnumSpec.scala | 71 - .../test/scala/soda/lib/OptionSDSpec.scala | 222 --- .../src/test/scala/soda/lib/Package.scala | 487 +++++++ .../test/scala/soda/lib/RecursionSpec.scala | 78 -- .../src/test/scala/soda/lib/SeqSDSpec.scala | 77 -- .../block/BlockTranslatorPipelineSpec.scala | 118 -- .../scala/soda/translator/block/Package.scala | 112 ++ .../tocoq/CoqFullTranslationSpec.scala | 61 - .../tocoq/MicroTranslatorToCoqSpec.scala | 41 - .../translator/extension/tocoq/Package.scala | 90 ++ .../todoc/DocFullTranslationSpec.scala | 50 - .../todoc/MicroTranslatorToDocSpec.scala | 49 - .../translator/extension/todoc/Package.scala | 87 ++ .../extension/toscala/BeautifierSpec.scala | 35 - .../ClassConstructorBlockTranslatorSpec.scala | 133 -- .../toscala/FullTranslationSpec.scala | 105 -- .../extension/toscala/LazySyntaxSpec.scala | 96 -- .../toscala/MicroTranslatorToScalaSpec.scala | 307 ----- .../extension/toscala/MultiLineSpec.scala | 87 -- .../extension/toscala/Package.scala | 948 +++++++++++++ .../extension/toscala/ScalaNonSodaSpec.scala | 96 -- .../toscala/TranslatorToScalaSpec.scala | 33 - .../UpperAndLowerBoundDeclarationSpec.scala | 110 -- .../translator/io/DirectoryScannerSpec.scala | 51 - .../scala/soda/translator/io/Package.scala | 43 + .../soda/translator/parser/BlockSpec.scala | 46 - .../soda/translator/parser/Package.scala | 116 ++ .../PreprocessorSequenceTranslatorSpec.scala | 86 -- .../annotation/BlockAnnotationSpec.scala | 163 --- .../ClassBeginningAnnotationSpec.scala | 199 --- .../parser/annotation/ExampleProgram.scala | 78 -- .../parser/annotation/Package.scala | 416 ++++++ .../translator/replacement/CharTypeSpec.scala | 61 - .../soda/translator/replacement/Package.scala | 283 ++++ .../replacement/ReplacementAuxSpec.scala | 173 --- .../replacement/TokenizerSpec.scala | 73 - 142 files changed, 7985 insertions(+), 9425 deletions(-) delete mode 100644 translator/src/main/resources/lib/soda/lib/CartesianProduct.scala delete mode 100644 translator/src/main/resources/lib/soda/lib/Doc.scala delete mode 100644 translator/src/main/resources/lib/soda/lib/EnumConstant.scala delete mode 100644 translator/src/main/resources/lib/soda/lib/OptionSD.scala delete mode 100644 translator/src/main/resources/lib/soda/lib/Recursion.scala delete mode 100644 translator/src/main/resources/lib/soda/lib/SeqSD.scala delete mode 100644 translator/src/main/resources/soda/translator/documentation/Manual.scala delete mode 100644 translator/src/main/scala/soda/lib/CartesianProduct.scala delete mode 100644 translator/src/main/scala/soda/lib/Doc.scala delete mode 100644 translator/src/main/scala/soda/lib/EnumConstant.scala delete mode 100644 translator/src/main/scala/soda/lib/OptionSD.scala delete mode 100644 translator/src/main/scala/soda/lib/Recursion.scala delete mode 100644 translator/src/main/scala/soda/lib/SeqSD.scala delete mode 100644 translator/src/main/scala/soda/lib/lib.scala delete mode 100644 translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala delete mode 100644 translator/src/main/scala/soda/translator/block/Block.scala delete mode 100644 translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala delete mode 100644 translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/block/BlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala delete mode 100644 translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/block/LineProcessor.scala delete mode 100644 translator/src/main/scala/soda/translator/block/LineTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/block/PlainBlock.scala delete mode 100644 translator/src/main/scala/soda/translator/block/Translator.scala delete mode 100644 translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala delete mode 100644 translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/common/Extension.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/help/Help.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/main/Main.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala delete mode 100644 translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala delete mode 100644 translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala delete mode 100644 translator/src/main/scala/soda/translator/io/DirectoryScanner.scala delete mode 100644 translator/src/main/scala/soda/translator/io/LibraryDeployer.scala delete mode 100644 translator/src/main/scala/soda/translator/io/SimpleIO.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/BlockBuilder.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/BlockProcessor.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/SodaConstant.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala delete mode 100644 translator/src/main/scala/soda/translator/replacement/CharType.scala delete mode 100644 translator/src/main/scala/soda/translator/replacement/ParserTransition.scala delete mode 100644 translator/src/main/scala/soda/translator/replacement/Replacement.scala delete mode 100644 translator/src/main/scala/soda/translator/replacement/Replacer.scala delete mode 100644 translator/src/main/scala/soda/translator/replacement/Tokenizer.scala delete mode 100644 translator/src/test/scala/soda/example/Example.scala delete mode 100644 translator/src/test/scala/soda/example/otherexample/OtherExample.scala delete mode 100644 translator/src/test/scala/soda/lib/CartesianProductSpec.scala delete mode 100644 translator/src/test/scala/soda/lib/EnumSpec.scala delete mode 100644 translator/src/test/scala/soda/lib/OptionSDSpec.scala delete mode 100644 translator/src/test/scala/soda/lib/RecursionSpec.scala delete mode 100644 translator/src/test/scala/soda/lib/SeqSDSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/parser/BlockSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala delete mode 100644 translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala delete mode 100644 translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala diff --git a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala b/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala deleted file mode 100644 index 5d8850a5..00000000 --- a/translator/src/main/resources/lib/soda/lib/CartesianProduct.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains auxiliary functions for combinations. - */ - -trait CartesianProduct -{ - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - private lazy val _fold = Fold_ () - - private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = - seq.map ( elem => Seq [A] (elem) ) - - private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = - seq_a.flatMap ( elem_a => - accum.map ( seq_b => seq_b.+: (elem_a) ) ) - -} - -case class CartesianProduct_ () extends CartesianProduct diff --git a/translator/src/main/resources/lib/soda/lib/Doc.scala b/translator/src/main/resources/lib/soda/lib/Doc.scala deleted file mode 100644 index 198b5f77..00000000 --- a/translator/src/main/resources/lib/soda/lib/Doc.scala +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * All concrete classes extending this class need to have a 'doc' attribute. - */ - -trait Doc -{ - - def doc : String - -} - -case class Doc_ (doc : String) extends Doc diff --git a/translator/src/main/resources/lib/soda/lib/EnumConstant.scala b/translator/src/main/resources/lib/soda/lib/EnumConstant.scala deleted file mode 100644 index 14ddb451..00000000 --- a/translator/src/main/resources/lib/soda/lib/EnumConstant.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is a constant to be used in enumerations. - */ - -trait EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class EnumConstant_ (ordinal : Int, name : String) extends EnumConstant - -trait Enum [A <: EnumConstant] -{ - - def values : Seq [A] - -} - -case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] diff --git a/translator/src/main/resources/lib/soda/lib/OptionSD.scala b/translator/src/main/resources/lib/soda/lib/OptionSD.scala deleted file mode 100644 index 7999a699..00000000 --- a/translator/src/main/resources/lib/soda/lib/OptionSD.scala +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is an Option implemented without exceptions. - */ - -trait OptionSD [A] -{ - - def toOption : Option [A] - def isEmpty : Boolean - def isDefined : Boolean - def isNonEmpty : Boolean - def toSeq : Seq [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = - this match { - case SomeSD_ (element) => ifNonEmpty (element) - case x => ifEmpty - } - - def map [B] (mapping : A => B) : OptionSD [B] = - this match { - case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) - case x => NoneSD_ [B] () - } - - def getOrElse (default : A) : A = - this match { - case SomeSD_ (element) => element - case x => default - } - - def fold [B] (ifEmpty : B) (f : A => B) : B = - this match { - case SomeSD_ (element) => f (element) - case x => ifEmpty - } - - def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = - this match { - case SomeSD_ (element) => mapping (element) - case x => NoneSD_ () - } - - def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = - flatMap [B] (mapping) - - def filter (predicate : A => Boolean) : OptionSD [A] = - this match { - case SomeSD_ (element) => - if ( predicate (element) - ) this - else NoneSD_ [A] () - case x => NoneSD_ () - } - -} - -case class OptionSD_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A]) extends OptionSD [A] - -trait NoneSD [A] - extends - OptionSD [A] -{ - - lazy val toOption : None.type = None - - lazy val isEmpty : Boolean = true - - lazy val isDefined : Boolean = ! isEmpty - - lazy val isNonEmpty : Boolean = ! isEmpty - - lazy val toSeq : Seq [A] = Seq () - -} - -case class NoneSD_ [A] () extends NoneSD [A] - -trait OptionSDWithElement [A] - extends - OptionSD [A] -{ - - def toOption : Option [A] - def isEmpty : Boolean - def isDefined : Boolean - def isNonEmpty : Boolean - def toSeq : Seq [A] - def element : A - -} - -case class OptionSDWithElement_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A], element : A) extends OptionSDWithElement [A] - -trait SomeSD [A] - extends - OptionSDWithElement [A] -{ - - def element : A - - lazy val value : A = element - - lazy val toOption : Some [A] = Some [A] (element) - - lazy val isEmpty : Boolean = false - - lazy val isDefined : Boolean = ! isEmpty - - lazy val isNonEmpty : Boolean = ! isEmpty - - lazy val toSeq : Seq [A] = Seq (element) - -} - -case class SomeSD_ [A] (element : A) extends SomeSD [A] - -trait OptionSDBuilder [A] -{ - - def build (option : Option [A] ) : OptionSD [A] = - if ( option.isEmpty - ) NoneSD_ [A] () - else SomeSD_ [A] (option.get) - -} - -case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] diff --git a/translator/src/main/resources/lib/soda/lib/Package.scala b/translator/src/main/resources/lib/soda/lib/Package.scala index e4600a4b..e2399fdc 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.scala +++ b/translator/src/main/resources/lib/soda/lib/Package.scala @@ -13,3 +13,362 @@ package soda.lib trait Package +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a Seq implemented without exceptions. + */ + +trait SeqSD [A] +{ + + def toSeq : Seq [A] + def reverse : SeqSD [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = + this match { + case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty + } + +} + +case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] + +trait EmptySeqSD [A] + extends + SeqSD [A] +{ + + lazy val toSeq : Seq [A] = Seq [A] () + + lazy val reverse : EmptySeqSD [A] = this + +} + +case class EmptySeqSD_ [A] () extends EmptySeqSD [A] + +trait NonEmptySeqSD [A] + extends + SeqSD [A] +{ + + def toSeq : Seq [A] + + lazy val head : A = toSeq.head + + lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) + + lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + +} + +case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + +trait SeqSDBuilder [A] +{ + + def build (seq : Seq [A] ) : SeqSD [A] = + if ( seq.isEmpty + ) EmptySeqSD_ [A] () + else NonEmptySeqSD_ [A] (seq) + +} + +case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This class contains tail recursive auxiliary functions. + */ + +trait FoldWhile +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) + ) current_value + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + +} + +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = + if ( sequence.isEmpty + ) current_value + else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) + +} + +case class Fold_ () extends Fold + +trait Range +{ + + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = + if ( n <= 0 + ) sequence + else _tailrec_range (n - 1) (sequence.+: (n - 1) ) + +} + +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + +case class Recursion_ () extends Recursion +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a constant to be used in enumerations. + */ + +trait EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class EnumConstant_ (ordinal : Int, name : String) extends EnumConstant + +trait Enum [A <: EnumConstant] +{ + + def values : Seq [A] + +} + +case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This class contains auxiliary functions for combinations. + */ + +trait CartesianProduct +{ + + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) + + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + + private lazy val _fold = Fold_ () + + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = + seq.map ( elem => Seq [A] (elem) ) + + private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = + seq_a.flatMap ( elem_a => + accum.map ( seq_b => seq_b.+: (elem_a) ) ) + +} + +case class CartesianProduct_ () extends CartesianProduct +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is an Option implemented without exceptions. + */ + +trait OptionSD [A] +{ + + def toOption : Option [A] + def isEmpty : Boolean + def isDefined : Boolean + def isNonEmpty : Boolean + def toSeq : Seq [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = + this match { + case SomeSD_ (element) => ifNonEmpty (element) + case x => ifEmpty + } + + def map [B] (mapping : A => B) : OptionSD [B] = + this match { + case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) + case x => NoneSD_ [B] () + } + + def getOrElse (default : A) : A = + this match { + case SomeSD_ (element) => element + case x => default + } + + def fold [B] (ifEmpty : B) (f : A => B) : B = + this match { + case SomeSD_ (element) => f (element) + case x => ifEmpty + } + + def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = + this match { + case SomeSD_ (element) => mapping (element) + case x => NoneSD_ () + } + + def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = + flatMap [B] (mapping) + + def filter (predicate : A => Boolean) : OptionSD [A] = + this match { + case SomeSD_ (element) => + if ( predicate (element) + ) this + else NoneSD_ [A] () + case x => NoneSD_ () + } + +} + +case class OptionSD_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A]) extends OptionSD [A] + +trait NoneSD [A] + extends + OptionSD [A] +{ + + lazy val toOption : None.type = None + + lazy val isEmpty : Boolean = true + + lazy val isDefined : Boolean = ! isEmpty + + lazy val isNonEmpty : Boolean = ! isEmpty + + lazy val toSeq : Seq [A] = Seq () + +} + +case class NoneSD_ [A] () extends NoneSD [A] + +trait OptionSDWithElement [A] + extends + OptionSD [A] +{ + + def toOption : Option [A] + def isEmpty : Boolean + def isDefined : Boolean + def isNonEmpty : Boolean + def toSeq : Seq [A] + def element : A + +} + +case class OptionSDWithElement_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A], element : A) extends OptionSDWithElement [A] + +trait SomeSD [A] + extends + OptionSDWithElement [A] +{ + + def element : A + + lazy val value : A = element + + lazy val toOption : Some [A] = Some [A] (element) + + lazy val isEmpty : Boolean = false + + lazy val isDefined : Boolean = ! isEmpty + + lazy val isNonEmpty : Boolean = ! isEmpty + + lazy val toSeq : Seq [A] = Seq (element) + +} + +case class SomeSD_ [A] (element : A) extends SomeSD [A] + +trait OptionSDBuilder [A] +{ + + def build (option : Option [A] ) : OptionSD [A] = + if ( option.isEmpty + ) NoneSD_ [A] () + else SomeSD_ [A] (option.get) + +} + +case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * All concrete classes extending this class need to have a 'doc' attribute. + */ + +trait Doc +{ + + def doc : String + +} + +case class Doc_ (doc : String) extends Doc diff --git a/translator/src/main/resources/lib/soda/lib/Recursion.scala b/translator/src/main/resources/lib/soda/lib/Recursion.scala deleted file mode 100644 index 84508f22..00000000 --- a/translator/src/main/resources/lib/soda/lib/Recursion.scala +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains tail recursive auxiliary functions. - */ - -trait FoldWhile -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - (condition : B => A => Boolean) - : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - -} - -case class FoldWhile_ () extends FoldWhile - -trait Fold -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = - if ( sequence.isEmpty - ) current_value - else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - -} - -case class Fold_ () extends Fold - -trait Range -{ - - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - -} - -case class Range_ () extends Range - -trait Recursion -{ - - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) - - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _fold.apply (sequence) (initial_value) (next_value_function) - - def range (length : Int) : Seq [Int] = - _range.apply (length) - -} - -case class Recursion_ () extends Recursion diff --git a/translator/src/main/resources/lib/soda/lib/SeqSD.scala b/translator/src/main/resources/lib/soda/lib/SeqSD.scala deleted file mode 100644 index 0a3886f1..00000000 --- a/translator/src/main/resources/lib/soda/lib/SeqSD.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is a Seq implemented without exceptions. - */ - -trait SeqSD [A] -{ - - def toSeq : Seq [A] - def reverse : SeqSD [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = - this match { - case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) - case x => ifEmpty - } - -} - -case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] - -trait EmptySeqSD [A] - extends - SeqSD [A] -{ - - lazy val toSeq : Seq [A] = Seq [A] () - - lazy val reverse : EmptySeqSD [A] = this - -} - -case class EmptySeqSD_ [A] () extends EmptySeqSD [A] - -trait NonEmptySeqSD [A] - extends - SeqSD [A] -{ - - def toSeq : Seq [A] - - lazy val head : A = toSeq.head - - lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) - - lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) - -} - -case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] - -trait SeqSDBuilder [A] -{ - - def build (seq : Seq [A] ) : SeqSD [A] = - if ( seq.isEmpty - ) EmptySeqSD_ [A] () - else NonEmptySeqSD_ [A] (seq) - -} - -case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] diff --git a/translator/src/main/resources/soda/translator/documentation/Manual.scala b/translator/src/main/resources/soda/translator/documentation/Manual.scala deleted file mode 100644 index b469ccd8..00000000 --- a/translator/src/main/resources/soda/translator/documentation/Manual.scala +++ /dev/null @@ -1,344 +0,0 @@ -package soda.translator.documentation - -/* - * This is a Soda tutorial written in Soda. - * Copyright 2020--2023 Julian Alfredo Mendez - * Version: 2023-01-17 - */ - -/* - * Source code written in Soda is intended to be descriptive. - * It is usually written in different files, and each file has `blocks`. - * These blocks are pieces of code that have some meaning. - * A block should be short, maybe less than 10 lines. - * However, it is more important to make things clear than concise. - * These are examples of blocks: - * 1. a constant or function definition - * 2. the beginning of a class definition - * 3. the end of a class definition - * 4. a block declaration of abstract constants and functions - * 5. a block of imports - * 6. a package declaration - * 7. a class alias - * 8. a comment - */ - -/* To declare a class, just add `class` before a class name, and end it with `end`. - * It is recommended to use camel case style starting with a capital letter. - * The name could be a noun or an adjective, but it should not be a verb. */ - -trait Shape -{ - -} - -case class Shape_ () extends Shape - -trait Movable -{ - -} - -case class Movable_ () extends Movable - -/* A class can be parameterized using square brackets ('[' and ']'). - * The parameter type can be constrained using `subtype` and `supertype`. - * For example, `A subtype B` means that `A` is a subtype of `B`. */ - -trait ShapePainter [A <: Shape] -{ - -} - -case class ShapePainter_ [A <: Shape] () extends ShapePainter [A] - -/* It is recommended to indent the constants and functions declared inside. */ - -trait EqualsExample -{ - - /* A constant does not have parameters and it is declared with the equals sign (`=`). - * It is recommended to use snake case and start in lowercase. - * The constant name should be a noun. - * In a function call the parameters can be specified with the colon-equals sign (`:=`). - * This is especially recommended when the parameters are of the same type. - * Constants are only evaluated once, which is the first time they are needed. */ - - lazy val answer : Int = f (x = 20) (y = 2) - - /* A function has parameters. - * If the parameters are empty, it is implied that the function produces some side effect. - * Functions, even with empty parameters, are evaluated every time they are invoked. */ - - def f (x : Int) (y : Int) : Int = 2 * x + y - -} - -case class EqualsExample_ () extends EqualsExample - -/* A class can extend another one by using `extends`. - * Abstract classes cannot be instantiated but can be extended. - * Conversely, concrete classes cannot be extended but can be instantiated. - * Concrete classes are declared with parentheses `(` and `)`. - * It is recommended that concrete classes do not have a body, because this cannot be reused. - * Concrete classes extending only one class could be named as its superclass, but ending with an underscore. */ - -/* A class does not need to define all its constants and functions. */ - -trait RegisteredPerson -{ - - /* A block starting with `abstract` denotes a constant or function that needs to be defined in extending classes. - * Only one `abstract` block should be defined per class, without leaving lines between the declared attributes. */ - - def first_name : String - def last_name : String - - /* If a constant or function is not meant to be exported, its name should start with an underscore. */ - - private lazy val _separator = " " - - /* Strings can be concatenated by using the plus sign (`+`). */ - - lazy val full_name = first_name + _separator + last_name - -} - -case class RegisteredPerson_ (first_name : String, last_name : String) extends RegisteredPerson - -trait Agent -{ - - def identifier : String - -} - -case class Agent_ (identifier : String) extends Agent - -/* A concrete class needs as parameters all the constants and functions that have not been defined in its super classes. */ - -trait RegisteredPersonAgent - extends - Agent - with RegisteredPerson -{ - - def identifier : String - def first_name : String - def last_name : String - -} - -case class RegisteredPersonAgent_ (identifier : String, first_name : String, last_name : String) extends RegisteredPersonAgent - -trait Element -{ - - def accept : Visitor => Boolean - -} - -case class Element_ (accept : Visitor => Boolean) extends Element - -trait Visitor -{ - - def visit : Element => Boolean - -} - -case class Visitor_ (visit : Element => Boolean) extends Visitor - -trait Item - extends Element -{ - - def identifier : Int - - /* It is possible to refer to an object instance by using `this`. */ - - lazy val accept : Visitor => Boolean = - visitor => - visitor.visit (this) - -} - -case class Item_ (identifier : Int) extends Item - -trait PersonName -{ - - def name : String - - /* It is possible to override a function by using the `@override` annotation. - * This is intended only for exceptional cases, like the `toString` function, or a diamond-shaped class hierarchy. */ - - override - lazy val toString = name - -} - -case class PersonName_ (name : String) extends PersonName - -/** - * This contains the examples shown in the manual. - */ - -trait Manual -{ - - import java.util.Date - - lazy val a = 1 - - lazy val b : Int = 2 - - /* An instance of a JVM class can be created with the `@new` annotation. - * If the code is translated to Scala 3, this annotation is not required. */ - - lazy val now : Date = new Date () - - def plus_one (x : Int) : Int = x + 1 - - /* A piecewise function can be defined using an `if`-`then`-`else` structure. - * The condition in the `if` is evaluated, and then only the corresponding branch is evaluated. */ - - def max (x : Int) (y : Int) : Int = - if ( x > y - ) x - else y - - /* Scala sequences (`Seq`) can be used, as well as other basic Scala classes. - * Lambda functions are declared with `lambda` and a long right arrow (`-->`). */ - - def plus_one (sequence : Seq [Int] ) : Seq [Int] = - sequence.map ( element => element + 1) - - /* A synonym for `lambda` is `any`, which sometimes brings more readability. */ - - def plus_two (sequence : Seq [Int] ) : Seq [Int] = - sequence.map ( element => element + 2) - - /* Boolean values `false` and `true` are available. */ - - def my_not (x : Boolean) : Boolean = - if ( x - ) false - else true - - def my_and (x : Boolean) (y : Boolean) : Boolean = - if ( x - ) y - else false - - def my_or (x : Boolean) (y : Boolean) : Boolean = - if ( x - ) true - else y - - /* Boolean values have the standard `not`-`and`-`or` functions. */ - - def my_xor (x : Boolean) (y : Boolean) : Boolean = - (x || y) && ! (x && y) - - /* It is possible to use pattern matching with `match` and `case`. - * The result of the matching case is put after a long double arrow `==>`. */ - - def if_then_else [A] (condition : Boolean) (if_true : A) (if_false : A) : A = - condition match { - case true => if_true - case x => if_false - } - - def sum (n : Int) = - _tailrec_ (n) (0) - - /* A tail recursive function cannot be declared inside another function, and its name could start with underscore. - * Annotation `@tailrec` helps ensuring that the tail recursion is detected and optimized. */ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_ (n : Int) (accum : Int) : Int = - if ( n < 0 - ) accum - else _tailrec_ (n - 1) (n + accum) - -} - -case class Manual_ () extends Manual - -/* The function used to compare equality is a long equals (`==`). */ - -trait FactorialConcise -{ - - def apply (n : Int) : Int = - _tailrec_get_factorial (n) (1) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_factorial (n : Int) (product : Int) : Int = - if ( n == 0 - ) product - else _tailrec_get_factorial (n - 1) (n * product) - -} - -case class FactorialConcise_ () extends FactorialConcise - -trait FoldWhile -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - - def apply [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - -} - -case class FoldWhile_ () extends FoldWhile - -trait Range -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - -} - -case class Range_ () extends Range - -/* The main class has to be named `Main` and requires a `main` function that receives an `Array [String]` and returns a `Unit`. - * Only one main class per package is allowed. */ - -trait Main -{ - - /* An output to the standard output can be sent with a `println` command. - * This is a shorter form of JVM's `System.out.println`. */ - - def main (arguments : Array [String] ) : Unit = - println ("Hello world!") - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main - -/* The main class has an extending concrete class. */ diff --git a/translator/src/main/scala/soda/lib/CartesianProduct.scala b/translator/src/main/scala/soda/lib/CartesianProduct.scala deleted file mode 100644 index 5d8850a5..00000000 --- a/translator/src/main/scala/soda/lib/CartesianProduct.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains auxiliary functions for combinations. - */ - -trait CartesianProduct -{ - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - private lazy val _fold = Fold_ () - - private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = - seq.map ( elem => Seq [A] (elem) ) - - private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = - seq_a.flatMap ( elem_a => - accum.map ( seq_b => seq_b.+: (elem_a) ) ) - -} - -case class CartesianProduct_ () extends CartesianProduct diff --git a/translator/src/main/scala/soda/lib/Doc.scala b/translator/src/main/scala/soda/lib/Doc.scala deleted file mode 100644 index 198b5f77..00000000 --- a/translator/src/main/scala/soda/lib/Doc.scala +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * All concrete classes extending this class need to have a 'doc' attribute. - */ - -trait Doc -{ - - def doc : String - -} - -case class Doc_ (doc : String) extends Doc diff --git a/translator/src/main/scala/soda/lib/EnumConstant.scala b/translator/src/main/scala/soda/lib/EnumConstant.scala deleted file mode 100644 index 14ddb451..00000000 --- a/translator/src/main/scala/soda/lib/EnumConstant.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is a constant to be used in enumerations. - */ - -trait EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class EnumConstant_ (ordinal : Int, name : String) extends EnumConstant - -trait Enum [A <: EnumConstant] -{ - - def values : Seq [A] - -} - -case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] diff --git a/translator/src/main/scala/soda/lib/OptionSD.scala b/translator/src/main/scala/soda/lib/OptionSD.scala deleted file mode 100644 index 7999a699..00000000 --- a/translator/src/main/scala/soda/lib/OptionSD.scala +++ /dev/null @@ -1,146 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is an Option implemented without exceptions. - */ - -trait OptionSD [A] -{ - - def toOption : Option [A] - def isEmpty : Boolean - def isDefined : Boolean - def isNonEmpty : Boolean - def toSeq : Seq [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = - this match { - case SomeSD_ (element) => ifNonEmpty (element) - case x => ifEmpty - } - - def map [B] (mapping : A => B) : OptionSD [B] = - this match { - case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) - case x => NoneSD_ [B] () - } - - def getOrElse (default : A) : A = - this match { - case SomeSD_ (element) => element - case x => default - } - - def fold [B] (ifEmpty : B) (f : A => B) : B = - this match { - case SomeSD_ (element) => f (element) - case x => ifEmpty - } - - def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = - this match { - case SomeSD_ (element) => mapping (element) - case x => NoneSD_ () - } - - def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = - flatMap [B] (mapping) - - def filter (predicate : A => Boolean) : OptionSD [A] = - this match { - case SomeSD_ (element) => - if ( predicate (element) - ) this - else NoneSD_ [A] () - case x => NoneSD_ () - } - -} - -case class OptionSD_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A]) extends OptionSD [A] - -trait NoneSD [A] - extends - OptionSD [A] -{ - - lazy val toOption : None.type = None - - lazy val isEmpty : Boolean = true - - lazy val isDefined : Boolean = ! isEmpty - - lazy val isNonEmpty : Boolean = ! isEmpty - - lazy val toSeq : Seq [A] = Seq () - -} - -case class NoneSD_ [A] () extends NoneSD [A] - -trait OptionSDWithElement [A] - extends - OptionSD [A] -{ - - def toOption : Option [A] - def isEmpty : Boolean - def isDefined : Boolean - def isNonEmpty : Boolean - def toSeq : Seq [A] - def element : A - -} - -case class OptionSDWithElement_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A], element : A) extends OptionSDWithElement [A] - -trait SomeSD [A] - extends - OptionSDWithElement [A] -{ - - def element : A - - lazy val value : A = element - - lazy val toOption : Some [A] = Some [A] (element) - - lazy val isEmpty : Boolean = false - - lazy val isDefined : Boolean = ! isEmpty - - lazy val isNonEmpty : Boolean = ! isEmpty - - lazy val toSeq : Seq [A] = Seq (element) - -} - -case class SomeSD_ [A] (element : A) extends SomeSD [A] - -trait OptionSDBuilder [A] -{ - - def build (option : Option [A] ) : OptionSD [A] = - if ( option.isEmpty - ) NoneSD_ [A] () - else SomeSD_ [A] (option.get) - -} - -case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] diff --git a/translator/src/main/scala/soda/lib/Package.scala b/translator/src/main/scala/soda/lib/Package.scala index 229a289d..d6aaec5d 100644 --- a/translator/src/main/scala/soda/lib/Package.scala +++ b/translator/src/main/scala/soda/lib/Package.scala @@ -11,3 +11,363 @@ package soda.lib */ trait Package +/* Soda library */ +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a Seq implemented without exceptions. + */ + +trait SeqSD [A] +{ + + def toSeq : Seq [A] + def reverse : SeqSD [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = + this match { + case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty + } + +} + +case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] + +trait EmptySeqSD [A] + extends + SeqSD [A] +{ + + lazy val toSeq : Seq [A] = Seq [A] () + + lazy val reverse : EmptySeqSD [A] = this + +} + +case class EmptySeqSD_ [A] () extends EmptySeqSD [A] + +trait NonEmptySeqSD [A] + extends + SeqSD [A] +{ + + def toSeq : Seq [A] + + lazy val head : A = toSeq.head + + lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) + + lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + +} + +case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + +trait SeqSDBuilder [A] +{ + + def build (seq : Seq [A] ) : SeqSD [A] = + if ( seq.isEmpty + ) EmptySeqSD_ [A] () + else NonEmptySeqSD_ [A] (seq) + +} + +case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This class contains tail recursive auxiliary functions. + */ + +trait FoldWhile +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) + ) current_value + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) + +} + +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = + if ( sequence.isEmpty + ) current_value + else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) + +} + +case class Fold_ () extends Fold + +trait Range +{ + + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = + if ( n <= 0 + ) sequence + else _tailrec_range (n - 1) (sequence.+: (n - 1) ) + +} + +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + +case class Recursion_ () extends Recursion +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a constant to be used in enumerations. + */ + +trait EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class EnumConstant_ (ordinal : Int, name : String) extends EnumConstant + +trait Enum [A <: EnumConstant] +{ + + def values : Seq [A] + +} + +case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This class contains auxiliary functions for combinations. + */ + +trait CartesianProduct +{ + + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) + + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) + + private lazy val _fold = Fold_ () + + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = + seq.map ( elem => Seq [A] (elem) ) + + private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = + seq_a.flatMap ( elem_a => + accum.map ( seq_b => seq_b.+: (elem_a) ) ) + +} + +case class CartesianProduct_ () extends CartesianProduct +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is an Option implemented without exceptions. + */ + +trait OptionSD [A] +{ + + def toOption : Option [A] + def isEmpty : Boolean + def isDefined : Boolean + def isNonEmpty : Boolean + def toSeq : Seq [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : A => B) : B = + this match { + case SomeSD_ (element) => ifNonEmpty (element) + case x => ifEmpty + } + + def map [B] (mapping : A => B) : OptionSD [B] = + this match { + case SomeSD_ (element) => SomeSD_ [B] (mapping (element) ) + case x => NoneSD_ [B] () + } + + def getOrElse (default : A) : A = + this match { + case SomeSD_ (element) => element + case x => default + } + + def fold [B] (ifEmpty : B) (f : A => B) : B = + this match { + case SomeSD_ (element) => f (element) + case x => ifEmpty + } + + def flatMap [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = + this match { + case SomeSD_ (element) => mapping (element) + case x => NoneSD_ () + } + + def bind [B] (mapping : A => OptionSD [B] ) : OptionSD [B] = + flatMap [B] (mapping) + + def filter (predicate : A => Boolean) : OptionSD [A] = + this match { + case SomeSD_ (element) => + if ( predicate (element) + ) this + else NoneSD_ [A] () + case x => NoneSD_ () + } + +} + +case class OptionSD_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A]) extends OptionSD [A] + +trait NoneSD [A] + extends + OptionSD [A] +{ + + lazy val toOption : None.type = None + + lazy val isEmpty : Boolean = true + + lazy val isDefined : Boolean = ! isEmpty + + lazy val isNonEmpty : Boolean = ! isEmpty + + lazy val toSeq : Seq [A] = Seq () + +} + +case class NoneSD_ [A] () extends NoneSD [A] + +trait OptionSDWithElement [A] + extends + OptionSD [A] +{ + + def toOption : Option [A] + def isEmpty : Boolean + def isDefined : Boolean + def isNonEmpty : Boolean + def toSeq : Seq [A] + def element : A + +} + +case class OptionSDWithElement_ [A] (toOption : Option [A], isEmpty : Boolean, isDefined : Boolean, isNonEmpty : Boolean, toSeq : Seq [A], element : A) extends OptionSDWithElement [A] + +trait SomeSD [A] + extends + OptionSDWithElement [A] +{ + + def element : A + + lazy val value : A = element + + lazy val toOption : Some [A] = Some [A] (element) + + lazy val isEmpty : Boolean = false + + lazy val isDefined : Boolean = ! isEmpty + + lazy val isNonEmpty : Boolean = ! isEmpty + + lazy val toSeq : Seq [A] = Seq (element) + +} + +case class SomeSD_ [A] (element : A) extends SomeSD [A] + +trait OptionSDBuilder [A] +{ + + def build (option : Option [A] ) : OptionSD [A] = + if ( option.isEmpty + ) NoneSD_ [A] () + else SomeSD_ [A] (option.get) + +} + +case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] +/* + * This file is automatically generated. Do not edit. + */ + +/** + * All concrete classes extending this class need to have a 'doc' attribute. + */ + +trait Doc +{ + + def doc : String + +} + +case class Doc_ (doc : String) extends Doc diff --git a/translator/src/main/scala/soda/lib/Recursion.scala b/translator/src/main/scala/soda/lib/Recursion.scala deleted file mode 100644 index 84508f22..00000000 --- a/translator/src/main/scala/soda/lib/Recursion.scala +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains tail recursive auxiliary functions. - */ - -trait FoldWhile -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - (condition : B => A => Boolean) - : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - -} - -case class FoldWhile_ () extends FoldWhile - -trait Fold -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = - if ( sequence.isEmpty - ) current_value - else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - -} - -case class Fold_ () extends Fold - -trait Range -{ - - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - -} - -case class Range_ () extends Range - -trait Recursion -{ - - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) - - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _fold.apply (sequence) (initial_value) (next_value_function) - - def range (length : Int) : Seq [Int] = - _range.apply (length) - -} - -case class Recursion_ () extends Recursion diff --git a/translator/src/main/scala/soda/lib/SeqSD.scala b/translator/src/main/scala/soda/lib/SeqSD.scala deleted file mode 100644 index 0a3886f1..00000000 --- a/translator/src/main/scala/soda/lib/SeqSD.scala +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This is a Seq implemented without exceptions. - */ - -trait SeqSD [A] -{ - - def toSeq : Seq [A] - def reverse : SeqSD [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = - this match { - case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) - case x => ifEmpty - } - -} - -case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] - -trait EmptySeqSD [A] - extends - SeqSD [A] -{ - - lazy val toSeq : Seq [A] = Seq [A] () - - lazy val reverse : EmptySeqSD [A] = this - -} - -case class EmptySeqSD_ [A] () extends EmptySeqSD [A] - -trait NonEmptySeqSD [A] - extends - SeqSD [A] -{ - - def toSeq : Seq [A] - - lazy val head : A = toSeq.head - - lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) - - lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) - -} - -case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] - -trait SeqSDBuilder [A] -{ - - def build (seq : Seq [A] ) : SeqSD [A] = - if ( seq.isEmpty - ) EmptySeqSD_ [A] () - else NonEmptySeqSD_ [A] (seq) - -} - -case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] diff --git a/translator/src/main/scala/soda/lib/lib.scala b/translator/src/main/scala/soda/lib/lib.scala deleted file mode 100644 index 9acc7528..00000000 --- a/translator/src/main/scala/soda/lib/lib.scala +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This file is automatically generated. Do not edit. - */ - -package soda.lib - -/* - * This package contains a small collection of classes that are useful in Soda. - * These classes can be imported instead of the Scala or Java classes, - * or can be used as an inspiration for similar developments. - */ - - - -/* Soda library */ diff --git a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala b/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala deleted file mode 100644 index 1572ad5c..00000000 --- a/translator/src/main/scala/soda/translator/block/AnnotatedBlock.scala +++ /dev/null @@ -1,21 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait AnnotatedBlock - extends - Block -{ - - def annotated_lines : Seq [AnnotatedLine] - def block_annotation : BlockAnnotationId - -} - -case class AnnotatedBlock_ (annotated_lines : Seq [AnnotatedLine], block_annotation : BlockAnnotationId) extends AnnotatedBlock diff --git a/translator/src/main/scala/soda/translator/block/Block.scala b/translator/src/main/scala/soda/translator/block/Block.scala deleted file mode 100644 index 2118bd13..00000000 --- a/translator/src/main/scala/soda/translator/block/Block.scala +++ /dev/null @@ -1,38 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait AnnotatedLine -{ - - def line : String - def is_comment : Boolean - -} - -case class AnnotatedLine_ (line : String, is_comment : Boolean) extends AnnotatedLine - -trait Block - extends - PlainBlock -{ - - def annotated_lines : Seq [AnnotatedLine] - - lazy val lines : Seq [String] = - annotated_lines - .map ( x => x.line) - - lazy val readable_lines : Seq [AnnotatedLine] = - annotated_lines - .filter ( line => ! line.is_comment) - -} - -case class Block_ (annotated_lines : Seq [AnnotatedLine]) extends Block diff --git a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala b/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala deleted file mode 100644 index dbc6a959..00000000 --- a/translator/src/main/scala/soda/translator/block/BlockAnnotationEnum.scala +++ /dev/null @@ -1,70 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait BlockAnnotationId - extends - soda.lib.EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class BlockAnnotationId_ (ordinal : Int, name : String) extends BlockAnnotationId - -trait BlockAnnotationEnum - extends - soda.lib.Enum [BlockAnnotationId] -{ - - lazy val undefined = BlockAnnotationId_ (0, "undefined") - - lazy val function_definition = BlockAnnotationId_ (1, "function_definition") - - lazy val class_beginning = BlockAnnotationId_ (2, "class_beginning") - - lazy val class_end = BlockAnnotationId_ (3, "class_end") - - lazy val abstract_declaration = BlockAnnotationId_ (4, "abstract_declaration") - - lazy val import_declaration = BlockAnnotationId_ (5, "import_declaration") - - lazy val package_declaration = BlockAnnotationId_ (6, "package_declaration") - - lazy val class_alias = BlockAnnotationId_ (7, "class_alias") - - lazy val theorem_block = BlockAnnotationId_ (8, "theorem_block") - - lazy val proof_block = BlockAnnotationId_ (9, "proof_block") - - lazy val comment = BlockAnnotationId_ (10, "comment") - - lazy val test_declaration = BlockAnnotationId_ (11, "test_declaration") - - lazy val values = - Seq ( - undefined, - function_definition, - class_beginning, - class_end, - abstract_declaration, - import_declaration, - package_declaration, - class_alias, - theorem_block, - proof_block, - comment, - test_declaration - ) - -} - -case class BlockAnnotationEnum_ () extends BlockAnnotationEnum diff --git a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala b/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala deleted file mode 100644 index 5f09fe2d..00000000 --- a/translator/src/main/scala/soda/translator/block/BlockSequenceTranslator.scala +++ /dev/null @@ -1,33 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait BlockSequenceTranslator -{ - - def translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] - -} - -case class BlockSequenceTranslator_ (translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock]) extends BlockSequenceTranslator - -trait DefaultBlockSequenceTranslator - extends - BlockSequenceTranslator -{ - - def translator : BlockTranslator - - lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = - block_sequence => - block_sequence.map ( block => translator.translate (block) ) - -} - -case class DefaultBlockSequenceTranslator_ (translator : BlockTranslator) extends DefaultBlockSequenceTranslator diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslator.scala b/translator/src/main/scala/soda/translator/block/BlockTranslator.scala deleted file mode 100644 index 7d52b28b..00000000 --- a/translator/src/main/scala/soda/translator/block/BlockTranslator.scala +++ /dev/null @@ -1,31 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait BlockTranslator -{ - - def translate : AnnotatedBlock => AnnotatedBlock - -} - -case class BlockTranslator_ (translate : AnnotatedBlock => AnnotatedBlock) extends BlockTranslator - -trait DefaultBlockTranslator - extends - BlockTranslator -{ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - block - -} - -case class DefaultBlockTranslator_ () extends DefaultBlockTranslator diff --git a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala b/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala deleted file mode 100644 index 38414381..00000000 --- a/translator/src/main/scala/soda/translator/block/BlockTranslatorPipeline.scala +++ /dev/null @@ -1,31 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait BlockTranslatorPipeline - extends - BlockTranslator -{ - - import soda.lib.Fold_ - - def pipeline : Seq [BlockTranslator] - - private lazy val _fold = Fold_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _fold.apply (pipeline) (block) (_next_value_function) - - private def _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = - translator.translate (block) - -} - -case class BlockTranslatorPipeline_ (pipeline : Seq [BlockTranslator]) extends BlockTranslatorPipeline diff --git a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala b/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala deleted file mode 100644 index f2557da1..00000000 --- a/translator/src/main/scala/soda/translator/block/ConditionalBlockTranslator.scala +++ /dev/null @@ -1,30 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait ConditionalBlockTranslator - extends - BlockTranslator -{ - - def accepted_annotations : Seq [BlockAnnotationId] - def translator : BlockTranslator - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (block : AnnotatedBlock) : AnnotatedBlock = - if ( accepted_annotations.contains (block.block_annotation) - ) translator.translate (block) - else block - -} - -case class ConditionalBlockTranslator_ (accepted_annotations : Seq [BlockAnnotationId], translator : BlockTranslator) extends ConditionalBlockTranslator diff --git a/translator/src/main/scala/soda/translator/block/LineProcessor.scala b/translator/src/main/scala/soda/translator/block/LineProcessor.scala deleted file mode 100644 index 3cb8a231..00000000 --- a/translator/src/main/scala/soda/translator/block/LineProcessor.scala +++ /dev/null @@ -1,18 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait SingleLineProcessor -{ - - def line : String - -} - -case class SingleLineProcessor_ (line : String) extends SingleLineProcessor diff --git a/translator/src/main/scala/soda/translator/block/LineTranslator.scala b/translator/src/main/scala/soda/translator/block/LineTranslator.scala deleted file mode 100644 index a5f5de48..00000000 --- a/translator/src/main/scala/soda/translator/block/LineTranslator.scala +++ /dev/null @@ -1,18 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait LineTranslator -{ - - def line : String - -} - -case class LineTranslator_ (line : String) extends LineTranslator diff --git a/translator/src/main/scala/soda/translator/block/Package.scala b/translator/src/main/scala/soda/translator/block/Package.scala index 88436a5f..f520fab7 100644 --- a/translator/src/main/scala/soda/translator/block/Package.scala +++ b/translator/src/main/scala/soda/translator/block/Package.scala @@ -7,3 +7,229 @@ package soda.translator.block trait Package +trait LineTranslator +{ + + def line : String + +} + +case class LineTranslator_ (line : String) extends LineTranslator +trait BlockSequenceTranslator +{ + + def translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] + +} + +case class BlockSequenceTranslator_ (translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock]) extends BlockSequenceTranslator + +trait DefaultBlockSequenceTranslator + extends + BlockSequenceTranslator +{ + + def translator : BlockTranslator + + lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = + block_sequence => + block_sequence.map ( block => translator.translate (block) ) + +} + +case class DefaultBlockSequenceTranslator_ (translator : BlockTranslator) extends DefaultBlockSequenceTranslator +trait PlainBlock +{ + + def lines : Seq [String] + + lazy val new_line = "\n" + + lazy val contents : String = + lines.mkString (new_line) + +} + +case class PlainBlock_ (lines : Seq [String]) extends PlainBlock +/** + * This models an abstract translator. + */ + +trait Translator +{ + + def translate : String => String + def keys : Seq [String] + +} + +case class Translator_ (translate : String => String, keys : Seq [String]) extends Translator +trait BlockTranslatorPipeline + extends + BlockTranslator +{ + + import soda.lib.Fold_ + + def pipeline : Seq [BlockTranslator] + + private lazy val _fold = Fold_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _fold.apply (pipeline) (block) (_next_value_function) + + private def _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = + translator.translate (block) + +} + +case class BlockTranslatorPipeline_ (pipeline : Seq [BlockTranslator]) extends BlockTranslatorPipeline +trait BlockTranslator +{ + + def translate : AnnotatedBlock => AnnotatedBlock + +} + +case class BlockTranslator_ (translate : AnnotatedBlock => AnnotatedBlock) extends BlockTranslator + +trait DefaultBlockTranslator + extends + BlockTranslator +{ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + block + +} + +case class DefaultBlockTranslator_ () extends DefaultBlockTranslator +trait BlockAnnotationId + extends + soda.lib.EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class BlockAnnotationId_ (ordinal : Int, name : String) extends BlockAnnotationId + +trait BlockAnnotationEnum + extends + soda.lib.Enum [BlockAnnotationId] +{ + + lazy val undefined = BlockAnnotationId_ (0, "undefined") + + lazy val function_definition = BlockAnnotationId_ (1, "function_definition") + + lazy val class_beginning = BlockAnnotationId_ (2, "class_beginning") + + lazy val class_end = BlockAnnotationId_ (3, "class_end") + + lazy val abstract_declaration = BlockAnnotationId_ (4, "abstract_declaration") + + lazy val import_declaration = BlockAnnotationId_ (5, "import_declaration") + + lazy val package_declaration = BlockAnnotationId_ (6, "package_declaration") + + lazy val class_alias = BlockAnnotationId_ (7, "class_alias") + + lazy val theorem_block = BlockAnnotationId_ (8, "theorem_block") + + lazy val proof_block = BlockAnnotationId_ (9, "proof_block") + + lazy val comment = BlockAnnotationId_ (10, "comment") + + lazy val test_declaration = BlockAnnotationId_ (11, "test_declaration") + + lazy val values = + Seq ( + undefined, + function_definition, + class_beginning, + class_end, + abstract_declaration, + import_declaration, + package_declaration, + class_alias, + theorem_block, + proof_block, + comment, + test_declaration + ) + +} + +case class BlockAnnotationEnum_ () extends BlockAnnotationEnum +trait AnnotatedBlock + extends + Block +{ + + def annotated_lines : Seq [AnnotatedLine] + def block_annotation : BlockAnnotationId + +} + +case class AnnotatedBlock_ (annotated_lines : Seq [AnnotatedLine], block_annotation : BlockAnnotationId) extends AnnotatedBlock +trait ConditionalBlockTranslator + extends + BlockTranslator +{ + + def accepted_annotations : Seq [BlockAnnotationId] + def translator : BlockTranslator + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if ( accepted_annotations.contains (block.block_annotation) + ) translator.translate (block) + else block + +} + +case class ConditionalBlockTranslator_ (accepted_annotations : Seq [BlockAnnotationId], translator : BlockTranslator) extends ConditionalBlockTranslator +trait AnnotatedLine +{ + + def line : String + def is_comment : Boolean + +} + +case class AnnotatedLine_ (line : String, is_comment : Boolean) extends AnnotatedLine + +trait Block + extends + PlainBlock +{ + + def annotated_lines : Seq [AnnotatedLine] + + lazy val lines : Seq [String] = + annotated_lines + .map ( x => x.line) + + lazy val readable_lines : Seq [AnnotatedLine] = + annotated_lines + .filter ( line => ! line.is_comment) + +} + +case class Block_ (annotated_lines : Seq [AnnotatedLine]) extends Block +trait SingleLineProcessor +{ + + def line : String + +} + +case class SingleLineProcessor_ (line : String) extends SingleLineProcessor diff --git a/translator/src/main/scala/soda/translator/block/PlainBlock.scala b/translator/src/main/scala/soda/translator/block/PlainBlock.scala deleted file mode 100644 index b5a1400a..00000000 --- a/translator/src/main/scala/soda/translator/block/PlainBlock.scala +++ /dev/null @@ -1,23 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -trait PlainBlock -{ - - def lines : Seq [String] - - lazy val new_line = "\n" - - lazy val contents : String = - lines.mkString (new_line) - -} - -case class PlainBlock_ (lines : Seq [String]) extends PlainBlock diff --git a/translator/src/main/scala/soda/translator/block/Translator.scala b/translator/src/main/scala/soda/translator/block/Translator.scala deleted file mode 100644 index ddf72386..00000000 --- a/translator/src/main/scala/soda/translator/block/Translator.scala +++ /dev/null @@ -1,23 +0,0 @@ -package soda.translator.block - -/* - * This package contains abstract and concrete classes to define a block and a block translator. - */ - - - - - -/** - * This models an abstract translator. - */ - -trait Translator -{ - - def translate : String => String - def keys : Seq [String] - -} - -case class Translator_ (translate : String => String, keys : Seq [String]) extends Translator diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.scala b/translator/src/main/scala/soda/translator/blocktr/Package.scala index 6422aa37..405a05ef 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.scala +++ b/translator/src/main/scala/soda/translator/blocktr/Package.scala @@ -9,3 +9,106 @@ package soda.translator.blocktr trait Package +trait Table +{ + + def table : Seq [Tuple2 [String, String] ] + +} + +case class Table_ (table : Seq [Tuple2 [String, String] ]) extends Table + +trait TableTranslator + extends + Table + with soda.translator.block.Translator +{ + + def table : Seq [Tuple2 [String, String] ] + + lazy val keys = table.map ( pair => pair._1) + + lazy val translate : String => String = + word => + table.toMap.get (word).getOrElse (word) + +} + +case class TableTranslator_ (table : Seq [Tuple2 [String, String] ]) extends TableTranslator +trait TokenizedBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + def replace_token : soda.translator.replacement.Token => String + + import soda.lib.SomeSD_ + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.replacement.ParserStateEnum_ + import soda.translator.replacement.Replacement_ + import soda.translator.replacement.Token + import soda.translator.replacement.Token_ + import soda.translator.replacement.Tokenizer_ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + AnnotationFactory_ ().update_block ( + block) ( + BlockBuilder_ ().build ( + block + .annotated_lines + .map ( annotated_line => _translate_if_not_a_comment (annotated_line) ) + ) + ) + + private def _translate_if_not_a_comment (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else _translate_non_comment (annotated_line.line) + + private def _translate_non_comment (line : String) : String = + SomeSD_ (line) + .map ( x => Replacement_ (x).add_space_to_soda_line ().line) + .map ( x => Tokenizer_ (x).tokens) + .map ( x => _translate_line (x) ) + .map ( x => _join_tokens (x) ) + .map ( x => Replacement_ (x).remove_space_from_scala_line ().line) + .getOrElse ("") + + private def _translate_line (tokens : Seq [Token] ) : Seq [Token] = + tokens + .map ( token => _get_token_translated_if_in_state (token) ) + + private def _get_token_translated_if_in_state (token : Token) : Token = + if ( token.parser_state == ParserStateEnum_ ().plain + ) Token_ (replace_token (token), token.parser_state, token.index) + else token + + private def _join_tokens (tokens : Seq [Token] ) : String = + tokens + .map ( token => token.text) + .mkString ("") + +} + +case class TokenizedBlockTranslator_ (replace_token : soda.translator.replacement.Token => String) extends TokenizedBlockTranslator +trait TokenReplacement +{ + + import soda.translator.replacement.ReplacementWithTranslator_ + + def replace (table : Seq [ Tuple2 [String, String] ] ) : TokenizedBlockTranslator = + TokenizedBlockTranslator_ ( + token => + ReplacementWithTranslator_ (TableTranslator_ (table) ).replace (token.text) + ) + +} + +case class TokenReplacement_ () extends TokenReplacement diff --git a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala b/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala deleted file mode 100644 index 94ab06de..00000000 --- a/translator/src/main/scala/soda/translator/blocktr/TableTranslator.scala +++ /dev/null @@ -1,38 +0,0 @@ -package soda.translator.blocktr - -/* - * This package contains shared block translators. - * - * @see soda.translator.block.BlockTranslator - */ - - - - - -trait Table -{ - - def table : Seq [Tuple2 [String, String] ] - -} - -case class Table_ (table : Seq [Tuple2 [String, String] ]) extends Table - -trait TableTranslator - extends - Table - with soda.translator.block.Translator -{ - - def table : Seq [Tuple2 [String, String] ] - - lazy val keys = table.map ( pair => pair._1) - - lazy val translate : String => String = - word => - table.toMap.get (word).getOrElse (word) - -} - -case class TableTranslator_ (table : Seq [Tuple2 [String, String] ]) extends TableTranslator diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala b/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala deleted file mode 100644 index d19eba49..00000000 --- a/translator/src/main/scala/soda/translator/blocktr/TokenReplacement.scala +++ /dev/null @@ -1,26 +0,0 @@ -package soda.translator.blocktr - -/* - * This package contains shared block translators. - * - * @see soda.translator.block.BlockTranslator - */ - - - - - -trait TokenReplacement -{ - - import soda.translator.replacement.ReplacementWithTranslator_ - - def replace (table : Seq [ Tuple2 [String, String] ] ) : TokenizedBlockTranslator = - TokenizedBlockTranslator_ ( - token => - ReplacementWithTranslator_ (TableTranslator_ (table) ).replace (token.text) - ) - -} - -case class TokenReplacement_ () extends TokenReplacement diff --git a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala b/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala deleted file mode 100644 index 032fe938..00000000 --- a/translator/src/main/scala/soda/translator/blocktr/TokenizedBlockTranslator.scala +++ /dev/null @@ -1,75 +0,0 @@ -package soda.translator.blocktr - -/* - * This package contains shared block translators. - * - * @see soda.translator.block.BlockTranslator - */ - - - - - -trait TokenizedBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - def replace_token : soda.translator.replacement.Token => String - - import soda.lib.SomeSD_ - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.AnnotationFactory_ - import soda.translator.replacement.ParserStateEnum_ - import soda.translator.replacement.Replacement_ - import soda.translator.replacement.Token - import soda.translator.replacement.Token_ - import soda.translator.replacement.Tokenizer_ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (block : AnnotatedBlock) : AnnotatedBlock = - AnnotationFactory_ ().update_block ( - block) ( - BlockBuilder_ ().build ( - block - .annotated_lines - .map ( annotated_line => _translate_if_not_a_comment (annotated_line) ) - ) - ) - - private def _translate_if_not_a_comment (annotated_line : AnnotatedLine) : String = - if ( annotated_line.is_comment - ) annotated_line.line - else _translate_non_comment (annotated_line.line) - - private def _translate_non_comment (line : String) : String = - SomeSD_ (line) - .map ( x => Replacement_ (x).add_space_to_soda_line ().line) - .map ( x => Tokenizer_ (x).tokens) - .map ( x => _translate_line (x) ) - .map ( x => _join_tokens (x) ) - .map ( x => Replacement_ (x).remove_space_from_scala_line ().line) - .getOrElse ("") - - private def _translate_line (tokens : Seq [Token] ) : Seq [Token] = - tokens - .map ( token => _get_token_translated_if_in_state (token) ) - - private def _get_token_translated_if_in_state (token : Token) : Token = - if ( token.parser_state == ParserStateEnum_ ().plain - ) Token_ (replace_token (token), token.parser_state, token.index) - else token - - private def _join_tokens (tokens : Seq [Token] ) : String = - tokens - .map ( token => token.text) - .mkString ("") - -} - -case class TokenizedBlockTranslator_ (replace_token : soda.translator.replacement.Token => String) extends TokenizedBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/common/Extension.scala b/translator/src/main/scala/soda/translator/extension/common/Extension.scala deleted file mode 100644 index 4938f412..00000000 --- a/translator/src/main/scala/soda/translator/extension/common/Extension.scala +++ /dev/null @@ -1,18 +0,0 @@ -package soda.translator.extension.common - -/* - * This package contains common classes used by the extensions. - */ - - - - - -trait Extension -{ - - def execute : Seq [String] => Boolean - -} - -case class Extension_ (execute : Seq [String] => Boolean) extends Extension diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.scala b/translator/src/main/scala/soda/translator/extension/common/Package.scala index 14b3c716..f2d8c88f 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Package.scala @@ -7,3 +7,11 @@ package soda.translator.extension.common trait Package +trait Extension +{ + + def execute : Seq [String] => Boolean + +} + +case class Extension_ (execute : Seq [String] => Boolean) extends Extension diff --git a/translator/src/main/scala/soda/translator/extension/help/Help.scala b/translator/src/main/scala/soda/translator/extension/help/Help.scala deleted file mode 100644 index eff57849..00000000 --- a/translator/src/main/scala/soda/translator/extension/help/Help.scala +++ /dev/null @@ -1,87 +0,0 @@ -package soda.translator.extension.help - -/* - * This package is for the help extension. - */ - - - - - -trait AbstractHelp - extends - soda.translator.extension.common.Extension -{ - - def execute : Seq [String] => Boolean - - import soda.lib.SomeSD_ - import soda.translator.io.SimpleFileReader_ - - lazy val path : String = "/soda/translator/documentation/" - - def read (file_name : String) : String = - SimpleFileReader_ ().read_resource (path + file_name) - - lazy val this_package = this.getClass.getPackage - - lazy val name : String = Option (this_package.getImplementationTitle).getOrElse ("") - - lazy val version : String = Option (this_package.getImplementationVersion).getOrElse ("") - - lazy val title_and_version : String = (name + " " + version).trim - - def output_content (content : String) : Boolean = - SomeSD_ (content) - .map ( x => println (x) ) - .map ( x => true) - .getOrElse (false) - -} - -case class AbstractHelp_ (execute : Seq [String] => Boolean) extends AbstractHelp - -trait Help - extends - AbstractHelp -{ - - lazy val file_name = "help.txt" - - lazy val execute : Seq [String] => Boolean = - arguments => - output_content (title_and_version + "\n\n" + read (file_name) ) - -} - -case class Help_ () extends Help - -trait Manual - extends - AbstractHelp -{ - - lazy val file_name = "Manual.soda" - - lazy val execute : Seq [String] => Boolean = - arguments => - output_content ("/* " + title_and_version + " */\n\n" + read (file_name) ) - -} - -case class Manual_ () extends Manual - -trait License - extends - AbstractHelp -{ - - lazy val file_name = "LICENSE.txt" - - lazy val execute : Seq [String] => Boolean = - arguments => - output_content (read (file_name)) - -} - -case class License_ () extends License diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.scala b/translator/src/main/scala/soda/translator/extension/help/Package.scala index a912007d..a7385de5 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Package.scala @@ -7,3 +7,80 @@ package soda.translator.extension.help trait Package +trait AbstractHelp + extends + soda.translator.extension.common.Extension +{ + + def execute : Seq [String] => Boolean + + import soda.lib.SomeSD_ + import soda.translator.io.SimpleFileReader_ + + lazy val path : String = "/soda/translator/documentation/" + + def read (file_name : String) : String = + SimpleFileReader_ ().read_resource (path + file_name) + + lazy val this_package = this.getClass.getPackage + + lazy val name : String = Option (this_package.getImplementationTitle).getOrElse ("") + + lazy val version : String = Option (this_package.getImplementationVersion).getOrElse ("") + + lazy val title_and_version : String = (name + " " + version).trim + + def output_content (content : String) : Boolean = + SomeSD_ (content) + .map ( x => println (x) ) + .map ( x => true) + .getOrElse (false) + +} + +case class AbstractHelp_ (execute : Seq [String] => Boolean) extends AbstractHelp + +trait Help + extends + AbstractHelp +{ + + lazy val file_name = "help.txt" + + lazy val execute : Seq [String] => Boolean = + arguments => + output_content (title_and_version + "\n\n" + read (file_name) ) + +} + +case class Help_ () extends Help + +trait Manual + extends + AbstractHelp +{ + + lazy val file_name = "Manual.soda" + + lazy val execute : Seq [String] => Boolean = + arguments => + output_content ("/* " + title_and_version + " */\n\n" + read (file_name) ) + +} + +case class Manual_ () extends Manual + +trait License + extends + AbstractHelp +{ + + lazy val file_name = "LICENSE.txt" + + lazy val execute : Seq [String] => Boolean = + arguments => + output_content (read (file_name)) + +} + +case class License_ () extends License diff --git a/translator/src/main/scala/soda/translator/extension/main/Main.scala b/translator/src/main/scala/soda/translator/extension/main/Main.scala deleted file mode 100644 index f0044ec1..00000000 --- a/translator/src/main/scala/soda/translator/extension/main/Main.scala +++ /dev/null @@ -1,61 +0,0 @@ -package soda.translator.extension.main - -/* - * This package is for the main extension. - * This is the entry point when the application is executed from a terminal. - */ - - - - - -/** - * This is the main entry point. - */ - -trait Main - extends - soda.translator.extension.common.Extension -{ - - import soda.translator.extension.common.Extension - - lazy val help = soda.translator.extension.help.Help_ () - - lazy val extensions : Map [String, Extension] = - Seq ( - ( ".", soda.translator.extension.toscala.TranslatorToScala_ () ), - ( "scala", soda.translator.extension.toscala.TranslatorToScala_ () ), - ( "coq", soda.translator.extension.tocoq.TranslatorToCoq_ () ), - ( "doc", soda.translator.extension.todoc.TranslatorToDoc_ () ), - ( "manual", soda.translator.extension.help.Manual_ () ), - ( "license", soda.translator.extension.help.License_ () ), - ( "help", help ), - ( "-h", help ), - ( "--help", help ), - ( "main", this ) - ).toMap - - def main (arguments : Array [String] ) : Unit = - execute (arguments.toSeq) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - - def execute_for (arguments : Seq [String] ) : Boolean = - if ( arguments.length == 0 - ) help.execute (arguments.toSeq) - else - extensions - .getOrElse (arguments.head, help) - .execute (arguments.tail) - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.scala b/translator/src/main/scala/soda/translator/extension/main/Package.scala index b7d97408..816e92b4 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Package.scala @@ -8,3 +8,53 @@ package soda.translator.extension.main trait Package +/** + * This is the main entry point. + */ + +trait Main + extends + soda.translator.extension.common.Extension +{ + + import soda.translator.extension.common.Extension + + lazy val help = soda.translator.extension.help.Help_ () + + lazy val extensions : Map [String, Extension] = + Seq ( + ( ".", soda.translator.extension.toscala.TranslatorToScala_ () ), + ( "scala", soda.translator.extension.toscala.TranslatorToScala_ () ), + ( "coq", soda.translator.extension.tocoq.TranslatorToCoq_ () ), + ( "doc", soda.translator.extension.todoc.TranslatorToDoc_ () ), + ( "manual", soda.translator.extension.help.Manual_ () ), + ( "license", soda.translator.extension.help.License_ () ), + ( "help", help ), + ( "-h", help ), + ( "--help", help ), + ( "main", this ) + ).toMap + + def main (arguments : Array [String] ) : Unit = + execute (arguments.toSeq) + + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + if ( arguments.length == 0 + ) help.execute (arguments.toSeq) + else + extensions + .getOrElse (arguments.head, help) + .execute (arguments.tail) + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala deleted file mode 100644 index 45ba738c..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassConstructorBlockTranslator.scala +++ /dev/null @@ -1,139 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqClassConstructorBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) - - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) - - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - if ( beginning.is_concrete - ) block - else _translate_block_with_abstract_beginning (beginning) (block) - - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ ( - BlockBuilder_ ().build ( - Seq (_tc.coq_opening_comment).++ ( - block.lines.++ ( - Seq [String] ( - _tc.coq_closing_comment, - "", - _get_constructor_declaration (beginning) (_get_types_of_abstract_functions (block) ) - ) - ) - ) - ), - block.references - ) - - private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = - _get_initial_spaces (beginning) + - _tc.coq_inductive_reserved_word + - _tc.coq_space + - beginning.class_name + - _tc.coq_space + - _tc.coq_type_membership_symbol + - _tc.coq_space + - _tc.coq_type_reserved_word + - _tc.coq_space + - _tc.coq_function_definition_symbol + - _tc.coq_new_line + - _get_initial_spaces (beginning) + - _tc.coq_space + - _tc.coq_space + - _tc.coq_vertical_bar_symbol + - _tc.coq_space + - beginning.class_name + - _sc.constructor_suffix + - _tc.coq_space + - _tc.coq_opening_parenthesis + - _tc.coq_some_variable_name + - _tc.coq_space + - _tc.coq_type_membership_symbol + - _tc.coq_space + - abstract_functions.mkString (_tc.coq_space + _tc.coq_product_type_symbol + _tc.coq_space) + - _tc.coq_closing_parenthesis + - _tc.coq_new_line + - _get_initial_spaces (beginning) + - _tc.coq_inductive_end_symbol - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - - private def _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = - block.abstract_functions - .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) - .map ( line => _remove_variable (line) ) - - private def _remove_variable (line : String) : String = - _remove_variable_with (line) (line.indexOf (_sc.type_membership_symbol) ) - - private def _remove_variable_with (line : String) (index : Int) : String = - if ( index < 0 - ) line - else line.substring (index + _sc.type_membership_symbol.length).trim - - private def _translate_type_symbols (line : String) : String = - line - .replaceAll (_sc.subtype_reserved_word, _tc.coq_subtype_symbol) - .replaceAll (_sc.supertype_reserved_word, _tc.coq_supertype_symbol) - .replaceAll (_sc.function_arrow_symbol, _tc.coq_function_arrow_symbol) - - private def _get_initial_spaces (block : AnnotatedBlock) : String = - _get_initial_spaces_with (_get_first_line (block) ) - - private def _get_initial_spaces_with (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - private def _get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class CoqClassConstructorBlockTranslator_ () extends CoqClassConstructorBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala deleted file mode 100644 index 56e18271..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassDeclarationBlockTranslator.scala +++ /dev/null @@ -1,106 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqClassDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.block.Translator - import soda.translator.blocktr.TableTranslator_ - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.replacement.Replacement_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val soda_space : String = _sc.space - - lazy val scala_space : String = " " - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = - ClassBeginningAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : AnnotatedBlock) : Block = - if ( (has_condition_for_type_alias (get_first_line (block) ) ) - ) block - else - BlockBuilder_ ().build ( - _process_head (block) ++ _process_tail (block) - ) - - private def _process_head (block : Block) : Seq [String] = - _process_head_with (get_first_line (block) ) (block) - - private def _process_head_with (line : String) (block : Block) : Seq [String] = - Seq [String] ( - Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) + _tc.coq_space + _tc.coq_end_symbol - ) - - private def _process_tail (block : Block) : Seq [String] = - _process_if_extends (remove_first_line (block) ) - - private def _process_if_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim == _sc.extends_reserved_word) - ) Seq [String] (get_initial_spaces (block) ).++ ( _process_after_extends (remove_first_line (block) ) ) - else block.lines - - def get_table_translator (line : String) : Translator = - TableTranslator_ ( - Seq (Tuple2 (_sc.class_reserved_word, _tc.coq_module_reserved_word ) ) - ) - - private def _process_after_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim.nonEmpty) - ) block.lines.map ( line => _tc.coq_import_reserved_word + _tc.coq_space + line.trim + _tc.coq_space + _tc.coq_end_symbol) - else Seq [String] () - - def remove_first_line (block : Block) : Block = - BlockBuilder_ ().build ( _remove_first_line (block.lines) ) - - private def _remove_first_line (lines : Seq [String] ) : Seq [String] = - if ( lines.isEmpty - ) lines - else lines.tail - - def get_first_line (block : Block) : String = - block.lines.headOption.getOrElse ("") - - def get_initial_spaces (block : Block) : String = - get_initial_spaces_for (get_first_line (block) ) - - def get_initial_spaces_for (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - def contains_equals (line : String) : Boolean = - line.trim.contains (_sc.function_definition_symbol) - - def has_condition_for_type_alias (line : String) : Boolean = - contains_equals (line) - -} - -case class CoqClassDeclarationBlockTranslator_ () extends CoqClassDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala deleted file mode 100644 index 3339052a..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqClassEndBlockTranslator.scala +++ /dev/null @@ -1,74 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqClassEndBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) - - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) - - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( beginning.is_concrete - ) block - else _translate_block_with_abstract_beginning (beginning) (block) - - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - Seq [String] ( - _tc.coq_module_end_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol, - "", - _tc.coq_import_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol - ) - ), - block.references - ) - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - -} - -case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala deleted file mode 100644 index 5d446231..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqDefinitionBlockTranslator.scala +++ /dev/null @@ -1,69 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqDefinitionBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_definition_block (FunctionDefinitionAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_definition_block (block : FunctionDefinitionAnnotation) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : FunctionDefinitionAnnotation) : Block = - if ( is_a_recursive_definition (block) - ) _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) - else _translate_non_recursive_definition (block) - - private def _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = - if ( is_a_definition (block) - ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) - else block - - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq[String] (prefix + block.lines.head) ++ block.lines.tail - ) - - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) - - def is_a_recursive_definition (block : Block) : Boolean = - _tc.coq_recursive_function_prefixes.exists ( prefix => first_line (block).startsWith (prefix) ) - - def first_line (block : Block) : String = - block.lines.headOption.getOrElse ("").trim - - def is_a_definition (block : Block) : Boolean = - ! is_a_recursive_definition (block) && - ! _tc.non_definition_block_prefixes.exists ( prefix => block.contents.trim.startsWith (prefix) ) - -} - -case class CoqDefinitionBlockTranslator_ () extends CoqDefinitionBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala deleted file mode 100644 index 84329d7b..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqImportDeclarationBlockTranslator.scala +++ /dev/null @@ -1,70 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqImportDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ImportDeclarationAnnotation - import soda.translator.parser.annotation.ImportDeclarationAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val coq_import_declaration_pattern = - _tc.coq_import_reserved_word + _tc.coq_space - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = - ImportDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - coq_import_declaration_pattern) ( - block.imported_items - .filter( annotated_line => ! annotated_line.is_comment) - .map ( annotated_line => AnnotatedLine_ (annotated_line.line + _tc.coq_space + _tc.coq_end_symbol, false) ) - ) - ) - - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - BlockBuilder_ ().build ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) - ) - - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = - if ( annotated_line.is_comment - ) annotated_line.line - else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) - - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile ( ch => ch.isSpaceChar) - .length - - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class CoqImportDeclarationBlockTranslator_ () extends CoqImportDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala deleted file mode 100644 index 80af8932..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqPackageDeclarationBlockTranslator.scala +++ /dev/null @@ -1,48 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqPackageDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.PackageDeclarationAnnotation - import soda.translator.parser.annotation.PackageDeclarationAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case PackageDeclarationAnnotation_ (block) => _translate_block (PackageDeclarationAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_block (block : PackageDeclarationAnnotation) : PackageDeclarationAnnotation = - PackageDeclarationAnnotation_ ( - _comment_block ( - block - ) - ) - - private def _comment_block (block : Block) : Block = - BlockBuilder_ ().build ( - ( (Seq (_tc.coq_opening_comment).++ (block.lines) ).++ (Seq (_tc.coq_closing_comment) ) ).++ (_tc.coq_prelude) - ) - -} - -case class CoqPackageDeclarationBlockTranslator_ () extends CoqPackageDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala deleted file mode 100644 index ee7c5c4d..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqProofBlockTranslator.scala +++ /dev/null @@ -1,59 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqProofBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ProofBlockAnnotation - import soda.translator.parser.annotation.ProofBlockAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ProofBlockAnnotation_ (block) => _translate_block (ProofBlockAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_block (block : ProofBlockAnnotation) : ProofBlockAnnotation = - ProofBlockAnnotation_ ( - _append ( - _tc.coq_proof_end_reserved_word) ( - _replace_first_line (_tc.coq_proof_begin_reserved_word) (block) - ) - ) - - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) - - private def _replace_first_line (first_line : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq (first_line) .++ (_get_tail_or_empty (block.lines) ) - ) - - private def _get_tail_or_empty (sequence : Seq [String] ) : Seq [String] = - if ( sequence.isEmpty - ) sequence - else sequence.tail - -} - -case class CoqProofBlockTranslator_ () extends CoqProofBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala deleted file mode 100644 index 1efa1dba..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/CoqTheoremBlockTranslator.scala +++ /dev/null @@ -1,60 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait CoqTheoremBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.TheoremBlockAnnotation - import soda.translator.parser.annotation.TheoremBlockAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case TheoremBlockAnnotation_ (block) => _translate_block (TheoremBlockAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_block (block : TheoremBlockAnnotation) : TheoremBlockAnnotation = - TheoremBlockAnnotation_ ( - _append ( - _tc.coq_theorem_end_symbol) (_prepend ( - _tc.coq_theorem_begin_reserved_word) (_remove_first_line (block) - ) - ) - ) - - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq[String] (prefix + block.lines.head).++ (block.lines.tail) - ) - - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) - - private def _remove_first_line (block : Block) : Block = - if ( block.lines.isEmpty - ) block - else BlockBuilder_ ().build (block.lines.tail) - -} - -case class CoqTheoremBlockTranslator_ () extends CoqTheoremBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala deleted file mode 100644 index 8995a36c..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/DefinitionLineTranslator.scala +++ /dev/null @@ -1,137 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -/** - * A line containing the definition sign will be classified as a definition. - * The definitions need to be identified as 'val', 'def', or 'class'. - * - * 'class' is for class definition. - * It is detected if the 'class' reserved word is also in the same line. - * - * 'val' is for value definition. - * It is detected in three cases. - * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` - * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` - * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` - * - * 'def' is for function definition. - * If it does not fit in any of the 'val' cases. - * - * Formerly there was another case for 'val'. - * Deprecated Case: - * This was implemented simply as: - * `line.trim.startsWith (soda_opening_parenthesis)` - * This is no longer supported. - * - */ - -trait DefinitionLineTranslator - extends - soda.translator.block.LineTranslator -{ - - def line: String - - import soda.lib.OptionSD - import soda.lib.SomeSD_ - import soda.translator.parser.SodaConstant_ - import soda.translator.replacement.Replacement - import soda.translator.replacement.Replacement_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToCoq_ () - - private lazy val _trimmed_line = line.trim - - lazy val translation = - find_definition (line).opt (ifEmpty = line) (ifNonEmpty = position => _try_found_definition (position).line) - - private lazy val _is_class_definition = - get_index (line) (_sc.space + _sc.class_reserved_word + _sc.space).isDefined - - private lazy val _translation_of_class_definition = - if ( _condition_for_type_alias - ) Replacement_ (line) - else Replacement_ (line).replace_all (_sc.space + _sc.function_definition_symbol) ("") - - private lazy val _ends_with_equals = false - - private lazy val _ends_with_opening_brace = false - - private lazy val _contains_equals = - _trimmed_line.contains (_sc.function_definition_symbol) - - private lazy val _condition_for_type_alias = - _contains_equals && ! (_ends_with_equals || _ends_with_opening_brace) - - private lazy val _translation_of_val_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) - - private lazy val _translation_of_def_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) - - private def _try_found_definition (position : Int) : Replacement = - if ( _is_class_definition - ) _translation_of_class_definition - else _decide_val_or_def_translation (position) - - private def _decide_val_or_def_translation (position : Int) : Replacement = - if ( _is_val_definition (position) - ) _translation_of_val_definition - else _translation_of_def_definition - - private def _is_val_definition (initial_position : Int) = - _is_val_definition_case_1 || - _is_val_definition_case_2 (initial_position) || - _is_val_definition_case_3 || - _is_val_definition_case_4 - - private lazy val _position_of_first_opening_parenthesis = - get_index (line) (_sc.opening_parenthesis_symbol) - - private lazy val _is_val_definition_case_1 = - _position_of_first_opening_parenthesis.isEmpty - - private def _is_val_definition_case_2 (initial_position : Int) = - _position_of_first_opening_parenthesis.opt (false) ( position => (position > initial_position) ) - - private lazy val _is_val_definition_case_3 = - (get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => - _position_of_first_opening_parenthesis.opt (false) ( position => (position > other_position) ) - ) - - private lazy val _is_val_definition_case_4 = - _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) - - /** - * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. - * This function finds the first occurrence of the definition sign, if it is present. - * - * @param line line - * @return maybe the position of the definition sign - */ - - def find_definition (line : String) : OptionSD [Int] = - if ( line.endsWith (_sc.space + _sc.function_definition_symbol) - ) SomeSD_ (line.length - _sc.function_definition_symbol.length) - else get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) - - def get_index (line : String) (pattern : String) : OptionSD [Int] = - get_index_from (line) (pattern) (0) - - def get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = - SomeSD_ (line.indexOf (pattern, start) ) - .filter ( position => ! (position == -1) ) - -} - -case class DefinitionLineTranslator_ (line: String) extends DefinitionLineTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala deleted file mode 100644 index 78b37f61..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MatchCaseBlockTranslator.scala +++ /dev/null @@ -1,94 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -trait MatchCaseBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ - import soda.translator.parser.annotation.TestDeclarationAnnotation - import soda.translator.parser.annotation.TestDeclarationAnnotation_ - import soda.translator.replacement.ReplacementAux_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _soda_case_pattern = _sc.case_reserved_word + _sc.space - - private lazy val _tc = TranslationConstantToCoq_ () - - private lazy val _soda_match_pattern = _sc.match_reserved_word + " " - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_function_block (FunctionDefinitionAnnotation_ (block) ) - case TestDeclarationAnnotation_ (block) => _translate_test_block (TestDeclarationAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) - - private def _translate_test_block (block : AnnotatedBlock) : TestDeclarationAnnotation = - TestDeclarationAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : AnnotatedBlock) : Block = - if ( _is_a_match_case_structure (block) - ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) - else block - - private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = - block.lines.exists ( line => _is_a_match_line (line) ) - - private def _is_a_match_line (line : String) : Boolean = - line.trim.startsWith (_soda_match_pattern) - - private def _is_a_case_line (line : String) : Boolean = - line.trim.startsWith (_soda_case_pattern) - - private def _get_tabulation_of_match (block : AnnotatedBlock) : String = - block.lines - .find ( line => _is_a_match_line (line) ) - .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) - .getOrElse (_tc.coq_space) - - private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = - BlockBuilder_ ().build ( - block.lines - .map ( line => _append_with_after_match (line) ) - .map ( line => _replace_case (line) ) - .++ ( Seq [String] () .+: (tabulation + _tc.coq_match_end_translation) ) - ) - - private def _append_with_after_match (line : String) : String = - if ( _is_a_match_line (line) - ) line + _tc.coq_space + _tc.coq_with_reserved_word - else line - - private def _replace_case (line : String) : String = - if ( _is_a_case_line (line) - ) ReplacementAux_ (). replace_first (line) (_soda_case_pattern) (_tc.coq_case_translation) - else line - - private def _left_part (index : Int) (line : String) : String = - line.substring (0, index) - -} - -case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala deleted file mode 100644 index 7421f344..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/MicroTranslatorToCoq.scala +++ /dev/null @@ -1,63 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -/** - * This class translates Soda snippets into Coq snippets. - */ - -trait MicroTranslatorToCoq - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token - - private lazy val _tc = TranslationConstantToCoq_ () - - private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - - private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - - lazy val functions_and_tests = Seq (_function_definition, _test_declaration) - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _translation_pipeline.translate (block) - - lazy val try_definition : Token => String = - token => - DefinitionLineTranslator_ (token.text).translation - - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - MatchCaseBlockTranslator_ (), - CoqDefinitionBlockTranslator_ (), - CoqClassConstructorBlockTranslator_ (), - CoqClassDeclarationBlockTranslator_ (), - CoqPackageDeclarationBlockTranslator_ (), - CoqClassEndBlockTranslator_ (), - CoqImportDeclarationBlockTranslator_ (), - CoqTheoremBlockTranslator_ (), - CoqProofBlockTranslator_ (), - ConditionalBlockTranslator_ (functions_and_tests, TokenizedBlockTranslator_ (try_definition) ), - ConditionalBlockTranslator_ (functions_and_tests, TokenReplacement_ ().replace (_tc.function_symbols_translation) ) - ) - ) - -} - -case class MicroTranslatorToCoq_ () extends MicroTranslatorToCoq diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala index d0e48f39..4737c44b 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala @@ -7,3 +7,1151 @@ package soda.translator.extension.tocoq trait Package +/** + * A line containing the definition sign will be classified as a definition. + * The definitions need to be identified as 'val', 'def', or 'class'. + * + * 'class' is for class definition. + * It is detected if the 'class' reserved word is also in the same line. + * + * 'val' is for value definition. + * It is detected in three cases. + * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` + * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` + * + * 'def' is for function definition. + * If it does not fit in any of the 'val' cases. + * + * Formerly there was another case for 'val'. + * Deprecated Case: + * This was implemented simply as: + * `line.trim.startsWith (soda_opening_parenthesis)` + * This is no longer supported. + * + */ + +trait DefinitionLineTranslator + extends + soda.translator.block.LineTranslator +{ + + def line: String + + import soda.lib.OptionSD + import soda.lib.SomeSD_ + import soda.translator.parser.SodaConstant_ + import soda.translator.replacement.Replacement + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToCoq_ () + + private lazy val _trimmed_line = line.trim + + lazy val translation = + find_definition (line).opt (ifEmpty = line) (ifNonEmpty = position => _try_found_definition (position).line) + + private lazy val _is_class_definition = + get_index (line) (_sc.space + _sc.class_reserved_word + _sc.space).isDefined + + private lazy val _translation_of_class_definition = + if ( _condition_for_type_alias + ) Replacement_ (line) + else Replacement_ (line).replace_all (_sc.space + _sc.function_definition_symbol) ("") + + private lazy val _ends_with_equals = false + + private lazy val _ends_with_opening_brace = false + + private lazy val _contains_equals = + _trimmed_line.contains (_sc.function_definition_symbol) + + private lazy val _condition_for_type_alias = + _contains_equals && ! (_ends_with_equals || _ends_with_opening_brace) + + private lazy val _translation_of_val_definition = + Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) + + private lazy val _translation_of_def_definition = + Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) + + private def _try_found_definition (position : Int) : Replacement = + if ( _is_class_definition + ) _translation_of_class_definition + else _decide_val_or_def_translation (position) + + private def _decide_val_or_def_translation (position : Int) : Replacement = + if ( _is_val_definition (position) + ) _translation_of_val_definition + else _translation_of_def_definition + + private def _is_val_definition (initial_position : Int) = + _is_val_definition_case_1 || + _is_val_definition_case_2 (initial_position) || + _is_val_definition_case_3 || + _is_val_definition_case_4 + + private lazy val _position_of_first_opening_parenthesis = + get_index (line) (_sc.opening_parenthesis_symbol) + + private lazy val _is_val_definition_case_1 = + _position_of_first_opening_parenthesis.isEmpty + + private def _is_val_definition_case_2 (initial_position : Int) = + _position_of_first_opening_parenthesis.opt (false) ( position => (position > initial_position) ) + + private lazy val _is_val_definition_case_3 = + (get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => + _position_of_first_opening_parenthesis.opt (false) ( position => (position > other_position) ) + ) + + private lazy val _is_val_definition_case_4 = + _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) + + /** + * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. + * This function finds the first occurrence of the definition sign, if it is present. + * + * @param line line + * @return maybe the position of the definition sign + */ + + def find_definition (line : String) : OptionSD [Int] = + if ( line.endsWith (_sc.space + _sc.function_definition_symbol) + ) SomeSD_ (line.length - _sc.function_definition_symbol.length) + else get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) + + def get_index (line : String) (pattern : String) : OptionSD [Int] = + get_index_from (line) (pattern) (0) + + def get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = + SomeSD_ (line.indexOf (pattern, start) ) + .filter ( position => ! (position == -1) ) + +} + +case class DefinitionLineTranslator_ (line: String) extends DefinitionLineTranslator +trait CoqClassDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.block.Translator + import soda.translator.blocktr.TableTranslator_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val soda_space : String = _sc.space + + lazy val scala_space : String = " " + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = + ClassBeginningAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : AnnotatedBlock) : Block = + if ( (has_condition_for_type_alias (get_first_line (block) ) ) + ) block + else + BlockBuilder_ ().build ( + _process_head (block) ++ _process_tail (block) + ) + + private def _process_head (block : Block) : Seq [String] = + _process_head_with (get_first_line (block) ) (block) + + private def _process_head_with (line : String) (block : Block) : Seq [String] = + Seq [String] ( + Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) + _tc.coq_space + _tc.coq_end_symbol + ) + + private def _process_tail (block : Block) : Seq [String] = + _process_if_extends (remove_first_line (block) ) + + private def _process_if_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim == _sc.extends_reserved_word) + ) Seq [String] (get_initial_spaces (block) ).++ ( _process_after_extends (remove_first_line (block) ) ) + else block.lines + + def get_table_translator (line : String) : Translator = + TableTranslator_ ( + Seq (Tuple2 (_sc.class_reserved_word, _tc.coq_module_reserved_word ) ) + ) + + private def _process_after_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim.nonEmpty) + ) block.lines.map ( line => _tc.coq_import_reserved_word + _tc.coq_space + line.trim + _tc.coq_space + _tc.coq_end_symbol) + else Seq [String] () + + def remove_first_line (block : Block) : Block = + BlockBuilder_ ().build ( _remove_first_line (block.lines) ) + + private def _remove_first_line (lines : Seq [String] ) : Seq [String] = + if ( lines.isEmpty + ) lines + else lines.tail + + def get_first_line (block : Block) : String = + block.lines.headOption.getOrElse ("") + + def get_initial_spaces (block : Block) : String = + get_initial_spaces_for (get_first_line (block) ) + + def get_initial_spaces_for (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) + + def contains_equals (line : String) : Boolean = + line.trim.contains (_sc.function_definition_symbol) + + def has_condition_for_type_alias (line : String) : Boolean = + contains_equals (line) + +} + +case class CoqClassDeclarationBlockTranslator_ () extends CoqClassDeclarationBlockTranslator +trait CoqImportDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ImportDeclarationAnnotation + import soda.translator.parser.annotation.ImportDeclarationAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val coq_import_declaration_pattern = + _tc.coq_import_reserved_word + _tc.coq_space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = + ImportDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + coq_import_declaration_pattern) ( + block.imported_items + .filter( annotated_line => ! annotated_line.is_comment) + .map ( annotated_line => AnnotatedLine_ (annotated_line.line + _tc.coq_space + _tc.coq_end_symbol, false) ) + ) + ) + + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + BlockBuilder_ ().build ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) + + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) + + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile ( ch => ch.isSpaceChar) + .length + + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class CoqImportDeclarationBlockTranslator_ () extends CoqImportDeclarationBlockTranslator +trait CoqClassConstructorBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) + + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) + + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) + + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ ( + BlockBuilder_ ().build ( + Seq (_tc.coq_opening_comment).++ ( + block.lines.++ ( + Seq [String] ( + _tc.coq_closing_comment, + "", + _get_constructor_declaration (beginning) (_get_types_of_abstract_functions (block) ) + ) + ) + ) + ), + block.references + ) + + private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = + _get_initial_spaces (beginning) + + _tc.coq_inductive_reserved_word + + _tc.coq_space + + beginning.class_name + + _tc.coq_space + + _tc.coq_type_membership_symbol + + _tc.coq_space + + _tc.coq_type_reserved_word + + _tc.coq_space + + _tc.coq_function_definition_symbol + + _tc.coq_new_line + + _get_initial_spaces (beginning) + + _tc.coq_space + + _tc.coq_space + + _tc.coq_vertical_bar_symbol + + _tc.coq_space + + beginning.class_name + + _sc.constructor_suffix + + _tc.coq_space + + _tc.coq_opening_parenthesis + + _tc.coq_some_variable_name + + _tc.coq_space + + _tc.coq_type_membership_symbol + + _tc.coq_space + + abstract_functions.mkString (_tc.coq_space + _tc.coq_product_type_symbol + _tc.coq_space) + + _tc.coq_closing_parenthesis + + _tc.coq_new_line + + _get_initial_spaces (beginning) + + _tc.coq_inductive_end_symbol + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + + private def _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = + block.abstract_functions + .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) + .map ( line => _remove_variable (line) ) + + private def _remove_variable (line : String) : String = + _remove_variable_with (line) (line.indexOf (_sc.type_membership_symbol) ) + + private def _remove_variable_with (line : String) (index : Int) : String = + if ( index < 0 + ) line + else line.substring (index + _sc.type_membership_symbol.length).trim + + private def _translate_type_symbols (line : String) : String = + line + .replaceAll (_sc.subtype_reserved_word, _tc.coq_subtype_symbol) + .replaceAll (_sc.supertype_reserved_word, _tc.coq_supertype_symbol) + .replaceAll (_sc.function_arrow_symbol, _tc.coq_function_arrow_symbol) + + private def _get_initial_spaces (block : AnnotatedBlock) : String = + _get_initial_spaces_with (_get_first_line (block) ) + + private def _get_initial_spaces_with (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) + + private def _get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class CoqClassConstructorBlockTranslator_ () extends CoqClassConstructorBlockTranslator +/** + * This class translates Soda snippets into Coq snippets. + */ + +trait MicroTranslatorToCoq + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token + + private lazy val _tc = TranslationConstantToCoq_ () + + private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition + + private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration + + lazy val functions_and_tests = Seq (_function_definition, _test_declaration) + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) + + lazy val try_definition : Token => String = + token => + DefinitionLineTranslator_ (token.text).translation + + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + MatchCaseBlockTranslator_ (), + CoqDefinitionBlockTranslator_ (), + CoqClassConstructorBlockTranslator_ (), + CoqClassDeclarationBlockTranslator_ (), + CoqPackageDeclarationBlockTranslator_ (), + CoqClassEndBlockTranslator_ (), + CoqImportDeclarationBlockTranslator_ (), + CoqTheoremBlockTranslator_ (), + CoqProofBlockTranslator_ (), + ConditionalBlockTranslator_ (functions_and_tests, TokenizedBlockTranslator_ (try_definition) ), + ConditionalBlockTranslator_ (functions_and_tests, TokenReplacement_ ().replace (_tc.function_symbols_translation) ) + ) + ) + +} + +case class MicroTranslatorToCoq_ () extends MicroTranslatorToCoq +/** + * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. + */ + +trait TranslationConstantToCoq +{ + + import soda.translator.parser.SodaConstant_ + + lazy val soda_constant = SodaConstant_ () + + lazy val coq_space = " " + + lazy val coq_new_line = "\n" + + lazy val coq_function_definition_symbol = ":=" + + lazy val coq_type_membership_symbol = ":" + + lazy val coq_subtype_symbol = "<:" + + lazy val coq_supertype_symbol = ">:" + + lazy val coq_function_arrow_symbol = "->" + + lazy val coq_empty_string = "" + + lazy val coq_vertical_bar_symbol = "|" + + lazy val coq_match_end_translation = "end" + + lazy val coq_opening_parenthesis = "(" + + lazy val coq_closing_parenthesis = ")" + + lazy val coq_opening_comment = "(*" + + lazy val coq_closing_comment = "*)" + + lazy val coq_opening_documentation = "(**" + + lazy val coq_closing_documentation = "*)" + + lazy val coq_some_variable_name = "x" + + lazy val coq_opening_brace = "{" + + lazy val coq_closing_brace = "}" + + lazy val coq_product_type_symbol = "*" + + lazy val coq_lambda_reserved_word = "fun" + + lazy val coq_lambda_arrow_symbol = "=>" + + lazy val coq_case_arrow_symbol = "=>" + + lazy val coq_case_translation = coq_vertical_bar_symbol + coq_space + + lazy val coq_not_reserved_word = "notb" + + lazy val coq_and_reserved_word = "andb" + + lazy val coq_or_reserved_word = "orb" + + lazy val coq_end_symbol = "." + + lazy val coq_definition_reserved_word : String = "Definition" + + lazy val coq_inductive_reserved_word : String = "Inductive" + + lazy val coq_set_reserved_word : String = "Set" + + lazy val coq_type_reserved_word : String = "Type" + + lazy val coq_module_reserved_word : String = "Module" + + lazy val coq_module_end_reserved_word : String = "End" + + lazy val coq_import_reserved_word : String = "Import" + + lazy val coq_recursive_definition_reserved_word : String = "Fixpoint" + + lazy val coq_inductive_end_symbol : String = coq_end_symbol + + lazy val coq_definition_end_symbol : String = coq_end_symbol + + lazy val coq_recursive_definition_end_symbol : String = coq_end_symbol + + lazy val coq_with_reserved_word : String = "with" + + lazy val coq_theorem_begin_reserved_word : String = "Theorem" + + lazy val coq_theorem_end_symbol : String = coq_end_symbol + + lazy val coq_proof_begin_reserved_word : String = "Proof." + + lazy val coq_proof_end_reserved_word : String = "Qed." + + lazy val coq_prelude : Seq [String] = + Seq ( + "", + "Require Import Coq.ZArith.BinInt .", + "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", + "", + "Require Import Coq.Lists.List .", + "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", + "", + "Notation Int := Z .", + "" + ) + + lazy val coq_recursive_function_prefixes : Seq [String] = + Seq ( + "rec_", + "_rec_", + "tailrec_", + "_tailrec_", + "@tailrec" + ) + + lazy val non_definition_block_prefixes : Seq [String] = + Seq ( + soda_constant.package_reserved_word, + soda_constant.import_reserved_word, + soda_constant.class_end_reserved_word, + soda_constant.class_reserved_word, + soda_constant.comment_opening_symbol + ) + + lazy val coq_reserved_words = + coq_1 ++ coq_2 ++ coq_3 ++ coq_4 + + lazy val coq_1 : Seq [String] = + Seq ( + "as", + "else", + "end", + "forall", + "fun", + "if", + "in", + "let", + "match", + "then", + "with" + ) + + lazy val coq_2 : Seq [String] = + Seq ( + "Admitted", + "Arguments", + "Check", + "Constructors", + "End", + "Eval", + "Export", + "Hint", + "Implicit", + "Import", + "Module", + "Notation", + "Print", + "Proof", + "Qed", + "Require", + "Resolve", + "Section", + "Set", + "Type", + "Unset" + ) + + lazy val coq_3 : Seq [String] = + Seq ( + "admit", + "apply", + "assert", + "auto", + "case", + "compute", + "destruct", + "discriminate", + "elim", + "exact", + "induction", + "intros", + "pose", + "refine", + "rewrite", + "simpl", + "specialize", + "unfold" + ) + + lazy val coq_4 : Seq [String] = + Seq ( + "CoFixpoint", + "CoInductive", + "Definition", + "Example", + "Fixpoint", + "Global", + "Hypothesis", + "Inductive", + "Instance", + "Lemma", + "Ltac", + "Parameter", + "Theorem", + "Variable" + ) + + lazy val type_symbols_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.subtype_reserved_word, coq_subtype_symbol), + Tuple2 (soda_constant.supertype_reserved_word, coq_supertype_symbol), + Tuple2 (soda_constant.function_arrow_symbol, coq_function_arrow_symbol) + ) + + lazy val function_symbols_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), + Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), + Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), + Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), + Tuple2 (soda_constant.and_reserved_word, coq_and_reserved_word ), + Tuple2 (soda_constant.or_reserved_word, coq_or_reserved_word ) + ) + + lazy val type_translation : Seq [ Tuple2 [String, String] ] = + Seq ( + Tuple2 ("Boolean", "bool"), + Tuple2 ("Nat", "nat"), + Tuple2 ("Option", "option"), + Tuple2 ("List", "list"), + Tuple2 ("String", "string"), + Tuple2 ("BigInt", "Z") + ) + + lazy val prefix_coq_non_soda : String = "__soda__" + + lazy val coq_non_soda : Seq [Tuple2 [String, String] ] = + coq_reserved_words + .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) + .map ( x => Tuple2 (x, prefix_coq_non_soda + x) ) + + def is_coq_word (word : String) : Boolean = + coq_reserved_words.contains (word) + + def is_soda_word (word : String) : Boolean = + soda_constant.soda_reserved_words.contains (word) + +} + +case class TranslationConstantToCoq_ () extends TranslationConstantToCoq +/** + * This translates Soda source code to Coq source code. + */ + +trait TranslatorToCoq + extends + soda.translator.extension.common.Extension +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File + + private lazy val _soda_extension : String = ".soda" + + private lazy val _coq_extension : String = ".v" + + private lazy val _default_argument = "." + + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToCoq_ () + ) + ) + + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } + + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () + + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) + + private def _get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, + input_name.substring (0, input_name.length - _soda_extension.length) + _coq_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _coq_extension) + + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( + SimpleFileReader_ ().read_file (input_file_name) ) ( + output_file_name + ) + + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file ( + output_file_name) ( + content = _translator.translate (input) + ) + +} + +case class TranslatorToCoq_ () extends TranslatorToCoq + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String + +} + +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair +trait CoqPackageDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.PackageDeclarationAnnotation + import soda.translator.parser.annotation.PackageDeclarationAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case PackageDeclarationAnnotation_ (block) => _translate_block (PackageDeclarationAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_block (block : PackageDeclarationAnnotation) : PackageDeclarationAnnotation = + PackageDeclarationAnnotation_ ( + _comment_block ( + block + ) + ) + + private def _comment_block (block : Block) : Block = + BlockBuilder_ ().build ( + ( (Seq (_tc.coq_opening_comment).++ (block.lines) ).++ (Seq (_tc.coq_closing_comment) ) ).++ (_tc.coq_prelude) + ) + +} + +case class CoqPackageDeclarationBlockTranslator_ () extends CoqPackageDeclarationBlockTranslator +trait MatchCaseBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + import soda.translator.parser.annotation.TestDeclarationAnnotation + import soda.translator.parser.annotation.TestDeclarationAnnotation_ + import soda.translator.replacement.ReplacementAux_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _soda_case_pattern = _sc.case_reserved_word + _sc.space + + private lazy val _tc = TranslationConstantToCoq_ () + + private lazy val _soda_match_pattern = _sc.match_reserved_word + " " + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case FunctionDefinitionAnnotation_ (block) => _translate_function_block (FunctionDefinitionAnnotation_ (block) ) + case TestDeclarationAnnotation_ (block) => _translate_test_block (TestDeclarationAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + private def _translate_test_block (block : AnnotatedBlock) : TestDeclarationAnnotation = + TestDeclarationAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : AnnotatedBlock) : Block = + if ( _is_a_match_case_structure (block) + ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( line => _is_a_match_line (line) ) + + private def _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + private def _is_a_case_line (line : String) : Boolean = + line.trim.startsWith (_soda_case_pattern) + + private def _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( line => _is_a_match_line (line) ) + .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.coq_space) + + private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = + BlockBuilder_ ().build ( + block.lines + .map ( line => _append_with_after_match (line) ) + .map ( line => _replace_case (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.coq_match_end_translation) ) + ) + + private def _append_with_after_match (line : String) : String = + if ( _is_a_match_line (line) + ) line + _tc.coq_space + _tc.coq_with_reserved_word + else line + + private def _replace_case (line : String) : String = + if ( _is_a_case_line (line) + ) ReplacementAux_ (). replace_first (line) (_soda_case_pattern) (_tc.coq_case_translation) + else line + + private def _left_part (index : Int) (line : String) : String = + line.substring (0, index) + +} + +case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator +trait CoqDefinitionBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case FunctionDefinitionAnnotation_ (block) => _translate_definition_block (FunctionDefinitionAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_definition_block (block : FunctionDefinitionAnnotation) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : FunctionDefinitionAnnotation) : Block = + if ( is_a_recursive_definition (block) + ) _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) + else _translate_non_recursive_definition (block) + + private def _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = + if ( is_a_definition (block) + ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) + else block + + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq[String] (prefix + block.lines.head) ++ block.lines.tail + ) + + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) + + def is_a_recursive_definition (block : Block) : Boolean = + _tc.coq_recursive_function_prefixes.exists ( prefix => first_line (block).startsWith (prefix) ) + + def first_line (block : Block) : String = + block.lines.headOption.getOrElse ("").trim + + def is_a_definition (block : Block) : Boolean = + ! is_a_recursive_definition (block) && + ! _tc.non_definition_block_prefixes.exists ( prefix => block.contents.trim.startsWith (prefix) ) + +} + +case class CoqDefinitionBlockTranslator_ () extends CoqDefinitionBlockTranslator +trait CoqTheoremBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.TheoremBlockAnnotation + import soda.translator.parser.annotation.TheoremBlockAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case TheoremBlockAnnotation_ (block) => _translate_block (TheoremBlockAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_block (block : TheoremBlockAnnotation) : TheoremBlockAnnotation = + TheoremBlockAnnotation_ ( + _append ( + _tc.coq_theorem_end_symbol) (_prepend ( + _tc.coq_theorem_begin_reserved_word) (_remove_first_line (block) + ) + ) + ) + + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq[String] (prefix + block.lines.head).++ (block.lines.tail) + ) + + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) + + private def _remove_first_line (block : Block) : Block = + if ( block.lines.isEmpty + ) block + else BlockBuilder_ ().build (block.lines.tail) + +} + +case class CoqTheoremBlockTranslator_ () extends CoqTheoremBlockTranslator +trait CoqClassEndBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) + + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) + + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) + + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _tc.coq_module_end_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol, + "", + _tc.coq_import_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol + ) + ), + block.references + ) + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + +} + +case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator +trait CoqProofBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ProofBlockAnnotation + import soda.translator.parser.annotation.ProofBlockAnnotation_ + + private lazy val _tc = TranslationConstantToCoq_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ProofBlockAnnotation_ (block) => _translate_block (ProofBlockAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_block (block : ProofBlockAnnotation) : ProofBlockAnnotation = + ProofBlockAnnotation_ ( + _append ( + _tc.coq_proof_end_reserved_word) ( + _replace_first_line (_tc.coq_proof_begin_reserved_word) (block) + ) + ) + + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) + + private def _replace_first_line (first_line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq (first_line) .++ (_get_tail_or_empty (block.lines) ) + ) + + private def _get_tail_or_empty (sequence : Seq [String] ) : Seq [String] = + if ( sequence.isEmpty + ) sequence + else sequence.tail + +} + +case class CoqProofBlockTranslator_ () extends CoqProofBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala deleted file mode 100644 index c1e26c9c..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslationConstantToCoq.scala +++ /dev/null @@ -1,268 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -/** - * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. - */ - -trait TranslationConstantToCoq -{ - - import soda.translator.parser.SodaConstant_ - - lazy val soda_constant = SodaConstant_ () - - lazy val coq_space = " " - - lazy val coq_new_line = "\n" - - lazy val coq_function_definition_symbol = ":=" - - lazy val coq_type_membership_symbol = ":" - - lazy val coq_subtype_symbol = "<:" - - lazy val coq_supertype_symbol = ">:" - - lazy val coq_function_arrow_symbol = "->" - - lazy val coq_empty_string = "" - - lazy val coq_vertical_bar_symbol = "|" - - lazy val coq_match_end_translation = "end" - - lazy val coq_opening_parenthesis = "(" - - lazy val coq_closing_parenthesis = ")" - - lazy val coq_opening_comment = "(*" - - lazy val coq_closing_comment = "*)" - - lazy val coq_opening_documentation = "(**" - - lazy val coq_closing_documentation = "*)" - - lazy val coq_some_variable_name = "x" - - lazy val coq_opening_brace = "{" - - lazy val coq_closing_brace = "}" - - lazy val coq_product_type_symbol = "*" - - lazy val coq_lambda_reserved_word = "fun" - - lazy val coq_lambda_arrow_symbol = "=>" - - lazy val coq_case_arrow_symbol = "=>" - - lazy val coq_case_translation = coq_vertical_bar_symbol + coq_space - - lazy val coq_not_reserved_word = "notb" - - lazy val coq_and_reserved_word = "andb" - - lazy val coq_or_reserved_word = "orb" - - lazy val coq_end_symbol = "." - - lazy val coq_definition_reserved_word : String = "Definition" - - lazy val coq_inductive_reserved_word : String = "Inductive" - - lazy val coq_set_reserved_word : String = "Set" - - lazy val coq_type_reserved_word : String = "Type" - - lazy val coq_module_reserved_word : String = "Module" - - lazy val coq_module_end_reserved_word : String = "End" - - lazy val coq_import_reserved_word : String = "Import" - - lazy val coq_recursive_definition_reserved_word : String = "Fixpoint" - - lazy val coq_inductive_end_symbol : String = coq_end_symbol - - lazy val coq_definition_end_symbol : String = coq_end_symbol - - lazy val coq_recursive_definition_end_symbol : String = coq_end_symbol - - lazy val coq_with_reserved_word : String = "with" - - lazy val coq_theorem_begin_reserved_word : String = "Theorem" - - lazy val coq_theorem_end_symbol : String = coq_end_symbol - - lazy val coq_proof_begin_reserved_word : String = "Proof." - - lazy val coq_proof_end_reserved_word : String = "Qed." - - lazy val coq_prelude : Seq [String] = - Seq ( - "", - "Require Import Coq.ZArith.BinInt .", - "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", - "", - "Require Import Coq.Lists.List .", - "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", - "", - "Notation Int := Z .", - "" - ) - - lazy val coq_recursive_function_prefixes : Seq [String] = - Seq ( - "rec_", - "_rec_", - "tailrec_", - "_tailrec_", - "@tailrec" - ) - - lazy val non_definition_block_prefixes : Seq [String] = - Seq ( - soda_constant.package_reserved_word, - soda_constant.import_reserved_word, - soda_constant.class_end_reserved_word, - soda_constant.class_reserved_word, - soda_constant.comment_opening_symbol - ) - - lazy val coq_reserved_words = - coq_1 ++ coq_2 ++ coq_3 ++ coq_4 - - lazy val coq_1 : Seq [String] = - Seq ( - "as", - "else", - "end", - "forall", - "fun", - "if", - "in", - "let", - "match", - "then", - "with" - ) - - lazy val coq_2 : Seq [String] = - Seq ( - "Admitted", - "Arguments", - "Check", - "Constructors", - "End", - "Eval", - "Export", - "Hint", - "Implicit", - "Import", - "Module", - "Notation", - "Print", - "Proof", - "Qed", - "Require", - "Resolve", - "Section", - "Set", - "Type", - "Unset" - ) - - lazy val coq_3 : Seq [String] = - Seq ( - "admit", - "apply", - "assert", - "auto", - "case", - "compute", - "destruct", - "discriminate", - "elim", - "exact", - "induction", - "intros", - "pose", - "refine", - "rewrite", - "simpl", - "specialize", - "unfold" - ) - - lazy val coq_4 : Seq [String] = - Seq ( - "CoFixpoint", - "CoInductive", - "Definition", - "Example", - "Fixpoint", - "Global", - "Hypothesis", - "Inductive", - "Instance", - "Lemma", - "Ltac", - "Parameter", - "Theorem", - "Variable" - ) - - lazy val type_symbols_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.subtype_reserved_word, coq_subtype_symbol), - Tuple2 (soda_constant.supertype_reserved_word, coq_supertype_symbol), - Tuple2 (soda_constant.function_arrow_symbol, coq_function_arrow_symbol) - ) - - lazy val function_symbols_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), - Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), - Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), - Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), - Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), - Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), - Tuple2 (soda_constant.and_reserved_word, coq_and_reserved_word ), - Tuple2 (soda_constant.or_reserved_word, coq_or_reserved_word ) - ) - - lazy val type_translation : Seq [ Tuple2 [String, String] ] = - Seq ( - Tuple2 ("Boolean", "bool"), - Tuple2 ("Nat", "nat"), - Tuple2 ("Option", "option"), - Tuple2 ("List", "list"), - Tuple2 ("String", "string"), - Tuple2 ("BigInt", "Z") - ) - - lazy val prefix_coq_non_soda : String = "__soda__" - - lazy val coq_non_soda : Seq [Tuple2 [String, String] ] = - coq_reserved_words - .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) - .map ( x => Tuple2 (x, prefix_coq_non_soda + x) ) - - def is_coq_word (word : String) : Boolean = - coq_reserved_words.contains (word) - - def is_soda_word (word : String) : Boolean = - soda_constant.soda_reserved_words.contains (word) - -} - -case class TranslationConstantToCoq_ () extends TranslationConstantToCoq diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala b/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala deleted file mode 100644 index 917c2ec8..00000000 --- a/translator/src/main/scala/soda/translator/extension/tocoq/TranslatorToCoq.scala +++ /dev/null @@ -1,91 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains classes for the translation to Gallina, the specification language used by Coq. - */ - - - - - -/** - * This translates Soda source code to Coq source code. - */ - -trait TranslatorToCoq - extends - soda.translator.extension.common.Extension -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File - - private lazy val _soda_extension : String = ".soda" - - private lazy val _coq_extension : String = ".v" - - private lazy val _default_argument = "." - - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToCoq_ () - ) - ) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => _translate (arguments (0) ) (arguments (1) ) - case x => false - } - - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () - - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) - - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) - - private def _get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _coq_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _coq_extension) - - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) - - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content = _translator.translate (input) - ) - -} - -case class TranslatorToCoq_ () extends TranslatorToCoq - -trait FileNamePair -{ - - def input_file_name : String - def output_file_name : String - -} - -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair diff --git a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala deleted file mode 100644 index 7bb46d7c..00000000 --- a/translator/src/main/scala/soda/translator/extension/todoc/DocBlockTranslator.scala +++ /dev/null @@ -1,108 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains classes for documentation generation. - */ - - - - - -trait DocBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.CommentAnnotation - import soda.translator.parser.annotation.CommentAnnotation_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToDoc_ () - - private lazy val _comment_line_prefix = _sc.comment_line_symbol + _sc.space - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case CommentAnnotation_ (block) => _translate_comment (CommentAnnotation_ (block) ) - case x => _translate_source_code (x) - } - - private def _translate_comment (block : CommentAnnotation) : CommentAnnotation = - CommentAnnotation_ ( - BlockBuilder_ ().build ( - _append ( - _tc.doc_closing_comment_translation) ( - _prepend (_tc.doc_opening_comment_translation) ( - _remove_comment_delimiter ( - _remove_comment_line_prefix (block.lines) - ) - ) - ) - ) - ) - - private def _translate_source_code (block : AnnotatedBlock) : CommentAnnotation = - CommentAnnotation_ ( - block - ) - - private def _prepend (prefix : String) (content : Seq [String] ) : Seq [String] = - if ( content.isEmpty - ) Seq [String] (prefix) - else Seq[String] (prefix + content.head).++ (content.tail) - - private def _append (suffix : String) (content : Seq [String] ) : Seq [String] = - content.:+ (suffix) - - private def _remove_comment_delimiter (content : Seq [String] ) : Seq [String] = - _remove_last_delimiter ( - _remove_first_delimiter (content) - ) - - private def _remove_first_delimiter (content : Seq [String] ) : Seq [String] = - if ( content.isEmpty - ) content - else _prepend ( - _remove_prefix_in_line (_sc.documentation_comment_opening_symbol) ( - _remove_prefix_in_line (_sc.comment_opening_symbol) (content.head) - ) - ) (content.tail) - - private def _remove_last_delimiter (content : Seq [String] ) : Seq [String] = - ( _remove_last_delimiter_on_first_line (content.reverse) ).reverse - - private def _remove_last_delimiter_on_first_line (content : Seq [String] ) : Seq [String] = - if ( content.isEmpty - ) content - else _prepend (_remove_suffix_in_line (_sc.comment_closing_symbol) (content.head) ) (content.tail) - - private def _remove_comment_line_prefix (content : Seq [String] ) : Seq [String] = - content.map ( line => _remove_prefix_in_line (_comment_line_prefix) (line) ) - - private def _remove_prefix_in_line (prefix : String) (line : String) : String = - _remove_prefix_in_line_at (line.indexOf (prefix) ) (prefix) (line) - - private def _remove_prefix_in_line_at (index : Int) (prefix : String) (line : String) : String = - if ( index >= 0 - ) line.substring (index + prefix.length) - else line - - private def _remove_suffix_in_line (suffix : String) (line : String) : String = - _remove_suffix_in_line_at (line.lastIndexOf (suffix) ) (line) - - private def _remove_suffix_in_line_at (index : Int) (line : String) : String = - if ( index >= 0 - ) line.substring (0, index) - else line - -} - -case class DocBlockTranslator_ () extends DocBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala deleted file mode 100644 index c8447d1f..00000000 --- a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.scala +++ /dev/null @@ -1,49 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains classes for documentation generation. - */ - - - - - -/** - * This class generates documentation from Soda snippets. - */ - -trait MicroTranslatorToDoc - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token - - private lazy val _tc = TranslationConstantToDoc_ () - - private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - - private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - - lazy val functions_and_tests = Seq (_function_definition, _test_declaration) - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _translation_pipeline.translate (block) - - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - DocBlockTranslator_ () - ) - ) - -} - -case class MicroTranslatorToDoc_ () extends MicroTranslatorToDoc diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index 8ae05f9e..7e43332e 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -7,3 +7,335 @@ package soda.translator.extension.todoc trait Package +/** + * This class generates documentation from Soda snippets. + */ + +trait MicroTranslatorToDoc + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token + + private lazy val _tc = TranslationConstantToDoc_ () + + private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition + + private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration + + lazy val functions_and_tests = Seq (_function_definition, _test_declaration) + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) + + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + DocBlockTranslator_ () + ) + ) + +} + +case class MicroTranslatorToDoc_ () extends MicroTranslatorToDoc +trait DocBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.CommentAnnotation + import soda.translator.parser.annotation.CommentAnnotation_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToDoc_ () + + private lazy val _comment_line_prefix = _sc.comment_line_symbol + _sc.space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case CommentAnnotation_ (block) => _translate_comment (CommentAnnotation_ (block) ) + case x => _translate_source_code (x) + } + + private def _translate_comment (block : CommentAnnotation) : CommentAnnotation = + CommentAnnotation_ ( + BlockBuilder_ ().build ( + _append ( + _tc.doc_closing_comment_translation) ( + _prepend (_tc.doc_opening_comment_translation) ( + _remove_comment_delimiter ( + _remove_comment_line_prefix (block.lines) + ) + ) + ) + ) + ) + + private def _translate_source_code (block : AnnotatedBlock) : CommentAnnotation = + CommentAnnotation_ ( + block + ) + + private def _prepend (prefix : String) (content : Seq [String] ) : Seq [String] = + if ( content.isEmpty + ) Seq [String] (prefix) + else Seq[String] (prefix + content.head).++ (content.tail) + + private def _append (suffix : String) (content : Seq [String] ) : Seq [String] = + content.:+ (suffix) + + private def _remove_comment_delimiter (content : Seq [String] ) : Seq [String] = + _remove_last_delimiter ( + _remove_first_delimiter (content) + ) + + private def _remove_first_delimiter (content : Seq [String] ) : Seq [String] = + if ( content.isEmpty + ) content + else _prepend ( + _remove_prefix_in_line (_sc.documentation_comment_opening_symbol) ( + _remove_prefix_in_line (_sc.comment_opening_symbol) (content.head) + ) + ) (content.tail) + + private def _remove_last_delimiter (content : Seq [String] ) : Seq [String] = + ( _remove_last_delimiter_on_first_line (content.reverse) ).reverse + + private def _remove_last_delimiter_on_first_line (content : Seq [String] ) : Seq [String] = + if ( content.isEmpty + ) content + else _prepend (_remove_suffix_in_line (_sc.comment_closing_symbol) (content.head) ) (content.tail) + + private def _remove_comment_line_prefix (content : Seq [String] ) : Seq [String] = + content.map ( line => _remove_prefix_in_line (_comment_line_prefix) (line) ) + + private def _remove_prefix_in_line (prefix : String) (line : String) : String = + _remove_prefix_in_line_at (line.indexOf (prefix) ) (prefix) (line) + + private def _remove_prefix_in_line_at (index : Int) (prefix : String) (line : String) : String = + if ( index >= 0 + ) line.substring (index + prefix.length) + else line + + private def _remove_suffix_in_line (suffix : String) (line : String) : String = + _remove_suffix_in_line_at (line.lastIndexOf (suffix) ) (line) + + private def _remove_suffix_in_line_at (index : Int) (line : String) : String = + if ( index >= 0 + ) line.substring (0, index) + else line + +} + +case class DocBlockTranslator_ () extends DocBlockTranslator +/** + * This generates documentation from Soda source code. + */ + +trait TranslatorToDoc + extends + soda.translator.extension.common.Extension +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File + + private lazy val _soda_extension : String = ".soda" + + private lazy val _doc_extension : String = ".tex" + + private lazy val _default_argument = "." + + private lazy val _tc = TranslationConstantToDoc_ () + + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToDoc_ () + ) + ) + + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } + + def translate_content (input : String) : String = + _tc.doc_header + _translator.translate (input) + _tc.doc_footer + + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () + + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) + + private def _get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, + input_name.substring (0, input_name.length - _soda_extension.length) + _doc_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _doc_extension) + + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( + SimpleFileReader_ ().read_file (input_file_name) ) ( + output_file_name + ) + + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file ( + output_file_name) ( + content = translate_content (input) + ) + +} + +case class TranslatorToDoc_ () extends TranslatorToDoc + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String + +} + +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair +/** + * This class contains constants that are specific for the documentation generation. + */ + +trait TranslationConstantToDoc +{ + + import soda.translator.parser.SodaConstant_ + + lazy val soda_constant = SodaConstant_ () + + lazy val doc_space = " " + + lazy val doc_new_line = "\n" + + lazy val doc_header = + doc_document_class + + doc_new_line + + doc_new_line + + doc_packages_text + + doc_new_line + + doc_new_line + + doc_language_definitions_text + + doc_new_line + + doc_new_line + + doc_begin_document + + doc_new_line + + doc_new_line + + doc_begin_lstlisting + + doc_new_line + + lazy val doc_footer = + doc_new_line + + doc_end_lstlisting + + doc_new_line + + doc_new_line + + doc_end_document + + doc_new_line + + doc_new_line + + lazy val doc_opening_comment_translation = + doc_new_line + + doc_end_lstlisting + + doc_new_line + + doc_new_line + + lazy val doc_closing_comment_translation = + doc_new_line + + doc_new_line + + doc_begin_lstlisting + + doc_new_line + + lazy val doc_document_class = "\\documentclass[12pt,a4paper]{article}" + + lazy val doc_begin_document = "\\begin{document}" + + lazy val doc_end_document = "\\end{document}" + + lazy val doc_begin_lstlisting = "\\begin{lstlisting}" + + lazy val doc_end_lstlisting = "\\end{lstlisting}" + + lazy val soda_reserved_words_csv = + (soda_constant.soda_reserved_words_words_only.++ (soda_constant.soda_reserved_words_annotations_only) ).mkString (", ") + + lazy val doc_packages : Seq [String] = + Seq ( + "\\usepackage[utf8]{inputenc}", + "\\usepackage{xcolor}", + "\\usepackage{hyperref}", + "\\usepackage{listings}" + ) + + lazy val doc_packages_text : String = + doc_packages.mkString ("\n") + + lazy val doc_language_definitions : Seq [String] = + Seq ( + "\\lstdefinelanguage{Soda}{", + " morekeywords={" + soda_reserved_words_csv + "},", + " sensitive=true,", + " morecomment=[s]{" + soda_constant.comment_opening_symbol + "}{" + soda_constant.comment_closing_symbol + "},", + " morestring=[b]\"", + "}", + "", + "\\lstset{frame=tb,", + " language=Soda,", + " aboveskip=3mm,", + " belowskip=3mm,", + " showstringspaces=false,", + " columns=flexible,", + " basicstyle={\\small\\ttfamily},", + " numbers=none,", + " numberstyle=\\tiny\\color{gray},", + " keywordstyle=\\color{blue},", + " commentstyle=\\color{gray},", + " stringstyle=\\color{teal},", + " breaklines=true,", + " breakatwhitespace=true,", + " tabsize=3", + "}" + ) + + lazy val doc_language_definitions_text : String = + doc_language_definitions.mkString ("\n") + +} + +case class TranslationConstantToDoc_ () extends TranslationConstantToDoc diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala deleted file mode 100644 index 8a107e3a..00000000 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslationConstantToDoc.scala +++ /dev/null @@ -1,119 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains classes for documentation generation. - */ - - - - - -/** - * This class contains constants that are specific for the documentation generation. - */ - -trait TranslationConstantToDoc -{ - - import soda.translator.parser.SodaConstant_ - - lazy val soda_constant = SodaConstant_ () - - lazy val doc_space = " " - - lazy val doc_new_line = "\n" - - lazy val doc_header = - doc_document_class + - doc_new_line + - doc_new_line + - doc_packages_text + - doc_new_line + - doc_new_line + - doc_language_definitions_text + - doc_new_line + - doc_new_line + - doc_begin_document + - doc_new_line + - doc_new_line + - doc_begin_lstlisting + - doc_new_line - - lazy val doc_footer = - doc_new_line + - doc_end_lstlisting + - doc_new_line + - doc_new_line + - doc_end_document + - doc_new_line + - doc_new_line - - lazy val doc_opening_comment_translation = - doc_new_line + - doc_end_lstlisting + - doc_new_line + - doc_new_line - - lazy val doc_closing_comment_translation = - doc_new_line + - doc_new_line + - doc_begin_lstlisting + - doc_new_line - - lazy val doc_document_class = "\\documentclass[12pt,a4paper]{article}" - - lazy val doc_begin_document = "\\begin{document}" - - lazy val doc_end_document = "\\end{document}" - - lazy val doc_begin_lstlisting = "\\begin{lstlisting}" - - lazy val doc_end_lstlisting = "\\end{lstlisting}" - - lazy val soda_reserved_words_csv = - (soda_constant.soda_reserved_words_words_only.++ (soda_constant.soda_reserved_words_annotations_only) ).mkString (", ") - - lazy val doc_packages : Seq [String] = - Seq ( - "\\usepackage[utf8]{inputenc}", - "\\usepackage{xcolor}", - "\\usepackage{hyperref}", - "\\usepackage{listings}" - ) - - lazy val doc_packages_text : String = - doc_packages.mkString ("\n") - - lazy val doc_language_definitions : Seq [String] = - Seq ( - "\\lstdefinelanguage{Soda}{", - " morekeywords={" + soda_reserved_words_csv + "},", - " sensitive=true,", - " morecomment=[s]{" + soda_constant.comment_opening_symbol + "}{" + soda_constant.comment_closing_symbol + "},", - " morestring=[b]\"", - "}", - "", - "\\lstset{frame=tb,", - " language=Soda,", - " aboveskip=3mm,", - " belowskip=3mm,", - " showstringspaces=false,", - " columns=flexible,", - " basicstyle={\\small\\ttfamily},", - " numbers=none,", - " numberstyle=\\tiny\\color{gray},", - " keywordstyle=\\color{blue},", - " commentstyle=\\color{gray},", - " stringstyle=\\color{teal},", - " breaklines=true,", - " breakatwhitespace=true,", - " tabsize=3", - "}" - ) - - lazy val doc_language_definitions_text : String = - doc_language_definitions.mkString ("\n") - -} - -case class TranslationConstantToDoc_ () extends TranslationConstantToDoc diff --git a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala b/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala deleted file mode 100644 index e1d40f2d..00000000 --- a/translator/src/main/scala/soda/translator/extension/todoc/TranslatorToDoc.scala +++ /dev/null @@ -1,96 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains classes for documentation generation. - */ - - - - - -/** - * This generates documentation from Soda source code. - */ - -trait TranslatorToDoc - extends - soda.translator.extension.common.Extension -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File - - private lazy val _soda_extension : String = ".soda" - - private lazy val _doc_extension : String = ".tex" - - private lazy val _default_argument = "." - - private lazy val _tc = TranslationConstantToDoc_ () - - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToDoc_ () - ) - ) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => _translate (arguments (0) ) (arguments (1) ) - case x => false - } - - def translate_content (input : String) : String = - _tc.doc_header + _translator.translate (input) + _tc.doc_footer - - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () - - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) - - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) - - private def _get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _doc_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _doc_extension) - - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) - - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content = translate_content (input) - ) - -} - -case class TranslatorToDoc_ () extends TranslatorToDoc - -trait FileNamePair -{ - - def input_file_name : String - def output_file_name : String - -} - -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair diff --git a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala deleted file mode 100644 index c3120314..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/AbstractDeclarationBlockTranslator.scala +++ /dev/null @@ -1,69 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait AbstractDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block - import soda.translator.block.Block_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val scala_abstract_function_declaration_pattern = - _tc.scala_abstract_function_declaration + _tc.scala_space - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - scala_abstract_function_declaration_pattern) ( - block.abstract_functions_with_comments - ), - block.references - ) - - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - Block_ ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) - ) - - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : AnnotatedLine = - if ( annotated_line.is_comment - ) annotated_line - else AnnotatedLine_ (annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index), annotated_line.is_comment) - - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile (ch => ch.isSpaceChar) - .length - - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class AbstractDeclarationBlockTranslator_ () extends AbstractDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala deleted file mode 100644 index ee69d721..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslator.scala +++ /dev/null @@ -1,128 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait ClassConstructorBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) - - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) - - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( beginning.is_concrete - ) block - else _translate_block_with_abstract_beginning (beginning) (block) - - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - block.lines.++ ( - Seq [String] ( - "", - _get_constructor_declaration (beginning) (_get_abstract_functions (block.references) ) - ) - ) - ), - block.references - ) - - private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = - _get_initial_spaces (beginning) + - _tc.class_declaration_translation_at_beginning_with_paren + - _tc.scala_space + - beginning.class_name + - _sc.constructor_suffix + - _translate_type_symbols (_get_as_parameter_list (beginning.type_parameters_and_bounds) ) + - _tc.scala_space + - _tc.scala_opening_parenthesis + - abstract_functions.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + - _tc.scala_closing_parenthesis + - _tc.scala_space + - _tc.scala_extends_translation + - _tc.scala_space + - beginning.class_name + - _get_as_parameter_list (beginning.type_parameters) - - private def _get_as_parameter_list (parameters : Seq [String] ) : String = - if ( parameters.isEmpty - ) "" - else _tc.scala_space + _tc.scala_opening_bracket + parameters.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + _tc.scala_closing_bracket - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - - private def _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = - references - .flatMap ( block => _get_as_abstract_declaration_annotation (block) ) - .flatMap ( block => block.abstract_functions) - .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) - - private def _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = - block match { - case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) - case x => None - } - - private def _translate_type_symbols (line : String) : String = - line - .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) - .replaceAll (_sc.supertype_reserved_word, _tc.scala_supertype_symbol) - .replaceAll (_sc.function_arrow_symbol, _tc.scala_function_arrow_symbol) - - private def _get_initial_spaces (block : AnnotatedBlock) : String = - _get_initial_spaces_with (_get_first_line (block) ) - - private def _get_initial_spaces_with (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - private def _get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class ClassConstructorBlockTranslator_ () extends ClassConstructorBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala deleted file mode 100644 index bd083907..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassDeclarationBlockTranslator.scala +++ /dev/null @@ -1,118 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait ClassDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.block.Translator - import soda.translator.blocktr.TableTranslator_ - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassAliasAnnotation - import soda.translator.parser.annotation.ClassAliasAnnotation_ - import soda.translator.replacement.Replacement_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val soda_space : String = _sc.space - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) - case ClassAliasAnnotation_ (block) => _translate_class_alias_block (ClassAliasAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = - ClassBeginningAnnotation_ (_translate_block (block) ) - - private def _translate_class_alias_block (block : ClassAliasAnnotation) : ClassAliasAnnotation = - ClassAliasAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : AnnotatedBlock) : Block = - BlockBuilder_ ().build ( - if ( (has_condition_for_type_alias (get_first_line (block) ) ) - ) _process_head (block) ++ _process_tail (block) - else _process_head (block) ++ _process_tail (block) ++ Seq [String] (get_initial_spaces (block) + _tc.scala_class_begin_symbol) - ) - - private def _process_head (block : Block) : Seq [String] = - _process_head_with (get_first_line (block) ) (block) - - private def _process_head_with (line : String) (block : Block) : Seq [String] = - Seq [String] (Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) ) - - private def _process_tail (block : Block) : Seq [String] = - _process_if_extends (remove_first_line (block) ) - - private def _process_if_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim == _sc.extends_reserved_word) - ) Seq [String] (get_initial_spaces (block) + _tc.scala_extends_translation) ++ _process_after_extends (remove_first_line (block) ) - else block.lines - - def get_table_translator (line : String) : Translator = - TableTranslator_ ( - Seq (Tuple2 (_sc.class_reserved_word, get_class_declaration_translation (line) ) ) - ) - - def get_class_declaration_translation (line : String) : String = - if ( line.contains (_sc.opening_parenthesis_symbol) - ) _tc.class_declaration_translation_at_beginning_with_paren - else - if ( has_condition_for_type_alias (line) - ) _tc.class_declaration_translation_at_beginning_without_paren_for_type_alias - else _tc.class_declaration_translation_at_beginning_without_paren - - private def _process_after_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim.nonEmpty) - ) Seq [String] (get_first_line (block) ) ++ remove_first_line (block).lines.map ( line => get_initial_spaces_for (line) + _tc.scala_with_translation + _tc.scala_space + line.trim) - else Seq [String] () - - def remove_first_line (block : Block) : Block = - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) block.lines - else block.lines.tail - ) - - def get_first_line (block : Block) : String = - block.lines.headOption.getOrElse ("") - - def get_initial_spaces (block : Block) : String = - get_initial_spaces_for (get_first_line (block) ) - - def get_initial_spaces_for (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - def ends_with_equals (line : String) : Boolean = false - - def ends_with_opening_brace (line : String) : Boolean = false - - def contains_equals (line : String) : Boolean = - line.trim.contains (_sc.function_definition_symbol) - - def has_condition_for_type_alias (line : String) : Boolean = - contains_equals (line) - -} - -case class ClassDeclarationBlockTranslator_ () extends ClassDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala deleted file mode 100644 index 5fe46ced..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/ClassEndBlockTranslator.scala +++ /dev/null @@ -1,57 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait ClassEndBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - Seq [String] ( - _get_translation (block) - ) - ), - block.references - ) - - private def _get_translation (block : ClassEndAnnotation) : String = - _get_initial_spaces (block) + _tc.scala_class_end_symbol - - private def _get_initial_spaces (block : ClassEndAnnotation) : String = - _get_initial_spaces_with (_get_first_line (block) ) - - private def _get_initial_spaces_with (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - private def _get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class ClassEndBlockTranslator_ () extends ClassEndBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala deleted file mode 100644 index 4e70320f..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionBlockTranslator.scala +++ /dev/null @@ -1,118 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait FunctionDefinitionBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block - import soda.translator.block.Block_ - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ - import soda.translator.replacement.Replacement_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_function_definition_block (block) - case x => annotated_block - } - - private def _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : Block) : Block = - if ( block.readable_lines.isEmpty - ) block - else _translate_block_with (block.readable_lines.head) (block) - - private def _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = - if ( _is_annotation (first_line.line) - ) _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) - else _translate_main_block (block) - - private def _translate_main_block (block : Block) : Block = - _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) - - private def _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = - detector.detect match { - case detector.val_detected => _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) - case detector.def_detected => _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) - case x => block - } - - private def _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = - Block_ ( - initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) - ) - - private def _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = - Block_ ( - initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) - ) - - private def _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = - lines.takeWhile ( annotated_line => annotated_line.is_comment ) - - private def _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = - lines.dropWhile ( annotated_line => annotated_line.is_comment ) - - private def _translate_val_definition (line : String) : String = - Replacement_ (line) - .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) - .line - - private def _translate_def_definition (line : String) : String = - Replacement_ (line) - .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) - .line - - private def _private_prefix_if_necessary (line : String) : String = - if ( line.trim.startsWith (_sc.private_function_prefix) - ) _tc.scala_private_reserved_word + _tc.scala_space - else "" - - private def _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = - if ( lines.isEmpty - ) Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) - else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) - - private def _remove_first_line_if_possible (block : Block) : Block = - if ( block.lines.isEmpty - ) block - else BlockBuilder_ ().build (block.lines.tail) - - private def _prepend_line (line : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq [String] (line) .++ (block.lines) - ) - - private def _flatten_block (block : Block) : String = - block.lines.mkString (_sc.space) - - private def _is_annotation (line : String) : Boolean = - (line.trim == _sc.tail_recursion_annotation) || (line.trim == _sc.override_annotation) - -} - -case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala b/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala deleted file mode 100644 index 1ae6cede..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/FunctionDefinitionLineDetector.scala +++ /dev/null @@ -1,104 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -/** - * A line containing the definition sign will be classified as a definition. - * The definitions need to be identified as 'val' or 'def'. - * - * 'val' is for value definition. - * It is detected in three cases. - * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` - * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` - * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` - * - * 'def' is for function definition. - * If it does not fit in any of the 'val' cases. - * - * Formerly there was another case for 'val'. - * Deprecated Case: - * This was implemented simply as: - * `line.trim.startsWith (soda_opening_parenthesis)` - * This is no longer supported. - * - */ - -trait FunctionDefinitionLineDetector -{ - - def line: String - - import soda.lib.OptionSD - import soda.lib.SomeSD_ - import soda.translator.parser.SodaConstant_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _trimmed_line = line.trim - - lazy val undetected = 0 - - lazy val val_detected = 1 - - lazy val def_detected = 2 - - lazy val detect : Int = - _find_definition (line).opt (ifEmpty = undetected) (ifNonEmpty = position => _try_found_definition (position) ) - - private def _try_found_definition (position : Int) : Int = - if ( _is_val_definition (position) - ) val_detected - else def_detected - - private def _is_val_definition (initial_position : Int) = - _is_val_definition_case_1 || - _is_val_definition_case_2 (initial_position) || - _is_val_definition_case_3 || - _is_val_definition_case_4 - - private lazy val _position_of_first_opening_parenthesis = - _get_index (line) (_sc.opening_parenthesis_symbol) - - private lazy val _is_val_definition_case_1 = - _position_of_first_opening_parenthesis.isEmpty - - private def _is_val_definition_case_2 (initial_position : Int) = - _position_of_first_opening_parenthesis.opt (false) ( position => position > initial_position) - - private lazy val _is_val_definition_case_3 = - (_get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => - _position_of_first_opening_parenthesis.opt (false) ( position => position > other_position) - ) - - private lazy val _is_val_definition_case_4 = - _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) - - /** - * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. - * This function finds the first occurrence of the definition sign, if it is present. - * - * @param line line - * @return maybe the position of the definition sign - */ - private def _find_definition (line : String) : OptionSD [Int] = - if ( line.endsWith (_sc.space + _sc.function_definition_symbol) - ) SomeSD_ (line.length - _sc.function_definition_symbol.length) - else _get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) - - private def _get_index (line : String) (pattern : String) : OptionSD [Int] = - _get_index_from (line) (pattern) (0) - - private def _get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = - SomeSD_ (line.indexOf (pattern, start) ) - .filter ( position => ! (position == -1) ) - -} - -case class FunctionDefinitionLineDetector_ (line: String) extends FunctionDefinitionLineDetector diff --git a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala deleted file mode 100644 index 5bbbb01c..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/ImportDeclarationBlockTranslator.scala +++ /dev/null @@ -1,67 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait ImportDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ImportDeclarationAnnotation - import soda.translator.parser.annotation.ImportDeclarationAnnotation_ - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val scala_import_declaration_pattern = - _tc.scala_import_declaration + _tc.scala_space - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = - ImportDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - scala_import_declaration_pattern) ( - block.imported_items - ) - ) - - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - BlockBuilder_ ().build ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) - ) - - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = - if ( annotated_line.is_comment - ) annotated_line.line - else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) - - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile ( ch => ch.isSpaceChar) - .length - - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") - -} - -case class ImportDeclarationBlockTranslator_ () extends ImportDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala deleted file mode 100644 index 086e5003..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.scala +++ /dev/null @@ -1,69 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait MainClassBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } - - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( _get_class_name (block.references) == _tc.soda_main_class_name - ) - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - Seq [String] ( - _tc.scala_class_end_symbol, - "", - _tc.scala_entry_point - ) - ), - block.references - ) - else block - - private def _get_class_name (references : Seq [AnnotatedBlock] ) : String = - _get_class_beginning (references) - .map ( x => x.class_name) - .getOrElse ("") - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - -} - -case class MainClassBlockTranslator_ () extends MainClassBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala deleted file mode 100644 index c7ecf877..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/MatchCaseBlockTranslator.scala +++ /dev/null @@ -1,88 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait MatchCaseBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ - import soda.translator.parser.annotation.TestDeclarationAnnotation - import soda.translator.parser.annotation.TestDeclarationAnnotation_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _tc = TranslationConstantToScala_ () - - private lazy val _soda_match_pattern = _sc.match_reserved_word + " " - - lazy val translate: AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_function_block (FunctionDefinitionAnnotation_ (block) ) - case TestDeclarationAnnotation_ (block) => _translate_test_block (TestDeclarationAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) - - private def _translate_test_block (block : AnnotatedBlock) : TestDeclarationAnnotation = - TestDeclarationAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : AnnotatedBlock) : Block = - if ( _is_a_match_case_structure (block) - ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) - else block - - private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = - block.lines.exists ( line => _is_a_match_line (line) ) - - private def _is_a_match_line (line : String) : Boolean = - line.trim.startsWith (_soda_match_pattern) - - private def _get_tabulation_of_match (block : AnnotatedBlock) : String = - block.lines - .find ( line => _is_a_match_line (line) ) - .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) - .getOrElse (_tc.scala_space) - - private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = - BlockBuilder_ ().build ( - block.lines - .map ( line => _insert_match_before_brace_if_found (line) ) - .++ ( Seq [String] () .+: (tabulation + _tc.scala_match_end_translation) ) - ) - - private def _insert_match_before_brace_if_found (line : String) : String = - if ( _is_a_match_line (line) - ) _assemble_parts (index = line.indexOf (_soda_match_pattern) ) (line) - else line - - private def _assemble_parts (index : Int) (line : String) : String = - (_left_part (index) (line) ) + (_right_part (index) (line) ) + _tc.scala_match_translation + _tc.scala_space + _tc.scala_opening_brace - - private def _left_part (index : Int) (line : String) : String = - line.substring (0, index) - - private def _right_part (index : Int) (line : String) : String = - line.substring (index + _soda_match_pattern.length, line.length) - -} - -case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala deleted file mode 100644 index 34fa9fcd..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.scala +++ /dev/null @@ -1,65 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -/** - * This class translates Soda source code into Scala source code. - */ - -trait MicroTranslatorToScala - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token - - private lazy val _tc = TranslationConstantToScala_ () - - private lazy val _ba = BlockAnnotationEnum_ () - - private lazy val _functions_and_tests = - Seq (_ba.function_definition, _ba.test_declaration) - - private lazy val _class_declarations = - Seq (_ba.class_alias, _ba.class_beginning, _ba.abstract_declaration) - - private lazy val _definitions_and_declarations = - _functions_and_tests.++ (_class_declarations) - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _translation_pipeline.translate (block) - - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - MatchCaseBlockTranslator_ (), - ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), - ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), - ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), - ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), - ClassDeclarationBlockTranslator_ (), - ImportDeclarationBlockTranslator_ (), - AbstractDeclarationBlockTranslator_ (), - TheoremAndProofBlockTranslator_ (), - ClassEndBlockTranslator_ (), - MainClassBlockTranslator_ (), - ClassConstructorBlockTranslator_ () - ) - ) - -} - -case class MicroTranslatorToScala_ () extends MicroTranslatorToScala diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index 7bfe8dfd..6d374bd5 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -7,3 +7,1213 @@ package soda.translator.extension.toscala trait Package +trait ClassEndBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _get_translation (block) + ) + ), + block.references + ) + + private def _get_translation (block : ClassEndAnnotation) : String = + _get_initial_spaces (block) + _tc.scala_class_end_symbol + + private def _get_initial_spaces (block : ClassEndAnnotation) : String = + _get_initial_spaces_with (_get_first_line (block) ) + + private def _get_initial_spaces_with (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) + + private def _get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class ClassEndBlockTranslator_ () extends ClassEndBlockTranslator +trait TheoremAndProofBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ProofBlockAnnotation + import soda.translator.parser.annotation.ProofBlockAnnotation_ + import soda.translator.parser.annotation.TheoremBlockAnnotation + import soda.translator.parser.annotation.TheoremBlockAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case TheoremBlockAnnotation_ (block) => _translate_theorem_block (TheoremBlockAnnotation_ (block) ) + case ProofBlockAnnotation_ (block) => _translate_proof_block (ProofBlockAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_theorem_block (block : AnnotatedBlock) : TheoremBlockAnnotation = + TheoremBlockAnnotation_ (_translate_block (block) ) + + private def _translate_proof_block (block : AnnotatedBlock) : ProofBlockAnnotation = + ProofBlockAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : AnnotatedBlock) : Block = + _append (_tc.scala_comment_closing_symbol) (_prepend (_tc.scala_comment_opening_symbol) (block) ) + + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) + ) + + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) + +} + +case class TheoremAndProofBlockTranslator_ () extends TheoremAndProofBlockTranslator +/** + * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. + */ + +trait TranslationConstantToScala +{ + + import soda.translator.parser.SodaConstant_ + + lazy val soda_constant = SodaConstant_ () + + lazy val scala_3_class_definition = ":" + + lazy val scala_match_translation = " match " + + lazy val scala_space = " " + + lazy val scala_empty_string = "" + + lazy val scala_comma = "," + + lazy val scala_parameter_separator_symbol = "," + + lazy val scala_lambda_arrow_symbol = "=>" + + lazy val scala_case_arrow_symbol = "=>" + + lazy val scala_parameter_definition_symbol = "=" + + lazy val scala_match_end_translation = "}" + + lazy val scala_opening_parenthesis = "(" + + lazy val scala_closing_parenthesis = ")" + + lazy val scala_opening_bracket = "[" + + lazy val scala_closing_bracket = "]" + + lazy val scala_opening_brace = "{" + + lazy val scala_closing_brace = "}" + + lazy val scala_class_begin_symbol = "{" + + lazy val scala_class_end_symbol = "}" + + lazy val scala_comment_opening_symbol = "/*" + + lazy val scala_comment_closing_symbol = "*/" + + lazy val scala_if_translation = "if (" + + lazy val scala_then_translation = ")" + + lazy val scala_abstract_function_declaration = "def" + + lazy val scala_definition = "def" + + lazy val scala_value = "lazy val" + + lazy val scala_import_declaration = "import" + + lazy val scala_with_translation = "with" + + lazy val scala_extends_translation = "extends" + + lazy val scala_function_arrow_symbol = "=>" + + lazy val scala_subtype_symbol = "<:" + + lazy val scala_supertype_symbol = ">:" + + lazy val scala_not_symbol = "!" + + lazy val scala_and_symbol = "&&" + + lazy val scala_or_symbol = "||" + + lazy val scala_tail_recursion_annotation_translation = "import scala.annotation.tailrec\n @tailrec final" + + lazy val scala_override_annotation_translation = "override" + + lazy val scala_new_annotation_translation = "new" + + lazy val soda_main_class_name = "Main" + + lazy val scala_entry_point = "object EntryPoint {\n def main (args: Array [String]): Unit = Main_ ().main (args)\n}\n" + + lazy val scala_private_reserved_word = "private" + + /** + * Scala 3 keywords: + * https://dotty.epfl.ch/docs/internals/syntax.html + * Scala 2 keywords: + * https://www.scala-lang.org/files/archive/spec/2.13/01-lexical-syntax.html + */ + lazy val scala_reserved_words = + scala_3_regular_keywords ++ scala_3_soft_keywords ++ scala_2_extra_keywords + + lazy val scala_3_regular_keywords = + Seq ( + "abstract", + "case", + "catch", + "class", + "def", + "do", + "else", + "enum", + "export", + "extends", + "false", + "final", + "finally", + "for", + "given", + "if", + "implicit", + "import", + "lazy", + "match", + "new", + "null", + "object", + "override", + "package", + "private", + "protected", + "return", + "sealed", + "super", + "then", + "throw", + "trait", + "true", + "try", + "type", + "val", + "var", + "while", + "with", + "yield", + ":", + "=", + "<-", + "=>", + "<:", + ">:", + "#", + "@", + "=>>", + "?=>" + ) + + lazy val scala_3_soft_keywords = + Seq ( + "as", + "derives", + "end", + "extension", + "infix", + "inline", + "opaque", + "open", + "transparent", + "using", + "|", + "*", + "+", + "-" + ) + + lazy val scala_2_extra_keywords = + Seq ( + "forSome", + "macro", + "this", + "_", + "<%", + "\u21D2", + "\u2190" + ) + + lazy val type_symbol_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.subtype_reserved_word, scala_subtype_symbol), + Tuple2 (soda_constant.supertype_reserved_word, scala_supertype_symbol), + Tuple2 (soda_constant.function_arrow_symbol, scala_function_arrow_symbol) + ) + + lazy val function_symbol_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), + Tuple2 (soda_constant.any_reserved_word, scala_empty_string), + Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), + Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), + Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), + Tuple2 (soda_constant.and_reserved_word, scala_and_symbol), + Tuple2 (soda_constant.or_reserved_word, scala_or_symbol), + Tuple2 (soda_constant.if_reserved_word, scala_if_translation), + Tuple2 (soda_constant.then_reserved_word, scala_then_translation), + Tuple2 (soda_constant.parameter_definition_symbol, scala_parameter_definition_symbol), + Tuple2 (soda_constant.tail_recursion_annotation, scala_tail_recursion_annotation_translation), + Tuple2 (soda_constant.override_annotation, scala_override_annotation_translation), + Tuple2 (soda_constant.new_annotation, scala_new_annotation_translation) + ) + + lazy val all_translations : Seq [Tuple2 [String, String] ] = + type_symbol_translation.++ (function_symbol_translation) + + lazy val class_declaration_translation_at_beginning_with_paren = "case class" + + lazy val class_declaration_translation_at_beginning_without_paren_for_type_alias = "type" + + lazy val class_declaration_translation_at_beginning_without_paren = "trait" + + lazy val prefix_scala_non_soda = "__soda__" + + lazy val scala_non_soda : Seq [Tuple2 [String, String] ] = + scala_reserved_words + .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) + .map ( x => Tuple2 (x, prefix_scala_non_soda + x) ) + + def is_scala_word (word : String) : Boolean = + scala_reserved_words.contains (word) + + def is_soda_word (word : String) : Boolean = + soda_constant.soda_reserved_words.contains (word) + +} + +case class TranslationConstantToScala_ () extends TranslationConstantToScala +trait ClassDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.block.Translator + import soda.translator.blocktr.TableTranslator_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassAliasAnnotation + import soda.translator.parser.annotation.ClassAliasAnnotation_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val soda_space : String = _sc.space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) + case ClassAliasAnnotation_ (block) => _translate_class_alias_block (ClassAliasAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = + ClassBeginningAnnotation_ (_translate_block (block) ) + + private def _translate_class_alias_block (block : ClassAliasAnnotation) : ClassAliasAnnotation = + ClassAliasAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : AnnotatedBlock) : Block = + BlockBuilder_ ().build ( + if ( (has_condition_for_type_alias (get_first_line (block) ) ) + ) _process_head (block) ++ _process_tail (block) + else _process_head (block) ++ _process_tail (block) ++ Seq [String] (get_initial_spaces (block) + _tc.scala_class_begin_symbol) + ) + + private def _process_head (block : Block) : Seq [String] = + _process_head_with (get_first_line (block) ) (block) + + private def _process_head_with (line : String) (block : Block) : Seq [String] = + Seq [String] (Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) ) + + private def _process_tail (block : Block) : Seq [String] = + _process_if_extends (remove_first_line (block) ) + + private def _process_if_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim == _sc.extends_reserved_word) + ) Seq [String] (get_initial_spaces (block) + _tc.scala_extends_translation) ++ _process_after_extends (remove_first_line (block) ) + else block.lines + + def get_table_translator (line : String) : Translator = + TableTranslator_ ( + Seq (Tuple2 (_sc.class_reserved_word, get_class_declaration_translation (line) ) ) + ) + + def get_class_declaration_translation (line : String) : String = + if ( line.contains (_sc.opening_parenthesis_symbol) + ) _tc.class_declaration_translation_at_beginning_with_paren + else + if ( has_condition_for_type_alias (line) + ) _tc.class_declaration_translation_at_beginning_without_paren_for_type_alias + else _tc.class_declaration_translation_at_beginning_without_paren + + private def _process_after_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim.nonEmpty) + ) Seq [String] (get_first_line (block) ) ++ remove_first_line (block).lines.map ( line => get_initial_spaces_for (line) + _tc.scala_with_translation + _tc.scala_space + line.trim) + else Seq [String] () + + def remove_first_line (block : Block) : Block = + BlockBuilder_ ().build ( + if ( block.lines.isEmpty + ) block.lines + else block.lines.tail + ) + + def get_first_line (block : Block) : String = + block.lines.headOption.getOrElse ("") + + def get_initial_spaces (block : Block) : String = + get_initial_spaces_for (get_first_line (block) ) + + def get_initial_spaces_for (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) + + def ends_with_equals (line : String) : Boolean = false + + def ends_with_opening_brace (line : String) : Boolean = false + + def contains_equals (line : String) : Boolean = + line.trim.contains (_sc.function_definition_symbol) + + def has_condition_for_type_alias (line : String) : Boolean = + contains_equals (line) + +} + +case class ClassDeclarationBlockTranslator_ () extends ClassDeclarationBlockTranslator +trait ClassConstructorBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) + + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) + + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) + + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + block.lines.++ ( + Seq [String] ( + "", + _get_constructor_declaration (beginning) (_get_abstract_functions (block.references) ) + ) + ) + ), + block.references + ) + + private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = + _get_initial_spaces (beginning) + + _tc.class_declaration_translation_at_beginning_with_paren + + _tc.scala_space + + beginning.class_name + + _sc.constructor_suffix + + _translate_type_symbols (_get_as_parameter_list (beginning.type_parameters_and_bounds) ) + + _tc.scala_space + + _tc.scala_opening_parenthesis + + abstract_functions.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + + _tc.scala_closing_parenthesis + + _tc.scala_space + + _tc.scala_extends_translation + + _tc.scala_space + + beginning.class_name + + _get_as_parameter_list (beginning.type_parameters) + + private def _get_as_parameter_list (parameters : Seq [String] ) : String = + if ( parameters.isEmpty + ) "" + else _tc.scala_space + _tc.scala_opening_bracket + parameters.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + _tc.scala_closing_bracket + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + + private def _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = + references + .flatMap ( block => _get_as_abstract_declaration_annotation (block) ) + .flatMap ( block => block.abstract_functions) + .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) + + private def _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = + block match { + case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) + case x => None + } + + private def _translate_type_symbols (line : String) : String = + line + .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) + .replaceAll (_sc.supertype_reserved_word, _tc.scala_supertype_symbol) + .replaceAll (_sc.function_arrow_symbol, _tc.scala_function_arrow_symbol) + + private def _get_initial_spaces (block : AnnotatedBlock) : String = + _get_initial_spaces_with (_get_first_line (block) ) + + private def _get_initial_spaces_with (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) + + private def _get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class ClassConstructorBlockTranslator_ () extends ClassConstructorBlockTranslator +/** + * A line containing the definition sign will be classified as a definition. + * The definitions need to be identified as 'val' or 'def'. + * + * 'val' is for value definition. + * It is detected in three cases. + * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` + * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` + * + * 'def' is for function definition. + * If it does not fit in any of the 'val' cases. + * + * Formerly there was another case for 'val'. + * Deprecated Case: + * This was implemented simply as: + * `line.trim.startsWith (soda_opening_parenthesis)` + * This is no longer supported. + * + */ + +trait FunctionDefinitionLineDetector +{ + + def line: String + + import soda.lib.OptionSD + import soda.lib.SomeSD_ + import soda.translator.parser.SodaConstant_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _trimmed_line = line.trim + + lazy val undetected = 0 + + lazy val val_detected = 1 + + lazy val def_detected = 2 + + lazy val detect : Int = + _find_definition (line).opt (ifEmpty = undetected) (ifNonEmpty = position => _try_found_definition (position) ) + + private def _try_found_definition (position : Int) : Int = + if ( _is_val_definition (position) + ) val_detected + else def_detected + + private def _is_val_definition (initial_position : Int) = + _is_val_definition_case_1 || + _is_val_definition_case_2 (initial_position) || + _is_val_definition_case_3 || + _is_val_definition_case_4 + + private lazy val _position_of_first_opening_parenthesis = + _get_index (line) (_sc.opening_parenthesis_symbol) + + private lazy val _is_val_definition_case_1 = + _position_of_first_opening_parenthesis.isEmpty + + private def _is_val_definition_case_2 (initial_position : Int) = + _position_of_first_opening_parenthesis.opt (false) ( position => position > initial_position) + + private lazy val _is_val_definition_case_3 = + (_get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => + _position_of_first_opening_parenthesis.opt (false) ( position => position > other_position) + ) + + private lazy val _is_val_definition_case_4 = + _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) + + /** + * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. + * This function finds the first occurrence of the definition sign, if it is present. + * + * @param line line + * @return maybe the position of the definition sign + */ + private def _find_definition (line : String) : OptionSD [Int] = + if ( line.endsWith (_sc.space + _sc.function_definition_symbol) + ) SomeSD_ (line.length - _sc.function_definition_symbol.length) + else _get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) + + private def _get_index (line : String) (pattern : String) : OptionSD [Int] = + _get_index_from (line) (pattern) (0) + + private def _get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = + SomeSD_ (line.indexOf (pattern, start) ) + .filter ( position => ! (position == -1) ) + +} + +case class FunctionDefinitionLineDetector_ (line: String) extends FunctionDefinitionLineDetector +/** + * This translates Soda source code to Scala source code. + */ + +trait TranslatorToScala + extends + soda.translator.extension.common.Extension +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File + + lazy val package_file_name : String = "Package.soda" + + lazy val prelude_file_name : String = package_file_name + + lazy val package_scala_file_name : String = "Package.scala" + + lazy val file_separator : String = File.separator + + lazy val default_prelude : String = "" + + lazy val new_line : String = "\n" + + lazy val prelude_separation : String = new_line + new_line + + lazy val prelude_file_body : String = new_line + "trait Package" + prelude_separation + + lazy val package_option_1 = "-p" + + lazy val package_option_2 = "--package" + + private lazy val _soda_extension : String = ".soda" + + private lazy val _scala_extension : String = ".scala" + + private lazy val _default_argument = "." + + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => + if ( _is_package_option (arguments (0) ) + ) _process_directory_with_package_option (arguments (1) ) + else _translate (arguments (0) ) (arguments (1) ) + case x => false + } + + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () + + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (get_input_output_file_names (file.getAbsolutePath) ) + + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) + + private def _process_directory_with_package_option (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () + + private def _process_soda_file_with_package_option (file : File) : Boolean = + if ( file.getName == package_file_name + ) _process_soda_file (file) + else _process_soda_file_with_package_option_with ( + get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) + ) + + private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = + _translate_append (pair.input_file_name) (pair.output_file_name) + + def get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) + + def get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) + + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) + + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) + + private def _translate_append (input_file_name : String) (output_file_name : String) : Boolean = + _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) + + private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) ) + + private def _read_input_with_prelude (input_file_name : String) : String = + if ( _is_a_prelude_file (input_file_name) + ) _read_input (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + _read_input (input_file_name) + + private def _read_input (input_file_name : String) : String = + SimpleFileReader_ ().read_file (input_file_name) + + private def _get_prelude (input_file_name : String) : String = + _get_prelude_with (_get_prelude_file (input_file_name) ) + + private def _get_prelude_with (prelude_file : File) : String = + if ( prelude_file.exists + ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation + else default_prelude + + private def _get_prelude_file (input_file_name : String) : File = + new File ( new File (input_file_name) .getParentFile , prelude_file_name ) + + private def _is_a_prelude_file (input_file_name : String) : Boolean = + prelude_file_name == ( ( new File (input_file_name) ) .getName) + + private def _is_package_option (s : String) : Boolean = + (s == package_option_1) || (s == package_option_2) + +} + +case class TranslatorToScala_ () extends TranslatorToScala + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String + +} + +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair +trait MatchCaseBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + import soda.translator.parser.annotation.TestDeclarationAnnotation + import soda.translator.parser.annotation.TestDeclarationAnnotation_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToScala_ () + + private lazy val _soda_match_pattern = _sc.match_reserved_word + " " + + lazy val translate: AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case FunctionDefinitionAnnotation_ (block) => _translate_function_block (FunctionDefinitionAnnotation_ (block) ) + case TestDeclarationAnnotation_ (block) => _translate_test_block (TestDeclarationAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_function_block (block : AnnotatedBlock) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + private def _translate_test_block (block : AnnotatedBlock) : TestDeclarationAnnotation = + TestDeclarationAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : AnnotatedBlock) : Block = + if ( _is_a_match_case_structure (block) + ) _translate_match_case_structure (block) (_get_tabulation_of_match (block) ) + else block + + private def _is_a_match_case_structure (block : AnnotatedBlock) : Boolean = + block.lines.exists ( line => _is_a_match_line (line) ) + + private def _is_a_match_line (line : String) : Boolean = + line.trim.startsWith (_soda_match_pattern) + + private def _get_tabulation_of_match (block : AnnotatedBlock) : String = + block.lines + .find ( line => _is_a_match_line (line) ) + .map ( line => _left_part (line.indexOf (_soda_match_pattern) ) (line) ) + .getOrElse (_tc.scala_space) + + private def _translate_match_case_structure (block: AnnotatedBlock) (tabulation : String) : Block = + BlockBuilder_ ().build ( + block.lines + .map ( line => _insert_match_before_brace_if_found (line) ) + .++ ( Seq [String] () .+: (tabulation + _tc.scala_match_end_translation) ) + ) + + private def _insert_match_before_brace_if_found (line : String) : String = + if ( _is_a_match_line (line) + ) _assemble_parts (index = line.indexOf (_soda_match_pattern) ) (line) + else line + + private def _assemble_parts (index : Int) (line : String) : String = + (_left_part (index) (line) ) + (_right_part (index) (line) ) + _tc.scala_match_translation + _tc.scala_space + _tc.scala_opening_brace + + private def _left_part (index : Int) (line : String) : String = + line.substring (0, index) + + private def _right_part (index : Int) (line : String) : String = + line.substring (index + _soda_match_pattern.length, line.length) + +} + +case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator +trait FunctionDefinitionBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.block.Block_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case FunctionDefinitionAnnotation_ (block) => _translate_function_definition_block (block) + case x => annotated_block + } + + private def _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) + + private def _translate_block (block : Block) : Block = + if ( block.readable_lines.isEmpty + ) block + else _translate_block_with (block.readable_lines.head) (block) + + private def _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = + if ( _is_annotation (first_line.line) + ) _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) + else _translate_main_block (block) + + private def _translate_main_block (block : Block) : Block = + _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) + + private def _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = + detector.detect match { + case detector.val_detected => _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case detector.def_detected => _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case x => block + } + + private def _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) + ) + + private def _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) + ) + + private def _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.takeWhile ( annotated_line => annotated_line.is_comment ) + + private def _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.dropWhile ( annotated_line => annotated_line.is_comment ) + + private def _translate_val_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) + .line + + private def _translate_def_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) + .line + + private def _private_prefix_if_necessary (line : String) : String = + if ( line.trim.startsWith (_sc.private_function_prefix) + ) _tc.scala_private_reserved_word + _tc.scala_space + else "" + + private def _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = + if ( lines.isEmpty + ) Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) + else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) + + private def _remove_first_line_if_possible (block : Block) : Block = + if ( block.lines.isEmpty + ) block + else BlockBuilder_ ().build (block.lines.tail) + + private def _prepend_line (line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (line) .++ (block.lines) + ) + + private def _flatten_block (block : Block) : String = + block.lines.mkString (_sc.space) + + private def _is_annotation (line : String) : Boolean = + (line.trim == _sc.tail_recursion_annotation) || (line.trim == _sc.override_annotation) + +} + +case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator +trait ImportDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ImportDeclarationAnnotation + import soda.translator.parser.annotation.ImportDeclarationAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val scala_import_declaration_pattern = + _tc.scala_import_declaration + _tc.scala_space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) + case x => annotated_block + } + + private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = + ImportDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + scala_import_declaration_pattern) ( + block.imported_items + ) + ) + + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + BlockBuilder_ ().build ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) + + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) + + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile ( ch => ch.isSpaceChar) + .length + + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class ImportDeclarationBlockTranslator_ () extends ImportDeclarationBlockTranslator +trait MainClassBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( _get_class_name (block.references) == _tc.soda_main_class_name + ) + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _tc.scala_class_end_symbol, + "", + _tc.scala_entry_point + ) + ), + block.references + ) + else block + + private def _get_class_name (references : Seq [AnnotatedBlock] ) : String = + _get_class_beginning (references) + .map ( x => x.class_name) + .getOrElse ("") + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + + private def _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + +} + +case class MainClassBlockTranslator_ () extends MainClassBlockTranslator +/** + * This class translates Soda source code into Scala source code. + */ + +trait MicroTranslatorToScala + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token + + private lazy val _tc = TranslationConstantToScala_ () + + private lazy val _ba = BlockAnnotationEnum_ () + + private lazy val _functions_and_tests = + Seq (_ba.function_definition, _ba.test_declaration) + + private lazy val _class_declarations = + Seq (_ba.class_alias, _ba.class_beginning, _ba.abstract_declaration) + + private lazy val _definitions_and_declarations = + _functions_and_tests.++ (_class_declarations) + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) + + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + MatchCaseBlockTranslator_ (), + ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), + ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), + ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), + ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), + ClassDeclarationBlockTranslator_ (), + ImportDeclarationBlockTranslator_ (), + AbstractDeclarationBlockTranslator_ (), + TheoremAndProofBlockTranslator_ (), + ClassEndBlockTranslator_ (), + MainClassBlockTranslator_ (), + ClassConstructorBlockTranslator_ () + ) + ) + +} + +case class MicroTranslatorToScala_ () extends MicroTranslatorToScala +trait AbstractDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.block.Block_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val scala_abstract_function_declaration_pattern = + _tc.scala_abstract_function_declaration + _tc.scala_space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + scala_abstract_function_declaration_pattern) ( + block.abstract_functions_with_comments + ), + block.references + ) + + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + Block_ ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) + + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : AnnotatedLine = + if ( annotated_line.is_comment + ) annotated_line + else AnnotatedLine_ (annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index), annotated_line.is_comment) + + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile (ch => ch.isSpaceChar) + .length + + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class AbstractDeclarationBlockTranslator_ () extends AbstractDeclarationBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala b/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala deleted file mode 100644 index ed177d85..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/TheoremAndProofBlockTranslator.scala +++ /dev/null @@ -1,58 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -trait TheoremAndProofBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ProofBlockAnnotation - import soda.translator.parser.annotation.ProofBlockAnnotation_ - import soda.translator.parser.annotation.TheoremBlockAnnotation - import soda.translator.parser.annotation.TheoremBlockAnnotation_ - - private lazy val _tc = TranslationConstantToScala_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case TheoremBlockAnnotation_ (block) => _translate_theorem_block (TheoremBlockAnnotation_ (block) ) - case ProofBlockAnnotation_ (block) => _translate_proof_block (ProofBlockAnnotation_ (block) ) - case x => annotated_block - } - - private def _translate_theorem_block (block : AnnotatedBlock) : TheoremBlockAnnotation = - TheoremBlockAnnotation_ (_translate_block (block) ) - - private def _translate_proof_block (block : AnnotatedBlock) : ProofBlockAnnotation = - ProofBlockAnnotation_ (_translate_block (block) ) - - private def _translate_block (block : AnnotatedBlock) : Block = - _append (_tc.scala_comment_closing_symbol) (_prepend (_tc.scala_comment_opening_symbol) (block) ) - - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) - ) - - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) - -} - -case class TheoremAndProofBlockTranslator_ () extends TheoremAndProofBlockTranslator diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala deleted file mode 100644 index 4d286679..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslationConstantToScala.scala +++ /dev/null @@ -1,243 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -/** - * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. - */ - -trait TranslationConstantToScala -{ - - import soda.translator.parser.SodaConstant_ - - lazy val soda_constant = SodaConstant_ () - - lazy val scala_3_class_definition = ":" - - lazy val scala_match_translation = " match " - - lazy val scala_space = " " - - lazy val scala_empty_string = "" - - lazy val scala_comma = "," - - lazy val scala_parameter_separator_symbol = "," - - lazy val scala_lambda_arrow_symbol = "=>" - - lazy val scala_case_arrow_symbol = "=>" - - lazy val scala_parameter_definition_symbol = "=" - - lazy val scala_match_end_translation = "}" - - lazy val scala_opening_parenthesis = "(" - - lazy val scala_closing_parenthesis = ")" - - lazy val scala_opening_bracket = "[" - - lazy val scala_closing_bracket = "]" - - lazy val scala_opening_brace = "{" - - lazy val scala_closing_brace = "}" - - lazy val scala_class_begin_symbol = "{" - - lazy val scala_class_end_symbol = "}" - - lazy val scala_comment_opening_symbol = "/*" - - lazy val scala_comment_closing_symbol = "*/" - - lazy val scala_if_translation = "if (" - - lazy val scala_then_translation = ")" - - lazy val scala_abstract_function_declaration = "def" - - lazy val scala_definition = "def" - - lazy val scala_value = "lazy val" - - lazy val scala_import_declaration = "import" - - lazy val scala_with_translation = "with" - - lazy val scala_extends_translation = "extends" - - lazy val scala_function_arrow_symbol = "=>" - - lazy val scala_subtype_symbol = "<:" - - lazy val scala_supertype_symbol = ">:" - - lazy val scala_not_symbol = "!" - - lazy val scala_and_symbol = "&&" - - lazy val scala_or_symbol = "||" - - lazy val scala_tail_recursion_annotation_translation = "import scala.annotation.tailrec\n @tailrec final" - - lazy val scala_override_annotation_translation = "override" - - lazy val scala_new_annotation_translation = "new" - - lazy val soda_main_class_name = "Main" - - lazy val scala_entry_point = "object EntryPoint {\n def main (args: Array [String]): Unit = Main_ ().main (args)\n}\n" - - lazy val scala_private_reserved_word = "private" - - /** - * Scala 3 keywords: - * https://dotty.epfl.ch/docs/internals/syntax.html - * Scala 2 keywords: - * https://www.scala-lang.org/files/archive/spec/2.13/01-lexical-syntax.html - */ - lazy val scala_reserved_words = - scala_3_regular_keywords ++ scala_3_soft_keywords ++ scala_2_extra_keywords - - lazy val scala_3_regular_keywords = - Seq ( - "abstract", - "case", - "catch", - "class", - "def", - "do", - "else", - "enum", - "export", - "extends", - "false", - "final", - "finally", - "for", - "given", - "if", - "implicit", - "import", - "lazy", - "match", - "new", - "null", - "object", - "override", - "package", - "private", - "protected", - "return", - "sealed", - "super", - "then", - "throw", - "trait", - "true", - "try", - "type", - "val", - "var", - "while", - "with", - "yield", - ":", - "=", - "<-", - "=>", - "<:", - ">:", - "#", - "@", - "=>>", - "?=>" - ) - - lazy val scala_3_soft_keywords = - Seq ( - "as", - "derives", - "end", - "extension", - "infix", - "inline", - "opaque", - "open", - "transparent", - "using", - "|", - "*", - "+", - "-" - ) - - lazy val scala_2_extra_keywords = - Seq ( - "forSome", - "macro", - "this", - "_", - "<%", - "\u21D2", - "\u2190" - ) - - lazy val type_symbol_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.subtype_reserved_word, scala_subtype_symbol), - Tuple2 (soda_constant.supertype_reserved_word, scala_supertype_symbol), - Tuple2 (soda_constant.function_arrow_symbol, scala_function_arrow_symbol) - ) - - lazy val function_symbol_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), - Tuple2 (soda_constant.any_reserved_word, scala_empty_string), - Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), - Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), - Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), - Tuple2 (soda_constant.and_reserved_word, scala_and_symbol), - Tuple2 (soda_constant.or_reserved_word, scala_or_symbol), - Tuple2 (soda_constant.if_reserved_word, scala_if_translation), - Tuple2 (soda_constant.then_reserved_word, scala_then_translation), - Tuple2 (soda_constant.parameter_definition_symbol, scala_parameter_definition_symbol), - Tuple2 (soda_constant.tail_recursion_annotation, scala_tail_recursion_annotation_translation), - Tuple2 (soda_constant.override_annotation, scala_override_annotation_translation), - Tuple2 (soda_constant.new_annotation, scala_new_annotation_translation) - ) - - lazy val all_translations : Seq [Tuple2 [String, String] ] = - type_symbol_translation.++ (function_symbol_translation) - - lazy val class_declaration_translation_at_beginning_with_paren = "case class" - - lazy val class_declaration_translation_at_beginning_without_paren_for_type_alias = "type" - - lazy val class_declaration_translation_at_beginning_without_paren = "trait" - - lazy val prefix_scala_non_soda = "__soda__" - - lazy val scala_non_soda : Seq [Tuple2 [String, String] ] = - scala_reserved_words - .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) - .map ( x => Tuple2 (x, prefix_scala_non_soda + x) ) - - def is_scala_word (word : String) : Boolean = - scala_reserved_words.contains (word) - - def is_soda_word (word : String) : Boolean = - soda_constant.soda_reserved_words.contains (word) - -} - -case class TranslationConstantToScala_ () extends TranslationConstantToScala diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala deleted file mode 100644 index 5dc3fd4c..00000000 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.scala +++ /dev/null @@ -1,156 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains classes for the translation to Scala. - */ - - - - - -/** - * This translates Soda source code to Scala source code. - */ - -trait TranslatorToScala - extends - soda.translator.extension.common.Extension -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File - - lazy val package_file_name : String = "Package.soda" - - lazy val prelude_file_name : String = package_file_name - - lazy val package_scala_file_name : String = "Package.scala" - - lazy val file_separator : String = File.separator - - lazy val default_prelude : String = "" - - lazy val new_line : String = "\n" - - lazy val prelude_separation : String = new_line + new_line - - lazy val prelude_file_body : String = new_line + "trait Package" + prelude_separation - - lazy val package_option_1 = "-p" - - lazy val package_option_2 = "--package" - - private lazy val _soda_extension : String = ".soda" - - private lazy val _scala_extension : String = ".scala" - - private lazy val _default_argument = "." - - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => - if ( _is_package_option (arguments (0) ) - ) _process_directory_with_package_option (arguments (1) ) - else _translate (arguments (0) ) (arguments (1) ) - case x => false - } - - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () - - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (get_input_output_file_names (file.getAbsolutePath) ) - - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) - - private def _process_directory_with_package_option (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () - - private def _process_soda_file_with_package_option (file : File) : Boolean = - if ( file.getName == package_file_name - ) _process_soda_file (file) - else _process_soda_file_with_package_option_with ( - get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) - ) - - private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = - _translate_append (pair.input_file_name) (pair.output_file_name) - - def get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) - - def get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) - else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) - - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) - - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) - - private def _translate_append (input_file_name : String) (output_file_name : String) : Boolean = - _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) - - private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) ) - - private def _read_input_with_prelude (input_file_name : String) : String = - if ( _is_a_prelude_file (input_file_name) - ) _read_input (input_file_name) + prelude_file_body - else _get_prelude (input_file_name) + _read_input (input_file_name) - - private def _read_input (input_file_name : String) : String = - SimpleFileReader_ ().read_file (input_file_name) - - private def _get_prelude (input_file_name : String) : String = - _get_prelude_with (_get_prelude_file (input_file_name) ) - - private def _get_prelude_with (prelude_file : File) : String = - if ( prelude_file.exists - ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation - else default_prelude - - private def _get_prelude_file (input_file_name : String) : File = - new File ( new File (input_file_name) .getParentFile , prelude_file_name ) - - private def _is_a_prelude_file (input_file_name : String) : Boolean = - prelude_file_name == ( ( new File (input_file_name) ) .getName) - - private def _is_package_option (s : String) : Boolean = - (s == package_option_1) || (s == package_option_2) - -} - -case class TranslatorToScala_ () extends TranslatorToScala - -trait FileNamePair -{ - - def input_file_name : String - def output_file_name : String - -} - -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala deleted file mode 100644 index 99462268..00000000 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.scala +++ /dev/null @@ -1,69 +0,0 @@ -package soda.translator.io - -/* - * This package contains all the classes for I/O communication. - * It is also the entry point for the translator. - */ - - - - - -trait AbstractDirectoryProcessor -{ - - def start : String - def process_soda_file : java.io.File => Boolean - -} - -case class AbstractDirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends AbstractDirectoryProcessor - -trait DirectoryProcessor - extends - AbstractDirectoryProcessor -{ - - def start : String - def process_soda_file : java.io.File => Boolean - - import java.io.File - - lazy val soda_suffix = ".soda" - - lazy val package_file_name = "Package.soda" - - private lazy val _all_files = - DirectoryScanner_ ().get_all_files ( new File (start)) - - private lazy val _all_soda_files = - _all_files - .filter ( x => x.isFile) - .filter ( x => x.getName.endsWith (soda_suffix)) - - private lazy val _package_files = - _all_files - .filter ( x => x.isFile) - .filter ( x => x.getName == package_file_name) - - private lazy val _soda_non_package_files = - _all_soda_files - .filter ( x => ! (x.getName == package_file_name) ) - - private lazy val _soda_files = - _package_files .++ (_soda_non_package_files) - - private lazy val _lib_files = - _all_files - .filter ( x => x.isFile) - .filter ( file => file.getName == LibraryDeployer_ ().library_marker_file) - - def process () : Boolean = - LibraryDeployer_ ().expand_library (_lib_files) && - _soda_files - .map (process_soda_file) - .forall ( x => x) - -} - -case class DirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends DirectoryProcessor diff --git a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala b/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala deleted file mode 100644 index a528efb8..00000000 --- a/translator/src/main/scala/soda/translator/io/DirectoryScanner.scala +++ /dev/null @@ -1,48 +0,0 @@ -package soda.translator.io - -/* - * This package contains all the classes for I/O communication. - * It is also the entry point for the translator. - */ - - - - - -/** - * This class is used to scan files in a given directory. - */ - -trait DirectoryScanner -{ - - import java.io.File - - def get_all_files (start : File) : Seq [File] = - if ( start.isFile - ) Seq (start) - else _scan (Seq () ) (start.listFiles ().toSeq) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = - if ( to_scan.isEmpty - ) found - else _tailrec_scan (found.+: (to_scan.head) ) (_get_files_to_scan (to_scan) ) - - private def _scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = - _tailrec_scan (found) (to_scan) - - private def _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = - if ( to_scan.isEmpty - ) to_scan - else _get_files_to_scan_with (to_scan.head) (to_scan.tail) - - private def _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = - if ( to_scan_head.isDirectory - ) to_scan_tail.++ (to_scan_head.listFiles () ) - else to_scan_tail - -} - -case class DirectoryScanner_ () extends DirectoryScanner diff --git a/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala b/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala deleted file mode 100644 index 6522e1b6..00000000 --- a/translator/src/main/scala/soda/translator/io/LibraryDeployer.scala +++ /dev/null @@ -1,44 +0,0 @@ -package soda.translator.io - -/* - * This package contains all the classes for I/O communication. - * It is also the entry point for the translator. - */ - - - - - -trait LibraryDeployer -{ - - import java.io.File - - lazy val library_marker_file = "lib.soda" - - private lazy val _library_directory_in_jar = "/lib/soda/lib/" - - private lazy val _library_content_files : Seq [String] = - SimpleFileReader_ () - .read_resource (_library_directory_in_jar + "files.txt") - .split ("\n") - .toSeq - - def expand_library (lib_files : Seq [File] ) : Boolean = - lib_files - .map ( lib_file => lib_file.getParent) - .map ( parent_directory => _expand_files (parent_directory) ) - .forall ( x => x) - - private def _expand_files (parent_directory : String) : Boolean = - _library_content_files - .map ( lib_file_name => - SimpleFileWriter_ ().write_file_with ( - file = SimpleFileWriter_ ().create_file (parent_directory) (lib_file_name) ) ( - content = SimpleFileReader_ ().read_resource (_library_directory_in_jar + lib_file_name) - ) ) - .forall ( x => x) - -} - -case class LibraryDeployer_ () extends LibraryDeployer diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index 0e75a3e4..c8da53e3 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -8,3 +8,201 @@ package soda.translator.io trait Package +/** + * This class is used to scan files in a given directory. + */ + +trait DirectoryScanner +{ + + import java.io.File + + def get_all_files (start : File) : Seq [File] = + if ( start.isFile + ) Seq (start) + else _scan (Seq () ) (start.listFiles ().toSeq) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = + if ( to_scan.isEmpty + ) found + else _tailrec_scan (found.+: (to_scan.head) ) (_get_files_to_scan (to_scan) ) + + private def _scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = + _tailrec_scan (found) (to_scan) + + private def _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = + if ( to_scan.isEmpty + ) to_scan + else _get_files_to_scan_with (to_scan.head) (to_scan.tail) + + private def _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = + if ( to_scan_head.isDirectory + ) to_scan_tail.++ (to_scan_head.listFiles () ) + else to_scan_tail + +} + +case class DirectoryScanner_ () extends DirectoryScanner +trait AbstractDirectoryProcessor +{ + + def start : String + def process_soda_file : java.io.File => Boolean + +} + +case class AbstractDirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends AbstractDirectoryProcessor + +trait DirectoryProcessor + extends + AbstractDirectoryProcessor +{ + + def start : String + def process_soda_file : java.io.File => Boolean + + import java.io.File + + lazy val soda_suffix = ".soda" + + lazy val package_file_name = "Package.soda" + + private lazy val _all_files = + DirectoryScanner_ ().get_all_files ( new File (start)) + + private lazy val _all_soda_files = + _all_files + .filter ( x => x.isFile) + .filter ( x => x.getName.endsWith (soda_suffix)) + + private lazy val _package_files = + _all_files + .filter ( x => x.isFile) + .filter ( x => x.getName == package_file_name) + + private lazy val _soda_non_package_files = + _all_soda_files + .filter ( x => ! (x.getName == package_file_name) ) + + private lazy val _soda_files = + _package_files .++ (_soda_non_package_files) + + private lazy val _lib_files = + _all_files + .filter ( x => x.isFile) + .filter ( file => file.getName == LibraryDeployer_ ().library_marker_file) + + def process () : Boolean = + LibraryDeployer_ ().expand_library (_lib_files) && + _soda_files + .map (process_soda_file) + .forall ( x => x) + +} + +case class DirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends DirectoryProcessor +trait LibraryDeployer +{ + + import java.io.File + + lazy val library_marker_file = "lib.soda" + + private lazy val _library_directory_in_jar = "/lib/soda/lib/" + + private lazy val _library_content_files : Seq [String] = + SimpleFileReader_ () + .read_resource (_library_directory_in_jar + "files.txt") + .split ("\n") + .toSeq + + def expand_library (lib_files : Seq [File] ) : Boolean = + lib_files + .map ( lib_file => lib_file.getParent) + .map ( parent_directory => _expand_files (parent_directory) ) + .forall ( x => x) + + private def _expand_files (parent_directory : String) : Boolean = + _library_content_files + .map ( lib_file_name => + SimpleFileWriter_ ().write_file_with ( + file = SimpleFileWriter_ ().create_file (parent_directory) (lib_file_name) ) ( + content = SimpleFileReader_ ().read_resource (_library_directory_in_jar + lib_file_name) + ) ) + .forall ( x => x) + +} + +case class LibraryDeployer_ () extends LibraryDeployer +/** + * This is an auxiliary class to read small files. + */ + +trait SimpleFileReader +{ + + import java.io.BufferedReader + import java.io.InputStream + import java.io.InputStreamReader + import java.nio.file.Files + import java.nio.file.Paths + import java.util.stream.Collectors + + lazy val new_line = "\n" + + def read_file (file_name : String) : String = + new String (Files.readAllBytes (Paths.get (file_name) ) ) + + def read_resource (file_name : String) : String = + read_input_stream (getClass.getResourceAsStream (file_name) ) + + def read_input_stream (input_stream : InputStream) : String = + _read_reader_content ( new BufferedReader ( new InputStreamReader (input_stream) ) ) + + private def _read_reader_content (reader : BufferedReader) : String = + reader.lines ().collect (Collectors.joining (new_line) ) + +} + +case class SimpleFileReader_ () extends SimpleFileReader + +/** + * This is an auxiliary class to write small files. + */ + +trait SimpleFileWriter +{ + + import soda.lib.SomeSD_ + import java.io.File + import java.io.FileWriter + import java.io.Writer + + def write_file (file_name : String) (content : String) : Boolean = + write_file_with ( new File (file_name) ) (content) + + def write_file_with (file : File) (content : String) : Boolean = + _write_content ( new FileWriter (file , false) ) (content) + + def append_file (file_name : String) (content : String) : Boolean = + append_file_with ( new File (file_name) ) (content) + + def append_file_with (file : File) (content : String) : Boolean = + _write_content ( new FileWriter (file , true) ) (content) + + private def _write_content (writer : Writer) (content : String) : Boolean = + SomeSD_ (true) + .map ( x => writer.write (content) ) + .map ( x => writer.flush () ) + .map ( x => writer.close () ) + .map ( x => true ) + .getOrElse (false) + + def create_file (parent_directory : String) (file_name : String) : File = + new File (parent_directory, file_name) + +} + +case class SimpleFileWriter_ () extends SimpleFileWriter diff --git a/translator/src/main/scala/soda/translator/io/SimpleIO.scala b/translator/src/main/scala/soda/translator/io/SimpleIO.scala deleted file mode 100644 index 8f9f5906..00000000 --- a/translator/src/main/scala/soda/translator/io/SimpleIO.scala +++ /dev/null @@ -1,81 +0,0 @@ -package soda.translator.io - -/* - * This package contains all the classes for I/O communication. - * It is also the entry point for the translator. - */ - - - - - -/** - * This is an auxiliary class to read small files. - */ - -trait SimpleFileReader -{ - - import java.io.BufferedReader - import java.io.InputStream - import java.io.InputStreamReader - import java.nio.file.Files - import java.nio.file.Paths - import java.util.stream.Collectors - - lazy val new_line = "\n" - - def read_file (file_name : String) : String = - new String (Files.readAllBytes (Paths.get (file_name) ) ) - - def read_resource (file_name : String) : String = - read_input_stream (getClass.getResourceAsStream (file_name) ) - - def read_input_stream (input_stream : InputStream) : String = - _read_reader_content ( new BufferedReader ( new InputStreamReader (input_stream) ) ) - - private def _read_reader_content (reader : BufferedReader) : String = - reader.lines ().collect (Collectors.joining (new_line) ) - -} - -case class SimpleFileReader_ () extends SimpleFileReader - -/** - * This is an auxiliary class to write small files. - */ - -trait SimpleFileWriter -{ - - import soda.lib.SomeSD_ - import java.io.File - import java.io.FileWriter - import java.io.Writer - - def write_file (file_name : String) (content : String) : Boolean = - write_file_with ( new File (file_name) ) (content) - - def write_file_with (file : File) (content : String) : Boolean = - _write_content ( new FileWriter (file , false) ) (content) - - def append_file (file_name : String) (content : String) : Boolean = - append_file_with ( new File (file_name) ) (content) - - def append_file_with (file : File) (content : String) : Boolean = - _write_content ( new FileWriter (file , true) ) (content) - - private def _write_content (writer : Writer) (content : String) : Boolean = - SomeSD_ (true) - .map ( x => writer.write (content) ) - .map ( x => writer.flush () ) - .map ( x => writer.close () ) - .map ( x => true ) - .getOrElse (false) - - def create_file (parent_directory : String) (file_name : String) : File = - new File (parent_directory, file_name) - -} - -case class SimpleFileWriter_ () extends SimpleFileWriter diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala b/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala deleted file mode 100644 index 34e90941..00000000 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.scala +++ /dev/null @@ -1,76 +0,0 @@ -package soda.translator.parser - -/* - * This package contains common classes used to describe and parse the Soda language. - */ - - - - - -trait BlockBuilder -{ - - import soda.lib.Fold_ - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedBlock_ - import soda.translator.block.Block - import soda.translator.block.Block_ - - private lazy val _sc = SodaConstant_ () - - private lazy val _fold = Fold_ () - - def build (lines : Seq [String] ) : Block = - Block_ ( - _get_annotated_lines (lines) - ) - - private def _get_annotated_lines (lines : Seq [String] ) : Seq [AnnotatedLine] = - _fold.apply (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) - .annotated_lines_rev - .reverse - - private lazy val _get_annotated_lines_initial_value : PreprocessorFoldTuple = PreprocessorFoldTuple_ (false, Seq () ) - - private def _get_annotated_lines_next_value_function (pair : PreprocessorFoldTuple) (line : String) : PreprocessorFoldTuple = - _get_annotated_lines_next_value_function_with (_annotate_this_line (line) (pair.comment_state) ) (pair) (line) - - private def _get_annotated_lines_next_value_function_with (t : CurrentAndNewCommentState) (pair : PreprocessorFoldTuple) (line : String) : PreprocessorFoldTuple = - PreprocessorFoldTuple_ (t.new_comment_state, pair.annotated_lines_rev.+: (AnnotatedLine_ (line, t.current_state) ) ) - - private def _annotate_this_line (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = - if ( comment_state - ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) - else _annotate_this_line_considering_opening_symbol (line) (comment_state) - - private def _annotate_this_line_considering_opening_symbol (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = - if ( line.trim.startsWith (_sc.comment_opening_symbol) - ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) - else CurrentAndNewCommentState_ (false, false) - -} - -case class BlockBuilder_ () extends BlockBuilder - -trait PreprocessorFoldTuple -{ - - def comment_state : Boolean - def annotated_lines_rev : Seq [soda.translator.block.AnnotatedLine] - -} - -case class PreprocessorFoldTuple_ (comment_state : Boolean, annotated_lines_rev : Seq [soda.translator.block.AnnotatedLine]) extends PreprocessorFoldTuple - -trait CurrentAndNewCommentState -{ - - def current_state : Boolean - def new_comment_state : Boolean - -} - -case class CurrentAndNewCommentState_ (current_state : Boolean, new_comment_state : Boolean) extends CurrentAndNewCommentState diff --git a/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala b/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala deleted file mode 100644 index 0792f797..00000000 --- a/translator/src/main/scala/soda/translator/parser/BlockProcessor.scala +++ /dev/null @@ -1,60 +0,0 @@ -package soda.translator.parser - -/* - * This package contains common classes used to describe and parse the Soda language. - */ - - - - - -/** - * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. - */ - -trait BlockProcessor -{ - - def translator : soda.translator.block.BlockSequenceTranslator - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.annotation.AnnotationFactory_ - - lazy val new_line = "\n" - - lazy val double_new_line = new_line + new_line - - lazy val translator_with_preprocessor = PreprocessorSequenceTranslator_ (translator) - - def translate (program : String) : String = - join_translated_blocks ( - translator_with_preprocessor.translate ( - split_blocks (program) - ) - ) - - def split_blocks (program : String) : Seq [AnnotatedBlock] = - program - .split (double_new_line) - .toIndexedSeq - .map ( paragraph => make_block (paragraph) ) - - def make_block (paragraph : String) : AnnotatedBlock = - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - remove_empty_lines (paragraph.split (new_line).toIndexedSeq) - ) - ) - - def join_translated_blocks (blocks : Seq [AnnotatedBlock] ) : String = - blocks - .map ( x => x.contents) - .mkString (double_new_line) + new_line - - def remove_empty_lines (lines : Seq [String] ) : Seq [String] = - lines - .filter ( line => line.trim.nonEmpty) - -} - -case class BlockProcessor_ (translator : soda.translator.block.BlockSequenceTranslator) extends BlockProcessor diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index a0c3ba4f..89192dbe 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -7,3 +7,391 @@ package soda.translator.parser trait Package +trait BlockBuilder +{ + + import soda.lib.Fold_ + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedBlock_ + import soda.translator.block.Block + import soda.translator.block.Block_ + + private lazy val _sc = SodaConstant_ () + + private lazy val _fold = Fold_ () + + def build (lines : Seq [String] ) : Block = + Block_ ( + _get_annotated_lines (lines) + ) + + private def _get_annotated_lines (lines : Seq [String] ) : Seq [AnnotatedLine] = + _fold.apply (lines) (_get_annotated_lines_initial_value) (_get_annotated_lines_next_value_function) + .annotated_lines_rev + .reverse + + private lazy val _get_annotated_lines_initial_value : PreprocessorFoldTuple = PreprocessorFoldTuple_ (false, Seq () ) + + private def _get_annotated_lines_next_value_function (pair : PreprocessorFoldTuple) (line : String) : PreprocessorFoldTuple = + _get_annotated_lines_next_value_function_with (_annotate_this_line (line) (pair.comment_state) ) (pair) (line) + + private def _get_annotated_lines_next_value_function_with (t : CurrentAndNewCommentState) (pair : PreprocessorFoldTuple) (line : String) : PreprocessorFoldTuple = + PreprocessorFoldTuple_ (t.new_comment_state, pair.annotated_lines_rev.+: (AnnotatedLine_ (line, t.current_state) ) ) + + private def _annotate_this_line (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = + if ( comment_state + ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) + else _annotate_this_line_considering_opening_symbol (line) (comment_state) + + private def _annotate_this_line_considering_opening_symbol (line : String) (comment_state : Boolean) : CurrentAndNewCommentState = + if ( line.trim.startsWith (_sc.comment_opening_symbol) + ) CurrentAndNewCommentState_ (true, ! line.trim.endsWith (_sc.comment_closing_symbol) ) + else CurrentAndNewCommentState_ (false, false) + +} + +case class BlockBuilder_ () extends BlockBuilder + +trait PreprocessorFoldTuple +{ + + def comment_state : Boolean + def annotated_lines_rev : Seq [soda.translator.block.AnnotatedLine] + +} + +case class PreprocessorFoldTuple_ (comment_state : Boolean, annotated_lines_rev : Seq [soda.translator.block.AnnotatedLine]) extends PreprocessorFoldTuple + +trait CurrentAndNewCommentState +{ + + def current_state : Boolean + def new_comment_state : Boolean + +} + +case class CurrentAndNewCommentState_ (current_state : Boolean, new_comment_state : Boolean) extends CurrentAndNewCommentState +trait SodaConstant +{ + + lazy val space = " " + + lazy val new_line = "\n" + + lazy val function_definition_symbol = "=" + + lazy val type_membership_symbol = ":" + + lazy val function_arrow_symbol = "->" + + lazy val lambda_arrow_symbol = "-->" + + lazy val case_arrow_symbol = "==>" + + lazy val parameter_definition_symbol = ":=" + + lazy val lambda_reserved_word = "lambda" + + lazy val any_reserved_word = "any" + + lazy val if_reserved_word = "if" + + lazy val then_reserved_word = "then" + + lazy val else_reserved_word = "else" + + lazy val match_reserved_word = "match" + + lazy val case_reserved_word = "case" + + lazy val class_reserved_word = "class" + + lazy val extends_reserved_word = "extends" + + lazy val abstract_reserved_word = "abstract" + + lazy val class_end_reserved_word = "end" + + lazy val this_reserved_word = "this" + + lazy val subtype_reserved_word = "subtype" + + lazy val supertype_reserved_word = "supertype" + + lazy val false_reserved_word = "false" + + lazy val true_reserved_word = "true" + + lazy val not_reserved_word = "not" + + lazy val and_reserved_word = "and" + + lazy val or_reserved_word = "or" + + lazy val package_reserved_word = "package" + + lazy val import_reserved_word = "import" + + lazy val theorem_reserved_word = "theorem" + + lazy val proof_reserved_word = "proof" + + lazy val constructor_suffix = "_" + + lazy val test_special_function = "test" + + lazy val subtype_abbreviation = "<:" + + lazy val supertype_abbreviation = ">:" + + lazy val opening_parenthesis_symbol = "(" + + lazy val closing_parenthesis_symbol = ")" + + lazy val opening_bracket_symbol = "[" + + lazy val closing_bracket_symbol = "]" + + lazy val parameter_separator_symbol = "," + + lazy val addition_symbol = "+" + + lazy val subtraction_symbol = "-" + + lazy val multiplication_symbol = "*" + + lazy val division_symbol = "/" + + lazy val modulo_symbol = "%" + + lazy val documentation_comment_opening_symbol = "/**" + + lazy val comment_opening_symbol = "/*" + + lazy val comment_closing_symbol = "*/" + + lazy val comment_line_symbol = "*" + + lazy val tail_recursion_annotation = "@tailrec" + + lazy val override_annotation = "@override" + + lazy val new_annotation = "@new" + + lazy val private_function_prefix = "_" + + lazy val soda_reserved_words_words_only : Seq [String] = + Seq ( + lambda_reserved_word, + any_reserved_word, + if_reserved_word, + then_reserved_word, + else_reserved_word, + match_reserved_word, + case_reserved_word, + class_reserved_word, + extends_reserved_word, + abstract_reserved_word, + class_end_reserved_word, + this_reserved_word, + subtype_reserved_word, + supertype_reserved_word, + false_reserved_word, + true_reserved_word, + not_reserved_word, + and_reserved_word, + or_reserved_word, + package_reserved_word, + import_reserved_word, + theorem_reserved_word, + proof_reserved_word + ) + + lazy val soda_reserved_words_symbols_only : Seq [String] = + Seq ( + function_definition_symbol, + type_membership_symbol, + function_arrow_symbol, + case_arrow_symbol, + parameter_definition_symbol, + addition_symbol, + subtraction_symbol, + multiplication_symbol, + division_symbol, + modulo_symbol, + subtype_abbreviation, + supertype_abbreviation + ) + + lazy val soda_reserved_words_annotations_only : Seq [String] = + Seq ( + tail_recursion_annotation, + override_annotation, + new_annotation + ) + + lazy val soda_reserved_words : Seq [String] = + soda_reserved_words_words_only.++ (soda_reserved_words_symbols_only.++ (soda_reserved_words_annotations_only) ) + +} + +case class SodaConstant_ () extends SodaConstant +trait PreprocessorSequenceTranslator + extends + soda.translator.block.BlockSequenceTranslator +{ + + def translator : soda.translator.block.BlockSequenceTranslator + + import soda.lib.Fold_ + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + lazy val block_annotator = AnnotationFactory_ () + + lazy val ba = soda.translator.block.BlockAnnotationEnum_ () + + lazy val sc = SodaConstant_ () + + private lazy val _fold = Fold_ () + + lazy val empty_line = AnnotatedLine_ ("", true) + + lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = + block_sequence => + translate_for (block_sequence) + + def translate_for (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + translator.translate ( + _get_second_pass ( + _get_first_pass (block_sequence) + ) + ) + + private def _get_first_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + block_sequence.map ( block => block_annotator.translate (block) ) + + private def _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) + .accumulated + .reverse + + private def _get_second_pass_initial_value (block_sequence : Seq [AnnotatedBlock] ) : AuxiliaryTuple = + AuxiliaryTuple_ ( + block_sequence = block_sequence, + accumulated = Seq [AnnotatedBlock] (), + references = Seq [Seq [AnnotatedBlock] ] () + ) + + private def _get_second_pass_next_value_function (current : AuxiliaryTuple) (index : Int) : AuxiliaryTuple = + _pass_next_step (current) (index) (_get_additional_information (current) (index) ) + + private def _get_additional_information (current : AuxiliaryTuple) (index : Int) : AnnotatedBlock = + current.block_sequence.apply (index) match { + case AbstractDeclarationAnnotation_ (block, references) => _get_abstract_declaration_updated_block (current) (AbstractDeclarationAnnotation_ (block, references) ) + case ClassEndAnnotation_ (block, references) => _get_class_end_updated_block (current) (ClassEndAnnotation_ (block, references) ) + case x => x + } + + private def _get_abstract_declaration_updated_block (current : AuxiliaryTuple) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) + + private def _get_class_end_updated_block (current : AuxiliaryTuple) (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) + + private def _pass_next_step (current : AuxiliaryTuple) (index : Int) (updated_block : AnnotatedBlock ) : AuxiliaryTuple = + AuxiliaryTuple_ ( + block_sequence = current.block_sequence, + accumulated = current.accumulated.+: (updated_block), + references = _update_references (current) (index) + ) + + private def _update_references (current : AuxiliaryTuple) (index : Int) : Seq [Seq [AnnotatedBlock] ] = + current.block_sequence.apply (index) match { + case ClassBeginningAnnotation_ (b) => current.references.+: (Seq [AnnotatedBlock] (ClassBeginningAnnotation_ (b) ) ) + case AbstractDeclarationAnnotation_ (b, references) => _update_first_element (current.references) (AbstractDeclarationAnnotation_ (b, references) ) + case ClassEndAnnotation_ (b, references) => _tail_non_empty (current.references) + case x => current.references + } + + private def _update_first_element (s : Seq [Seq [AnnotatedBlock] ] ) (b : AnnotatedBlock) : Seq [Seq [AnnotatedBlock] ] = + _tail_non_empty (s).+: (s.headOption.getOrElse (Seq [AnnotatedBlock] () ).+: (b) ) + + private def _tail_non_empty [A] (s : Seq [A] ) : Seq [A] = + if ( s.isEmpty + ) s + else s.tail + +} + +case class PreprocessorSequenceTranslator_ (translator : soda.translator.block.BlockSequenceTranslator) extends PreprocessorSequenceTranslator + +trait AuxiliaryTuple +{ + + def block_sequence : Seq [soda.translator.block.AnnotatedBlock] + def accumulated : Seq [soda.translator.block.AnnotatedBlock] + def references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ] + +} + +case class AuxiliaryTuple_ (block_sequence : Seq [soda.translator.block.AnnotatedBlock], accumulated : Seq [soda.translator.block.AnnotatedBlock], references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ]) extends AuxiliaryTuple +/** + * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. + */ + +trait BlockProcessor +{ + + def translator : soda.translator.block.BlockSequenceTranslator + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.annotation.AnnotationFactory_ + + lazy val new_line = "\n" + + lazy val double_new_line = new_line + new_line + + lazy val translator_with_preprocessor = PreprocessorSequenceTranslator_ (translator) + + def translate (program : String) : String = + join_translated_blocks ( + translator_with_preprocessor.translate ( + split_blocks (program) + ) + ) + + def split_blocks (program : String) : Seq [AnnotatedBlock] = + program + .split (double_new_line) + .toIndexedSeq + .map ( paragraph => make_block (paragraph) ) + + def make_block (paragraph : String) : AnnotatedBlock = + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + remove_empty_lines (paragraph.split (new_line).toIndexedSeq) + ) + ) + + def join_translated_blocks (blocks : Seq [AnnotatedBlock] ) : String = + blocks + .map ( x => x.contents) + .mkString (double_new_line) + new_line + + def remove_empty_lines (lines : Seq [String] ) : Seq [String] = + lines + .filter ( line => line.trim.nonEmpty) + +} + +case class BlockProcessor_ (translator : soda.translator.block.BlockSequenceTranslator) extends BlockProcessor diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala deleted file mode 100644 index b5f57acb..00000000 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.scala +++ /dev/null @@ -1,117 +0,0 @@ -package soda.translator.parser - -/* - * This package contains common classes used to describe and parse the Soda language. - */ - - - - - -trait PreprocessorSequenceTranslator - extends - soda.translator.block.BlockSequenceTranslator -{ - - def translator : soda.translator.block.BlockSequenceTranslator - - import soda.lib.Fold_ - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.annotation.AnnotationFactory_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - lazy val block_annotator = AnnotationFactory_ () - - lazy val ba = soda.translator.block.BlockAnnotationEnum_ () - - lazy val sc = SodaConstant_ () - - private lazy val _fold = Fold_ () - - lazy val empty_line = AnnotatedLine_ ("", true) - - lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = - block_sequence => - translate_for (block_sequence) - - def translate_for (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - translator.translate ( - _get_second_pass ( - _get_first_pass (block_sequence) - ) - ) - - private def _get_first_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - block_sequence.map ( block => block_annotator.translate (block) ) - - private def _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) - .accumulated - .reverse - - private def _get_second_pass_initial_value (block_sequence : Seq [AnnotatedBlock] ) : AuxiliaryTuple = - AuxiliaryTuple_ ( - block_sequence = block_sequence, - accumulated = Seq [AnnotatedBlock] (), - references = Seq [Seq [AnnotatedBlock] ] () - ) - - private def _get_second_pass_next_value_function (current : AuxiliaryTuple) (index : Int) : AuxiliaryTuple = - _pass_next_step (current) (index) (_get_additional_information (current) (index) ) - - private def _get_additional_information (current : AuxiliaryTuple) (index : Int) : AnnotatedBlock = - current.block_sequence.apply (index) match { - case AbstractDeclarationAnnotation_ (block, references) => _get_abstract_declaration_updated_block (current) (AbstractDeclarationAnnotation_ (block, references) ) - case ClassEndAnnotation_ (block, references) => _get_class_end_updated_block (current) (ClassEndAnnotation_ (block, references) ) - case x => x - } - - private def _get_abstract_declaration_updated_block (current : AuxiliaryTuple) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) - - private def _get_class_end_updated_block (current : AuxiliaryTuple) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) - - private def _pass_next_step (current : AuxiliaryTuple) (index : Int) (updated_block : AnnotatedBlock ) : AuxiliaryTuple = - AuxiliaryTuple_ ( - block_sequence = current.block_sequence, - accumulated = current.accumulated.+: (updated_block), - references = _update_references (current) (index) - ) - - private def _update_references (current : AuxiliaryTuple) (index : Int) : Seq [Seq [AnnotatedBlock] ] = - current.block_sequence.apply (index) match { - case ClassBeginningAnnotation_ (b) => current.references.+: (Seq [AnnotatedBlock] (ClassBeginningAnnotation_ (b) ) ) - case AbstractDeclarationAnnotation_ (b, references) => _update_first_element (current.references) (AbstractDeclarationAnnotation_ (b, references) ) - case ClassEndAnnotation_ (b, references) => _tail_non_empty (current.references) - case x => current.references - } - - private def _update_first_element (s : Seq [Seq [AnnotatedBlock] ] ) (b : AnnotatedBlock) : Seq [Seq [AnnotatedBlock] ] = - _tail_non_empty (s).+: (s.headOption.getOrElse (Seq [AnnotatedBlock] () ).+: (b) ) - - private def _tail_non_empty [A] (s : Seq [A] ) : Seq [A] = - if ( s.isEmpty - ) s - else s.tail - -} - -case class PreprocessorSequenceTranslator_ (translator : soda.translator.block.BlockSequenceTranslator) extends PreprocessorSequenceTranslator - -trait AuxiliaryTuple -{ - - def block_sequence : Seq [soda.translator.block.AnnotatedBlock] - def accumulated : Seq [soda.translator.block.AnnotatedBlock] - def references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ] - -} - -case class AuxiliaryTuple_ (block_sequence : Seq [soda.translator.block.AnnotatedBlock], accumulated : Seq [soda.translator.block.AnnotatedBlock], references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ]) extends AuxiliaryTuple diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala b/translator/src/main/scala/soda/translator/parser/SodaConstant.scala deleted file mode 100644 index f3bbbc5f..00000000 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.scala +++ /dev/null @@ -1,175 +0,0 @@ -package soda.translator.parser - -/* - * This package contains common classes used to describe and parse the Soda language. - */ - - - - - -trait SodaConstant -{ - - lazy val space = " " - - lazy val new_line = "\n" - - lazy val function_definition_symbol = "=" - - lazy val type_membership_symbol = ":" - - lazy val function_arrow_symbol = "->" - - lazy val lambda_arrow_symbol = "-->" - - lazy val case_arrow_symbol = "==>" - - lazy val parameter_definition_symbol = ":=" - - lazy val lambda_reserved_word = "lambda" - - lazy val any_reserved_word = "any" - - lazy val if_reserved_word = "if" - - lazy val then_reserved_word = "then" - - lazy val else_reserved_word = "else" - - lazy val match_reserved_word = "match" - - lazy val case_reserved_word = "case" - - lazy val class_reserved_word = "class" - - lazy val extends_reserved_word = "extends" - - lazy val abstract_reserved_word = "abstract" - - lazy val class_end_reserved_word = "end" - - lazy val this_reserved_word = "this" - - lazy val subtype_reserved_word = "subtype" - - lazy val supertype_reserved_word = "supertype" - - lazy val false_reserved_word = "false" - - lazy val true_reserved_word = "true" - - lazy val not_reserved_word = "not" - - lazy val and_reserved_word = "and" - - lazy val or_reserved_word = "or" - - lazy val package_reserved_word = "package" - - lazy val import_reserved_word = "import" - - lazy val theorem_reserved_word = "theorem" - - lazy val proof_reserved_word = "proof" - - lazy val constructor_suffix = "_" - - lazy val test_special_function = "test" - - lazy val subtype_abbreviation = "<:" - - lazy val supertype_abbreviation = ">:" - - lazy val opening_parenthesis_symbol = "(" - - lazy val closing_parenthesis_symbol = ")" - - lazy val opening_bracket_symbol = "[" - - lazy val closing_bracket_symbol = "]" - - lazy val parameter_separator_symbol = "," - - lazy val addition_symbol = "+" - - lazy val subtraction_symbol = "-" - - lazy val multiplication_symbol = "*" - - lazy val division_symbol = "/" - - lazy val modulo_symbol = "%" - - lazy val documentation_comment_opening_symbol = "/**" - - lazy val comment_opening_symbol = "/*" - - lazy val comment_closing_symbol = "*/" - - lazy val comment_line_symbol = "*" - - lazy val tail_recursion_annotation = "@tailrec" - - lazy val override_annotation = "@override" - - lazy val new_annotation = "@new" - - lazy val private_function_prefix = "_" - - lazy val soda_reserved_words_words_only : Seq [String] = - Seq ( - lambda_reserved_word, - any_reserved_word, - if_reserved_word, - then_reserved_word, - else_reserved_word, - match_reserved_word, - case_reserved_word, - class_reserved_word, - extends_reserved_word, - abstract_reserved_word, - class_end_reserved_word, - this_reserved_word, - subtype_reserved_word, - supertype_reserved_word, - false_reserved_word, - true_reserved_word, - not_reserved_word, - and_reserved_word, - or_reserved_word, - package_reserved_word, - import_reserved_word, - theorem_reserved_word, - proof_reserved_word - ) - - lazy val soda_reserved_words_symbols_only : Seq [String] = - Seq ( - function_definition_symbol, - type_membership_symbol, - function_arrow_symbol, - case_arrow_symbol, - parameter_definition_symbol, - addition_symbol, - subtraction_symbol, - multiplication_symbol, - division_symbol, - modulo_symbol, - subtype_abbreviation, - supertype_abbreviation - ) - - lazy val soda_reserved_words_annotations_only : Seq [String] = - Seq ( - tail_recursion_annotation, - override_annotation, - new_annotation - ) - - lazy val soda_reserved_words : Seq [String] = - soda_reserved_words_words_only.++ (soda_reserved_words_symbols_only.++ (soda_reserved_words_annotations_only) ) - -} - -case class SodaConstant_ () extends SodaConstant diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala deleted file mode 100644 index 361c4db6..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/AbstractDeclarationAnnotation.scala +++ /dev/null @@ -1,36 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait AbstractDeclarationAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - def references : Seq [soda.translator.block.AnnotatedBlock] - - import soda.translator.block.AnnotatedLine - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().abstract_declaration - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().abstract_reserved_word) - - lazy val abstract_functions_with_comments : Seq [AnnotatedLine] = - content_lines - - lazy val abstract_functions : Seq [AnnotatedLine] = - abstract_functions_with_comments - .filter ( line => ! line.is_comment) - -} - -case class AbstractDeclarationAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends AbstractDeclarationAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala b/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala deleted file mode 100644 index 1c9de9ca..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/AnnotationFactory.scala +++ /dev/null @@ -1,76 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait AnnotationFactory - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedBlock_ - import soda.translator.block.Block - import soda.translator.block.BlockAnnotationEnum_ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) - - def translate_for (block : AnnotatedBlock) : AnnotatedBlock = - if ( block.block_annotation == BlockAnnotationEnum_ ().undefined - ) annotate (block) - else block - - def annotate (block : Block) : AnnotatedBlock = - block match { - case AnnotatedBlock_ (annotated_lines, block_annotation) => AnnotatedBlock_ (annotated_lines, block_annotation) - case x => _get_first_or_undefined (_find_candidates (x) ) (x) - } - - def update_block (original_content : AnnotatedBlock) (new_content : Block) : AnnotatedBlock = - original_content match { - case FunctionDefinitionAnnotation_ (b) => FunctionDefinitionAnnotation_ (new_content) - case ClassBeginningAnnotation_ (b) => ClassBeginningAnnotation_ (new_content) - case ClassEndAnnotation_ (b, references) => ClassEndAnnotation_ (new_content, references) - case AbstractDeclarationAnnotation_ (b, references) => AbstractDeclarationAnnotation_ (new_content, references) - case ImportDeclarationAnnotation_ (b) => ImportDeclarationAnnotation_ (new_content) - case PackageDeclarationAnnotation_ (b) => PackageDeclarationAnnotation_ (new_content) - case ClassAliasAnnotation_ (b) => ClassAliasAnnotation_ (new_content) - case TheoremBlockAnnotation_ (b) => TheoremBlockAnnotation_ (new_content) - case ProofBlockAnnotation_ (b) => ProofBlockAnnotation_ (new_content) - case CommentAnnotation_ (b) => CommentAnnotation_ (new_content) - case TestDeclarationAnnotation_ (b) => TestDeclarationAnnotation_ (new_content) - case x => AnnotatedBlock_ (new_content.annotated_lines, x.block_annotation) - } - - private def _detectors (block : Block) : Seq [BlockAnnotationParser] = - Seq ( - FunctionDefinitionAnnotation_ (block), - ClassBeginningAnnotation_ (block), - ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), - AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), - ImportDeclarationAnnotation_ (block), - PackageDeclarationAnnotation_ (block), - ClassAliasAnnotation_ (block), - TheoremBlockAnnotation_ (block), - ProofBlockAnnotation_ (block), - CommentAnnotation_ (block), - TestDeclarationAnnotation_ (block) - ) - - private def _find_candidates (block : Block) : Seq [BlockAnnotationParser] = - _detectors (block) - .filter ( detector => detector.applies) - - private def _get_first_or_undefined (candidates : Seq [BlockAnnotationParser] ) (block : Block) : AnnotatedBlock = - if ( candidates.length == 1 - ) candidates.head - else AnnotatedBlock_ (block.annotated_lines, BlockAnnotationEnum_ ().undefined ) - -} - -case class AnnotationFactory_ () extends AnnotationFactory diff --git a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala b/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala deleted file mode 100644 index 1214cc1f..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/BlockAnnotationParser.scala +++ /dev/null @@ -1,66 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait BlockAnnotationParser - extends - soda.translator.block.AnnotatedBlock -{ - - def block : soda.translator.block.Block - def applies : Boolean - def identifier : soda.translator.block.BlockAnnotationId - - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block - import soda.translator.block.BlockAnnotationId - import soda.translator.parser.SodaConstant_ - - lazy val space = SodaConstant_ ().space - - lazy val default_annotated_line = AnnotatedLine_ ("", true) - - lazy val annotated_lines : Seq [AnnotatedLine] = block.annotated_lines - - lazy val block_annotation : BlockAnnotationId = identifier - - def starts_with_prefix_and_space (prefix : String) : Boolean = - block.readable_lines.nonEmpty && - block.readable_lines.head.line.trim.startsWith (prefix + space) - - lazy val content_lines : Seq [AnnotatedLine] = - if ( block.readable_lines.isEmpty - ) block.annotated_lines - else - block - .annotated_lines - .tail - .filter ( x => ! x.line.trim.isEmpty) - - lazy val first_readable_line : AnnotatedLine = - block.readable_lines.headOption.getOrElse (default_annotated_line) - - def get_first_word (line : String) : String = - (_get_first_word_with (line.trim.indexOf (space) ) (line) ).trim - - private def _get_first_word_with (index : Int) (line : String) : String = - if ( index >= 0 - ) line.substring (0, index) - else line - - def skip_first_word (line : String) : String = - (_skip_first_word_with (line.trim.indexOf (space) ) (line) ).trim - - private def _skip_first_word_with (index : Int) (line : String) : String = - if ( index >= 0 - ) line.trim.substring (index) - else "" - -} - -case class BlockAnnotationParser_ (block : soda.translator.block.Block, applies : Boolean, identifier : soda.translator.block.BlockAnnotationId) extends BlockAnnotationParser diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala deleted file mode 100644 index 43b9a4c0..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassAliasAnnotation.scala +++ /dev/null @@ -1,32 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait ClassAliasAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().class_alias - - lazy val sc = SodaConstant_ () - - lazy val applies : Boolean = - starts_with_prefix_and_space (sc.class_reserved_word) && - _contains_the_equals_symbol - - private lazy val _contains_the_equals_symbol : Boolean = - FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol - -} - -case class ClassAliasAnnotation_ (block : soda.translator.block.Block) extends ClassAliasAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala deleted file mode 100644 index 6203ee8e..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassBeginningAnnotation.scala +++ /dev/null @@ -1,63 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait ClassBeginningAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().class_beginning - - lazy val sc = SodaConstant_ () - - lazy val applies : Boolean = - starts_with_prefix_and_space (sc.class_reserved_word) && - ! _contains_the_equals_symbol - - private lazy val _contains_the_equals_symbol : Boolean = - FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol - - private lazy val _contains_an_opening_parenthesis : Boolean = - first_readable_line.line.contains (sc.opening_parenthesis_symbol) - - private lazy val _class_name_and_type_parameters : String = - skip_first_word (first_readable_line.line) - - lazy val class_name : String = - get_first_word (_class_name_and_type_parameters) - - lazy val type_parameters_and_bounds : Seq [String] = - remove_brackets (skip_first_word (_class_name_and_type_parameters) ) - .split (sc.parameter_separator_symbol) - .toIndexedSeq - .map ( parameter => parameter.trim) - .filter ( parameter => ! parameter.isEmpty) - - lazy val type_parameters : Seq [String] = - type_parameters_and_bounds - .map ( parameter => get_first_word (parameter) ) - - def remove_brackets (text : String) : String = - remove_brackets_with (text.trim) - - def remove_brackets_with (trimmed_text : String) : String = - if ( trimmed_text.startsWith (sc.opening_bracket_symbol) && - trimmed_text.endsWith (sc.closing_bracket_symbol) - ) trimmed_text.substring (sc.opening_bracket_symbol.length, trimmed_text.length - sc.closing_bracket_symbol.length) - else trimmed_text - - lazy val is_concrete : Boolean = applies && _contains_an_opening_parenthesis - -} - -case class ClassBeginningAnnotation_ (block : soda.translator.block.Block) extends ClassBeginningAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala deleted file mode 100644 index 94395826..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/ClassEndAnnotation.scala +++ /dev/null @@ -1,28 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait ClassEndAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - def references : Seq [soda.translator.block.AnnotatedBlock] - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().class_end - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().class_end_reserved_word) - -} - -case class ClassEndAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends ClassEndAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala deleted file mode 100644 index f24acf94..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/CommentAnnotation.scala +++ /dev/null @@ -1,27 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait CommentAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - - lazy val identifier = BlockAnnotationEnum_ ().comment - - lazy val applies : Boolean = - block - .annotated_lines - .forall ( annotated_line => annotated_line.is_comment) - -} - -case class CommentAnnotation_ (block : soda.translator.block.Block) extends CommentAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala deleted file mode 100644 index a9629540..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/FunctionDefinitionAnnotation.scala +++ /dev/null @@ -1,83 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait FunctionDefinitionAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - import soda.translator.replacement.ParserStateEnum_ - import soda.translator.replacement.Tokenizer_ - - lazy val identifier = BlockAnnotationEnum_ ().function_definition - - lazy val sc = SodaConstant_ () - - private lazy val _symbol_at_the_end : String = - sc.space + - sc.function_definition_symbol - - private lazy val _symbol_in_the_middle : String = - sc.space + - sc.function_definition_symbol + - sc.space - - private lazy val _plain_state = ParserStateEnum_ ().plain - - lazy val applies : Boolean = - ! is_a_theorem && - ! is_a_proof && - ! is_a_class_declaration && - (contains_the_equals_symbol || _starts_with_valid_annotation) - - lazy val contains_the_equals_symbol : Boolean = - block.readable_lines.nonEmpty && - block.readable_lines - .filter ( annotated_line => ! annotated_line.is_comment) - .exists ( annotated_line => _contains_the_equals_symbol_in_line (annotated_line.line) ) - - private def _contains_the_equals_symbol_in_line (line : String) : Boolean = - Tokenizer_ (line) - .tokens - .exists ( token => - token.parser_state == _plain_state && - _contains_the_equals_symbol_in_token (token.text) - ) - - private def _contains_the_equals_symbol_in_token (token_text : String) : Boolean = - ( - (token_text.contains (_symbol_in_the_middle) ) || - (token_text.endsWith (_symbol_at_the_end) ) - ) - - private lazy val _starts_with_valid_annotation : Boolean = - block.readable_lines.nonEmpty && - _starts_with_valid_annotation_with (block.readable_lines.head.line.trim) - - private def _starts_with_valid_annotation_with (first_line_trimmed : String) : Boolean = - ( first_line_trimmed == sc.tail_recursion_annotation || - first_line_trimmed == sc.override_annotation ) - - lazy val is_a_class_declaration : Boolean = - starts_with_prefix_and_space (sc.class_reserved_word) - - lazy val is_a_theorem : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) - - lazy val is_a_proof : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) - -} - -case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala deleted file mode 100644 index 97226962..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/ImportDeclarationAnnotation.scala +++ /dev/null @@ -1,31 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait ImportDeclarationAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.AnnotatedLine - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().import_declaration - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().import_reserved_word) - - lazy val imported_items : Seq [AnnotatedLine] = - content_lines - -} - -case class ImportDeclarationAnnotation_ (block : soda.translator.block.Block) extends ImportDeclarationAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala index 780ffea8..5a541d9d 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -5,3 +5,447 @@ package soda.translator.parser.annotation */ trait Package +trait ProofBlockAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().proof_block + + lazy val applies : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) + +} + +case class ProofBlockAnnotation_ (block : soda.translator.block.Block) extends ProofBlockAnnotation +trait FunctionDefinitionAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + import soda.translator.replacement.ParserStateEnum_ + import soda.translator.replacement.Tokenizer_ + + lazy val identifier = BlockAnnotationEnum_ ().function_definition + + lazy val sc = SodaConstant_ () + + private lazy val _symbol_at_the_end : String = + sc.space + + sc.function_definition_symbol + + private lazy val _symbol_in_the_middle : String = + sc.space + + sc.function_definition_symbol + + sc.space + + private lazy val _plain_state = ParserStateEnum_ ().plain + + lazy val applies : Boolean = + ! is_a_theorem && + ! is_a_proof && + ! is_a_class_declaration && + (contains_the_equals_symbol || _starts_with_valid_annotation) + + lazy val contains_the_equals_symbol : Boolean = + block.readable_lines.nonEmpty && + block.readable_lines + .filter ( annotated_line => ! annotated_line.is_comment) + .exists ( annotated_line => _contains_the_equals_symbol_in_line (annotated_line.line) ) + + private def _contains_the_equals_symbol_in_line (line : String) : Boolean = + Tokenizer_ (line) + .tokens + .exists ( token => + token.parser_state == _plain_state && + _contains_the_equals_symbol_in_token (token.text) + ) + + private def _contains_the_equals_symbol_in_token (token_text : String) : Boolean = + ( + (token_text.contains (_symbol_in_the_middle) ) || + (token_text.endsWith (_symbol_at_the_end) ) + ) + + private lazy val _starts_with_valid_annotation : Boolean = + block.readable_lines.nonEmpty && + _starts_with_valid_annotation_with (block.readable_lines.head.line.trim) + + private def _starts_with_valid_annotation_with (first_line_trimmed : String) : Boolean = + ( first_line_trimmed == sc.tail_recursion_annotation || + first_line_trimmed == sc.override_annotation ) + + lazy val is_a_class_declaration : Boolean = + starts_with_prefix_and_space (sc.class_reserved_word) + + lazy val is_a_theorem : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + + lazy val is_a_proof : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) + +} + +case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation +trait ImportDeclarationAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.AnnotatedLine + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().import_declaration + + lazy val applies : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().import_reserved_word) + + lazy val imported_items : Seq [AnnotatedLine] = + content_lines + +} + +case class ImportDeclarationAnnotation_ (block : soda.translator.block.Block) extends ImportDeclarationAnnotation +trait PackageDeclarationAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().package_declaration + + lazy val applies : Boolean = + starts_with_prefix_and_space (SodaConstant_ ().package_reserved_word) + +} + +case class PackageDeclarationAnnotation_ (block : soda.translator.block.Block) extends PackageDeclarationAnnotation +trait BlockAnnotationParser + extends + soda.translator.block.AnnotatedBlock +{ + + def block : soda.translator.block.Block + def applies : Boolean + def identifier : soda.translator.block.BlockAnnotationId + + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.block.BlockAnnotationId + import soda.translator.parser.SodaConstant_ + + lazy val space = SodaConstant_ ().space + + lazy val default_annotated_line = AnnotatedLine_ ("", true) + + lazy val annotated_lines : Seq [AnnotatedLine] = block.annotated_lines + + lazy val block_annotation : BlockAnnotationId = identifier + + def starts_with_prefix_and_space (prefix : String) : Boolean = + block.readable_lines.nonEmpty && + block.readable_lines.head.line.trim.startsWith (prefix + space) + + lazy val content_lines : Seq [AnnotatedLine] = + if ( block.readable_lines.isEmpty + ) block.annotated_lines + else + block + .annotated_lines + .tail + .filter ( x => ! x.line.trim.isEmpty) + + lazy val first_readable_line : AnnotatedLine = + block.readable_lines.headOption.getOrElse (default_annotated_line) + + def get_first_word (line : String) : String = + (_get_first_word_with (line.trim.indexOf (space) ) (line) ).trim + + private def _get_first_word_with (index : Int) (line : String) : String = + if ( index >= 0 + ) line.substring (0, index) + else line + + def skip_first_word (line : String) : String = + (_skip_first_word_with (line.trim.indexOf (space) ) (line) ).trim + + private def _skip_first_word_with (index : Int) (line : String) : String = + if ( index >= 0 + ) line.trim.substring (index) + else "" + +} + +case class BlockAnnotationParser_ (block : soda.translator.block.Block, applies : Boolean, identifier : soda.translator.block.BlockAnnotationId) extends BlockAnnotationParser +trait ClassBeginningAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().class_beginning + + lazy val sc = SodaConstant_ () + + lazy val applies : Boolean = + starts_with_prefix_and_space (sc.class_reserved_word) && + ! _contains_the_equals_symbol + + private lazy val _contains_the_equals_symbol : Boolean = + FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol + + private lazy val _contains_an_opening_parenthesis : Boolean = + first_readable_line.line.contains (sc.opening_parenthesis_symbol) + + private lazy val _class_name_and_type_parameters : String = + skip_first_word (first_readable_line.line) + + lazy val class_name : String = + get_first_word (_class_name_and_type_parameters) + + lazy val type_parameters_and_bounds : Seq [String] = + remove_brackets (skip_first_word (_class_name_and_type_parameters) ) + .split (sc.parameter_separator_symbol) + .toIndexedSeq + .map ( parameter => parameter.trim) + .filter ( parameter => ! parameter.isEmpty) + + lazy val type_parameters : Seq [String] = + type_parameters_and_bounds + .map ( parameter => get_first_word (parameter) ) + + def remove_brackets (text : String) : String = + remove_brackets_with (text.trim) + + def remove_brackets_with (trimmed_text : String) : String = + if ( trimmed_text.startsWith (sc.opening_bracket_symbol) && + trimmed_text.endsWith (sc.closing_bracket_symbol) + ) trimmed_text.substring (sc.opening_bracket_symbol.length, trimmed_text.length - sc.closing_bracket_symbol.length) + else trimmed_text + + lazy val is_concrete : Boolean = applies && _contains_an_opening_parenthesis + +} + +case class ClassBeginningAnnotation_ (block : soda.translator.block.Block) extends ClassBeginningAnnotation +trait AbstractDeclarationAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + def references : Seq [soda.translator.block.AnnotatedBlock] + + import soda.translator.block.AnnotatedLine + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().abstract_declaration + + lazy val applies : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().abstract_reserved_word) + + lazy val abstract_functions_with_comments : Seq [AnnotatedLine] = + content_lines + + lazy val abstract_functions : Seq [AnnotatedLine] = + abstract_functions_with_comments + .filter ( line => ! line.is_comment) + +} + +case class AbstractDeclarationAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends AbstractDeclarationAnnotation +trait ClassAliasAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().class_alias + + lazy val sc = SodaConstant_ () + + lazy val applies : Boolean = + starts_with_prefix_and_space (sc.class_reserved_word) && + _contains_the_equals_symbol + + private lazy val _contains_the_equals_symbol : Boolean = + FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol + +} + +case class ClassAliasAnnotation_ (block : soda.translator.block.Block) extends ClassAliasAnnotation +trait AnnotationFactory + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedBlock_ + import soda.translator.block.Block + import soda.translator.block.BlockAnnotationEnum_ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if ( block.block_annotation == BlockAnnotationEnum_ ().undefined + ) annotate (block) + else block + + def annotate (block : Block) : AnnotatedBlock = + block match { + case AnnotatedBlock_ (annotated_lines, block_annotation) => AnnotatedBlock_ (annotated_lines, block_annotation) + case x => _get_first_or_undefined (_find_candidates (x) ) (x) + } + + def update_block (original_content : AnnotatedBlock) (new_content : Block) : AnnotatedBlock = + original_content match { + case FunctionDefinitionAnnotation_ (b) => FunctionDefinitionAnnotation_ (new_content) + case ClassBeginningAnnotation_ (b) => ClassBeginningAnnotation_ (new_content) + case ClassEndAnnotation_ (b, references) => ClassEndAnnotation_ (new_content, references) + case AbstractDeclarationAnnotation_ (b, references) => AbstractDeclarationAnnotation_ (new_content, references) + case ImportDeclarationAnnotation_ (b) => ImportDeclarationAnnotation_ (new_content) + case PackageDeclarationAnnotation_ (b) => PackageDeclarationAnnotation_ (new_content) + case ClassAliasAnnotation_ (b) => ClassAliasAnnotation_ (new_content) + case TheoremBlockAnnotation_ (b) => TheoremBlockAnnotation_ (new_content) + case ProofBlockAnnotation_ (b) => ProofBlockAnnotation_ (new_content) + case CommentAnnotation_ (b) => CommentAnnotation_ (new_content) + case TestDeclarationAnnotation_ (b) => TestDeclarationAnnotation_ (new_content) + case x => AnnotatedBlock_ (new_content.annotated_lines, x.block_annotation) + } + + private def _detectors (block : Block) : Seq [BlockAnnotationParser] = + Seq ( + FunctionDefinitionAnnotation_ (block), + ClassBeginningAnnotation_ (block), + ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), + AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), + ImportDeclarationAnnotation_ (block), + PackageDeclarationAnnotation_ (block), + ClassAliasAnnotation_ (block), + TheoremBlockAnnotation_ (block), + ProofBlockAnnotation_ (block), + CommentAnnotation_ (block), + TestDeclarationAnnotation_ (block) + ) + + private def _find_candidates (block : Block) : Seq [BlockAnnotationParser] = + _detectors (block) + .filter ( detector => detector.applies) + + private def _get_first_or_undefined (candidates : Seq [BlockAnnotationParser] ) (block : Block) : AnnotatedBlock = + if ( candidates.length == 1 + ) candidates.head + else AnnotatedBlock_ (block.annotated_lines, BlockAnnotationEnum_ ().undefined ) + +} + +case class AnnotationFactory_ () extends AnnotationFactory +trait CommentAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + + lazy val identifier = BlockAnnotationEnum_ ().comment + + lazy val applies : Boolean = + block + .annotated_lines + .forall ( annotated_line => annotated_line.is_comment) + +} + +case class CommentAnnotation_ (block : soda.translator.block.Block) extends CommentAnnotation +trait TestDeclarationAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().test_declaration + + lazy val applies : Boolean = + starts_with_prefix_and_space (SodaConstant_ ().test_special_function) + +} + +case class TestDeclarationAnnotation_ (block : soda.translator.block.Block) extends TestDeclarationAnnotation +trait ClassEndAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + def references : Seq [soda.translator.block.AnnotatedBlock] + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().class_end + + lazy val applies : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().class_end_reserved_word) + +} + +case class ClassEndAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends ClassEndAnnotation +trait TheoremBlockAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().theorem_block + + lazy val applies : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + +} + +case class TheoremBlockAnnotation_ (block : soda.translator.block.Block) extends TheoremBlockAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala deleted file mode 100644 index e2475fe4..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/PackageDeclarationAnnotation.scala +++ /dev/null @@ -1,26 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait PackageDeclarationAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().package_declaration - - lazy val applies : Boolean = - starts_with_prefix_and_space (SodaConstant_ ().package_reserved_word) - -} - -case class PackageDeclarationAnnotation_ (block : soda.translator.block.Block) extends PackageDeclarationAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala deleted file mode 100644 index f02b2a8e..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/ProofBlockAnnotation.scala +++ /dev/null @@ -1,27 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait ProofBlockAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().proof_block - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) - -} - -case class ProofBlockAnnotation_ (block : soda.translator.block.Block) extends ProofBlockAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala deleted file mode 100644 index c5513bcd..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/TestDeclarationAnnotation.scala +++ /dev/null @@ -1,26 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait TestDeclarationAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().test_declaration - - lazy val applies : Boolean = - starts_with_prefix_and_space (SodaConstant_ ().test_special_function) - -} - -case class TestDeclarationAnnotation_ (block : soda.translator.block.Block) extends TestDeclarationAnnotation diff --git a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala b/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala deleted file mode 100644 index eda81c0c..00000000 --- a/translator/src/main/scala/soda/translator/parser/annotation/TheoremBlockAnnotation.scala +++ /dev/null @@ -1,27 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains classes to handle block annotations for parsing. - */ - - - -trait TheoremBlockAnnotation - extends - BlockAnnotationParser -{ - - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().theorem_block - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) - -} - -case class TheoremBlockAnnotation_ (block : soda.translator.block.Block) extends TheoremBlockAnnotation diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.scala b/translator/src/main/scala/soda/translator/replacement/CharType.scala deleted file mode 100644 index 23423e05..00000000 --- a/translator/src/main/scala/soda/translator/replacement/CharType.scala +++ /dev/null @@ -1,90 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains auxiliary classes for string manipulation, - * especially related to replacement. - */ - - - - - -/** - * This is to classify characters. - */ - -trait CharType - extends - soda.lib.EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class CharType_ (ordinal : Int, name : String) extends CharType - -/** - * This is an enumeration for all types of characters. - */ - -trait CharTypeEnum - extends - soda.lib.Enum [CharType] -{ - - lazy val undefined_type = CharType_ (0, "undefined_type") - - lazy val quotes_type = CharType_ (1, "quotes_type") - - lazy val apostrophe_type = CharType_ (2, "apostrophe_type") - - lazy val backslash_type = CharType_ (3, "backslash_type") - - lazy val plain_type = CharType_ (4, "plain_type") - - lazy val values = Seq (undefined_type, quotes_type, apostrophe_type, backslash_type, plain_type) - - lazy val backslash_char = '\\' - - lazy val quotes_char = '\"' - - lazy val apostrophe_char = '\'' - - lazy val underscore_char = '_' - - lazy val symbol_chars : Seq [Char] = - Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') - - lazy val simple_char_type_map : Map [Char , CharType] = - Map ( - Tuple2 ( quotes_char , quotes_type ), - Tuple2 ( apostrophe_char , apostrophe_type ), - Tuple2 ( backslash_char, backslash_type ) - ) - - def get_char_type (ch : Char) : CharType = - simple_char_type_map - .getOrElse (ch, _get_char_type_if_plain (ch) ) - - private def _get_char_type_if_plain (ch : Char) : CharType = - if ( _is_plain (ch) - ) plain_type - else undefined_type - - private def _is_plain (ch : Char) : Boolean = - _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) - - private def _is_whitespace (ch : Char) : Boolean = - ch.isWhitespace - - private def _is_letter_or_digit_or_underscore (ch : Char) : Boolean = - ch.isLetterOrDigit || ch == underscore_char - - private def _is_symbol (ch : Char) : Boolean = - symbol_chars.contains (ch) - -} - -case class CharTypeEnum_ () extends CharTypeEnum diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index 348bd716..2ac7539c 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -8,3 +8,495 @@ package soda.translator.replacement trait Package +/** + * A token is a piece of code, that can contain one or more words combined with symbols. + */ + +trait Token +{ + + def text : String + def parser_state : ParserState + def index : Int + +} + +case class Token_ (text : String, parser_state : ParserState, index : Int) extends Token + +/** + * This class processes a line to divide it into tokens. + */ + +trait Tokenizer + extends + soda.translator.block.SingleLineProcessor +{ + + def line : String + + import soda.lib.Fold_ + import soda.lib.Range_ + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + lazy val tokens : Seq [Token] = + _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) + + private lazy val _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) + + private def _postprocess (tuple : TokenizerFoldTuple) : Seq [Token] = + (tuple.rev_tokens.+: (Token_ (line.substring (tuple.last_index), tuple.parser_state, tuple.last_index) ) ) + .reverse + + private def _next_value_function (tuple : TokenizerFoldTuple) (current_index : Int) : TokenizerFoldTuple = + _new_value_function_with (tuple) (current_index) (_new_parser_state (tuple) (current_index) ) + + private def _new_value_function_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = + if ( ParserStateEnum_ ().is_same_class (new_parser_state) (tuple.parser_state) + ) TokenizerFoldTuple_ (tuple.last_index, new_parser_state, tuple.rev_tokens) + else _next_value_function_of_different_class (tuple) (current_index) (new_parser_state) + + private def _new_parser_state (tuple : TokenizerFoldTuple) (current_index : Int) : ParserState = + ParserTransition_ () + .next_parser_state ( + tuple.parser_state) ( + CharTypeEnum_ ().get_char_type (line.charAt (current_index) ) + ) + + private def _next_value_function_of_different_class (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = + _next_value_function_of_different_class_with ( + tuple) ( + current_index) ( + new_parser_state) ( + _get_new_current_index (tuple) (current_index) + ) + + private def _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = + if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || + tuple.parser_state == ParserStateEnum_ ().apostrophe_state + ) current_index + 1 + else current_index + + private def _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = + TokenizerFoldTuple_ (index, new_parser_state, + tuple.rev_tokens.+: ( + Token_ ( + line.substring (tuple.last_index, index), + tuple.parser_state, + tuple.last_index + ) + ) + ) + +} + +case class Tokenizer_ (line : String) extends Tokenizer + +trait TokenizerFoldTuple +{ + + def last_index : Int + def parser_state : ParserState + def rev_tokens : Seq [Token] + +} + +case class TokenizerFoldTuple_ (last_index : Int, parser_state : ParserState, rev_tokens : Seq [Token]) extends TokenizerFoldTuple +/** + * This models a collection of replacement functions. + * This is intended to be used as a pipeline. + */ + +trait Replacement + extends + soda.translator.block.SingleLineProcessor +{ + + def line : String + + import soda.translator.block.Translator + + lazy val aux = ReplacementAux_ () + + lazy val soda_space = aux.soda_space + + def replace_at_beginning (index : Int) (translator : Translator) : Replacement = + Replacement_ (ReplacementWithTranslator_ (translator).replace_at_beginning (line) (index) ) + + def replace_all (pattern : String) (replacement : String) : Replacement = + Replacement_ (aux.replace_all (line) (pattern) (replacement) ) + + def add_space_to_soda_line () : Replacement = + Replacement_ (soda_space + line + soda_space) + + def remove_space_from_scala_line () : Replacement = + Replacement_ (aux.remove_space_from_scala_line (line) ) + + def add_after_spaces_or_pattern (pattern : String) (text_to_prepend : String) : Replacement = + Replacement_ (aux.add_after_spaces_or_pattern (line) (pattern) (text_to_prepend) ) + +} + +case class Replacement_ (line : String) extends Replacement + +trait ReplacementAux +{ + + lazy val soda_space = " " + + lazy val scala_space = " " + + def replace_if_found_at_beginning (line : String) (pattern : String) (new_text : String) : String = + if ( line.trim.startsWith (pattern.trim) + ) replace_first (line) (pattern) (new_text) + else line + + def replace_first (line : String) (pattern : String) (replacement : String) : String = + replace_at (line.indexOf (pattern) ) (line) (pattern) (replacement) + + def replace_at (index : Int) (line : String) (pattern : String) (replacement : String) : String = + if ( (0 <= index) && (index + pattern.length <= line.length) + ) line.substring (0, index) + replacement + line.substring (index + pattern.length, line.length) + else line + + def replace_if_found (line : String) (pattern : String) (new_text : String) : String = + if ( line.contains (pattern) + ) replace_all (line) (pattern) (new_text) + else line + + def replace_all (line : String) (pattern : String) (replacement : String) : String = + Replacer_ (line, pattern, replacement).replaced_text + + def add_spaces_to_symbols (line : String) (symbols : Set [Char] ) : String = + line + .indices + .map ( index => _add_spaces_to_symbols_with (line (index) ) (index ) (line) (symbols) ) + .mkString ("") + + private def _add_spaces_to_symbols_with (ch : Char) (index : Int) (line : String) (symbols : Set [Char] ) : String = + (_left_part_of_symbols (line) (symbols) (index) (ch) ) + ch + (_right_part_of_symbols (line) (symbols) (index) (ch) ) + + private def _left_part_of_symbols (line : String) (symbols : Set [Char] ) (index : Int) (ch : Char) : String = + if ( (index > 0) && symbols.contains (ch) && + ! line (index - 1).isWhitespace + ) scala_space + else "" + + private def _right_part_of_symbols (line : String) (symbols : Set [Char] ) (index : Int) (ch : Char) : String = + if ( (index < line.length - 1) && symbols.contains (ch) && + ! line (index + 1).isWhitespace + ) scala_space + else "" + + def remove_space_from_scala_line (line : String) : String = + _get_line_without_ending_space ( _get_line_without_starting_space (line) ) + + private def _get_line_without_starting_space (line : String) : String = + if ( line.startsWith (scala_space) + ) line.substring (1) + else line + + private def _get_line_without_ending_space (line : String) : String = + if ( line.endsWith (scala_space) + ) line.substring (0, line.length - 1) + else line + + def add_after_spaces_or_pattern (line : String) (pattern : String) (text_to_prepend : String) : String = + _add_after_spaces_or_pattern_with (_get_prefix_length (line) (pattern) ) (line) (pattern) (text_to_prepend) + + private def _add_after_spaces_or_pattern_with (prefix_length : Int) (line : String) (pattern : String) (text_to_prepend : String) : String = + line.substring (0, prefix_length) + text_to_prepend + line.substring (prefix_length) + + private def _get_prefix_length (line : String) (pattern : String) : Int = + if ( line.trim.startsWith (pattern) + ) line.indexOf (pattern) + pattern.length + else line.takeWhile ( ch => ch.isSpaceChar).length + +} + +case class ReplacementAux_ () extends ReplacementAux + +trait ReplacementWithTranslator +{ + + def translator : soda.translator.block.Translator + + import soda.lib.Fold_ + + lazy val aux = ReplacementAux_ () + + lazy val soda_space = aux.soda_space + + lazy val scala_space = aux.scala_space + + private lazy val _fold = Fold_ () + + def replace_at_beginning (line : String) (index : Int) : String = + if ( index == 0 + ) _replace_only_beginning (line) + else line + + private def _replace_only_beginning (line : String) : String = + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_only_beginning) + + private def _next_replace_only_beginning (line : String) (reserved_word : String) : String = + aux.replace_if_found_at_beginning (line) ( + soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) + + def replace (line : String) : String = + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace) + + private def _next_replace (line : String) (reserved_word : String) : String = + aux.replace_if_found (line) ( + soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) + + def replace_regex (line : String) : String = + _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_regex) + + private def _next_replace_regex (line : String) (regex : String) : String = + line.replaceAll (regex, translator.translate (regex) ) + +} + +case class ReplacementWithTranslator_ (translator : soda.translator.block.Translator) extends ReplacementWithTranslator +trait LinePatternProcessor +{ + + def line : String + def pattern : String + def replacement : String + +} + +case class LinePatternProcessor_ (line : String, pattern : String, replacement : String) extends LinePatternProcessor + +trait Replacer + extends + LinePatternProcessor +{ + + def line : String + def pattern : String + def replacement : String + + import soda.lib.FoldWhile_ + import soda.lib.Range_ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _range = Range_ () + + lazy val replaced_text = + postprocess (_fold_while.apply (_range.apply (line.length) ) (initial_value) (next_value_function) (should_continue) ) + + lazy val initial_value : ReplacerFoldTuple = ReplacerFoldTuple_ (Seq (), 0 ) + + def next_value_function (tuple : ReplacerFoldTuple) (x : Int) : ReplacerFoldTuple = + _get_next_tuple ( + replaced_text_rev = tuple.replaced_text_rev) ( + start_index = tuple.start_index) ( + pos = line.indexOf (pattern, tuple.start_index) + ) + + private def _get_next_tuple (replaced_text_rev : Seq [String] ) (start_index : Int) (pos : Int) : ReplacerFoldTuple = + if ( pos == -1 + ) ReplacerFoldTuple_ (replaced_text_rev.+: (line.substring (start_index) ), pos ) + else + ReplacerFoldTuple_ ( + (replaced_text_rev.+: (line.substring (start_index, pos) ) ).+: (replacement), + pos + pattern.length + ) + + def should_continue (tuple : ReplacerFoldTuple) (x : Int) : Boolean = + ! (tuple.start_index == -1) + + def postprocess (tuple : ReplacerFoldTuple) : String = + tuple.replaced_text_rev.reverse.mkString ("") + +} + +case class Replacer_ (line : String, pattern : String, replacement : String) extends Replacer + +trait ReplacerFoldTuple +{ + + def replaced_text_rev : Seq [String] + def start_index : Int + +} + +case class ReplacerFoldTuple_ (replaced_text_rev : Seq [String], start_index : Int) extends ReplacerFoldTuple +/** + * This is to classify characters. + */ + +trait CharType + extends + soda.lib.EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class CharType_ (ordinal : Int, name : String) extends CharType + +/** + * This is an enumeration for all types of characters. + */ + +trait CharTypeEnum + extends + soda.lib.Enum [CharType] +{ + + lazy val undefined_type = CharType_ (0, "undefined_type") + + lazy val quotes_type = CharType_ (1, "quotes_type") + + lazy val apostrophe_type = CharType_ (2, "apostrophe_type") + + lazy val backslash_type = CharType_ (3, "backslash_type") + + lazy val plain_type = CharType_ (4, "plain_type") + + lazy val values = Seq (undefined_type, quotes_type, apostrophe_type, backslash_type, plain_type) + + lazy val backslash_char = '\\' + + lazy val quotes_char = '\"' + + lazy val apostrophe_char = '\'' + + lazy val underscore_char = '_' + + lazy val symbol_chars : Seq [Char] = + Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + + lazy val simple_char_type_map : Map [Char , CharType] = + Map ( + Tuple2 ( quotes_char , quotes_type ), + Tuple2 ( apostrophe_char , apostrophe_type ), + Tuple2 ( backslash_char, backslash_type ) + ) + + def get_char_type (ch : Char) : CharType = + simple_char_type_map + .getOrElse (ch, _get_char_type_if_plain (ch) ) + + private def _get_char_type_if_plain (ch : Char) : CharType = + if ( _is_plain (ch) + ) plain_type + else undefined_type + + private def _is_plain (ch : Char) : Boolean = + _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) + + private def _is_whitespace (ch : Char) : Boolean = + ch.isWhitespace + + private def _is_letter_or_digit_or_underscore (ch : Char) : Boolean = + ch.isLetterOrDigit || ch == underscore_char + + private def _is_symbol (ch : Char) : Boolean = + symbol_chars.contains (ch) + +} + +case class CharTypeEnum_ () extends CharTypeEnum +/** + * This models all the possible states that the parser can be. + */ + +trait ParserState + extends + soda.lib.EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class ParserState_ (ordinal : Int, name : String) extends ParserState + +/** + * This is an enumeration of all the parser states. + */ + +trait ParserStateEnum + extends + soda.lib.Enum [ParserState] +{ + + lazy val undefined_state = ParserState_ (0, "undefined_state") + + lazy val quotes_state = ParserState_ (1, "quotes_state") + + lazy val apostrophe_state = ParserState_ (2, "apostrophe_state") + + lazy val quotes_backslash_state = ParserState_ (3, "quotes_backslash_state") + + lazy val apostrophe_backslash_state = ParserState_ (4, "apostrophe_backslash_state") + + lazy val plain = ParserState_ (5, "plain") + + lazy val values = Seq (undefined_state, quotes_state, apostrophe_state, quotes_backslash_state, apostrophe_backslash_state, plain) + + def is_same_class (x : ParserState) (y : ParserState) : Boolean = + (x == y) || _is_like (x) (y) || _is_like (y) (x) + + private def _is_like (x : ParserState) (y : ParserState) : Boolean = + (x == quotes_state && y == quotes_backslash_state) || + (x == apostrophe_state && y == apostrophe_backslash_state) + +} + +case class ParserStateEnum_ () extends ParserStateEnum + +trait ParserTransition +{ + + lazy val ps = ParserStateEnum_ () + + lazy val ct = CharTypeEnum_ () + + lazy val transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = + Map ( + /* */ + Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), + Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), + /* */ + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), + /* */ + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), + /* */ + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), + /* */ + Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), + Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) + ) + + def next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = + transitions_that_change_states.getOrElse ( Tuple2 (parser_state, char_type), parser_state) + +} + +case class ParserTransition_ () extends ParserTransition diff --git a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala b/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala deleted file mode 100644 index e65cfc70..00000000 --- a/translator/src/main/scala/soda/translator/replacement/ParserTransition.scala +++ /dev/null @@ -1,104 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains auxiliary classes for string manipulation, - * especially related to replacement. - */ - - - - - -/** - * This models all the possible states that the parser can be. - */ - -trait ParserState - extends - soda.lib.EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class ParserState_ (ordinal : Int, name : String) extends ParserState - -/** - * This is an enumeration of all the parser states. - */ - -trait ParserStateEnum - extends - soda.lib.Enum [ParserState] -{ - - lazy val undefined_state = ParserState_ (0, "undefined_state") - - lazy val quotes_state = ParserState_ (1, "quotes_state") - - lazy val apostrophe_state = ParserState_ (2, "apostrophe_state") - - lazy val quotes_backslash_state = ParserState_ (3, "quotes_backslash_state") - - lazy val apostrophe_backslash_state = ParserState_ (4, "apostrophe_backslash_state") - - lazy val plain = ParserState_ (5, "plain") - - lazy val values = Seq (undefined_state, quotes_state, apostrophe_state, quotes_backslash_state, apostrophe_backslash_state, plain) - - def is_same_class (x : ParserState) (y : ParserState) : Boolean = - (x == y) || _is_like (x) (y) || _is_like (y) (x) - - private def _is_like (x : ParserState) (y : ParserState) : Boolean = - (x == quotes_state && y == quotes_backslash_state) || - (x == apostrophe_state && y == apostrophe_backslash_state) - -} - -case class ParserStateEnum_ () extends ParserStateEnum - -trait ParserTransition -{ - - lazy val ps = ParserStateEnum_ () - - lazy val ct = CharTypeEnum_ () - - lazy val transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = - Map ( - /* */ - Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), - Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), - /* */ - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), - /* */ - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), - /* */ - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), - /* */ - Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), - Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) - ) - - def next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = - transitions_that_change_states.getOrElse ( Tuple2 (parser_state, char_type), parser_state) - -} - -case class ParserTransition_ () extends ParserTransition diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.scala b/translator/src/main/scala/soda/translator/replacement/Replacement.scala deleted file mode 100644 index 75b29c6d..00000000 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.scala +++ /dev/null @@ -1,168 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains auxiliary classes for string manipulation, - * especially related to replacement. - */ - - - - - -/** - * This models a collection of replacement functions. - * This is intended to be used as a pipeline. - */ - -trait Replacement - extends - soda.translator.block.SingleLineProcessor -{ - - def line : String - - import soda.translator.block.Translator - - lazy val aux = ReplacementAux_ () - - lazy val soda_space = aux.soda_space - - def replace_at_beginning (index : Int) (translator : Translator) : Replacement = - Replacement_ (ReplacementWithTranslator_ (translator).replace_at_beginning (line) (index) ) - - def replace_all (pattern : String) (replacement : String) : Replacement = - Replacement_ (aux.replace_all (line) (pattern) (replacement) ) - - def add_space_to_soda_line () : Replacement = - Replacement_ (soda_space + line + soda_space) - - def remove_space_from_scala_line () : Replacement = - Replacement_ (aux.remove_space_from_scala_line (line) ) - - def add_after_spaces_or_pattern (pattern : String) (text_to_prepend : String) : Replacement = - Replacement_ (aux.add_after_spaces_or_pattern (line) (pattern) (text_to_prepend) ) - -} - -case class Replacement_ (line : String) extends Replacement - -trait ReplacementAux -{ - - lazy val soda_space = " " - - lazy val scala_space = " " - - def replace_if_found_at_beginning (line : String) (pattern : String) (new_text : String) : String = - if ( line.trim.startsWith (pattern.trim) - ) replace_first (line) (pattern) (new_text) - else line - - def replace_first (line : String) (pattern : String) (replacement : String) : String = - replace_at (line.indexOf (pattern) ) (line) (pattern) (replacement) - - def replace_at (index : Int) (line : String) (pattern : String) (replacement : String) : String = - if ( (0 <= index) && (index + pattern.length <= line.length) - ) line.substring (0, index) + replacement + line.substring (index + pattern.length, line.length) - else line - - def replace_if_found (line : String) (pattern : String) (new_text : String) : String = - if ( line.contains (pattern) - ) replace_all (line) (pattern) (new_text) - else line - - def replace_all (line : String) (pattern : String) (replacement : String) : String = - Replacer_ (line, pattern, replacement).replaced_text - - def add_spaces_to_symbols (line : String) (symbols : Set [Char] ) : String = - line - .indices - .map ( index => _add_spaces_to_symbols_with (line (index) ) (index ) (line) (symbols) ) - .mkString ("") - - private def _add_spaces_to_symbols_with (ch : Char) (index : Int) (line : String) (symbols : Set [Char] ) : String = - (_left_part_of_symbols (line) (symbols) (index) (ch) ) + ch + (_right_part_of_symbols (line) (symbols) (index) (ch) ) - - private def _left_part_of_symbols (line : String) (symbols : Set [Char] ) (index : Int) (ch : Char) : String = - if ( (index > 0) && symbols.contains (ch) && - ! line (index - 1).isWhitespace - ) scala_space - else "" - - private def _right_part_of_symbols (line : String) (symbols : Set [Char] ) (index : Int) (ch : Char) : String = - if ( (index < line.length - 1) && symbols.contains (ch) && - ! line (index + 1).isWhitespace - ) scala_space - else "" - - def remove_space_from_scala_line (line : String) : String = - _get_line_without_ending_space ( _get_line_without_starting_space (line) ) - - private def _get_line_without_starting_space (line : String) : String = - if ( line.startsWith (scala_space) - ) line.substring (1) - else line - - private def _get_line_without_ending_space (line : String) : String = - if ( line.endsWith (scala_space) - ) line.substring (0, line.length - 1) - else line - - def add_after_spaces_or_pattern (line : String) (pattern : String) (text_to_prepend : String) : String = - _add_after_spaces_or_pattern_with (_get_prefix_length (line) (pattern) ) (line) (pattern) (text_to_prepend) - - private def _add_after_spaces_or_pattern_with (prefix_length : Int) (line : String) (pattern : String) (text_to_prepend : String) : String = - line.substring (0, prefix_length) + text_to_prepend + line.substring (prefix_length) - - private def _get_prefix_length (line : String) (pattern : String) : Int = - if ( line.trim.startsWith (pattern) - ) line.indexOf (pattern) + pattern.length - else line.takeWhile ( ch => ch.isSpaceChar).length - -} - -case class ReplacementAux_ () extends ReplacementAux - -trait ReplacementWithTranslator -{ - - def translator : soda.translator.block.Translator - - import soda.lib.Fold_ - - lazy val aux = ReplacementAux_ () - - lazy val soda_space = aux.soda_space - - lazy val scala_space = aux.scala_space - - private lazy val _fold = Fold_ () - - def replace_at_beginning (line : String) (index : Int) : String = - if ( index == 0 - ) _replace_only_beginning (line) - else line - - private def _replace_only_beginning (line : String) : String = - _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_only_beginning) - - private def _next_replace_only_beginning (line : String) (reserved_word : String) : String = - aux.replace_if_found_at_beginning (line) ( - soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) - - def replace (line : String) : String = - _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace) - - private def _next_replace (line : String) (reserved_word : String) : String = - aux.replace_if_found (line) ( - soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) - - def replace_regex (line : String) : String = - _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_regex) - - private def _next_replace_regex (line : String) (regex : String) : String = - line.replaceAll (regex, translator.translate (regex) ) - -} - -case class ReplacementWithTranslator_ (translator : soda.translator.block.Translator) extends ReplacementWithTranslator diff --git a/translator/src/main/scala/soda/translator/replacement/Replacer.scala b/translator/src/main/scala/soda/translator/replacement/Replacer.scala deleted file mode 100644 index 41aa09d9..00000000 --- a/translator/src/main/scala/soda/translator/replacement/Replacer.scala +++ /dev/null @@ -1,78 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains auxiliary classes for string manipulation, - * especially related to replacement. - */ - - - - - -trait LinePatternProcessor -{ - - def line : String - def pattern : String - def replacement : String - -} - -case class LinePatternProcessor_ (line : String, pattern : String, replacement : String) extends LinePatternProcessor - -trait Replacer - extends - LinePatternProcessor -{ - - def line : String - def pattern : String - def replacement : String - - import soda.lib.FoldWhile_ - import soda.lib.Range_ - - private lazy val _fold_while = FoldWhile_ () - - private lazy val _range = Range_ () - - lazy val replaced_text = - postprocess (_fold_while.apply (_range.apply (line.length) ) (initial_value) (next_value_function) (should_continue) ) - - lazy val initial_value : ReplacerFoldTuple = ReplacerFoldTuple_ (Seq (), 0 ) - - def next_value_function (tuple : ReplacerFoldTuple) (x : Int) : ReplacerFoldTuple = - _get_next_tuple ( - replaced_text_rev = tuple.replaced_text_rev) ( - start_index = tuple.start_index) ( - pos = line.indexOf (pattern, tuple.start_index) - ) - - private def _get_next_tuple (replaced_text_rev : Seq [String] ) (start_index : Int) (pos : Int) : ReplacerFoldTuple = - if ( pos == -1 - ) ReplacerFoldTuple_ (replaced_text_rev.+: (line.substring (start_index) ), pos ) - else - ReplacerFoldTuple_ ( - (replaced_text_rev.+: (line.substring (start_index, pos) ) ).+: (replacement), - pos + pattern.length - ) - - def should_continue (tuple : ReplacerFoldTuple) (x : Int) : Boolean = - ! (tuple.start_index == -1) - - def postprocess (tuple : ReplacerFoldTuple) : String = - tuple.replaced_text_rev.reverse.mkString ("") - -} - -case class Replacer_ (line : String, pattern : String, replacement : String) extends Replacer - -trait ReplacerFoldTuple -{ - - def replaced_text_rev : Seq [String] - def start_index : Int - -} - -case class ReplacerFoldTuple_ (replaced_text_rev : Seq [String], start_index : Int) extends ReplacerFoldTuple diff --git a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala b/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala deleted file mode 100644 index 9f85dee4..00000000 --- a/translator/src/main/scala/soda/translator/replacement/Tokenizer.scala +++ /dev/null @@ -1,107 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains auxiliary classes for string manipulation, - * especially related to replacement. - */ - - - - - -/** - * A token is a piece of code, that can contain one or more words combined with symbols. - */ - -trait Token -{ - - def text : String - def parser_state : ParserState - def index : Int - -} - -case class Token_ (text : String, parser_state : ParserState, index : Int) extends Token - -/** - * This class processes a line to divide it into tokens. - */ - -trait Tokenizer - extends - soda.translator.block.SingleLineProcessor -{ - - def line : String - - import soda.lib.Fold_ - import soda.lib.Range_ - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - lazy val tokens : Seq [Token] = - _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) - - private lazy val _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) - - private def _postprocess (tuple : TokenizerFoldTuple) : Seq [Token] = - (tuple.rev_tokens.+: (Token_ (line.substring (tuple.last_index), tuple.parser_state, tuple.last_index) ) ) - .reverse - - private def _next_value_function (tuple : TokenizerFoldTuple) (current_index : Int) : TokenizerFoldTuple = - _new_value_function_with (tuple) (current_index) (_new_parser_state (tuple) (current_index) ) - - private def _new_value_function_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = - if ( ParserStateEnum_ ().is_same_class (new_parser_state) (tuple.parser_state) - ) TokenizerFoldTuple_ (tuple.last_index, new_parser_state, tuple.rev_tokens) - else _next_value_function_of_different_class (tuple) (current_index) (new_parser_state) - - private def _new_parser_state (tuple : TokenizerFoldTuple) (current_index : Int) : ParserState = - ParserTransition_ () - .next_parser_state ( - tuple.parser_state) ( - CharTypeEnum_ ().get_char_type (line.charAt (current_index) ) - ) - - private def _next_value_function_of_different_class (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = - _next_value_function_of_different_class_with ( - tuple) ( - current_index) ( - new_parser_state) ( - _get_new_current_index (tuple) (current_index) - ) - - private def _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = - if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || - tuple.parser_state == ParserStateEnum_ ().apostrophe_state - ) current_index + 1 - else current_index - - private def _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = - TokenizerFoldTuple_ (index, new_parser_state, - tuple.rev_tokens.+: ( - Token_ ( - line.substring (tuple.last_index, index), - tuple.parser_state, - tuple.last_index - ) - ) - ) - -} - -case class Tokenizer_ (line : String) extends Tokenizer - -trait TokenizerFoldTuple -{ - - def last_index : Int - def parser_state : ParserState - def rev_tokens : Seq [Token] - -} - -case class TokenizerFoldTuple_ (last_index : Int, parser_state : ParserState, rev_tokens : Seq [Token]) extends TokenizerFoldTuple diff --git a/translator/src/test/resources/soda/example/Package.scala b/translator/src/test/resources/soda/example/Package.scala index ebd484d9..05296ed7 100644 --- a/translator/src/test/resources/soda/example/Package.scala +++ b/translator/src/test/resources/soda/example/Package.scala @@ -4,3 +4,7 @@ package soda.example * This package is just a minimal example. */ trait Package +case class Example() +{ + +} diff --git a/translator/src/test/resources/soda/example/otherexample/Package.scala b/translator/src/test/resources/soda/example/otherexample/Package.scala index 28667f58..398862c3 100644 --- a/translator/src/test/resources/soda/example/otherexample/Package.scala +++ b/translator/src/test/resources/soda/example/otherexample/Package.scala @@ -5,3 +5,7 @@ package soda.example.otherexample */ trait Package +case class OtherExample() +{ + +} diff --git a/translator/src/test/scala/soda/example/Example.scala b/translator/src/test/scala/soda/example/Example.scala deleted file mode 100644 index aeab0f26..00000000 --- a/translator/src/test/scala/soda/example/Example.scala +++ /dev/null @@ -1,3 +0,0 @@ -package soda.example - -case class Example () diff --git a/translator/src/test/scala/soda/example/otherexample/OtherExample.scala b/translator/src/test/scala/soda/example/otherexample/OtherExample.scala deleted file mode 100644 index 0e35eb2e..00000000 --- a/translator/src/test/scala/soda/example/otherexample/OtherExample.scala +++ /dev/null @@ -1,3 +0,0 @@ -package soda.example.otherexample - -case class OtherExample () diff --git a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala b/translator/src/test/scala/soda/lib/CartesianProductSpec.scala deleted file mode 100644 index 58be69b3..00000000 --- a/translator/src/test/scala/soda/lib/CartesianProductSpec.scala +++ /dev/null @@ -1,79 +0,0 @@ -package soda.lib - -/* - * This package contains tests for the Soda library. - */ - - - -case class CartesianProductSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val int_seq_a = Seq (10, 20) - - lazy val int_seq_b = Seq (100, 200, 300) - - lazy val str_seq_a = Seq ("A", "B") - - lazy val str_seq_b = Seq ("0", "1", "2") - - lazy val str_seq_c = Seq ("a", "b", "c", "d") - - lazy val instance = CartesianProduct_ () - - test ("Cartesian product of two sequences") ( - check ( - obtained = instance.apply (Seq (int_seq_a, int_seq_b) ) - ) ( - expected = Seq ( - Seq (10, 100), Seq (10, 200), Seq (10, 300), - Seq (20, 100), Seq (20, 200), Seq (20, 300) - ) - ) - ) - - test ("Cartesian product of an empty sequence") ( - check ( - obtained = instance.apply (Seq () ) - ) ( - expected = Seq () - ) - ) - - test ("Cartesian product of only empty sequences") ( - check ( - obtained = instance.apply (Seq (Seq (), Seq (), Seq () ) ) - ) ( - expected = Seq () - ) - ) - - test ("Cartesian product with at least one empty sequence") ( - check ( - obtained = instance.apply (Seq (Seq ("A"), Seq () ) ) - ) ( - expected = Seq () - ) - ) - - test ("Cartesian product of three sequences") ( - check ( - obtained = instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) - ) ( - expected = Seq ( - Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), - Seq ("A", "1", "a"), Seq ("A", "1", "b"), Seq ("A", "1", "c"), Seq ("A", "1", "d"), - Seq ("A", "2", "a"), Seq ("A", "2", "b"), Seq ("A", "2", "c"), Seq ("A", "2", "d"), - Seq ("B", "0", "a"), Seq ("B", "0", "b"), Seq ("B", "0", "c"), Seq ("B", "0", "d"), - Seq ("B", "1", "a"), Seq ("B", "1", "b"), Seq ("B", "1", "c"), Seq ("B", "1", "d"), - Seq ("B", "2", "a"), Seq ("B", "2", "b"), Seq ("B", "2", "c"), Seq ("B", "2", "d") - ) - ) - ) - -} diff --git a/translator/src/test/scala/soda/lib/EnumSpec.scala b/translator/src/test/scala/soda/lib/EnumSpec.scala deleted file mode 100644 index 0a164558..00000000 --- a/translator/src/test/scala/soda/lib/EnumSpec.scala +++ /dev/null @@ -1,71 +0,0 @@ -package soda.lib - -/* - * This package contains tests for the Soda library. - */ - - - -trait DayOfTheWeek - extends - EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class DayOfTheWeek_ (ordinal : Int, name : String) extends DayOfTheWeek - -trait DayOfTheWeekConstant -{ - - lazy val sunday = DayOfTheWeek_ (0, "Sunday") - - lazy val monday = DayOfTheWeek_ (1, "Monday") - - lazy val tuesday = DayOfTheWeek_ (2, "Tuesday") - - lazy val wednesday = DayOfTheWeek_ (3, "Wednesday") - - lazy val thursday = DayOfTheWeek_ (4, "Thursday") - - lazy val friday = DayOfTheWeek_ (5, "Friday") - - lazy val saturday = DayOfTheWeek_ (6, "Saturday") - - lazy val DayOfTheWeek_values = Seq (sunday, monday, tuesday, wednesday, thursday, friday, saturday) - -} - -case class DayOfTheWeekConstant_ () extends DayOfTheWeekConstant - -trait DayOfTheWeekEnum - extends - DayOfTheWeekConstant -{ - - lazy val values = DayOfTheWeek_values - -} - -case class DayOfTheWeekEnum_ () extends DayOfTheWeekEnum - -case class EnumSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("the names of the elements in enumerations") ( - check ( - obtained = DayOfTheWeekEnum_ ().values.map ( x => x.toString) - ) ( - expected = Seq ("DayOfTheWeek_(0,Sunday)", "DayOfTheWeek_(1,Monday)", "DayOfTheWeek_(2,Tuesday)", "DayOfTheWeek_(3,Wednesday)", "DayOfTheWeek_(4,Thursday)", "DayOfTheWeek_(5,Friday)", "DayOfTheWeek_(6,Saturday)") - ) - ) - -} diff --git a/translator/src/test/scala/soda/lib/OptionSDSpec.scala b/translator/src/test/scala/soda/lib/OptionSDSpec.scala deleted file mode 100644 index 22594e74..00000000 --- a/translator/src/test/scala/soda/lib/OptionSDSpec.scala +++ /dev/null @@ -1,222 +0,0 @@ -package soda.lib - -/* - * This package contains tests for the Soda library. - */ - - - -case class OptionSDSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import scala.util.Try - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val result_if_empty : String = "It is empty." - - def result_if_non_empty (value : String) : String = "Its value is " + value + "." - - def int_to_string (n : Int) : String = "" + n - - def maybe_int_to_string (n : Int) : SomeSD_ [String] = SomeSD_ [String] ("" + n) - - def maybe_string_to_int (s : String) : OptionSD [Int] = - OptionSDBuilder_ ().build ( - Try ( Integer.parseInt (s.trim) ) - .toOption - ) - - test ("should test an empty option") ( - check ( - obtained = empty_opt.isEmpty && ! empty_opt.isDefined && ! empty_opt.isNonEmpty - ) ( - expected = true - ) - ) - - lazy val empty_opt = NoneSD_ () - - test ("should test a non empty option") ( - check ( - obtained = ! non_empty_opt.isEmpty && non_empty_opt.isDefined && non_empty_opt.isNonEmpty - ) ( - expected = true - ) - ) - - lazy val non_empty_opt = SomeSD_ (1) - - test ("should get a default value, when empty") ( - check ( - obtained = (NoneSD_ [Int] () ).getOrElse (1) - ) ( - expected = 1 - ) - ) - - test ("should get a value") ( - check ( - obtained = (SomeSD_ [Int] (2) ).getOrElse (1) - ) ( - expected = 2 - ) - ) - - test ("should open an empty option") ( - check ( - obtained = (NoneSD_ [String] () ).opt (ifEmpty = result_if_empty) (ifNonEmpty = result_if_non_empty) - ) ( - expected = "It is empty." - ) - ) - - test ("should open an non empty option") ( - check ( - obtained = (SomeSD_ [String] ("0") ).opt (ifEmpty = result_if_empty) (ifNonEmpty = result_if_non_empty) - ) ( - expected = "Its value is 0." - ) - ) - - test ("should try fold an empty option") ( - check ( - obtained = (NoneSD_ [String] () ).fold (ifEmpty = result_if_empty) (f = result_if_non_empty) - ) ( - expected = "It is empty." - ) - ) - - test ("should try fold an non empty option") ( - check ( - obtained = (SomeSD_ [String] ("0") ).fold (ifEmpty = result_if_empty) (f = result_if_non_empty) - ) ( - expected = "Its value is 0." - ) - ) - - test ("should map empty to empty") ( - check ( - obtained = (NoneSD_ [Int] () ).map (int_to_string) - ) ( - expected = NoneSD_ [String] () - ) - ) - - test ("should map a non-empty to another non-empty") ( - check ( - obtained = (SomeSD_ [Int] (2) ).map (int_to_string) - ) ( - expected = SomeSD_ [String] ("2") - ) - ) - - test ("should flat map empty to empty") ( - check ( - obtained = (NoneSD_ [Int] () ).flatMap (maybe_int_to_string) - ) ( - expected = NoneSD_ [String] () - ) - ) - - test ("should flat map a non-empty to another non-empty") ( - check ( - obtained = (SomeSD_ [Int] (2) ).flatMap (maybe_int_to_string) - ) ( - expected = SomeSD_ [String] ("2") - ) - ) - - test ("should try how successive applications of open works") ( - check ( - obtained = - maybe_string_to_int ("1").opt (ifEmpty = _empty_opt ) ( - ifNonEmpty = a => - maybe_string_to_int ("2").opt (ifEmpty = _empty_opt ) ( - ifNonEmpty = b => - maybe_string_to_int ("3").opt (ifEmpty = _empty_opt ) ( - ifNonEmpty = c => - SomeSD_ (a + b + c) ) ) ) - ) ( - expected = SomeSD_ (6) - ) - ) - - private lazy val _empty_opt : OptionSD [Int] = NoneSD_ [Int] () - - test ("toOption with non empty option") ( - check ( - obtained = (SomeSD_ [Int] (1) ).toOption - ) ( - expected = Some (1) - ) - ) - - test ("toOption with another non empty option") ( - check ( - obtained = (SomeSD_ [Int] (2) ).toOption - ) ( - expected = Some (2) - ) - ) - - test ("toOption with empty option") ( - check ( - obtained = (NoneSD_ [Int] () ).toOption - ) ( - expected = None - ) - ) - - test ("toSeq with non empty option") ( - check ( - obtained = (SomeSD_ (1) ).toSeq - ) ( - expected = Seq (1) - ) - ) - - test ("toSeq with another non empty option") ( - check ( - obtained = (SomeSD_ (2) ).toSeq - ) ( - expected = Seq (2) - ) - ) - - test ("toSeq with empty option") ( - check ( - obtained = (NoneSD_ () ).toSeq - ) ( - expected = Seq () - ) - ) - - test ("filter should work for None") ( - check ( - obtained = (NoneSD_ [Int] () ).filter ( x => true) - ) ( - expected = NoneSD_ [Int] () - ) - ) - - test ("filter should work for Some, if predicate does not hold") ( - check ( - obtained = (SomeSD_ [Int] (0) ).filter ( x => x > 0) - ) ( - expected = NoneSD_ [Int] () - ) - ) - - test ("filter should work for Some, if predicate holds") ( - check ( - obtained = (SomeSD_ [Int] (1) ).filter ( x => x > 0) - ) ( - expected = SomeSD_ [Int] (1) - ) - ) - -} diff --git a/translator/src/test/scala/soda/lib/Package.scala b/translator/src/test/scala/soda/lib/Package.scala index 82a0d4c5..cd325d17 100644 --- a/translator/src/test/scala/soda/lib/Package.scala +++ b/translator/src/test/scala/soda/lib/Package.scala @@ -5,3 +5,490 @@ package soda.lib */ trait Package +case class OptionSDSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import scala.util.Try + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val result_if_empty : String = "It is empty." + + def result_if_non_empty (value : String) : String = "Its value is " + value + "." + + def int_to_string (n : Int) : String = "" + n + + def maybe_int_to_string (n : Int) : SomeSD_ [String] = SomeSD_ [String] ("" + n) + + def maybe_string_to_int (s : String) : OptionSD [Int] = + OptionSDBuilder_ ().build ( + Try ( Integer.parseInt (s.trim) ) + .toOption + ) + + test ("should test an empty option") ( + check ( + obtained = empty_opt.isEmpty && ! empty_opt.isDefined && ! empty_opt.isNonEmpty + ) ( + expected = true + ) + ) + + lazy val empty_opt = NoneSD_ () + + test ("should test a non empty option") ( + check ( + obtained = ! non_empty_opt.isEmpty && non_empty_opt.isDefined && non_empty_opt.isNonEmpty + ) ( + expected = true + ) + ) + + lazy val non_empty_opt = SomeSD_ (1) + + test ("should get a default value, when empty") ( + check ( + obtained = (NoneSD_ [Int] () ).getOrElse (1) + ) ( + expected = 1 + ) + ) + + test ("should get a value") ( + check ( + obtained = (SomeSD_ [Int] (2) ).getOrElse (1) + ) ( + expected = 2 + ) + ) + + test ("should open an empty option") ( + check ( + obtained = (NoneSD_ [String] () ).opt (ifEmpty = result_if_empty) (ifNonEmpty = result_if_non_empty) + ) ( + expected = "It is empty." + ) + ) + + test ("should open an non empty option") ( + check ( + obtained = (SomeSD_ [String] ("0") ).opt (ifEmpty = result_if_empty) (ifNonEmpty = result_if_non_empty) + ) ( + expected = "Its value is 0." + ) + ) + + test ("should try fold an empty option") ( + check ( + obtained = (NoneSD_ [String] () ).fold (ifEmpty = result_if_empty) (f = result_if_non_empty) + ) ( + expected = "It is empty." + ) + ) + + test ("should try fold an non empty option") ( + check ( + obtained = (SomeSD_ [String] ("0") ).fold (ifEmpty = result_if_empty) (f = result_if_non_empty) + ) ( + expected = "Its value is 0." + ) + ) + + test ("should map empty to empty") ( + check ( + obtained = (NoneSD_ [Int] () ).map (int_to_string) + ) ( + expected = NoneSD_ [String] () + ) + ) + + test ("should map a non-empty to another non-empty") ( + check ( + obtained = (SomeSD_ [Int] (2) ).map (int_to_string) + ) ( + expected = SomeSD_ [String] ("2") + ) + ) + + test ("should flat map empty to empty") ( + check ( + obtained = (NoneSD_ [Int] () ).flatMap (maybe_int_to_string) + ) ( + expected = NoneSD_ [String] () + ) + ) + + test ("should flat map a non-empty to another non-empty") ( + check ( + obtained = (SomeSD_ [Int] (2) ).flatMap (maybe_int_to_string) + ) ( + expected = SomeSD_ [String] ("2") + ) + ) + + test ("should try how successive applications of open works") ( + check ( + obtained = + maybe_string_to_int ("1").opt (ifEmpty = _empty_opt ) ( + ifNonEmpty = a => + maybe_string_to_int ("2").opt (ifEmpty = _empty_opt ) ( + ifNonEmpty = b => + maybe_string_to_int ("3").opt (ifEmpty = _empty_opt ) ( + ifNonEmpty = c => + SomeSD_ (a + b + c) ) ) ) + ) ( + expected = SomeSD_ (6) + ) + ) + + private lazy val _empty_opt : OptionSD [Int] = NoneSD_ [Int] () + + test ("toOption with non empty option") ( + check ( + obtained = (SomeSD_ [Int] (1) ).toOption + ) ( + expected = Some (1) + ) + ) + + test ("toOption with another non empty option") ( + check ( + obtained = (SomeSD_ [Int] (2) ).toOption + ) ( + expected = Some (2) + ) + ) + + test ("toOption with empty option") ( + check ( + obtained = (NoneSD_ [Int] () ).toOption + ) ( + expected = None + ) + ) + + test ("toSeq with non empty option") ( + check ( + obtained = (SomeSD_ (1) ).toSeq + ) ( + expected = Seq (1) + ) + ) + + test ("toSeq with another non empty option") ( + check ( + obtained = (SomeSD_ (2) ).toSeq + ) ( + expected = Seq (2) + ) + ) + + test ("toSeq with empty option") ( + check ( + obtained = (NoneSD_ () ).toSeq + ) ( + expected = Seq () + ) + ) + + test ("filter should work for None") ( + check ( + obtained = (NoneSD_ [Int] () ).filter ( x => true) + ) ( + expected = NoneSD_ [Int] () + ) + ) + + test ("filter should work for Some, if predicate does not hold") ( + check ( + obtained = (SomeSD_ [Int] (0) ).filter ( x => x > 0) + ) ( + expected = NoneSD_ [Int] () + ) + ) + + test ("filter should work for Some, if predicate holds") ( + check ( + obtained = (SomeSD_ [Int] (1) ).filter ( x => x > 0) + ) ( + expected = SomeSD_ [Int] (1) + ) + ) + +} +case class CartesianProductSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val int_seq_a = Seq (10, 20) + + lazy val int_seq_b = Seq (100, 200, 300) + + lazy val str_seq_a = Seq ("A", "B") + + lazy val str_seq_b = Seq ("0", "1", "2") + + lazy val str_seq_c = Seq ("a", "b", "c", "d") + + lazy val instance = CartesianProduct_ () + + test ("Cartesian product of two sequences") ( + check ( + obtained = instance.apply (Seq (int_seq_a, int_seq_b) ) + ) ( + expected = Seq ( + Seq (10, 100), Seq (10, 200), Seq (10, 300), + Seq (20, 100), Seq (20, 200), Seq (20, 300) + ) + ) + ) + + test ("Cartesian product of an empty sequence") ( + check ( + obtained = instance.apply (Seq () ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product of only empty sequences") ( + check ( + obtained = instance.apply (Seq (Seq (), Seq (), Seq () ) ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product with at least one empty sequence") ( + check ( + obtained = instance.apply (Seq (Seq ("A"), Seq () ) ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product of three sequences") ( + check ( + obtained = instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) + ) ( + expected = Seq ( + Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), + Seq ("A", "1", "a"), Seq ("A", "1", "b"), Seq ("A", "1", "c"), Seq ("A", "1", "d"), + Seq ("A", "2", "a"), Seq ("A", "2", "b"), Seq ("A", "2", "c"), Seq ("A", "2", "d"), + Seq ("B", "0", "a"), Seq ("B", "0", "b"), Seq ("B", "0", "c"), Seq ("B", "0", "d"), + Seq ("B", "1", "a"), Seq ("B", "1", "b"), Seq ("B", "1", "c"), Seq ("B", "1", "d"), + Seq ("B", "2", "a"), Seq ("B", "2", "b"), Seq ("B", "2", "c"), Seq ("B", "2", "d") + ) + ) + ) + +} +case class SeqSDSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val int_seq : Seq [Int] = Seq (2, 7, 1, 8, 2, 8, 1, 8, 2, 8, 4, 5, 9) + + lazy val rev_int_seq : Seq [Int] = Seq (9, 5 ,4, 8, 2, 8, 1, 8, 2, 8, 1, 7, 2) + + test ("should detect an empty sequence") ( + check ( + obtained = SeqSDBuilder_ ().build (Seq [Int] () ).opt (ifEmpty = true) (ifNonEmpty = nonEmpty => false) + ) ( + expected = true + ) + ) + + test ("should detect an non empty sequence") ( + check ( + obtained = SeqSDBuilder_ ().build (Seq [Int] (1) ).opt (ifEmpty = false) (ifNonEmpty = nonEmpty => true) + ) ( + expected = true + ) + ) + + test ("should get the maximum") ( + check ( + obtained = SeqSDBuilder_ ().build (int_seq).opt (ifEmpty = empty_opt) (ifNonEmpty = non_empty_opt) + ) ( + expected = SomeSD_ [Int] (9) + ) + ) + + lazy val empty_opt : OptionSD [Int] = NoneSD_ () + + lazy val non_empty_opt : NonEmptySeqSD [Int] => SomeSD [Int] = sequence => SomeSD_ (max (sequence) ) + + private lazy val _fold = Fold_ () + + def max_of_2 (a : Int) (b : Int) : Int = + if ( a > b ) a else b + + def max (s : NonEmptySeqSD [Int]) : Int = + _fold.apply (s.tail.toSeq) (s.head) (max_of_2) + + test ("should reverse a sequence") ( + check ( + obtained = SeqSDBuilder_ ().build (int_seq).reverse + ) ( + expected = SeqSDBuilder_ ().build (rev_int_seq) + ) + ) + + test ("should reverse another sequence") ( + check ( + obtained = SeqSDBuilder_ ().build (int_seq).opt (ifEmpty = empty_seq) (ifNonEmpty = non_empty_seq) + ) ( + expected = SeqSDBuilder_ ().build (rev_int_seq) + ) + ) + + lazy val empty_seq : SeqSD [Int] = EmptySeqSD_ () + + lazy val non_empty_seq : NonEmptySeqSD [Int] => NonEmptySeqSD [Int] = sequence => sequence.reverse + +} +trait DayOfTheWeek + extends + EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class DayOfTheWeek_ (ordinal : Int, name : String) extends DayOfTheWeek + +trait DayOfTheWeekConstant +{ + + lazy val sunday = DayOfTheWeek_ (0, "Sunday") + + lazy val monday = DayOfTheWeek_ (1, "Monday") + + lazy val tuesday = DayOfTheWeek_ (2, "Tuesday") + + lazy val wednesday = DayOfTheWeek_ (3, "Wednesday") + + lazy val thursday = DayOfTheWeek_ (4, "Thursday") + + lazy val friday = DayOfTheWeek_ (5, "Friday") + + lazy val saturday = DayOfTheWeek_ (6, "Saturday") + + lazy val DayOfTheWeek_values = Seq (sunday, monday, tuesday, wednesday, thursday, friday, saturday) + +} + +case class DayOfTheWeekConstant_ () extends DayOfTheWeekConstant + +trait DayOfTheWeekEnum + extends + DayOfTheWeekConstant +{ + + lazy val values = DayOfTheWeek_values + +} + +case class DayOfTheWeekEnum_ () extends DayOfTheWeekEnum + +case class EnumSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("the names of the elements in enumerations") ( + check ( + obtained = DayOfTheWeekEnum_ ().values.map ( x => x.toString) + ) ( + expected = Seq ("DayOfTheWeek_(0,Sunday)", "DayOfTheWeek_(1,Monday)", "DayOfTheWeek_(2,Tuesday)", "DayOfTheWeek_(3,Wednesday)", "DayOfTheWeek_(4,Thursday)", "DayOfTheWeek_(5,Friday)", "DayOfTheWeek_(6,Saturday)") + ) + ) + +} +case class RecursionSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + + test ("fold left while with Seq") ( + check ( + obtained = _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) + ) ( + expected = Seq ("103", "102", "101", "101", "100") + ) + ) + + private lazy val _fold0_initial_value = Seq [String] () + + private lazy val _fold0_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String]) => (e : Int) => (s.+: ("" + (e + 100) ) ) + + private lazy val _fold0_condition : Seq [String] => Int => Boolean = + (s : Seq [String] ) => (e : Int) => (e < 5) + + test ("fold left with Seq") ( + check ( + obtained = _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) + ) ( + expected = Seq ("108", "105", "103", "102", "101", "101", "100") + ) + ) + + private lazy val _fold1_initial_value = Seq [String] () + + private lazy val _fold1_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String] ) => (e : Int) => (s.+: ("" + (e + 100) ) ) + + test ("range with positive number") ( + check ( + obtained = _range.apply (8) + ) ( + expected = Seq (0, 1, 2, 3, 4, 5, 6, 7) + ) + ) + + test ("range with zero size") ( + check ( + obtained = _range.apply (-1) + ) ( + expected = Seq () + ) + ) + + test ("range with negative number") ( + check ( + obtained = _range.apply (-1) + ) ( + expected = Seq () + ) + ) + +} diff --git a/translator/src/test/scala/soda/lib/RecursionSpec.scala b/translator/src/test/scala/soda/lib/RecursionSpec.scala deleted file mode 100644 index 5868948e..00000000 --- a/translator/src/test/scala/soda/lib/RecursionSpec.scala +++ /dev/null @@ -1,78 +0,0 @@ -package soda.lib - -/* - * This package contains tests for the Soda library. - */ - - - -case class RecursionSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) - - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - test ("fold left while with Seq") ( - check ( - obtained = _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) - ) ( - expected = Seq ("103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold0_initial_value = Seq [String] () - - private lazy val _fold0_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String]) => (e : Int) => (s.+: ("" + (e + 100) ) ) - - private lazy val _fold0_condition : Seq [String] => Int => Boolean = - (s : Seq [String] ) => (e : Int) => (e < 5) - - test ("fold left with Seq") ( - check ( - obtained = _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) - ) ( - expected = Seq ("108", "105", "103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold1_initial_value = Seq [String] () - - private lazy val _fold1_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String] ) => (e : Int) => (s.+: ("" + (e + 100) ) ) - - test ("range with positive number") ( - check ( - obtained = _range.apply (8) - ) ( - expected = Seq (0, 1, 2, 3, 4, 5, 6, 7) - ) - ) - - test ("range with zero size") ( - check ( - obtained = _range.apply (-1) - ) ( - expected = Seq () - ) - ) - - test ("range with negative number") ( - check ( - obtained = _range.apply (-1) - ) ( - expected = Seq () - ) - ) - -} diff --git a/translator/src/test/scala/soda/lib/SeqSDSpec.scala b/translator/src/test/scala/soda/lib/SeqSDSpec.scala deleted file mode 100644 index 8bbee88f..00000000 --- a/translator/src/test/scala/soda/lib/SeqSDSpec.scala +++ /dev/null @@ -1,77 +0,0 @@ -package soda.lib - -/* - * This package contains tests for the Soda library. - */ - - - -case class SeqSDSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val int_seq : Seq [Int] = Seq (2, 7, 1, 8, 2, 8, 1, 8, 2, 8, 4, 5, 9) - - lazy val rev_int_seq : Seq [Int] = Seq (9, 5 ,4, 8, 2, 8, 1, 8, 2, 8, 1, 7, 2) - - test ("should detect an empty sequence") ( - check ( - obtained = SeqSDBuilder_ ().build (Seq [Int] () ).opt (ifEmpty = true) (ifNonEmpty = nonEmpty => false) - ) ( - expected = true - ) - ) - - test ("should detect an non empty sequence") ( - check ( - obtained = SeqSDBuilder_ ().build (Seq [Int] (1) ).opt (ifEmpty = false) (ifNonEmpty = nonEmpty => true) - ) ( - expected = true - ) - ) - - test ("should get the maximum") ( - check ( - obtained = SeqSDBuilder_ ().build (int_seq).opt (ifEmpty = empty_opt) (ifNonEmpty = non_empty_opt) - ) ( - expected = SomeSD_ [Int] (9) - ) - ) - - lazy val empty_opt : OptionSD [Int] = NoneSD_ () - - lazy val non_empty_opt : NonEmptySeqSD [Int] => SomeSD [Int] = sequence => SomeSD_ (max (sequence) ) - - private lazy val _fold = Fold_ () - - def max_of_2 (a : Int) (b : Int) : Int = - if ( a > b ) a else b - - def max (s : NonEmptySeqSD [Int]) : Int = - _fold.apply (s.tail.toSeq) (s.head) (max_of_2) - - test ("should reverse a sequence") ( - check ( - obtained = SeqSDBuilder_ ().build (int_seq).reverse - ) ( - expected = SeqSDBuilder_ ().build (rev_int_seq) - ) - ) - - test ("should reverse another sequence") ( - check ( - obtained = SeqSDBuilder_ ().build (int_seq).opt (ifEmpty = empty_seq) (ifNonEmpty = non_empty_seq) - ) ( - expected = SeqSDBuilder_ ().build (rev_int_seq) - ) - ) - - lazy val empty_seq : SeqSD [Int] = EmptySeqSD_ () - - lazy val non_empty_seq : NonEmptySeqSD [Int] => NonEmptySeqSD [Int] = sequence => sequence.reverse - -} diff --git a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala b/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala deleted file mode 100644 index 239c6c69..00000000 --- a/translator/src/test/scala/soda/translator/block/BlockTranslatorPipelineSpec.scala +++ /dev/null @@ -1,118 +0,0 @@ -package soda.translator.block - -/* - * This package contains tests for block translators. - */ - -trait BlockTranslator00 - extends - BlockTranslator -{ - - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.AnnotationFactory_ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) Seq ("") - else block.lines.++ ( Seq ("tr00") ) - ) - ) - -} - -case class BlockTranslator00_ () extends BlockTranslator00 - -trait BlockTranslator01 - extends - BlockTranslator -{ - - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.AnnotationFactory_ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) Seq ("") - else block.lines.++ ( Seq ("tr01") ) - ) - ) - -} - -case class BlockTranslator01_ () extends BlockTranslator01 - -trait BlockTranslator02 - extends - BlockTranslator -{ - - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.AnnotationFactory_ - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) Seq ("") - else block.lines.++ ( Seq ("tr02") ) - ) - ) - -} - -case class BlockTranslator02_ () extends BlockTranslator02 - -case class BlockTranslatorPipelineSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.AnnotationFactory_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockTranslatorPipeline_ ( - Seq ( - BlockTranslator00_ (), - BlockTranslator01_ (), - BlockTranslator02_ () - ) - ) - - lazy val original = - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - Seq ( "first line" ) - ) - ) - - test ("block translator pipeline") ( - check ( - obtained = instance.translate (original) - ) ( - expected = - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - Seq ( - "first line", - "tr00", - "tr01", - "tr02" - ) - ) - ) - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/block/Package.scala b/translator/src/test/scala/soda/translator/block/Package.scala index b86c0ee0..f2a618a6 100644 --- a/translator/src/test/scala/soda/translator/block/Package.scala +++ b/translator/src/test/scala/soda/translator/block/Package.scala @@ -4,3 +4,115 @@ package soda.translator.block * This package contains tests for block translators. */ trait Package +trait BlockTranslator00 + extends + BlockTranslator +{ + + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.AnnotationFactory_ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + if ( block.lines.isEmpty + ) Seq ("") + else block.lines.++ ( Seq ("tr00") ) + ) + ) + +} + +case class BlockTranslator00_ () extends BlockTranslator00 + +trait BlockTranslator01 + extends + BlockTranslator +{ + + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.AnnotationFactory_ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + if ( block.lines.isEmpty + ) Seq ("") + else block.lines.++ ( Seq ("tr01") ) + ) + ) + +} + +case class BlockTranslator01_ () extends BlockTranslator01 + +trait BlockTranslator02 + extends + BlockTranslator +{ + + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.AnnotationFactory_ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + if ( block.lines.isEmpty + ) Seq ("") + else block.lines.++ ( Seq ("tr02") ) + ) + ) + +} + +case class BlockTranslator02_ () extends BlockTranslator02 + +case class BlockTranslatorPipelineSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.AnnotationFactory_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockTranslatorPipeline_ ( + Seq ( + BlockTranslator00_ (), + BlockTranslator01_ (), + BlockTranslator02_ () + ) + ) + + lazy val original = + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + Seq ( "first line" ) + ) + ) + + test ("block translator pipeline") ( + check ( + obtained = instance.translate (original) + ) ( + expected = + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + Seq ( + "first line", + "tr00", + "tr01", + "tr02" + ) + ) + ) + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala deleted file mode 100644 index a5e3c32b..00000000 --- a/translator/src/test/scala/soda/translator/extension/tocoq/CoqFullTranslationSpec.scala +++ /dev/null @@ -1,61 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains test for the translator to Coq. - */ - -case class CoqFullTranslationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import org.scalatest.Assertion - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - import java.nio.file.Files - import java.nio.file.Paths - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val Base = "/soda/translator/example/" - - lazy val SodaSuffix = ".soda" - - lazy val CoqSuffix = ".v" - - lazy val SwapExample = "algorithms/SwapExample" - - lazy val TriangularNumber = "forcoq/mathematics/TriangularNumberForCoq" - - def test_translation (file_name : String) : Assertion = - test_translation_with (input_file_name = Base + file_name + SodaSuffix) (expected_file_name = Base + file_name + CoqSuffix) - - def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = - check ( - obtained = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToCoq_() - ) - ).translate (read_file (input_file_name) ) - ) ( - expected = read_file (expected_file_name) - ) - - def read_file (file_name : String) : String = - new String ( - Files.readAllBytes ( - Paths.get (getClass.getResource (file_name).toURI) - ) - ) - - test ("should translate the swap example") ( - test_translation (SwapExample) - ) - - test ("should translate the example of triangular numbers") ( - test_translation (TriangularNumber) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala b/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala deleted file mode 100644 index 6cfe2428..00000000 --- a/translator/src/test/scala/soda/translator/extension/tocoq/MicroTranslatorToCoqSpec.scala +++ /dev/null @@ -1,41 +0,0 @@ -package soda.translator.extension.tocoq - -/* - * This package contains test for the translator to Coq. - */ - -case class MicroTranslatorToCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToCoq_ () - ) - ) - - test ("Coq translation of a constant") ( - check ( - obtained = instance.translate ("x = 0") - ) ( - expected = " Definition x := 0\n.\n" - ) - ) - - test ("Coq translation of a function") ( - check ( - obtained = instance.translate ("f (a: nat) = 0") - ) ( - expected = " Definition f (a: nat) := 0\n.\n" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala index 1fc6c2b3..8d14322a 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala @@ -4,3 +4,93 @@ package soda.translator.extension.tocoq * This package contains test for the translator to Coq. */ trait Package +case class MicroTranslatorToCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToCoq_ () + ) + ) + + test ("Coq translation of a constant") ( + check ( + obtained = instance.translate ("x = 0") + ) ( + expected = " Definition x := 0\n.\n" + ) + ) + + test ("Coq translation of a function") ( + check ( + obtained = instance.translate ("f (a: nat) = 0") + ) ( + expected = " Definition f (a: nat) := 0\n.\n" + ) + ) + +} +case class CoqFullTranslationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import org.scalatest.Assertion + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + import java.nio.file.Files + import java.nio.file.Paths + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val Base = "/soda/translator/example/" + + lazy val SodaSuffix = ".soda" + + lazy val CoqSuffix = ".v" + + lazy val SwapExample = "algorithms/SwapExample" + + lazy val TriangularNumber = "forcoq/mathematics/TriangularNumberForCoq" + + def test_translation (file_name : String) : Assertion = + test_translation_with (input_file_name = Base + file_name + SodaSuffix) (expected_file_name = Base + file_name + CoqSuffix) + + def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = + check ( + obtained = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToCoq_() + ) + ).translate (read_file (input_file_name) ) + ) ( + expected = read_file (expected_file_name) + ) + + def read_file (file_name : String) : String = + new String ( + Files.readAllBytes ( + Paths.get (getClass.getResource (file_name).toURI) + ) + ) + + test ("should translate the swap example") ( + test_translation (SwapExample) + ) + + test ("should translate the example of triangular numbers") ( + test_translation (TriangularNumber) + ) + +} diff --git a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala deleted file mode 100644 index 8665e24e..00000000 --- a/translator/src/test/scala/soda/translator/extension/todoc/DocFullTranslationSpec.scala +++ /dev/null @@ -1,50 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains tests for the translator to documents. - */ - -case class DocFullTranslationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import org.scalatest.Assertion - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - import java.nio.file.Files - import java.nio.file.Paths - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val base = "/soda/translator/documentation/" - - lazy val soda_suffix = ".soda" - - lazy val doc_suffix = ".tex" - - lazy val manual = "Manual" - - def test_translation (file_name : String) : Assertion = - test_translation_with (input_file_name = base + file_name + soda_suffix) (expected_file_name = base + file_name + doc_suffix) - - def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = - check ( - obtained = TranslatorToDoc_ ().translate_content (read_file (input_file_name) ) - ) ( - expected = read_file (expected_file_name) - ) - - def read_file (file_name : String) : String = - new String ( - Files.readAllBytes ( - Paths.get (getClass.getResource (file_name).toURI) - ) - ) - - test ("should translate the manual") ( - test_translation (manual) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala b/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala deleted file mode 100644 index b1c10725..00000000 --- a/translator/src/test/scala/soda/translator/extension/todoc/MicroTranslatorToDocSpec.scala +++ /dev/null @@ -1,49 +0,0 @@ -package soda.translator.extension.todoc - -/* - * This package contains tests for the translator to documents. - */ - -case class MicroTranslatorToDocSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToDoc_ () - ) - ) - - lazy val original_snippet = "" + - "/*" + - "\n * This is an example" + - "\n*/" + - "\n" - - lazy val translated_snippet = "" + - "\n\\end{lstlisting}" + - "\n" + - "\nThis is an example" + - "\n" + - "\n" + - "\n\\begin{lstlisting}" + - "\n" + - "\n" - - test ("Document generation of a snippet") ( - check ( - obtained = instance.translate (original_snippet) - ) ( - expected = translated_snippet - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala index 3a976d81..4dd9be1e 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala @@ -4,3 +4,90 @@ package soda.translator.extension.todoc * This package contains tests for the translator to documents. */ trait Package +case class MicroTranslatorToDocSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToDoc_ () + ) + ) + + lazy val original_snippet = "" + + "/*" + + "\n * This is an example" + + "\n*/" + + "\n" + + lazy val translated_snippet = "" + + "\n\\end{lstlisting}" + + "\n" + + "\nThis is an example" + + "\n" + + "\n" + + "\n\\begin{lstlisting}" + + "\n" + + "\n" + + test ("Document generation of a snippet") ( + check ( + obtained = instance.translate (original_snippet) + ) ( + expected = translated_snippet + ) + ) + +} +case class DocFullTranslationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import org.scalatest.Assertion + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + import java.nio.file.Files + import java.nio.file.Paths + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val base = "/soda/translator/documentation/" + + lazy val soda_suffix = ".soda" + + lazy val doc_suffix = ".tex" + + lazy val manual = "Manual" + + def test_translation (file_name : String) : Assertion = + test_translation_with (input_file_name = base + file_name + soda_suffix) (expected_file_name = base + file_name + doc_suffix) + + def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = + check ( + obtained = TranslatorToDoc_ ().translate_content (read_file (input_file_name) ) + ) ( + expected = read_file (expected_file_name) + ) + + def read_file (file_name : String) : String = + new String ( + Files.readAllBytes ( + Paths.get (getClass.getResource (file_name).toURI) + ) + ) + + test ("should translate the manual") ( + test_translation (manual) + ) + +} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala deleted file mode 100644 index d5ade30e..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/BeautifierSpec.scala +++ /dev/null @@ -1,35 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class BeautifierSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val original = " beautify_this ( original : String ) : String = \n" + - " original . replaceAll(\" \" , \" \") \n" - - test ("the translated source code should respect unnecessary spaces") ( - check ( - obtained = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_() - ) - ).translate (original) - ) ( - expected = " def beautify_this ( original : String ) : String = \n" + - " original . replaceAll(\" \" , \" \") \n" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala deleted file mode 100644 index 8c0818da..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/ClassConstructorBlockTranslatorSpec.scala +++ /dev/null @@ -1,133 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class ClassConstructorBlockTranslatorSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_program_0 = - "package soda.example.mytest" + - "\n" + - "\nclass Example0" + - "\n extends" + - "\n SuperClassExample" + - "\n" + - "\n abstract" + - "\n /** this value is an example */" + - "\n value: Int" + - "\n /** this function is also an example */" + - "\n a_function: Int -> Double -> String" + - "\n" + - "\nend" + - "\n" + - "\nclass Example0Spec ()" + - "\n extends" + - "\n org.scalatest.funsuite.AnyFunSuite" + - "\n" + - "\nend" + - "\n" + - "\n" - - lazy val expected_program_0 = - "package soda.example.mytest" + - "\n" + - "\nclass Example0" + - "\n extends" + - "\n SuperClassExample" + - "\n" + - "\n abstract" + - "\n /** this value is an example */" + - "\n value: Int" + - "\n /** this function is also an example */" + - "\n a_function: Int -> Double -> String" + - "\n" + - "\nend" + - "\n" + - "\ncase class Example0_ (value: Int, a_function: Int => Double => String) extends Example0" + - "\n" + - "\nclass Example0Spec ()" + - "\n extends" + - "\n org.scalatest.funsuite.AnyFunSuite" + - "\n" + - "\nend" + - "\n" - - lazy val example_program_1 = - "package soda.example.mytest" + - "\n" + - "\nclass Example [A, B subtype SuperType]" + - "\n extends" + - "\n SuperClassExample" + - "\n AnotherSuperClassExample [A]" + - "\n" + - "\n abstract" + - "\n value: Int" + - "\n a_function: Int -> Double -> String" + - "\n" + - "\nend" + - "\n" + - "\nclass ExampleSpec ()" + - "\n extends" + - "\n org.scalatest.funsuite.AnyFunSuite" + - "\n" + - "\nend" + - "\n" + - "\n" - - lazy val expected_program_1 = - "package soda.example.mytest" + - "\n" + - "\nclass Example [A, B subtype SuperType]" + - "\n extends" + - "\n SuperClassExample" + - "\n AnotherSuperClassExample [A]" + - "\n" + - "\n abstract" + - "\n value: Int" + - "\n a_function: Int -> Double -> String" + - "\n" + - "\nend" + - "\n" + - "\ncase class Example_ [A, B <: SuperType] (value: Int, a_function: Int => Double => String) extends Example [A, B]" + - "\n" + - "\nclass ExampleSpec ()" + - "\n extends" + - "\n org.scalatest.funsuite.AnyFunSuite" + - "\n" + - "\nend" + - "\n" - - lazy val translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - ClassConstructorBlockTranslator_ () - ) - ) - - test ("should produce the constructors for a simple class") ( - check ( - obtained = translator.translate (example_program_0) - ) ( - expected = expected_program_0 - ) - ) - - test ("should produce the constructors for a class with type parameters") ( - check ( - obtained = translator.translate (example_program_1) - ) ( - expected = expected_program_1 - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala deleted file mode 100644 index 809a307b..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.scala +++ /dev/null @@ -1,105 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class FullTranslationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import org.scalatest.Assertion - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - import java.nio.file.Files - import java.nio.file.Paths - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val Base = "/soda/translator/example/" - - lazy val SodaSuffix = ".soda" - - lazy val ScalaSuffix = ".scala" - - lazy val SwapExample = "algorithms/SwapExample" - - lazy val FiboExample = "mathematics/FiboExample" - - lazy val FactorialConcise = "mathematics/FactorialConcise" - - lazy val FactorialVerbose = "mathematics/FactorialVerbose" - - lazy val Fairness = "ethicalissues/fairness/Fairness" - - lazy val PiIterator = "mathematics/PiIterator" - - lazy val ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" - - lazy val InANutshell = "inanutshell/InANutshell" - - lazy val ManualInput = "/soda/translator/documentation/Manual.soda" - - lazy val ManualExpected = "/soda/translator/documentation/Manual.scala" - - def test_translation (file_name : String) : Assertion = - test_translation_with (input_file_name = Base + file_name + SodaSuffix) (expected_file_name = Base + file_name + ScalaSuffix) - - def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = - check ( - obtained = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_() - ) - ).translate (read_file (input_file_name) ) - ) ( - expected = read_file (expected_file_name) - ) - - def read_file (file_name : String) : String = - new String ( - Files.readAllBytes ( - Paths.get (getClass.getResource (file_name).toURI) - ) - ) - - test ("should translate the swap example") ( - test_translation (SwapExample) - ) - - test ("should translate the Fibonacci example") ( - test_translation (FiboExample) - ) - - test ("should translate the Factorial Concise example") ( - test_translation (FactorialConcise) - ) - - test ("should translate the Factorial Verbose example") ( - test_translation (FactorialVerbose) - ) - - test ("should translate the Fairness example") ( - test_translation (Fairness) - ) - - test ("should translate the example that calculates pi") ( - test_translation (PiIterator) - ) - - test ("should translated Soda code that uses Scala reserved words as variables and functions") ( - test_translation (ScalaReservedWordEscaping) - ) - - test ("should translate the manual In A Nutshell") ( - test_translation (InANutshell) - ) - - test ("should translate the manual") ( - test_translation_with (ManualInput) (ManualExpected) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala deleted file mode 100644 index 11012fff..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/LazySyntaxSpec.scala +++ /dev/null @@ -1,96 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -trait ExampleWithWrongOrder -{ - - lazy val this_is_null_but = constant_defined_later - - lazy val constant_defined_later = "Success!" - -} - -case class ExampleWithWrongOrder_ () extends ExampleWithWrongOrder - -trait ExampleWithRightOrder -{ - - lazy val constant_defined_before = "Success!" - - lazy val this_is_not_null = constant_defined_before - -} - -case class ExampleWithRightOrder_ () extends ExampleWithRightOrder - -trait ExampleWithEmptyParentheses -{ - - def this_is_not_null () = constant_defined_later - - lazy val constant_defined_later = "Success!" - -} - -case class ExampleWithEmptyParentheses_ () extends ExampleWithEmptyParentheses - -trait AnotherExampleWithEmptyParentheses -{ - - lazy val this_is_not_null = constant_function_defined_later () - - def constant_function_defined_later () = "Success!" - -} - -case class AnotherExampleWithEmptyParentheses_ () extends AnotherExampleWithEmptyParentheses - -/** - * In Soda constants cannot be defined as 'lazy val'. - * These tests detect and test this problem, and test work-arounds. - */ - -case class LazySyntaxSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should show what happens when constants are defined in the wrong order") ( - check ( - obtained = ExampleWithWrongOrder_ ().this_is_null_but - ) ( - expected = "Success!" - ) - ) - - test ("should show what happens when constants are defined in the right order") ( - check ( - obtained = ExampleWithRightOrder_ ().this_is_not_null - ) ( - expected = "Success!" - ) - ) - - test ("should show what happens when one work-around is used") ( - check ( - obtained = ExampleWithEmptyParentheses_ ().this_is_not_null () - ) ( - expected = "Success!" - ) - ) - - test ("should show what happens when another work-around is used") ( - check ( - obtained = AnotherExampleWithEmptyParentheses_ ().this_is_not_null - ) ( - expected = "Success!" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala deleted file mode 100644 index cbdd5eeb..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/MicroTranslatorToScalaSpec.scala +++ /dev/null @@ -1,307 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class MicroTranslatorToScalaSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - test ("should translate a small snippet") ( - check ( - obtained = instance.translate (" input_lines = Seq (" + - "\n \" f ( x : Int,\\t\", " + - "\n \" y : Int) =\"," + - "\n \" x + y\")" + - "\n" - ) - ) ( - expected = " lazy val input_lines = Seq (" + - "\n \" f ( x : Int,\\t\", " + - "\n \" y : Int) =\"," + - "\n \" x + y\")" + - "\n" - ) - ) - - test ("should leave content of apostrophes unchanged") ( - check ( - obtained = instance.translate (" a = Seq ('\\'', \'', '\\\"', ' or ', \'or\', '0x00', '->', '/*', '*/')\n") - ) ( - expected = " lazy val a = Seq ('\\'', '', '\\\"', ' or ', 'or', '0x00', '->', '/*', '*/')\n" - ) - ) - - test ("should leave content of quotation marks unchanged") ( - check ( - obtained = instance.translate (" a = Seq (\"\\\"\", \"\", \"\\\'\", \" or \", \"or\", \"0x00\", \"->\", \"/*\", \"*/\")\n" ) - ) ( - expected = " lazy val a = Seq (\"\\\"\", \"\", \"\\'\", \" or \", \"or\", \"0x00\", \"->\", \"/*\", \"*/\")\n" - ) - ) - - test ("should translate classes") ( - check ( - obtained = instance.translate ("class D" + - "\n" + - "\n f (x : Int) : Int = x + 1" + - "\n" + - "\nend" + - "\n" + - "\nclass E" + - "\n" + - "\n g (x : Int) : Int = 2 * x" + - "\n" + - "\nend" + - "\n" + - "\nclass F ()" + - "\n extends" + - "\n D" + - "\n" + - "\n abstract" + - "\n /** name for this object */" + - "\n name : String" + - "\n /**" + - "\n * value for this object" + - "\n */" + - "\n value : Int" + - "\n" + - "\n h (x : Int) : Int = 2 * x + 1" + - "\n" + - "\nend" + - "\n" + - "\nclass E [A]" + - "\n" + - "\n i (x : A) : A = x" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = - "trait D" + - "\n{" + - "\n" + - "\n def f (x : Int) : Int = x + 1" + - "\n" + - "\n}" + - "\n" + - "\ncase class D_ () extends D" + - "\n" + - "\ntrait E" + - "\n{" + - "\n" + - "\n def g (x : Int) : Int = 2 * x" + - "\n" + - "\n}" + - "\n" + - "\ncase class E_ () extends E" + - "\n" + - "\ncase class F ()" + - "\n extends" + - "\n D" + - "\n{" + - "\n" + - "\n /** name for this object */" + - "\n def name : String" + - "\n /**" + - "\n * value for this object" + - "\n */" + - "\n def value : Int" + - "\n" + - "\n def h (x : Int) : Int = 2 * x + 1" + - "\n" + - "\n}" + - "\n" + - "\ntrait E [A]" + - "\n{" + - "\n" + - "\n def i (x : A) : A = x" + - "\n" + - "\n}" + - "\n" + - "\ncase class E_ [A] () extends E [A]" + - "\n" - ) - ) - - test ("should translate a class in a class") ( - check ( - obtained = instance.translate ("class D" + - "\n" + - "\n f (x : Int) : Int = x + 1" + - "\n" + - "\n class E" + - "\n extends" + - "\n D" + - "\n" + - "\n g (x : Int) : Int = 2 * x" + - "\n" + - "\n end" + - "\n" + - "\n class F = E" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = - "trait D" + - "\n{" + - "\n" + - "\n def f (x : Int) : Int = x + 1" + - "\n" + - "\n trait E" + - "\n extends" + - "\n D" + - "\n {" + - "\n" + - "\n def g (x : Int) : Int = 2 * x" + - "\n" + - "\n }" + - "\n" + - "\n case class E_ () extends E" + - "\n" + - "\n type F = E" + - "\n" + - "\n}" + - "\n" + - "\ncase class D_ () extends D" + - "\n" - ) - ) - - test ("should translate type aliases") ( - check ( - obtained = instance.translate ("class A [T] = B [T]" + - "\n" + - "\nclass C = D" + - "\n" + - "\nclass M = Map [Int, Seq [Int]]" + - "\n" - ) - ) ( - expected = - "type A [T] = B [T]" + - "\n" + - "\ntype C = D" + - "\n" + - "\ntype M = Map [Int, Seq [Int]]" + - "\n" - ) - ) - - test ("should translate a tuple assignment") ( - check ( - obtained = instance.translate (" (x, y) = (f (a), g (a))" + - "\n" + - "\n (p, q) =" + - "\n h (1, 2)" + - "\n" - ) - ) ( - expected = " lazy val (x, y) = (f (a), g (a))" + - "\n" + - "\n lazy val (p, q) =" + - "\n h (1, 2)" + - "\n" - ) - ) - - test ("should translate a pattern matching") ( - check ( - obtained = instance.translate ("fibo (n : Int) : Int = " + - "\n match n" + - "\n case 0 ==> 1 " + - "\n case 1 ==> 1 " + - "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n" - ) - ) ( - expected = "def fibo (n : Int) : Int = " + - "\n n match {" + - "\n case 0 => 1 " + - "\n case 1 => 1 " + - "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + - "\n }" + - "\n" - ) - ) - - test ("should translate another pattern matching") ( - check ( - obtained = instance.translate ("fibo (n : Int) : Int = " + - "\n match n" + - "\n case 0 ==> 1 " + - "\n case 1 ==> 1 " + - "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n" - ) - ) ( - expected = "def fibo (n : Int) : Int = " + - "\n n match {" + - "\n case 0 => 1 " + - "\n case 1 => 1 " + - "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + - "\n }" + - "\n" - ) - ) - - test ("should ignore a pattern matching written in the Scala style") ( - check ( - obtained = instance.translate ("fibo (n : Int) : Int = " + - "\n n match" + - "\n case 0 ==> 1 " + - "\n case 1 ==> 1 " + - "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + - "\n" - ) - ) ( - expected = "def fibo (n : Int) : Int = " + - "\n n match" + - "\n case 0 => 1 " + - "\n case 1 => 1 " + - "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + - "\n" - ) - ) - - test ("should translate an explicit lambda expression") ( - check ( - obtained = instance.translate ("plus_1 : Int = lambda (x : Int) --> x + 1" + - "\n" - ) - ) ( - expected = "lazy val plus_1 : Int = (x : Int) => x + 1" + - "\n" - ) - ) - - test ("should translate another explicit lambda expression") ( - check ( - obtained = instance.translate ("plus_1 : Int = any (x : Int) --> x + 1" + - "\n" - ) - ) ( - expected = "lazy val plus_1 : Int = (x : Int) => x + 1" + - "\n" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala deleted file mode 100644 index 134b079c..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/MultiLineSpec.scala +++ /dev/null @@ -1,87 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class MultiLineSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.DefaultBlockTranslator_ - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.annotation.AnnotationFactory_ - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val bp = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - lazy val mt = MicroTranslatorToScala_ () - - lazy val original_input = - " value = 1\n" + - " sequence = Seq(1 ,\n" + - " 2, \n" + - " 3)\n" + - " f( x: Int,\t\n" + - " y: Int,\n" + - " z: Int) =\n" + - " x * x + y * y + z * z\n" - - lazy val original_input_lines = Seq( - " value = 1", - " sequence = Seq(1 ,", - " 2, ", - " 3)", - " f( x: Int,\t", - " y: Int,", - " z: Int) =", - " x * x + y * y + z * z") - - lazy val joined_comma_lines = Seq( - " value = 1", - " sequence = Seq(1 , 2, 3)", - " f( x: Int,\t y: Int, z: Int) =", - " x * x + y * y + z * z") - - lazy val joined_output = - " value = 1\n" + - " sequence = Seq(1 ," + - " 2, " + - " 3)\n" + - " f( x: Int,\t" + - " y: Int," + - " z: Int) =\n" + - " x * x + y * y + z * z" - - def build_block (lines: Seq [String]): AnnotatedBlock = - AnnotationFactory_ ().annotate (BlockBuilder_ ().build (lines) ) - - test ("should split a program in multiple lines") ( - check ( - obtained = bp.make_block (original_input) - ) ( - expected = build_block (original_input_lines ) - ) - ) - - test ("should join the translated lines of a program") ( - check ( - obtained = build_block (joined_comma_lines) - ) ( - expected = bp.make_block (joined_output) - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala index 138179bf..4a8d5af0 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -4,3 +4,951 @@ package soda.translator.extension.toscala * This package contains tests for the translator to Scala. */ trait Package +case class MultiLineSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val bp = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + lazy val mt = MicroTranslatorToScala_ () + + lazy val original_input = + " value = 1\n" + + " sequence = Seq(1 ,\n" + + " 2, \n" + + " 3)\n" + + " f( x: Int,\t\n" + + " y: Int,\n" + + " z: Int) =\n" + + " x * x + y * y + z * z\n" + + lazy val original_input_lines = Seq( + " value = 1", + " sequence = Seq(1 ,", + " 2, ", + " 3)", + " f( x: Int,\t", + " y: Int,", + " z: Int) =", + " x * x + y * y + z * z") + + lazy val joined_comma_lines = Seq( + " value = 1", + " sequence = Seq(1 , 2, 3)", + " f( x: Int,\t y: Int, z: Int) =", + " x * x + y * y + z * z") + + lazy val joined_output = + " value = 1\n" + + " sequence = Seq(1 ," + + " 2, " + + " 3)\n" + + " f( x: Int,\t" + + " y: Int," + + " z: Int) =\n" + + " x * x + y * y + z * z" + + def build_block (lines: Seq [String]): AnnotatedBlock = + AnnotationFactory_ ().annotate (BlockBuilder_ ().build (lines) ) + + test ("should split a program in multiple lines") ( + check ( + obtained = bp.make_block (original_input) + ) ( + expected = build_block (original_input_lines ) + ) + ) + + test ("should join the translated lines of a program") ( + check ( + obtained = build_block (joined_comma_lines) + ) ( + expected = bp.make_block (joined_output) + ) + ) + +} +case class ClassConstructorBlockTranslatorSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_program_0 = + "package soda.example.mytest" + + "\n" + + "\nclass Example0" + + "\n extends" + + "\n SuperClassExample" + + "\n" + + "\n abstract" + + "\n /** this value is an example */" + + "\n value: Int" + + "\n /** this function is also an example */" + + "\n a_function: Int -> Double -> String" + + "\n" + + "\nend" + + "\n" + + "\nclass Example0Spec ()" + + "\n extends" + + "\n org.scalatest.funsuite.AnyFunSuite" + + "\n" + + "\nend" + + "\n" + + "\n" + + lazy val expected_program_0 = + "package soda.example.mytest" + + "\n" + + "\nclass Example0" + + "\n extends" + + "\n SuperClassExample" + + "\n" + + "\n abstract" + + "\n /** this value is an example */" + + "\n value: Int" + + "\n /** this function is also an example */" + + "\n a_function: Int -> Double -> String" + + "\n" + + "\nend" + + "\n" + + "\ncase class Example0_ (value: Int, a_function: Int => Double => String) extends Example0" + + "\n" + + "\nclass Example0Spec ()" + + "\n extends" + + "\n org.scalatest.funsuite.AnyFunSuite" + + "\n" + + "\nend" + + "\n" + + lazy val example_program_1 = + "package soda.example.mytest" + + "\n" + + "\nclass Example [A, B subtype SuperType]" + + "\n extends" + + "\n SuperClassExample" + + "\n AnotherSuperClassExample [A]" + + "\n" + + "\n abstract" + + "\n value: Int" + + "\n a_function: Int -> Double -> String" + + "\n" + + "\nend" + + "\n" + + "\nclass ExampleSpec ()" + + "\n extends" + + "\n org.scalatest.funsuite.AnyFunSuite" + + "\n" + + "\nend" + + "\n" + + "\n" + + lazy val expected_program_1 = + "package soda.example.mytest" + + "\n" + + "\nclass Example [A, B subtype SuperType]" + + "\n extends" + + "\n SuperClassExample" + + "\n AnotherSuperClassExample [A]" + + "\n" + + "\n abstract" + + "\n value: Int" + + "\n a_function: Int -> Double -> String" + + "\n" + + "\nend" + + "\n" + + "\ncase class Example_ [A, B <: SuperType] (value: Int, a_function: Int => Double => String) extends Example [A, B]" + + "\n" + + "\nclass ExampleSpec ()" + + "\n extends" + + "\n org.scalatest.funsuite.AnyFunSuite" + + "\n" + + "\nend" + + "\n" + + lazy val translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + ClassConstructorBlockTranslator_ () + ) + ) + + test ("should produce the constructors for a simple class") ( + check ( + obtained = translator.translate (example_program_0) + ) ( + expected = expected_program_0 + ) + ) + + test ("should produce the constructors for a class with type parameters") ( + check ( + obtained = translator.translate (example_program_1) + ) ( + expected = expected_program_1 + ) + ) + +} +/** + * This tests how translation is done for Scala reserved words that are not Soda reserved words. + */ + +case class ScalaNonSodaSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val bp = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + test ("Scala reserved words are replaced") ( + check ( + obtained = bp.translate ("" + + "\nval x =" + + "\n while (x != 0)" + ) + ) ( + expected = "" + + "private lazy val __soda__val x =" + + "\n __soda__while (x != 0)" + + "\n" + ) + ) + + test ("some synonyms are Scala reserved words") ( + check ( + obtained = bp.translate ("" + + "\nclass A0 [B0 <: C0]" + + "\n" + + "\nend" + + "\n" + + "\nclass C0 [D0 >: E0]" + + "\n" + + "\nend" + + "\n" + + "\nclass A1 [B1 subtype C1]" + + "\n" + + "\nend" + + "\n" + + "\nclass C1 [D1 supertype E1]" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = "" + + "trait A0 [B0 <: C0]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class A0_ [B0 <: C0] () extends A0 [B0]" + + "\n" + + "\ntrait C0 [D0 >: E0]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class C0_ [D0 >: E0] () extends C0 [D0]" + + "\n" + + "\ntrait A1 [B1 <: C1]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class A1_ [B1 <: C1] () extends A1 [B1]" + + "\n" + + "\ntrait C1 [D1 >: E1]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class C1_ [D1 >: E1] () extends C1 [D1]" + + "\n" + ) + ) + +} +case class FullTranslationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import org.scalatest.Assertion + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + import java.nio.file.Files + import java.nio.file.Paths + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val Base = "/soda/translator/example/" + + lazy val SodaSuffix = ".soda" + + lazy val ScalaSuffix = ".scala" + + lazy val SwapExample = "algorithms/SwapExample" + + lazy val FiboExample = "mathematics/FiboExample" + + lazy val FactorialConcise = "mathematics/FactorialConcise" + + lazy val FactorialVerbose = "mathematics/FactorialVerbose" + + lazy val Fairness = "ethicalissues/fairness/Fairness" + + lazy val PiIterator = "mathematics/PiIterator" + + lazy val ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" + + lazy val InANutshell = "inanutshell/InANutshell" + + lazy val ManualInput = "/soda/translator/documentation/Manual.soda" + + lazy val ManualExpected = "/soda/translator/documentation/Manual.scala" + + def test_translation (file_name : String) : Assertion = + test_translation_with (input_file_name = Base + file_name + SodaSuffix) (expected_file_name = Base + file_name + ScalaSuffix) + + def test_translation_with (input_file_name : String) (expected_file_name : String) : Assertion = + check ( + obtained = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_() + ) + ).translate (read_file (input_file_name) ) + ) ( + expected = read_file (expected_file_name) + ) + + def read_file (file_name : String) : String = + new String ( + Files.readAllBytes ( + Paths.get (getClass.getResource (file_name).toURI) + ) + ) + + test ("should translate the swap example") ( + test_translation (SwapExample) + ) + + test ("should translate the Fibonacci example") ( + test_translation (FiboExample) + ) + + test ("should translate the Factorial Concise example") ( + test_translation (FactorialConcise) + ) + + test ("should translate the Factorial Verbose example") ( + test_translation (FactorialVerbose) + ) + + test ("should translate the Fairness example") ( + test_translation (Fairness) + ) + + test ("should translate the example that calculates pi") ( + test_translation (PiIterator) + ) + + test ("should translated Soda code that uses Scala reserved words as variables and functions") ( + test_translation (ScalaReservedWordEscaping) + ) + + test ("should translate the manual In A Nutshell") ( + test_translation (InANutshell) + ) + + test ("should translate the manual") ( + test_translation_with (ManualInput) (ManualExpected) + ) + +} +case class UpperAndLowerBoundDeclarationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + test ("should translate a single upper bound") ( + check ( + obtained = instance.translate ("class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A subtype AbstractInput]" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = + "case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A <: AbstractInput]" + + "\n{" + + "\n" + + "\n}" + + "\n" + ) + ) + + test ("should translate multiple upper bounds") ( + check ( + obtained = instance.translate ( " class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A subtype AbstractInput]" + + "\n AbstractDevice[B subtype AbstractDeviceInput]" + + "\n" + + "\n end" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A <: AbstractInput]" + + "\n with AbstractDevice[B <: AbstractDeviceInput]" + + "\n {" + + "\n" + + "\n }" + + "\n" + ) + ) + + test ("should translate a single lower bound") ( + check ( + obtained = instance.translate (" class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A supertype (AbstractInput)]" + + "\n" + + "\n end" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A >: (AbstractInput)]" + + "\n {" + + "\n" + + "\n }" + + "\n" + ) + ) + + test ("should translate multiple lower bounds") ( + check ( + obtained = instance.translate (" class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A supertype (AbstractInput)]" + + "\n AbstractDevice[B supertype (AbstractDeviceInput)]" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A >: (AbstractInput)]" + + "\n with AbstractDevice[B >: (AbstractDeviceInput)]" + + "\n {" + + "\n" + + "\n}" + + "\n" + ) + ) + +} +trait ExampleWithWrongOrder +{ + + lazy val this_is_null_but = constant_defined_later + + lazy val constant_defined_later = "Success!" + +} + +case class ExampleWithWrongOrder_ () extends ExampleWithWrongOrder + +trait ExampleWithRightOrder +{ + + lazy val constant_defined_before = "Success!" + + lazy val this_is_not_null = constant_defined_before + +} + +case class ExampleWithRightOrder_ () extends ExampleWithRightOrder + +trait ExampleWithEmptyParentheses +{ + + def this_is_not_null () = constant_defined_later + + lazy val constant_defined_later = "Success!" + +} + +case class ExampleWithEmptyParentheses_ () extends ExampleWithEmptyParentheses + +trait AnotherExampleWithEmptyParentheses +{ + + lazy val this_is_not_null = constant_function_defined_later () + + def constant_function_defined_later () = "Success!" + +} + +case class AnotherExampleWithEmptyParentheses_ () extends AnotherExampleWithEmptyParentheses + +/** + * In Soda constants cannot be defined as 'lazy val'. + * These tests detect and test this problem, and test work-arounds. + */ + +case class LazySyntaxSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should show what happens when constants are defined in the wrong order") ( + check ( + obtained = ExampleWithWrongOrder_ ().this_is_null_but + ) ( + expected = "Success!" + ) + ) + + test ("should show what happens when constants are defined in the right order") ( + check ( + obtained = ExampleWithRightOrder_ ().this_is_not_null + ) ( + expected = "Success!" + ) + ) + + test ("should show what happens when one work-around is used") ( + check ( + obtained = ExampleWithEmptyParentheses_ ().this_is_not_null () + ) ( + expected = "Success!" + ) + ) + + test ("should show what happens when another work-around is used") ( + check ( + obtained = AnotherExampleWithEmptyParentheses_ ().this_is_not_null + ) ( + expected = "Success!" + ) + ) + +} +case class MicroTranslatorToScalaSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + test ("should translate a small snippet") ( + check ( + obtained = instance.translate (" input_lines = Seq (" + + "\n \" f ( x : Int,\\t\", " + + "\n \" y : Int) =\"," + + "\n \" x + y\")" + + "\n" + ) + ) ( + expected = " lazy val input_lines = Seq (" + + "\n \" f ( x : Int,\\t\", " + + "\n \" y : Int) =\"," + + "\n \" x + y\")" + + "\n" + ) + ) + + test ("should leave content of apostrophes unchanged") ( + check ( + obtained = instance.translate (" a = Seq ('\\'', \'', '\\\"', ' or ', \'or\', '0x00', '->', '/*', '*/')\n") + ) ( + expected = " lazy val a = Seq ('\\'', '', '\\\"', ' or ', 'or', '0x00', '->', '/*', '*/')\n" + ) + ) + + test ("should leave content of quotation marks unchanged") ( + check ( + obtained = instance.translate (" a = Seq (\"\\\"\", \"\", \"\\\'\", \" or \", \"or\", \"0x00\", \"->\", \"/*\", \"*/\")\n" ) + ) ( + expected = " lazy val a = Seq (\"\\\"\", \"\", \"\\'\", \" or \", \"or\", \"0x00\", \"->\", \"/*\", \"*/\")\n" + ) + ) + + test ("should translate classes") ( + check ( + obtained = instance.translate ("class D" + + "\n" + + "\n f (x : Int) : Int = x + 1" + + "\n" + + "\nend" + + "\n" + + "\nclass E" + + "\n" + + "\n g (x : Int) : Int = 2 * x" + + "\n" + + "\nend" + + "\n" + + "\nclass F ()" + + "\n extends" + + "\n D" + + "\n" + + "\n abstract" + + "\n /** name for this object */" + + "\n name : String" + + "\n /**" + + "\n * value for this object" + + "\n */" + + "\n value : Int" + + "\n" + + "\n h (x : Int) : Int = 2 * x + 1" + + "\n" + + "\nend" + + "\n" + + "\nclass E [A]" + + "\n" + + "\n i (x : A) : A = x" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = + "trait D" + + "\n{" + + "\n" + + "\n def f (x : Int) : Int = x + 1" + + "\n" + + "\n}" + + "\n" + + "\ncase class D_ () extends D" + + "\n" + + "\ntrait E" + + "\n{" + + "\n" + + "\n def g (x : Int) : Int = 2 * x" + + "\n" + + "\n}" + + "\n" + + "\ncase class E_ () extends E" + + "\n" + + "\ncase class F ()" + + "\n extends" + + "\n D" + + "\n{" + + "\n" + + "\n /** name for this object */" + + "\n def name : String" + + "\n /**" + + "\n * value for this object" + + "\n */" + + "\n def value : Int" + + "\n" + + "\n def h (x : Int) : Int = 2 * x + 1" + + "\n" + + "\n}" + + "\n" + + "\ntrait E [A]" + + "\n{" + + "\n" + + "\n def i (x : A) : A = x" + + "\n" + + "\n}" + + "\n" + + "\ncase class E_ [A] () extends E [A]" + + "\n" + ) + ) + + test ("should translate a class in a class") ( + check ( + obtained = instance.translate ("class D" + + "\n" + + "\n f (x : Int) : Int = x + 1" + + "\n" + + "\n class E" + + "\n extends" + + "\n D" + + "\n" + + "\n g (x : Int) : Int = 2 * x" + + "\n" + + "\n end" + + "\n" + + "\n class F = E" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = + "trait D" + + "\n{" + + "\n" + + "\n def f (x : Int) : Int = x + 1" + + "\n" + + "\n trait E" + + "\n extends" + + "\n D" + + "\n {" + + "\n" + + "\n def g (x : Int) : Int = 2 * x" + + "\n" + + "\n }" + + "\n" + + "\n case class E_ () extends E" + + "\n" + + "\n type F = E" + + "\n" + + "\n}" + + "\n" + + "\ncase class D_ () extends D" + + "\n" + ) + ) + + test ("should translate type aliases") ( + check ( + obtained = instance.translate ("class A [T] = B [T]" + + "\n" + + "\nclass C = D" + + "\n" + + "\nclass M = Map [Int, Seq [Int]]" + + "\n" + ) + ) ( + expected = + "type A [T] = B [T]" + + "\n" + + "\ntype C = D" + + "\n" + + "\ntype M = Map [Int, Seq [Int]]" + + "\n" + ) + ) + + test ("should translate a tuple assignment") ( + check ( + obtained = instance.translate (" (x, y) = (f (a), g (a))" + + "\n" + + "\n (p, q) =" + + "\n h (1, 2)" + + "\n" + ) + ) ( + expected = " lazy val (x, y) = (f (a), g (a))" + + "\n" + + "\n lazy val (p, q) =" + + "\n h (1, 2)" + + "\n" + ) + ) + + test ("should translate a pattern matching") ( + check ( + obtained = instance.translate ("fibo (n : Int) : Int = " + + "\n match n" + + "\n case 0 ==> 1 " + + "\n case 1 ==> 1 " + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + + "\n" + ) + ) ( + expected = "def fibo (n : Int) : Int = " + + "\n n match {" + + "\n case 0 => 1 " + + "\n case 1 => 1 " + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + + "\n }" + + "\n" + ) + ) + + test ("should translate another pattern matching") ( + check ( + obtained = instance.translate ("fibo (n : Int) : Int = " + + "\n match n" + + "\n case 0 ==> 1 " + + "\n case 1 ==> 1 " + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + + "\n" + ) + ) ( + expected = "def fibo (n : Int) : Int = " + + "\n n match {" + + "\n case 0 => 1 " + + "\n case 1 => 1 " + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + + "\n }" + + "\n" + ) + ) + + test ("should ignore a pattern matching written in the Scala style") ( + check ( + obtained = instance.translate ("fibo (n : Int) : Int = " + + "\n n match" + + "\n case 0 ==> 1 " + + "\n case 1 ==> 1 " + + "\n case x ==> if x > 0 then fibo (x - 1) + fibo (x - 2) else 0" + + "\n" + ) + ) ( + expected = "def fibo (n : Int) : Int = " + + "\n n match" + + "\n case 0 => 1 " + + "\n case 1 => 1 " + + "\n case x => if ( x > 0 ) fibo (x - 1) + fibo (x - 2) else 0" + + "\n" + ) + ) + + test ("should translate an explicit lambda expression") ( + check ( + obtained = instance.translate ("plus_1 : Int = lambda (x : Int) --> x + 1" + + "\n" + ) + ) ( + expected = "lazy val plus_1 : Int = (x : Int) => x + 1" + + "\n" + ) + ) + + test ("should translate another explicit lambda expression") ( + check ( + obtained = instance.translate ("plus_1 : Int = any (x : Int) --> x + 1" + + "\n" + ) + ) ( + expected = "lazy val plus_1 : Int = (x : Int) => x + 1" + + "\n" + ) + ) + +} +case class MainSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + lazy val instance = TranslatorToScala_ () + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should get the input and output file names without path") ( + check ( + obtained = instance.get_input_output_file_names("my_file.soda") + ) ( + expected = FileNamePair_("my_file.soda", "my_file.scala") + ) + ) + + test ("should get the input and output file names with path") ( + check ( + obtained = instance.get_input_output_file_names("/path/to/file.soda") + ) ( + expected = FileNamePair_("/path/to/file.soda", "/path/to/file.scala") + ) + ) + +} +case class BeautifierSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val original = " beautify_this ( original : String ) : String = \n" + + " original . replaceAll(\" \" , \" \") \n" + + test ("the translated source code should respect unnecessary spaces") ( + check ( + obtained = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_() + ) + ).translate (original) + ) ( + expected = " def beautify_this ( original : String ) : String = \n" + + " original . replaceAll(\" \" , \" \") \n" + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala deleted file mode 100644 index 05948f7d..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/ScalaNonSodaSpec.scala +++ /dev/null @@ -1,96 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -/** - * This tests how translation is done for Scala reserved words that are not Soda reserved words. - */ - -case class ScalaNonSodaSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val bp = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - test ("Scala reserved words are replaced") ( - check ( - obtained = bp.translate ("" + - "\nval x =" + - "\n while (x != 0)" - ) - ) ( - expected = "" + - "private lazy val __soda__val x =" + - "\n __soda__while (x != 0)" + - "\n" - ) - ) - - test ("some synonyms are Scala reserved words") ( - check ( - obtained = bp.translate ("" + - "\nclass A0 [B0 <: C0]" + - "\n" + - "\nend" + - "\n" + - "\nclass C0 [D0 >: E0]" + - "\n" + - "\nend" + - "\n" + - "\nclass A1 [B1 subtype C1]" + - "\n" + - "\nend" + - "\n" + - "\nclass C1 [D1 supertype E1]" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = "" + - "trait A0 [B0 <: C0]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class A0_ [B0 <: C0] () extends A0 [B0]" + - "\n" + - "\ntrait C0 [D0 >: E0]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class C0_ [D0 >: E0] () extends C0 [D0]" + - "\n" + - "\ntrait A1 [B1 <: C1]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class A1_ [B1 <: C1] () extends A1 [B1]" + - "\n" + - "\ntrait C1 [D1 >: E1]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class C1_ [D1 >: E1] () extends C1 [D1]" + - "\n" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala deleted file mode 100644 index 9bab7f71..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/TranslatorToScalaSpec.scala +++ /dev/null @@ -1,33 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class MainSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - lazy val instance = TranslatorToScala_ () - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should get the input and output file names without path") ( - check ( - obtained = instance.get_input_output_file_names("my_file.soda") - ) ( - expected = FileNamePair_("my_file.soda", "my_file.scala") - ) - ) - - test ("should get the input and output file names with path") ( - check ( - obtained = instance.get_input_output_file_names("/path/to/file.soda") - ) ( - expected = FileNamePair_("/path/to/file.soda", "/path/to/file.scala") - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala b/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala deleted file mode 100644 index d3659b07..00000000 --- a/translator/src/test/scala/soda/translator/extension/toscala/UpperAndLowerBoundDeclarationSpec.scala +++ /dev/null @@ -1,110 +0,0 @@ -package soda.translator.extension.toscala - -/* - * This package contains tests for the translator to Scala. - */ - -case class UpperAndLowerBoundDeclarationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - test ("should translate a single upper bound") ( - check ( - obtained = instance.translate ("class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A subtype AbstractInput]" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = - "case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A <: AbstractInput]" + - "\n{" + - "\n" + - "\n}" + - "\n" - ) - ) - - test ("should translate multiple upper bounds") ( - check ( - obtained = instance.translate ( " class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A subtype AbstractInput]" + - "\n AbstractDevice[B subtype AbstractDeviceInput]" + - "\n" + - "\n end" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A <: AbstractInput]" + - "\n with AbstractDevice[B <: AbstractDeviceInput]" + - "\n {" + - "\n" + - "\n }" + - "\n" - ) - ) - - test ("should translate a single lower bound") ( - check ( - obtained = instance.translate (" class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A supertype (AbstractInput)]" + - "\n" + - "\n end" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A >: (AbstractInput)]" + - "\n {" + - "\n" + - "\n }" + - "\n" - ) - ) - - test ("should translate multiple lower bounds") ( - check ( - obtained = instance.translate (" class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A supertype (AbstractInput)]" + - "\n AbstractDevice[B supertype (AbstractDeviceInput)]" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A >: (AbstractInput)]" + - "\n with AbstractDevice[B >: (AbstractDeviceInput)]" + - "\n {" + - "\n" + - "\n}" + - "\n" - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala b/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala deleted file mode 100644 index d075f049..00000000 --- a/translator/src/test/scala/soda/translator/io/DirectoryScannerSpec.scala +++ /dev/null @@ -1,51 +0,0 @@ -package soda.translator.io - -/* - * This package contains tests for the directory scanner. - */ - - - -case class DirectoryScannerSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import java.io.File - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val start = "translator/src/test/resources/soda/example" - - lazy val single_start_file = new File (start, "Example.soda") - - test ("scan a file that is not a directory") ( - check ( - obtained = DirectoryScanner_ ().get_all_files (single_start_file).toSet - ) ( - expected = Seq (single_start_file).toSet - ) - ) - - test ("simple scan of all files") ( - check ( - obtained = DirectoryScanner_ ().get_all_files ( new File (start) ).toSet - ) ( - expected = Seq ( - "otherexample", - "Example.md", - "Example.scala", - "Example.soda", - "Package.scala", - "Package.soda", - "otherexample/OtherExample.scala", - "otherexample/OtherExample.soda", - "otherexample/OtherExample.txt", - "otherexample/Package.scala", - "otherexample/Package.soda" - ).map ( x => new File (start, x) ).toSet - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/io/Package.scala b/translator/src/test/scala/soda/translator/io/Package.scala index f3f34ca3..7d7491eb 100644 --- a/translator/src/test/scala/soda/translator/io/Package.scala +++ b/translator/src/test/scala/soda/translator/io/Package.scala @@ -5,3 +5,46 @@ package soda.translator.io */ trait Package +case class DirectoryScannerSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import java.io.File + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val start = "translator/src/test/resources/soda/example" + + lazy val single_start_file = new File (start, "Example.soda") + + test ("scan a file that is not a directory") ( + check ( + obtained = DirectoryScanner_ ().get_all_files (single_start_file).toSet + ) ( + expected = Seq (single_start_file).toSet + ) + ) + + test ("simple scan of all files") ( + check ( + obtained = DirectoryScanner_ ().get_all_files ( new File (start) ).toSet + ) ( + expected = Seq ( + "otherexample", + "Example.md", + "Example.scala", + "Example.soda", + "Package.scala", + "Package.soda", + "otherexample/OtherExample.scala", + "otherexample/OtherExample.soda", + "otherexample/OtherExample.txt", + "otherexample/Package.scala", + "otherexample/Package.soda" + ).map ( x => new File (start, x) ).toSet + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/parser/BlockSpec.scala b/translator/src/test/scala/soda/translator/parser/BlockSpec.scala deleted file mode 100644 index 09141e6d..00000000 --- a/translator/src/test/scala/soda/translator/parser/BlockSpec.scala +++ /dev/null @@ -1,46 +0,0 @@ -package soda.translator.parser - -/* - * This package contains tests for the Soda parser. - */ - - - -case class BlockSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.AnnotatedLine_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val input = ("\n" + - "\n/** This is an example */" + - "\n* Example () {" + - "\n /* This is a comment */" + - "\n a = \"/** this is not a comment */\"" + - "\n}" + - "\n") - .split ("\n") - .toSeq - - /* This is to test how to find commented text. */ - test ("should find commented text") ( - check ( - obtained = BlockBuilder_ ().build (input).annotated_lines - ) ( - expected = Seq ( - AnnotatedLine_ ("", is_comment = false), - AnnotatedLine_ ("", is_comment = false), - AnnotatedLine_ ("/** This is an example */", is_comment = true), - AnnotatedLine_ ("* Example () {", is_comment = false), - AnnotatedLine_ (" /* This is a comment */", is_comment = true), - AnnotatedLine_ (" a = \"/** this is not a comment */\"", is_comment = false), - AnnotatedLine_ ("}", is_comment = false) - ) - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index adfd8166..922ff440 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -5,3 +5,119 @@ package soda.translator.parser */ trait Package +case class BlockSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.AnnotatedLine_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val input = ("\n" + + "\n/** This is an example */" + + "\n* Example () {" + + "\n /* This is a comment */" + + "\n a = \"/** this is not a comment */\"" + + "\n}" + + "\n") + .split ("\n") + .toSeq + + /* This is to test how to find commented text. */ + test ("should find commented text") ( + check ( + obtained = BlockBuilder_ ().build (input).annotated_lines + ) ( + expected = Seq ( + AnnotatedLine_ ("", is_comment = false), + AnnotatedLine_ ("", is_comment = false), + AnnotatedLine_ ("/** This is an example */", is_comment = true), + AnnotatedLine_ ("* Example () {", is_comment = false), + AnnotatedLine_ (" /* This is a comment */", is_comment = true), + AnnotatedLine_ (" a = \"/** this is not a comment */\"", is_comment = false), + AnnotatedLine_ ("}", is_comment = false) + ) + ) + ) + +} +case class PreprocessorSequenceTranslatorSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.block.DefaultBlockTranslator_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_program = + ("package soda.example.mytest" + + "\n" + + "\n/**" + + "\n * Example class for testing." + + "\n */" + + "\n" + + "\nclass Example" + + "\n" + + "\n import" + + "\n soda.lib.Fold_" + + "\n soda.lib.Enum" + + "\n" + + "\n abstract" + + "\n number: Int" + + "\n name: String" + + "\n" + + "\n my_constant: Int = 0" + + "\n" + + "\n my_function (x: Int, y: Int): Int =" + + "\n x + y" + + "\n" + + "\nend" + + "\n" + + "\n") + + lazy val expected_output = + ("package soda.example.mytest" + + "\n" + + "\n/**" + + "\n * Example class for testing." + + "\n */" + + "\n" + + "\nclass Example" + + "\n" + + "\n import" + + "\n soda.lib.Fold_" + + "\n soda.lib.Enum" + + "\n" + + "\n abstract" + + "\n number: Int" + + "\n name: String" + + "\n" + + "\n my_constant: Int = 0" + + "\n" + + "\n my_function (x: Int, y: Int): Int =" + + "\n x + y" + + "\n" + + "\nend" + + "\n") + + lazy val block_processor = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + DefaultBlockTranslator_ () + ) + ) + + test ("should test the preprocessor") ( + check ( + obtained = block_processor.translate (example_program) + ) ( + expected = expected_output + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala deleted file mode 100644 index edf5d7c4..00000000 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.scala +++ /dev/null @@ -1,86 +0,0 @@ -package soda.translator.parser - -/* - * This package contains tests for the Soda parser. - */ - - - -case class PreprocessorSequenceTranslatorSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.block.DefaultBlockTranslator_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_program = - ("package soda.example.mytest" + - "\n" + - "\n/**" + - "\n * Example class for testing." + - "\n */" + - "\n" + - "\nclass Example" + - "\n" + - "\n import" + - "\n soda.lib.Fold_" + - "\n soda.lib.Enum" + - "\n" + - "\n abstract" + - "\n number: Int" + - "\n name: String" + - "\n" + - "\n my_constant: Int = 0" + - "\n" + - "\n my_function (x: Int, y: Int): Int =" + - "\n x + y" + - "\n" + - "\nend" + - "\n" + - "\n") - - lazy val expected_output = - ("package soda.example.mytest" + - "\n" + - "\n/**" + - "\n * Example class for testing." + - "\n */" + - "\n" + - "\nclass Example" + - "\n" + - "\n import" + - "\n soda.lib.Fold_" + - "\n soda.lib.Enum" + - "\n" + - "\n abstract" + - "\n number: Int" + - "\n name: String" + - "\n" + - "\n my_constant: Int = 0" + - "\n" + - "\n my_function (x: Int, y: Int): Int =" + - "\n x + y" + - "\n" + - "\nend" + - "\n") - - lazy val block_processor = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - DefaultBlockTranslator_ () - ) - ) - - test ("should test the preprocessor") ( - check ( - obtained = block_processor.translate (example_program) - ) ( - expected = expected_output - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala deleted file mode 100644 index c2a38046..00000000 --- a/translator/src/test/scala/soda/translator/parser/annotation/BlockAnnotationSpec.scala +++ /dev/null @@ -1,163 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains tests for block annotations. - */ - - - -case class BlockAnnotationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.Block - import soda.translator.block.DefaultBlockTranslator_ - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_blocks = - ExampleProgram_ ().example_blocks - - def detectors (block: Block): Seq [BlockAnnotationParser] = - Seq ( - FunctionDefinitionAnnotation_ (block), - ClassBeginningAnnotation_ (block), - ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), - AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), - ImportDeclarationAnnotation_ (block), - PackageDeclarationAnnotation_ (block), - ClassAliasAnnotation_ (block), - TheoremBlockAnnotation_ (block), - ProofBlockAnnotation_ (block), - CommentAnnotation_ (block), - TestDeclarationAnnotation_ (block) - ) - - def apply_detectors (block : Block) : Seq [Boolean] = - detectors (block).map ( detector => detector.applies) - - test ("should detect a package declaration") ( - check ( - obtained = apply_detectors (example_blocks (0) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, true, false, false, false, false, false) - ) - ) - - test ("should detect a comment") ( - check ( - obtained = apply_detectors (example_blocks (1) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, true, false) - ) - ) - - test ("should detect a class beginning") ( - check ( - obtained = apply_detectors (example_blocks (2) ) - ) ( - expected = Seq [Boolean] (false, true, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect an abstract block declaration") ( - check ( - obtained = apply_detectors (example_blocks (3) ) - ) ( - expected = Seq [Boolean] (false, false, false, true, false, false, false, false, false, false, false) - ) - ) - - test ("should detect an import declaration") ( - check ( - obtained = apply_detectors (example_blocks (4) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, true, false, false, false, false, false, false) - ) - ) - - test ("should detect a constant declaration") ( - check ( - obtained = apply_detectors (example_blocks (5) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a function declaration") ( - check ( - obtained = apply_detectors (example_blocks (6) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect another function declaration") ( - check ( - obtained = apply_detectors (example_blocks (7) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a test declaration") ( - check ( - obtained = apply_detectors (example_blocks (8) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) - ) - ) - - test ("should detect a theorem block") ( - check ( - obtained = apply_detectors (example_blocks (9) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) - ) - ) - - test ("should detect a proof block") ( - check ( - obtained = apply_detectors (example_blocks (10) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) - ) - ) - - test ("should detect a class end") ( - check ( - obtained = apply_detectors (example_blocks (11) ) - ) ( - expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a class alias") ( - check ( - obtained = apply_detectors (example_blocks (12) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) - ) - ) - - test ("should find only 13 blocks") ( - check ( - obtained = example_blocks.length - ) ( - expected = 13 - ) - ) - - test ("should be ordered by the identifier ordinal") ( - check ( - obtained = detectors (example_blocks (0) ).map ( detector => detector.identifier.ordinal) - ) ( - expected = Seq [Int] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala deleted file mode 100644 index 761afee8..00000000 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.scala +++ /dev/null @@ -1,199 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains tests for block annotations. - */ - - - -case class ClassBeginningAnnotationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.Block - import soda.translator.block.DefaultBlockTranslator_ - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_blocks = ExampleProgram_ ().example_blocks - - lazy val default_block_processor = ExampleProgram_ ().default_block_processor - - lazy val example_0 = example_blocks.apply (2) - - def get_as_block (text: String): Block = - default_block_processor - .split_blocks (text) - .head - - lazy val example_1 = - get_as_block ( - "class Example [A]" + - "\n extends" + - "\n SuperExample0" + - "\n SuperExample1 [A]" + - "\n" - ) - - lazy val example_2 = - get_as_block ( - "class Example [A, B]" + - "\n extends" + - "\n SuperExample0" + - "\n SuperExample2 [A, B]" + - "\n SuperExample1 [A]" + - "\n" - ) - - lazy val example_3 = - get_as_block ( - "class Example [A subtype SuperTypeExample]" + - "\n extends" + - "\n SuperExample0" + - "\n SuperExample1 [A]" + - "\n" - ) - - lazy val example_4 = - get_as_block ( - "class Example [A supertype SubTypeExample, B subtype SuperTypeExample]" + - "\n extends" + - "\n SuperExample2 [A, B]" + - "\n SuperExample1 [A]" + - "\n SuperExample0" + - "\n" - ) - - test ("should find the right block for ClassBeginningAnnotation") ( - check ( - obtained = example_blocks.map ( block => ClassBeginningAnnotation_ (block).applies ) - ) ( - expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should extract the class name") ( - check ( - obtained = ClassBeginningAnnotation_ (example_0).class_name - ) ( - expected = "Example" - ) - ) - - test ("should extract the type parameters and bounds in example 0") ( - check ( - obtained = ClassBeginningAnnotation_ (example_0).type_parameters_and_bounds - ) ( - expected = Seq [String] () - ) - ) - - test ("should extract the type parameters in example 0") ( - check ( - obtained = ClassBeginningAnnotation_ (example_0).type_parameters - ) ( - expected = Seq [String] () - ) - ) - - test ("should extract the class name in example 1") ( - check ( - obtained = ClassBeginningAnnotation_ (example_1).class_name - ) ( - expected = "Example" - ) - ) - - test ("should extract the type parameters and bounds in example 1") ( - check ( - obtained = ClassBeginningAnnotation_ (example_1).type_parameters_and_bounds - ) ( - expected = Seq ("A") - ) - ) - - test ("should extract the type parameters in example 1") ( - check ( - obtained = ClassBeginningAnnotation_ (example_1).type_parameters - ) ( - expected = Seq ("A") - ) - ) - - test ("should extract the class name in example 2") ( - check ( - obtained = ClassBeginningAnnotation_ (example_2).class_name - ) ( - expected = "Example" - ) - ) - - test ("should extract the type parameters and bounds in example 2") ( - check ( - obtained = ClassBeginningAnnotation_ (example_2).type_parameters_and_bounds - ) ( - expected = Seq ("A", "B") - ) - ) - - test ("should extract the type parameters in example 2") ( - check ( - obtained = ClassBeginningAnnotation_ (example_2).type_parameters - ) ( - expected = Seq ("A", "B") - ) - ) - - test ("should extract the class name in example 3") ( - check ( - obtained = ClassBeginningAnnotation_ (example_3).class_name - ) ( - expected = "Example" - ) - ) - - test ("should extract the type parameters and bounds in example 3") ( - check ( - obtained = ClassBeginningAnnotation_ (example_3).type_parameters_and_bounds - ) ( - expected = Seq ("A subtype SuperTypeExample") - ) - ) - - test ("should extract the type parameters in example 3") ( - check ( - obtained = ClassBeginningAnnotation_ (example_3).type_parameters - ) ( - expected = Seq ("A") - ) - ) - - test ("should extract the class name in example 4") ( - check ( - obtained = ClassBeginningAnnotation_ (example_4).class_name - ) ( - expected = "Example" - ) - ) - - test ("should extract the type parameters and bounds in example 4") ( - check ( - obtained = ClassBeginningAnnotation_ (example_4).type_parameters_and_bounds - ) ( - expected = Seq ("A supertype SubTypeExample", "B subtype SuperTypeExample") - ) - ) - - test ("should extract the type parameters in example 4") ( - check ( - obtained = ClassBeginningAnnotation_ (example_4).type_parameters - ) ( - expected = Seq ("A", "B") - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala deleted file mode 100644 index 78042c09..00000000 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.scala +++ /dev/null @@ -1,78 +0,0 @@ -package soda.translator.parser.annotation - -/* - * This package contains tests for block annotations. - */ - - - -trait ExampleProgram -{ - - import soda.translator.block.Block - import soda.translator.block.DefaultBlockTranslator_ - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor - import soda.translator.parser.BlockProcessor_ - - lazy val example_program = - ("package soda.example.mytest" + - "\n" + - "\n/**" + - "\n * Example class for testing." + - "\n */" + - "\n" + - "\nclass Example" + - "\n extends" + - "\n SuperClassExample" + - "\n" + - "\n abstract" + - "\n value : Int" + - "\n" + - "\n import" + - "\n soda.lib.Fold_" + - "\n soda.lib.Enum" + - "\n" + - "\n my_constant : Int = 0" + - "\n" + - "\n my_function (x : Int) (y : Int) : Int =" + - "\n x + y" + - "\n" + - "\n another_function" + - "\n (x : Int)" + - "\n (y : Int)" + - "\n : Int =" + - "\n x + y" + - "\n" + - "\n test (\"should test the example\")" + - "\n check (" + - "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + - "\n ) (" + - "\n expected := Seq (\"A\", \"B\")" + - "\n )" + - "\n" + - "\n theorem" + - "\n True" + - "\n" + - "\n proof" + - "\n auto." + - "\n" + - "\nend" + - "\n" + - "\nclass AnotherExample = Example" + - "\n" + - "\n") - - lazy val default_block_processor : BlockProcessor = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - DefaultBlockTranslator_ () - ) - ) - - lazy val example_blocks : Seq [Block] = - default_block_processor.split_blocks (example_program) - -} - -case class ExampleProgram_ () extends ExampleProgram diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala index c42eab1d..53360323 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala @@ -5,3 +5,419 @@ package soda.translator.parser.annotation */ trait Package +case class ClassBeginningAnnotationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.Block + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_blocks = ExampleProgram_ ().example_blocks + + lazy val default_block_processor = ExampleProgram_ ().default_block_processor + + lazy val example_0 = example_blocks.apply (2) + + def get_as_block (text: String): Block = + default_block_processor + .split_blocks (text) + .head + + lazy val example_1 = + get_as_block ( + "class Example [A]" + + "\n extends" + + "\n SuperExample0" + + "\n SuperExample1 [A]" + + "\n" + ) + + lazy val example_2 = + get_as_block ( + "class Example [A, B]" + + "\n extends" + + "\n SuperExample0" + + "\n SuperExample2 [A, B]" + + "\n SuperExample1 [A]" + + "\n" + ) + + lazy val example_3 = + get_as_block ( + "class Example [A subtype SuperTypeExample]" + + "\n extends" + + "\n SuperExample0" + + "\n SuperExample1 [A]" + + "\n" + ) + + lazy val example_4 = + get_as_block ( + "class Example [A supertype SubTypeExample, B subtype SuperTypeExample]" + + "\n extends" + + "\n SuperExample2 [A, B]" + + "\n SuperExample1 [A]" + + "\n SuperExample0" + + "\n" + ) + + test ("should find the right block for ClassBeginningAnnotation") ( + check ( + obtained = example_blocks.map ( block => ClassBeginningAnnotation_ (block).applies ) + ) ( + expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should extract the class name") ( + check ( + obtained = ClassBeginningAnnotation_ (example_0).class_name + ) ( + expected = "Example" + ) + ) + + test ("should extract the type parameters and bounds in example 0") ( + check ( + obtained = ClassBeginningAnnotation_ (example_0).type_parameters_and_bounds + ) ( + expected = Seq [String] () + ) + ) + + test ("should extract the type parameters in example 0") ( + check ( + obtained = ClassBeginningAnnotation_ (example_0).type_parameters + ) ( + expected = Seq [String] () + ) + ) + + test ("should extract the class name in example 1") ( + check ( + obtained = ClassBeginningAnnotation_ (example_1).class_name + ) ( + expected = "Example" + ) + ) + + test ("should extract the type parameters and bounds in example 1") ( + check ( + obtained = ClassBeginningAnnotation_ (example_1).type_parameters_and_bounds + ) ( + expected = Seq ("A") + ) + ) + + test ("should extract the type parameters in example 1") ( + check ( + obtained = ClassBeginningAnnotation_ (example_1).type_parameters + ) ( + expected = Seq ("A") + ) + ) + + test ("should extract the class name in example 2") ( + check ( + obtained = ClassBeginningAnnotation_ (example_2).class_name + ) ( + expected = "Example" + ) + ) + + test ("should extract the type parameters and bounds in example 2") ( + check ( + obtained = ClassBeginningAnnotation_ (example_2).type_parameters_and_bounds + ) ( + expected = Seq ("A", "B") + ) + ) + + test ("should extract the type parameters in example 2") ( + check ( + obtained = ClassBeginningAnnotation_ (example_2).type_parameters + ) ( + expected = Seq ("A", "B") + ) + ) + + test ("should extract the class name in example 3") ( + check ( + obtained = ClassBeginningAnnotation_ (example_3).class_name + ) ( + expected = "Example" + ) + ) + + test ("should extract the type parameters and bounds in example 3") ( + check ( + obtained = ClassBeginningAnnotation_ (example_3).type_parameters_and_bounds + ) ( + expected = Seq ("A subtype SuperTypeExample") + ) + ) + + test ("should extract the type parameters in example 3") ( + check ( + obtained = ClassBeginningAnnotation_ (example_3).type_parameters + ) ( + expected = Seq ("A") + ) + ) + + test ("should extract the class name in example 4") ( + check ( + obtained = ClassBeginningAnnotation_ (example_4).class_name + ) ( + expected = "Example" + ) + ) + + test ("should extract the type parameters and bounds in example 4") ( + check ( + obtained = ClassBeginningAnnotation_ (example_4).type_parameters_and_bounds + ) ( + expected = Seq ("A supertype SubTypeExample", "B subtype SuperTypeExample") + ) + ) + + test ("should extract the type parameters in example 4") ( + check ( + obtained = ClassBeginningAnnotation_ (example_4).type_parameters + ) ( + expected = Seq ("A", "B") + ) + ) + +} +case class BlockAnnotationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.Block + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_blocks = + ExampleProgram_ ().example_blocks + + def detectors (block: Block): Seq [BlockAnnotationParser] = + Seq ( + FunctionDefinitionAnnotation_ (block), + ClassBeginningAnnotation_ (block), + ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), + AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), + ImportDeclarationAnnotation_ (block), + PackageDeclarationAnnotation_ (block), + ClassAliasAnnotation_ (block), + TheoremBlockAnnotation_ (block), + ProofBlockAnnotation_ (block), + CommentAnnotation_ (block), + TestDeclarationAnnotation_ (block) + ) + + def apply_detectors (block : Block) : Seq [Boolean] = + detectors (block).map ( detector => detector.applies) + + test ("should detect a package declaration") ( + check ( + obtained = apply_detectors (example_blocks (0) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, true, false, false, false, false, false) + ) + ) + + test ("should detect a comment") ( + check ( + obtained = apply_detectors (example_blocks (1) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, true, false) + ) + ) + + test ("should detect a class beginning") ( + check ( + obtained = apply_detectors (example_blocks (2) ) + ) ( + expected = Seq [Boolean] (false, true, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect an abstract block declaration") ( + check ( + obtained = apply_detectors (example_blocks (3) ) + ) ( + expected = Seq [Boolean] (false, false, false, true, false, false, false, false, false, false, false) + ) + ) + + test ("should detect an import declaration") ( + check ( + obtained = apply_detectors (example_blocks (4) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, true, false, false, false, false, false, false) + ) + ) + + test ("should detect a constant declaration") ( + check ( + obtained = apply_detectors (example_blocks (5) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a function declaration") ( + check ( + obtained = apply_detectors (example_blocks (6) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect another function declaration") ( + check ( + obtained = apply_detectors (example_blocks (7) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a test declaration") ( + check ( + obtained = apply_detectors (example_blocks (8) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) + ) + ) + + test ("should detect a theorem block") ( + check ( + obtained = apply_detectors (example_blocks (9) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) + ) + ) + + test ("should detect a proof block") ( + check ( + obtained = apply_detectors (example_blocks (10) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) + ) + ) + + test ("should detect a class end") ( + check ( + obtained = apply_detectors (example_blocks (11) ) + ) ( + expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a class alias") ( + check ( + obtained = apply_detectors (example_blocks (12) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) + ) + ) + + test ("should find only 13 blocks") ( + check ( + obtained = example_blocks.length + ) ( + expected = 13 + ) + ) + + test ("should be ordered by the identifier ordinal") ( + check ( + obtained = detectors (example_blocks (0) ).map ( detector => detector.identifier.ordinal) + ) ( + expected = Seq [Int] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) + ) + ) + +} +trait ExampleProgram +{ + + import soda.translator.block.Block + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor + import soda.translator.parser.BlockProcessor_ + + lazy val example_program = + ("package soda.example.mytest" + + "\n" + + "\n/**" + + "\n * Example class for testing." + + "\n */" + + "\n" + + "\nclass Example" + + "\n extends" + + "\n SuperClassExample" + + "\n" + + "\n abstract" + + "\n value : Int" + + "\n" + + "\n import" + + "\n soda.lib.Fold_" + + "\n soda.lib.Enum" + + "\n" + + "\n my_constant : Int = 0" + + "\n" + + "\n my_function (x : Int) (y : Int) : Int =" + + "\n x + y" + + "\n" + + "\n another_function" + + "\n (x : Int)" + + "\n (y : Int)" + + "\n : Int =" + + "\n x + y" + + "\n" + + "\n test (\"should test the example\")" + + "\n check (" + + "\n obtained := ClassBeginningAnnotation_ (example_4).type_parameters" + + "\n ) (" + + "\n expected := Seq (\"A\", \"B\")" + + "\n )" + + "\n" + + "\n theorem" + + "\n True" + + "\n" + + "\n proof" + + "\n auto." + + "\n" + + "\nend" + + "\n" + + "\nclass AnotherExample = Example" + + "\n" + + "\n") + + lazy val default_block_processor : BlockProcessor = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + DefaultBlockTranslator_ () + ) + ) + + lazy val example_blocks : Seq [Block] = + default_block_processor.split_blocks (example_program) + +} + +case class ExampleProgram_ () extends ExampleProgram diff --git a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala b/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala deleted file mode 100644 index abd8f6e4..00000000 --- a/translator/src/test/scala/soda/translator/replacement/CharTypeSpec.scala +++ /dev/null @@ -1,61 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains tests for replacement helper functions. - */ - - - -case class CharTypeSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should recognize quotation marks") ( - check ( - obtained = CharTypeEnum_ ().get_char_type ('"') - ) ( - expected = CharTypeEnum_ ().quotes_type - ) - ) - - test ("should recognize apostrophes") ( - check ( - obtained = CharTypeEnum_ ().get_char_type ('\'') - ) ( - expected = CharTypeEnum_ ().apostrophe_type - ) - ) - - test ("should recognize backslash") ( - check ( - obtained = CharTypeEnum_ ().get_char_type ('\\') - ) ( - expected = CharTypeEnum_ ().backslash_type - ) - ) - - test ("should recognize a simple char") ( - check ( - obtained = CharTypeEnum_ ().get_char_type ('a') - ) ( - expected = CharTypeEnum_ ().plain_type - ) - ) - - test ("should recognize plain text") ( - check ( - obtained = - "This is plain text with symbols. 0123456789 _ . !?" - .map ( ch => CharTypeEnum_ ().get_char_type (ch) ) - .toSet - .toSeq - ) ( - expected = Seq ( CharTypeEnum_ ().plain_type ) - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/replacement/Package.scala b/translator/src/test/scala/soda/translator/replacement/Package.scala index 4bb16f74..a219e793 100644 --- a/translator/src/test/scala/soda/translator/replacement/Package.scala +++ b/translator/src/test/scala/soda/translator/replacement/Package.scala @@ -5,3 +5,286 @@ package soda.translator.replacement */ trait Package +case class CharTypeSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should recognize quotation marks") ( + check ( + obtained = CharTypeEnum_ ().get_char_type ('"') + ) ( + expected = CharTypeEnum_ ().quotes_type + ) + ) + + test ("should recognize apostrophes") ( + check ( + obtained = CharTypeEnum_ ().get_char_type ('\'') + ) ( + expected = CharTypeEnum_ ().apostrophe_type + ) + ) + + test ("should recognize backslash") ( + check ( + obtained = CharTypeEnum_ ().get_char_type ('\\') + ) ( + expected = CharTypeEnum_ ().backslash_type + ) + ) + + test ("should recognize a simple char") ( + check ( + obtained = CharTypeEnum_ ().get_char_type ('a') + ) ( + expected = CharTypeEnum_ ().plain_type + ) + ) + + test ("should recognize plain text") ( + check ( + obtained = + "This is plain text with symbols. 0123456789 _ . !?" + .map ( ch => CharTypeEnum_ ().get_char_type (ch) ) + .toSet + .toSeq + ) ( + expected = Seq ( CharTypeEnum_ ().plain_type ) + ) + ) + +} +case class TokenizerSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should tokenize a small example") ( + check ( + obtained = Tokenizer_ (" val Constant = \"my text\"").tokens + ) ( + expected = Seq ( + Token_ (" val Constant = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"my text\"", ParserStateEnum_ ().quotes_state, 19), + Token_ ("", ParserStateEnum_ ().plain, 28) + ) + ) + ) + + test ("should tokenize a common tab in a string") ( + check ( + obtained = Tokenizer_ (" x = \"abc\tde\"").tokens + ) ( + expected = Seq ( + Token_ (" x = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"abc\tde\"", ParserStateEnum_ ().quotes_state, 6), + Token_ ("", ParserStateEnum_ ().plain, 14) + ) + ) + ) + + test ("should tokenize an escaped tab in a string") ( + check ( + obtained = Tokenizer_ (" x = \"abc\\tde\"").tokens + ) ( + expected = Seq ( + Token_ (" x = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"abc\\tde\"", ParserStateEnum_ ().quotes_state, 6), + Token_ ("", ParserStateEnum_ ().plain, 15) + ) + ) + ) + + test ("should tokenize a single function definition") ( + check ( + obtained = Tokenizer_ ("def f (x: Int): Int = x").tokens + ) ( + expected = Seq ( + Token_ ("def f (x: Int): Int = x", ParserStateEnum_ ().plain, 0) + ) + ) + ) + + test ("should tokenize a function call") ( + check ( + obtained = Tokenizer_ ("\tas_digits (5 * number)").tokens + ) ( + expected = Seq ( + Token_ ("\tas_digits (5 * number)", ParserStateEnum_ ().plain, 0) + ) + ) + ) + +} +case class ReplacementAuxSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = ReplacementAux_ () + + lazy val line_0 = "lambda, if, then, else, match, case" + + lazy val line_1 = "class has extends with this subtype supertype " + + lazy val line_2 = " false ,true ,not ,and ,or ,package ,import ,theorem ,proof ,is ,lambda" + + lazy val line_3 = " @new, @tailrec, @override " + + lazy val one_word = "lambda" + + test ("replace_if_found_at_beginning 1") ( + check ( + obtained = instance.replace_if_found_at_beginning (line_1) ("class") ("trait") + ) ( + expected = "trait has extends with this subtype supertype " + ) + ) + + test ("replace_if_found_at_beginning 2") ( + check ( + obtained = instance.replace_if_found_at_beginning (line_1) ("has") ("---") + ) ( + expected = line_1 + ) + ) + + test ("replace_first 1") ( + check ( + obtained = instance.replace_first (line_1) ("class") ("trait") + ) ( + expected = "trait has extends with this subtype supertype " + ) + ) + + test ("replace_first 2") ( + check ( + obtained = instance.replace_first (line_1) ("this") ("that") + ) ( + expected = "class has extends with that subtype supertype " + ) + ) + + test ("replace_at 1") ( + check ( + obtained = instance.replace_at (22) (line_1) (" ") ("out ") + ) ( + expected = "class has extends without this subtype supertype " + ) + ) + + test ("replace_at 2") ( + check ( + obtained = instance.replace_at (-1) (line_1) (" ") ("no replacement here") + ) ( + expected = line_1 + ) + ) + + test ("replace_at 3") ( + check ( + obtained = instance.replace_at (line_1.length - 1) (line_1) (" ") ("") + ) ( + expected = "class has extends with this subtype supertype" + ) + ) + + test ("replace_at 4") ( + check ( + obtained = instance.replace_at (line_1.length) (line_1) (" ") ("no replacement") + ) ( + expected = line_1 + ) + ) + + test ("replace_if_found") ( + check ( + obtained = instance.replace_if_found (line_1) ("type") ("class") + ) ( + expected = "class has extends with this subclass superclass " + ) + ) + + test ("replace_all 1") ( + check ( + obtained = instance.replace_all (line_1) (" ") (",") + ) ( + expected = "class,has,extends,with,this,subtype,supertype," + ) + ) + + test ("replace_all 2") ( + check ( + obtained = instance.replace_all (line_1) ("z") ("-") + ) ( + expected = line_1 + ) + ) + + test ("add_spaces_to_symbols 1") ( + check ( + obtained = instance.add_spaces_to_symbols (line_0) ( (Seq [Char] (',') ).toSet ) + ) ( + expected = "lambda , if , then , else , match , case" + ) + ) + + test ("add_spaces_to_symbols 2") ( + check ( + obtained = instance.add_spaces_to_symbols (line_2) ( (Seq [Char] (',') ).toSet ) + ) ( + expected = " false , true , not , and , or , package , import , theorem , proof , is , lambda" + ) + ) + + test ("add_spaces_to_symbols 3") ( + check ( + obtained = instance.add_spaces_to_symbols (line_1) ( (Seq [Char] ('a', 'e', 'i', 'o', 'u') ).toSet ) + ) ( + expected = "cl a ss h a s e xt e nds w i th th i s s u btyp e s u p e rtyp e " + ) + ) + + test ("remove_space_from_scala_line") ( + check ( + obtained = instance.remove_space_from_scala_line (line_3) + ) ( + expected = " @new, @tailrec, @override" + ) + ) + + test ("add_after_spaces_or_pattern 1") ( + check ( + obtained = instance.add_after_spaces_or_pattern (line_1) ("class") (" here") + ) ( + expected = "class here has extends with this subtype supertype " + ) + ) + + test ("add_after_spaces_or_pattern 2") ( + check ( + obtained = instance.add_after_spaces_or_pattern (line_1) ("has") (" here ") + ) ( + expected = " here class has extends with this subtype supertype " + ) + ) + + test ("add_after_spaces_or_pattern 3") ( + check ( + obtained = instance.add_after_spaces_or_pattern (line_3) ("@new") (", here") + ) ( + expected = " @new, here, @tailrec, @override " + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala b/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala deleted file mode 100644 index d201f989..00000000 --- a/translator/src/test/scala/soda/translator/replacement/ReplacementAuxSpec.scala +++ /dev/null @@ -1,173 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains tests for replacement helper functions. - */ - - - -case class ReplacementAuxSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = ReplacementAux_ () - - lazy val line_0 = "lambda, if, then, else, match, case" - - lazy val line_1 = "class has extends with this subtype supertype " - - lazy val line_2 = " false ,true ,not ,and ,or ,package ,import ,theorem ,proof ,is ,lambda" - - lazy val line_3 = " @new, @tailrec, @override " - - lazy val one_word = "lambda" - - test ("replace_if_found_at_beginning 1") ( - check ( - obtained = instance.replace_if_found_at_beginning (line_1) ("class") ("trait") - ) ( - expected = "trait has extends with this subtype supertype " - ) - ) - - test ("replace_if_found_at_beginning 2") ( - check ( - obtained = instance.replace_if_found_at_beginning (line_1) ("has") ("---") - ) ( - expected = line_1 - ) - ) - - test ("replace_first 1") ( - check ( - obtained = instance.replace_first (line_1) ("class") ("trait") - ) ( - expected = "trait has extends with this subtype supertype " - ) - ) - - test ("replace_first 2") ( - check ( - obtained = instance.replace_first (line_1) ("this") ("that") - ) ( - expected = "class has extends with that subtype supertype " - ) - ) - - test ("replace_at 1") ( - check ( - obtained = instance.replace_at (22) (line_1) (" ") ("out ") - ) ( - expected = "class has extends without this subtype supertype " - ) - ) - - test ("replace_at 2") ( - check ( - obtained = instance.replace_at (-1) (line_1) (" ") ("no replacement here") - ) ( - expected = line_1 - ) - ) - - test ("replace_at 3") ( - check ( - obtained = instance.replace_at (line_1.length - 1) (line_1) (" ") ("") - ) ( - expected = "class has extends with this subtype supertype" - ) - ) - - test ("replace_at 4") ( - check ( - obtained = instance.replace_at (line_1.length) (line_1) (" ") ("no replacement") - ) ( - expected = line_1 - ) - ) - - test ("replace_if_found") ( - check ( - obtained = instance.replace_if_found (line_1) ("type") ("class") - ) ( - expected = "class has extends with this subclass superclass " - ) - ) - - test ("replace_all 1") ( - check ( - obtained = instance.replace_all (line_1) (" ") (",") - ) ( - expected = "class,has,extends,with,this,subtype,supertype," - ) - ) - - test ("replace_all 2") ( - check ( - obtained = instance.replace_all (line_1) ("z") ("-") - ) ( - expected = line_1 - ) - ) - - test ("add_spaces_to_symbols 1") ( - check ( - obtained = instance.add_spaces_to_symbols (line_0) ( (Seq [Char] (',') ).toSet ) - ) ( - expected = "lambda , if , then , else , match , case" - ) - ) - - test ("add_spaces_to_symbols 2") ( - check ( - obtained = instance.add_spaces_to_symbols (line_2) ( (Seq [Char] (',') ).toSet ) - ) ( - expected = " false , true , not , and , or , package , import , theorem , proof , is , lambda" - ) - ) - - test ("add_spaces_to_symbols 3") ( - check ( - obtained = instance.add_spaces_to_symbols (line_1) ( (Seq [Char] ('a', 'e', 'i', 'o', 'u') ).toSet ) - ) ( - expected = "cl a ss h a s e xt e nds w i th th i s s u btyp e s u p e rtyp e " - ) - ) - - test ("remove_space_from_scala_line") ( - check ( - obtained = instance.remove_space_from_scala_line (line_3) - ) ( - expected = " @new, @tailrec, @override" - ) - ) - - test ("add_after_spaces_or_pattern 1") ( - check ( - obtained = instance.add_after_spaces_or_pattern (line_1) ("class") (" here") - ) ( - expected = "class here has extends with this subtype supertype " - ) - ) - - test ("add_after_spaces_or_pattern 2") ( - check ( - obtained = instance.add_after_spaces_or_pattern (line_1) ("has") (" here ") - ) ( - expected = " here class has extends with this subtype supertype " - ) - ) - - test ("add_after_spaces_or_pattern 3") ( - check ( - obtained = instance.add_after_spaces_or_pattern (line_3) ("@new") (", here") - ) ( - expected = " @new, here, @tailrec, @override " - ) - ) - -} diff --git a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala b/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala deleted file mode 100644 index 191acab2..00000000 --- a/translator/src/test/scala/soda/translator/replacement/TokenizerSpec.scala +++ /dev/null @@ -1,73 +0,0 @@ -package soda.translator.replacement - -/* - * This package contains tests for replacement helper functions. - */ - - - -case class TokenizerSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should tokenize a small example") ( - check ( - obtained = Tokenizer_ (" val Constant = \"my text\"").tokens - ) ( - expected = Seq ( - Token_ (" val Constant = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"my text\"", ParserStateEnum_ ().quotes_state, 19), - Token_ ("", ParserStateEnum_ ().plain, 28) - ) - ) - ) - - test ("should tokenize a common tab in a string") ( - check ( - obtained = Tokenizer_ (" x = \"abc\tde\"").tokens - ) ( - expected = Seq ( - Token_ (" x = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"abc\tde\"", ParserStateEnum_ ().quotes_state, 6), - Token_ ("", ParserStateEnum_ ().plain, 14) - ) - ) - ) - - test ("should tokenize an escaped tab in a string") ( - check ( - obtained = Tokenizer_ (" x = \"abc\\tde\"").tokens - ) ( - expected = Seq ( - Token_ (" x = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"abc\\tde\"", ParserStateEnum_ ().quotes_state, 6), - Token_ ("", ParserStateEnum_ ().plain, 15) - ) - ) - ) - - test ("should tokenize a single function definition") ( - check ( - obtained = Tokenizer_ ("def f (x: Int): Int = x").tokens - ) ( - expected = Seq ( - Token_ ("def f (x: Int): Int = x", ParserStateEnum_ ().plain, 0) - ) - ) - ) - - test ("should tokenize a function call") ( - check ( - obtained = Tokenizer_ ("\tas_digits (5 * number)").tokens - ) ( - expected = Seq ( - Token_ ("\tas_digits (5 * number)", ParserStateEnum_ ().plain, 0) - ) - ) - ) - -} From a65697c87d44a3edc5a9ba65cdab325bdccdedaf Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 21:44:55 +0100 Subject: [PATCH 53/71] Update format of translator to Scala --- .../extension/toscala/Package.scala | 30 +++++++++---------- .../extension/toscala/TranslatorToScala.soda | 30 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index 6d374bd5..b7e82720 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -671,11 +671,17 @@ trait TranslatorToScala import soda.translator.parser.BlockProcessor_ import java.io.File - lazy val package_file_name : String = "Package.soda" + private lazy val _soda_extension : String = ".soda" + + private lazy val _scala_extension : String = ".scala" + + private lazy val _default_argument = "." + + lazy val package_file_prefix : String = "Package" - lazy val prelude_file_name : String = package_file_name + lazy val package_file_name : String = package_file_prefix + _soda_extension - lazy val package_scala_file_name : String = "Package.scala" + lazy val package_scala_file_name : String = package_file_prefix + _scala_extension lazy val file_separator : String = File.separator @@ -683,20 +689,14 @@ trait TranslatorToScala lazy val new_line : String = "\n" - lazy val prelude_separation : String = new_line + new_line + lazy val append_separation : String = new_line + new_line - lazy val prelude_file_body : String = new_line + "trait Package" + prelude_separation + lazy val prelude_file_body : String = new_line + "trait Package" + append_separation lazy val package_option_1 = "-p" lazy val package_option_2 = "--package" - private lazy val _soda_extension : String = ".soda" - - private lazy val _scala_extension : String = ".scala" - - private lazy val _default_argument = "." - private lazy val _translator = BlockProcessor_ ( DefaultBlockSequenceTranslator_ ( @@ -761,7 +761,7 @@ trait TranslatorToScala _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) ) + SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) + append_separation) private def _read_input_with_prelude (input_file_name : String) : String = if ( _is_a_prelude_file (input_file_name) @@ -776,14 +776,14 @@ trait TranslatorToScala private def _get_prelude_with (prelude_file : File) : String = if ( prelude_file.exists - ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation + ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + append_separation else default_prelude private def _get_prelude_file (input_file_name : String) : File = - new File ( new File (input_file_name) .getParentFile , prelude_file_name ) + new File ( new File (input_file_name) .getParentFile , package_file_name ) private def _is_a_prelude_file (input_file_name : String) : Boolean = - prelude_file_name == ( ( new File (input_file_name) ) .getName) + package_file_name == ( ( new File (input_file_name) ) .getName) private def _is_package_option (s : String) : Boolean = (s == package_option_1) || (s == package_option_2) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index 8f390624..e228299f 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -15,11 +15,17 @@ class TranslatorToScala soda.translator.parser.BlockProcessor_ java.io.File - package_file_name : String = "Package.soda" + _soda_extension : String = ".soda" + + _scala_extension : String = ".scala" + + _default_argument = "." + + package_file_prefix : String = "Package" - prelude_file_name : String = package_file_name + package_file_name : String = package_file_prefix + _soda_extension - package_scala_file_name : String = "Package.scala" + package_scala_file_name : String = package_file_prefix + _scala_extension file_separator : String = File.separator @@ -27,20 +33,14 @@ class TranslatorToScala new_line : String = "\n" - prelude_separation : String = new_line + new_line + append_separation : String = new_line + new_line - prelude_file_body : String = new_line + "trait Package" + prelude_separation + prelude_file_body : String = new_line + "trait Package" + append_separation package_option_1 = "-p" package_option_2 = "--package" - _soda_extension : String = ".soda" - - _scala_extension : String = ".scala" - - _default_argument = "." - _translator = BlockProcessor_ ( DefaultBlockSequenceTranslator_ ( @@ -104,7 +104,7 @@ class TranslatorToScala _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content := _translator.translate (input) ) + SimpleFileWriter_ ().append_file (output_file_name) (content := _translator.translate (input) + append_separation) _read_input_with_prelude (input_file_name : String) : String = if _is_a_prelude_file (input_file_name) @@ -119,14 +119,14 @@ class TranslatorToScala _get_prelude_with (prelude_file : File) : String = if prelude_file.exists - then (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + prelude_separation + then (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + append_separation else default_prelude _get_prelude_file (input_file_name : String) : File = - @new File ( @new File (input_file_name) .getParentFile , prelude_file_name ) + @new File ( @new File (input_file_name) .getParentFile , package_file_name ) _is_a_prelude_file (input_file_name : String) : Boolean = - prelude_file_name == ( ( @new File (input_file_name) ) .getName) + package_file_name == ( ( @new File (input_file_name) ) .getName) _is_package_option (s : String) : Boolean = (s == package_option_1) or (s == package_option_2) From a0386e4aa5644734c5910a2cb1484e620d1a2973 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 21:48:08 +0100 Subject: [PATCH 54/71] Update Package.scala files --- .../soda/example/algorithms/Package.scala | 16 ++++++++++++ .../ethicalissues/fairness/Package.scala | 2 ++ .../ethicalissues/pricemonitor/Package.scala | 8 ++++++ .../example/forcoq/algorithms/Package.scala | 2 ++ .../soda/example/forcoq/lib/Package.scala | 4 +++ .../example/forcoq/mathematics/Package.scala | 6 +++++ .../soda/example/inanutshell/Package.scala | 2 ++ .../soda/example/mathematics/Package.scala | 12 +++++++++ .../soda/example/miniexample/Package.scala | 2 ++ .../soda/example/algorithms/Package.scala | 8 ++++++ .../ethicalissues/fairness/Package.scala | 2 ++ .../ethicalissues/pricemonitor/Package.scala | 2 ++ .../example/forcoq/algorithms/Package.scala | 2 ++ .../soda/example/forcoq/lib/Package.scala | 4 +++ .../example/forcoq/mathematics/Package.scala | 6 +++++ .../soda/example/mathematics/Package.scala | 8 ++++++ .../main/scala/soda/collection/Package.scala | 4 +++ .../soda/collection/example/Package.scala | 4 +++ .../test/scala/soda/collection/Package.scala | 2 ++ .../soda/collection/example/Package.scala | 2 ++ .../main/resources/lib/soda/lib/Package.scala | 12 +++++++++ .../src/main/scala/soda/lib/Package.scala | 14 ++++++++++ .../scala/soda/translator/block/Package.scala | 22 ++++++++++++++++ .../soda/translator/blocktr/Package.scala | 6 +++++ .../translator/extension/common/Package.scala | 2 ++ .../translator/extension/help/Package.scala | 2 ++ .../translator/extension/main/Package.scala | 2 ++ .../translator/extension/tocoq/Package.scala | 26 +++++++++++++++++++ .../translator/extension/todoc/Package.scala | 8 ++++++ .../extension/toscala/Package.scala | 26 +++++++++++++++++++ .../scala/soda/translator/io/Package.scala | 8 ++++++ .../soda/translator/parser/Package.scala | 8 ++++++ .../parser/annotation/Package.scala | 26 +++++++++++++++++++ .../soda/translator/replacement/Package.scala | 10 +++++++ .../test/resources/soda/example/Package.scala | 2 ++ .../soda/example/otherexample/Package.scala | 2 ++ .../src/test/scala/soda/lib/Package.scala | 10 +++++++ .../scala/soda/translator/block/Package.scala | 2 ++ .../translator/extension/tocoq/Package.scala | 4 +++ .../translator/extension/todoc/Package.scala | 4 +++ .../extension/toscala/Package.scala | 18 +++++++++++++ .../scala/soda/translator/io/Package.scala | 2 ++ .../soda/translator/parser/Package.scala | 4 +++ .../parser/annotation/Package.scala | 6 +++++ .../soda/translator/replacement/Package.scala | 6 +++++ 45 files changed, 330 insertions(+) diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index c992054a..87165b78 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -31,6 +31,8 @@ trait FizzBuzzPatternMatching } case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching + + trait SaladMaker { @@ -47,6 +49,8 @@ trait SaladMaker } case class SaladMaker_ () extends SaladMaker + + trait ScalaReservedWordEscaping { @@ -83,6 +87,8 @@ trait MyPair [A, B] } case class MyPair_ [A, B] (key : A, value : B) extends MyPair [A, B] + + trait Parameter { @@ -156,6 +162,8 @@ trait Triplet } case class Triplet_ (x : Int, y : Int, z : Int) extends Triplet + + trait FizzBuzz { @@ -182,6 +190,8 @@ trait FizzBuzz } case class FizzBuzz_ () extends FizzBuzz + + trait SortExample { @@ -397,6 +407,8 @@ trait SortedSequenceBuilder [A <: Comparable [A] ] } case class SortedSequenceBuilder_ [A <: Comparable [A]] () extends SortedSequenceBuilder [A] + + trait PairExample { @@ -438,6 +450,8 @@ trait SwapExample } case class SwapExample_ () extends SwapExample + + trait Main { @@ -452,3 +466,5 @@ object EntryPoint { case class Main_ () extends Main + + diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala index 1d7527ab..e4c85eb8 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala @@ -53,3 +53,5 @@ trait Fairness } case class Fairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends Fairness + + diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala index 33a35f78..2c8346b8 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -76,6 +76,8 @@ trait SegmentsForFlight } case class SegmentsForFlight_ (flight : Flight) extends SegmentsForFlight + + trait Report2 { @@ -111,6 +113,8 @@ trait Requirement2Monitor } case class Requirement2Monitor_ (pricing_agent : PricingAgent) extends Requirement2Monitor + + trait Report1 { @@ -160,6 +164,8 @@ trait Requirement1Monitor } case class Requirement1Monitor_ (pricing_agent : PricingAgent) extends Requirement1Monitor + + trait Customer { @@ -212,3 +218,5 @@ trait RequirementMonitor } case class RequirementMonitor_ (pricing_agent : PricingAgent) extends RequirementMonitor + + diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala index 4c908703..1d5dc166 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala @@ -50,3 +50,5 @@ trait RecursionForCoq } case class RecursionForCoq_ () extends RecursionForCoq + + diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala index e9120e4c..e9150371 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala @@ -92,6 +92,8 @@ trait IntNat } case class IntNat_ () extends IntNat + + trait list [A] { @@ -159,3 +161,5 @@ trait SeqList } case class SeqList_ () extends SeqList + + diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala index dae949f8..289d99e1 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala @@ -26,6 +26,8 @@ trait TriangularNumberForCoq } case class TriangularNumberForCoq_ () extends TriangularNumberForCoq + + trait FactorialForCoq { @@ -47,6 +49,8 @@ trait FactorialForCoq } case class FactorialForCoq_ () extends FactorialForCoq + + trait FiboExampleInSodaForCoq { @@ -69,3 +73,5 @@ trait FiboExampleInSodaForCoq } case class FiboExampleInSodaForCoq_ () extends FiboExampleInSodaForCoq + + diff --git a/examples/src/main/scala/soda/example/inanutshell/Package.scala b/examples/src/main/scala/soda/example/inanutshell/Package.scala index 32eaee22..2d184d85 100644 --- a/examples/src/main/scala/soda/example/inanutshell/Package.scala +++ b/examples/src/main/scala/soda/example/inanutshell/Package.scala @@ -169,3 +169,5 @@ trait PersonName } case class PersonName_ (name : String) extends PersonName + + diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index c5449479..6c8e87aa 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -22,6 +22,8 @@ trait FactorialConcise } case class FactorialConcise_ () extends FactorialConcise + + trait Status { @@ -104,6 +106,8 @@ trait IntAndStatus } case class IntAndStatus_ (digit : Int, new_status : Status) extends IntAndStatus + + trait InputPair [A, B] { @@ -252,6 +256,8 @@ trait MemoizedFibonacci } case class MemoizedFibonacci_ () extends MemoizedFibonacci + + trait FactorialWithFold { @@ -265,6 +271,8 @@ trait FactorialWithFold } case class FactorialWithFold_ () extends FactorialWithFold + + trait FiboExampleInSoda { @@ -279,6 +287,8 @@ trait FiboExampleInSoda } case class FiboExampleInSoda_ () extends FiboExampleInSoda + + trait FactorialPatternMatching { @@ -296,3 +306,5 @@ trait FactorialPatternMatching } case class FactorialPatternMatching_ () extends FactorialPatternMatching + + diff --git a/examples/src/main/scala/soda/example/miniexample/Package.scala b/examples/src/main/scala/soda/example/miniexample/Package.scala index 40a43845..2ad5d834 100644 --- a/examples/src/main/scala/soda/example/miniexample/Package.scala +++ b/examples/src/main/scala/soda/example/miniexample/Package.scala @@ -34,3 +34,5 @@ object EntryPoint { case class Main_ () extends Main + + diff --git a/examples/src/test/scala/soda/example/algorithms/Package.scala b/examples/src/test/scala/soda/example/algorithms/Package.scala index 9fc61a74..1d6e83ed 100644 --- a/examples/src/test/scala/soda/example/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/algorithms/Package.scala @@ -96,6 +96,8 @@ case class SortExampleSpec () ) } + + case class PatternMatchingSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -155,6 +157,8 @@ case class PatternMatchingSpec () ) } + + trait SaladIngredient extends soda.lib.EnumConstant @@ -215,6 +219,8 @@ case class SaladMakerSpec () ) } + + case class FizzBuzzSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -257,3 +263,5 @@ case class FizzBuzzSpec () ) } + + diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala index b046dc23..614ded16 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala @@ -40,3 +40,5 @@ case class FairnessSpec () ) } + + diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala index 491cecb9..9ed46edb 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -139,3 +139,5 @@ case class PriceMonitorSpec () .build } + + diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala index ae4b0ff5..a7765038 100644 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala @@ -69,3 +69,5 @@ case class RecursionForCoqSpec () ) } + + diff --git a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala index 8d6a3106..9f861710 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala @@ -30,6 +30,8 @@ case class ListSpec () ) } + + case class NatSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -71,3 +73,5 @@ case class NatSpec () ) } + + diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala index d3c9aed9..07a1816c 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala @@ -37,6 +37,8 @@ case class FactorialForCoqSpec () ) } + + case class TriangularNumberForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -69,6 +71,8 @@ case class TriangularNumberForCoqSpec () ) } + + case class FiboExampleInSodaForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -101,3 +105,5 @@ case class FiboExampleInSodaForCoqSpec () ) } + + diff --git a/examples/src/test/scala/soda/example/mathematics/Package.scala b/examples/src/test/scala/soda/example/mathematics/Package.scala index 763680b2..8316f64e 100644 --- a/examples/src/test/scala/soda/example/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/mathematics/Package.scala @@ -28,6 +28,8 @@ case class PiIteratorSpec () ) } + + case class FiboExampleSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -53,6 +55,8 @@ case class FiboExampleSpec () ) } + + case class FactorialSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -102,6 +106,8 @@ case class FactorialSpec () ) } + + case class HardProblemSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -178,3 +184,5 @@ case class HardProblemSpec () ) } + + diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index 1365dbad..fe507499 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -423,6 +423,8 @@ trait SpanRevFoldTuple [A] } case class SpanRevFoldTuple_ [A] (left : MSeq [A], right : MSeq [A], taking : Boolean, condition : A => Boolean) extends SpanRevFoldTuple [A] + + trait MSeq [A] { @@ -499,3 +501,5 @@ trait NESeq [A] } case class NESeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NESeq [A] + + diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala index bf587d7b..9678e057 100644 --- a/library/src/main/scala/soda/collection/example/Package.scala +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -49,6 +49,8 @@ object EntryPoint { case class Main_ () extends Main + + trait Pair [A] { @@ -141,3 +143,5 @@ trait ListExample } case class ListExample_ () extends ListExample + + diff --git a/library/src/test/scala/soda/collection/Package.scala b/library/src/test/scala/soda/collection/Package.scala index 59780e63..4d3e8808 100644 --- a/library/src/test/scala/soda/collection/Package.scala +++ b/library/src/test/scala/soda/collection/Package.scala @@ -589,3 +589,5 @@ case class MinSpec () ) } + + diff --git a/library/src/test/scala/soda/collection/example/Package.scala b/library/src/test/scala/soda/collection/example/Package.scala index e40cdddb..d963bc7e 100644 --- a/library/src/test/scala/soda/collection/example/Package.scala +++ b/library/src/test/scala/soda/collection/example/Package.scala @@ -190,3 +190,5 @@ case class ListExampleSpec () ) } + + diff --git a/translator/src/main/resources/lib/soda/lib/Package.scala b/translator/src/main/resources/lib/soda/lib/Package.scala index e2399fdc..a7279693 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.scala +++ b/translator/src/main/resources/lib/soda/lib/Package.scala @@ -78,6 +78,8 @@ trait SeqSDBuilder [A] } case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] + + /* * This file is automatically generated. Do not edit. */ @@ -167,6 +169,8 @@ trait Recursion } case class Recursion_ () extends Recursion + + /* * This file is automatically generated. Do not edit. */ @@ -193,6 +197,8 @@ trait Enum [A <: EnumConstant] } case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] + + /* * This file is automatically generated. Do not edit. */ @@ -224,6 +230,8 @@ trait CartesianProduct } case class CartesianProduct_ () extends CartesianProduct + + /* * This file is automatically generated. Do not edit. */ @@ -356,6 +364,8 @@ trait OptionSDBuilder [A] } case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] + + /* * This file is automatically generated. Do not edit. */ @@ -372,3 +382,5 @@ trait Doc } case class Doc_ (doc : String) extends Doc + + diff --git a/translator/src/main/scala/soda/lib/Package.scala b/translator/src/main/scala/soda/lib/Package.scala index d6aaec5d..2c4634f0 100644 --- a/translator/src/main/scala/soda/lib/Package.scala +++ b/translator/src/main/scala/soda/lib/Package.scala @@ -12,6 +12,8 @@ package soda.lib trait Package /* Soda library */ + + /* * This file is automatically generated. Do not edit. */ @@ -77,6 +79,8 @@ trait SeqSDBuilder [A] } case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] + + /* * This file is automatically generated. Do not edit. */ @@ -166,6 +170,8 @@ trait Recursion } case class Recursion_ () extends Recursion + + /* * This file is automatically generated. Do not edit. */ @@ -192,6 +198,8 @@ trait Enum [A <: EnumConstant] } case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] + + /* * This file is automatically generated. Do not edit. */ @@ -223,6 +231,8 @@ trait CartesianProduct } case class CartesianProduct_ () extends CartesianProduct + + /* * This file is automatically generated. Do not edit. */ @@ -355,6 +365,8 @@ trait OptionSDBuilder [A] } case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] + + /* * This file is automatically generated. Do not edit. */ @@ -371,3 +383,5 @@ trait Doc } case class Doc_ (doc : String) extends Doc + + diff --git a/translator/src/main/scala/soda/translator/block/Package.scala b/translator/src/main/scala/soda/translator/block/Package.scala index f520fab7..c1be2dd3 100644 --- a/translator/src/main/scala/soda/translator/block/Package.scala +++ b/translator/src/main/scala/soda/translator/block/Package.scala @@ -15,6 +15,8 @@ trait LineTranslator } case class LineTranslator_ (line : String) extends LineTranslator + + trait BlockSequenceTranslator { @@ -38,6 +40,8 @@ trait DefaultBlockSequenceTranslator } case class DefaultBlockSequenceTranslator_ (translator : BlockTranslator) extends DefaultBlockSequenceTranslator + + trait PlainBlock { @@ -51,6 +55,8 @@ trait PlainBlock } case class PlainBlock_ (lines : Seq [String]) extends PlainBlock + + /** * This models an abstract translator. */ @@ -64,6 +70,8 @@ trait Translator } case class Translator_ (translate : String => String, keys : Seq [String]) extends Translator + + trait BlockTranslatorPipeline extends BlockTranslator @@ -85,6 +93,8 @@ trait BlockTranslatorPipeline } case class BlockTranslatorPipeline_ (pipeline : Seq [BlockTranslator]) extends BlockTranslatorPipeline + + trait BlockTranslator { @@ -106,6 +116,8 @@ trait DefaultBlockTranslator } case class DefaultBlockTranslator_ () extends DefaultBlockTranslator + + trait BlockAnnotationId extends soda.lib.EnumConstant @@ -166,6 +178,8 @@ trait BlockAnnotationEnum } case class BlockAnnotationEnum_ () extends BlockAnnotationEnum + + trait AnnotatedBlock extends Block @@ -177,6 +191,8 @@ trait AnnotatedBlock } case class AnnotatedBlock_ (annotated_lines : Seq [AnnotatedLine], block_annotation : BlockAnnotationId) extends AnnotatedBlock + + trait ConditionalBlockTranslator extends BlockTranslator @@ -197,6 +213,8 @@ trait ConditionalBlockTranslator } case class ConditionalBlockTranslator_ (accepted_annotations : Seq [BlockAnnotationId], translator : BlockTranslator) extends ConditionalBlockTranslator + + trait AnnotatedLine { @@ -225,6 +243,8 @@ trait Block } case class Block_ (annotated_lines : Seq [AnnotatedLine]) extends Block + + trait SingleLineProcessor { @@ -233,3 +253,5 @@ trait SingleLineProcessor } case class SingleLineProcessor_ (line : String) extends SingleLineProcessor + + diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.scala b/translator/src/main/scala/soda/translator/blocktr/Package.scala index 405a05ef..2df50c5a 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.scala +++ b/translator/src/main/scala/soda/translator/blocktr/Package.scala @@ -35,6 +35,8 @@ trait TableTranslator } case class TableTranslator_ (table : Seq [Tuple2 [String, String] ]) extends TableTranslator + + trait TokenizedBlockTranslator extends soda.translator.block.BlockTranslator @@ -98,6 +100,8 @@ trait TokenizedBlockTranslator } case class TokenizedBlockTranslator_ (replace_token : soda.translator.replacement.Token => String) extends TokenizedBlockTranslator + + trait TokenReplacement { @@ -112,3 +116,5 @@ trait TokenReplacement } case class TokenReplacement_ () extends TokenReplacement + + diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.scala b/translator/src/main/scala/soda/translator/extension/common/Package.scala index f2d8c88f..f353ae9d 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Package.scala @@ -15,3 +15,5 @@ trait Extension } case class Extension_ (execute : Seq [String] => Boolean) extends Extension + + diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.scala b/translator/src/main/scala/soda/translator/extension/help/Package.scala index a7385de5..7a3653d6 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Package.scala @@ -84,3 +84,5 @@ trait License } case class License_ () extends License + + diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.scala b/translator/src/main/scala/soda/translator/extension/main/Package.scala index 816e92b4..3b3d76bc 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Package.scala @@ -58,3 +58,5 @@ object EntryPoint { case class Main_ () extends Main + + diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala index 4737c44b..31f49b59 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala @@ -134,6 +134,8 @@ trait DefinitionLineTranslator } case class DefinitionLineTranslator_ (line: String) extends DefinitionLineTranslator + + trait CoqClassDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -230,6 +232,8 @@ trait CoqClassDeclarationBlockTranslator } case class CoqClassDeclarationBlockTranslator_ () extends CoqClassDeclarationBlockTranslator + + trait CoqImportDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -290,6 +294,8 @@ trait CoqImportDeclarationBlockTranslator } case class CoqImportDeclarationBlockTranslator_ () extends CoqImportDeclarationBlockTranslator + + trait CoqClassConstructorBlockTranslator extends soda.translator.block.BlockTranslator @@ -419,6 +425,8 @@ trait CoqClassConstructorBlockTranslator } case class CoqClassConstructorBlockTranslator_ () extends CoqClassConstructorBlockTranslator + + /** * This class translates Soda snippets into Coq snippets. */ @@ -472,6 +480,8 @@ trait MicroTranslatorToCoq } case class MicroTranslatorToCoq_ () extends MicroTranslatorToCoq + + /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. */ @@ -730,6 +740,8 @@ trait TranslationConstantToCoq } case class TranslationConstantToCoq_ () extends TranslationConstantToCoq + + /** * This translates Soda source code to Coq source code. */ @@ -811,6 +823,8 @@ trait FileNamePair } case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair + + trait CoqPackageDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -849,6 +863,8 @@ trait CoqPackageDeclarationBlockTranslator } case class CoqPackageDeclarationBlockTranslator_ () extends CoqPackageDeclarationBlockTranslator + + trait MatchCaseBlockTranslator extends soda.translator.block.BlockTranslator @@ -933,6 +949,8 @@ trait MatchCaseBlockTranslator } case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator + + trait CoqDefinitionBlockTranslator extends soda.translator.block.BlockTranslator @@ -992,6 +1010,8 @@ trait CoqDefinitionBlockTranslator } case class CoqDefinitionBlockTranslator_ () extends CoqDefinitionBlockTranslator + + trait CoqTheoremBlockTranslator extends soda.translator.block.BlockTranslator @@ -1042,6 +1062,8 @@ trait CoqTheoremBlockTranslator } case class CoqTheoremBlockTranslator_ () extends CoqTheoremBlockTranslator + + trait CoqClassEndBlockTranslator extends soda.translator.block.BlockTranslator @@ -1106,6 +1128,8 @@ trait CoqClassEndBlockTranslator } case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator + + trait CoqProofBlockTranslator extends soda.translator.block.BlockTranslator @@ -1155,3 +1179,5 @@ trait CoqProofBlockTranslator } case class CoqProofBlockTranslator_ () extends CoqProofBlockTranslator + + diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index 7e43332e..e92ef407 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -46,6 +46,8 @@ trait MicroTranslatorToDoc } case class MicroTranslatorToDoc_ () extends MicroTranslatorToDoc + + trait DocBlockTranslator extends soda.translator.block.BlockTranslator @@ -144,6 +146,8 @@ trait DocBlockTranslator } case class DocBlockTranslator_ () extends DocBlockTranslator + + /** * This generates documentation from Soda source code. */ @@ -230,6 +234,8 @@ trait FileNamePair } case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair + + /** * This class contains constants that are specific for the documentation generation. */ @@ -339,3 +345,5 @@ trait TranslationConstantToDoc } case class TranslationConstantToDoc_ () extends TranslationConstantToDoc + + diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index b7e82720..2e7500fb 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -54,6 +54,8 @@ trait ClassEndBlockTranslator } case class ClassEndBlockTranslator_ () extends ClassEndBlockTranslator + + trait TheoremAndProofBlockTranslator extends soda.translator.block.BlockTranslator @@ -102,6 +104,8 @@ trait TheoremAndProofBlockTranslator } case class TheoremAndProofBlockTranslator_ () extends TheoremAndProofBlockTranslator + + /** * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. */ @@ -335,6 +339,8 @@ trait TranslationConstantToScala } case class TranslationConstantToScala_ () extends TranslationConstantToScala + + trait ClassDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -443,6 +449,8 @@ trait ClassDeclarationBlockTranslator } case class ClassDeclarationBlockTranslator_ () extends ClassDeclarationBlockTranslator + + trait ClassConstructorBlockTranslator extends soda.translator.block.BlockTranslator @@ -561,6 +569,8 @@ trait ClassConstructorBlockTranslator } case class ClassConstructorBlockTranslator_ () extends ClassConstructorBlockTranslator + + /** * A line containing the definition sign will be classified as a definition. * The definitions need to be identified as 'val' or 'def'. @@ -655,6 +665,8 @@ trait FunctionDefinitionLineDetector } case class FunctionDefinitionLineDetector_ (line: String) extends FunctionDefinitionLineDetector + + /** * This translates Soda source code to Scala source code. */ @@ -801,6 +813,8 @@ trait FileNamePair } case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair + + trait MatchCaseBlockTranslator extends soda.translator.block.BlockTranslator @@ -879,6 +893,8 @@ trait MatchCaseBlockTranslator } case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator + + trait FunctionDefinitionBlockTranslator extends soda.translator.block.BlockTranslator @@ -987,6 +1003,8 @@ trait FunctionDefinitionBlockTranslator } case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator + + trait ImportDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -1044,6 +1062,8 @@ trait ImportDeclarationBlockTranslator } case class ImportDeclarationBlockTranslator_ () extends ImportDeclarationBlockTranslator + + trait MainClassBlockTranslator extends soda.translator.block.BlockTranslator @@ -1103,6 +1123,8 @@ trait MainClassBlockTranslator } case class MainClassBlockTranslator_ () extends MainClassBlockTranslator + + /** * This class translates Soda source code into Scala source code. */ @@ -1158,6 +1180,8 @@ trait MicroTranslatorToScala } case class MicroTranslatorToScala_ () extends MicroTranslatorToScala + + trait AbstractDeclarationBlockTranslator extends soda.translator.block.BlockTranslator @@ -1217,3 +1241,5 @@ trait AbstractDeclarationBlockTranslator } case class AbstractDeclarationBlockTranslator_ () extends AbstractDeclarationBlockTranslator + + diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index c8da53e3..d5da069f 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -45,6 +45,8 @@ trait DirectoryScanner } case class DirectoryScanner_ () extends DirectoryScanner + + trait AbstractDirectoryProcessor { @@ -103,6 +105,8 @@ trait DirectoryProcessor } case class DirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends DirectoryProcessor + + trait LibraryDeployer { @@ -136,6 +140,8 @@ trait LibraryDeployer } case class LibraryDeployer_ () extends LibraryDeployer + + /** * This is an auxiliary class to read small files. */ @@ -206,3 +212,5 @@ trait SimpleFileWriter } case class SimpleFileWriter_ () extends SimpleFileWriter + + diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index 89192dbe..a59c34dd 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -73,6 +73,8 @@ trait CurrentAndNewCommentState } case class CurrentAndNewCommentState_ (current_state : Boolean, new_comment_state : Boolean) extends CurrentAndNewCommentState + + trait SodaConstant { @@ -238,6 +240,8 @@ trait SodaConstant } case class SodaConstant_ () extends SodaConstant + + trait PreprocessorSequenceTranslator extends soda.translator.block.BlockSequenceTranslator @@ -345,6 +349,8 @@ trait AuxiliaryTuple } case class AuxiliaryTuple_ (block_sequence : Seq [soda.translator.block.AnnotatedBlock], accumulated : Seq [soda.translator.block.AnnotatedBlock], references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ]) extends AuxiliaryTuple + + /** * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. */ @@ -395,3 +401,5 @@ trait BlockProcessor } case class BlockProcessor_ (translator : soda.translator.block.BlockSequenceTranslator) extends BlockProcessor + + diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala index 5a541d9d..74f4d3dd 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -24,6 +24,8 @@ trait ProofBlockAnnotation } case class ProofBlockAnnotation_ (block : soda.translator.block.Block) extends ProofBlockAnnotation + + trait FunctionDefinitionAnnotation extends BlockAnnotationParser @@ -99,6 +101,8 @@ trait FunctionDefinitionAnnotation } case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation + + trait ImportDeclarationAnnotation extends BlockAnnotationParser @@ -122,6 +126,8 @@ trait ImportDeclarationAnnotation } case class ImportDeclarationAnnotation_ (block : soda.translator.block.Block) extends ImportDeclarationAnnotation + + trait PackageDeclarationAnnotation extends BlockAnnotationParser @@ -140,6 +146,8 @@ trait PackageDeclarationAnnotation } case class PackageDeclarationAnnotation_ (block : soda.translator.block.Block) extends PackageDeclarationAnnotation + + trait BlockAnnotationParser extends soda.translator.block.AnnotatedBlock @@ -198,6 +206,8 @@ trait BlockAnnotationParser } case class BlockAnnotationParser_ (block : soda.translator.block.Block, applies : Boolean, identifier : soda.translator.block.BlockAnnotationId) extends BlockAnnotationParser + + trait ClassBeginningAnnotation extends BlockAnnotationParser @@ -253,6 +263,8 @@ trait ClassBeginningAnnotation } case class ClassBeginningAnnotation_ (block : soda.translator.block.Block) extends ClassBeginningAnnotation + + trait AbstractDeclarationAnnotation extends BlockAnnotationParser @@ -281,6 +293,8 @@ trait AbstractDeclarationAnnotation } case class AbstractDeclarationAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends AbstractDeclarationAnnotation + + trait ClassAliasAnnotation extends BlockAnnotationParser @@ -305,6 +319,8 @@ trait ClassAliasAnnotation } case class ClassAliasAnnotation_ (block : soda.translator.block.Block) extends ClassAliasAnnotation + + trait AnnotationFactory extends soda.translator.block.BlockTranslator @@ -373,6 +389,8 @@ trait AnnotationFactory } case class AnnotationFactory_ () extends AnnotationFactory + + trait CommentAnnotation extends BlockAnnotationParser @@ -392,6 +410,8 @@ trait CommentAnnotation } case class CommentAnnotation_ (block : soda.translator.block.Block) extends CommentAnnotation + + trait TestDeclarationAnnotation extends BlockAnnotationParser @@ -410,6 +430,8 @@ trait TestDeclarationAnnotation } case class TestDeclarationAnnotation_ (block : soda.translator.block.Block) extends TestDeclarationAnnotation + + trait ClassEndAnnotation extends BlockAnnotationParser @@ -430,6 +452,8 @@ trait ClassEndAnnotation } case class ClassEndAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends ClassEndAnnotation + + trait TheoremBlockAnnotation extends BlockAnnotationParser @@ -449,3 +473,5 @@ trait TheoremBlockAnnotation } case class TheoremBlockAnnotation_ (block : soda.translator.block.Block) extends TheoremBlockAnnotation + + diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index 2ac7539c..f29b6648 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -104,6 +104,8 @@ trait TokenizerFoldTuple } case class TokenizerFoldTuple_ (last_index : Int, parser_state : ParserState, rev_tokens : Seq [Token]) extends TokenizerFoldTuple + + /** * This models a collection of replacement functions. * This is intended to be used as a pipeline. @@ -261,6 +263,8 @@ trait ReplacementWithTranslator } case class ReplacementWithTranslator_ (translator : soda.translator.block.Translator) extends ReplacementWithTranslator + + trait LinePatternProcessor { @@ -328,6 +332,8 @@ trait ReplacerFoldTuple } case class ReplacerFoldTuple_ (replaced_text_rev : Seq [String], start_index : Int) extends ReplacerFoldTuple + + /** * This is to classify characters. */ @@ -407,6 +413,8 @@ trait CharTypeEnum } case class CharTypeEnum_ () extends CharTypeEnum + + /** * This models all the possible states that the parser can be. */ @@ -500,3 +508,5 @@ trait ParserTransition } case class ParserTransition_ () extends ParserTransition + + diff --git a/translator/src/test/resources/soda/example/Package.scala b/translator/src/test/resources/soda/example/Package.scala index 05296ed7..c13885b1 100644 --- a/translator/src/test/resources/soda/example/Package.scala +++ b/translator/src/test/resources/soda/example/Package.scala @@ -8,3 +8,5 @@ case class Example() { } + + diff --git a/translator/src/test/resources/soda/example/otherexample/Package.scala b/translator/src/test/resources/soda/example/otherexample/Package.scala index 398862c3..fe43d823 100644 --- a/translator/src/test/resources/soda/example/otherexample/Package.scala +++ b/translator/src/test/resources/soda/example/otherexample/Package.scala @@ -9,3 +9,5 @@ case class OtherExample() { } + + diff --git a/translator/src/test/scala/soda/lib/Package.scala b/translator/src/test/scala/soda/lib/Package.scala index cd325d17..19815933 100644 --- a/translator/src/test/scala/soda/lib/Package.scala +++ b/translator/src/test/scala/soda/lib/Package.scala @@ -219,6 +219,8 @@ case class OptionSDSpec () ) } + + case class CartesianProductSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -290,6 +292,8 @@ case class CartesianProductSpec () ) } + + case class SeqSDSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -359,6 +363,8 @@ case class SeqSDSpec () lazy val non_empty_seq : NonEmptySeqSD [Int] => NonEmptySeqSD [Int] = sequence => sequence.reverse } + + trait DayOfTheWeek extends EnumConstant @@ -422,6 +428,8 @@ case class EnumSpec () ) } + + case class RecursionSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -492,3 +500,5 @@ case class RecursionSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/block/Package.scala b/translator/src/test/scala/soda/translator/block/Package.scala index f2a618a6..b3bc5e17 100644 --- a/translator/src/test/scala/soda/translator/block/Package.scala +++ b/translator/src/test/scala/soda/translator/block/Package.scala @@ -116,3 +116,5 @@ case class BlockTranslatorPipelineSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala index 8d14322a..257466d3 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala @@ -39,6 +39,8 @@ case class MicroTranslatorToCoqSpec () ) } + + case class CoqFullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -94,3 +96,5 @@ case class CoqFullTranslationSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala index 4dd9be1e..07a3c0c4 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala @@ -47,6 +47,8 @@ case class MicroTranslatorToDocSpec () ) } + + case class DocFullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -91,3 +93,5 @@ case class DocFullTranslationSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala index 4a8d5af0..6663e9a4 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -85,6 +85,8 @@ case class MultiLineSpec () ) } + + case class ClassConstructorBlockTranslatorSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -212,6 +214,8 @@ case class ClassConstructorBlockTranslatorSpec () ) } + + /** * This tests how translation is done for Scala reserved words that are not Soda reserved words. */ @@ -302,6 +306,8 @@ case class ScalaNonSodaSpec () ) } + + case class FullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -401,6 +407,8 @@ case class FullTranslationSpec () ) } + + case class UpperAndLowerBoundDeclarationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -505,6 +513,8 @@ case class UpperAndLowerBoundDeclarationSpec () ) } + + trait ExampleWithWrongOrder { @@ -595,6 +605,8 @@ case class LazySyntaxSpec () ) } + + case class MicroTranslatorToScalaSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -896,6 +908,8 @@ case class MicroTranslatorToScalaSpec () ) } + + case class MainSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -923,6 +937,8 @@ case class MainSpec () ) } + + case class BeautifierSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -952,3 +968,5 @@ case class BeautifierSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/io/Package.scala b/translator/src/test/scala/soda/translator/io/Package.scala index 7d7491eb..e834e2d6 100644 --- a/translator/src/test/scala/soda/translator/io/Package.scala +++ b/translator/src/test/scala/soda/translator/io/Package.scala @@ -48,3 +48,5 @@ case class DirectoryScannerSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index 922ff440..01e9b988 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -43,6 +43,8 @@ case class BlockSpec () ) } + + case class PreprocessorSequenceTranslatorSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -121,3 +123,5 @@ case class PreprocessorSequenceTranslatorSpec () ) } + + diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala index 53360323..e7bf8aba 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala @@ -196,6 +196,8 @@ case class ClassBeginningAnnotationSpec () ) } + + case class BlockAnnotationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -351,6 +353,8 @@ case class BlockAnnotationSpec () ) } + + trait ExampleProgram { @@ -421,3 +425,5 @@ trait ExampleProgram } case class ExampleProgram_ () extends ExampleProgram + + diff --git a/translator/src/test/scala/soda/translator/replacement/Package.scala b/translator/src/test/scala/soda/translator/replacement/Package.scala index a219e793..a21a15e6 100644 --- a/translator/src/test/scala/soda/translator/replacement/Package.scala +++ b/translator/src/test/scala/soda/translator/replacement/Package.scala @@ -58,6 +58,8 @@ case class CharTypeSpec () ) } + + case class TokenizerSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -123,6 +125,8 @@ case class TokenizerSpec () ) } + + case class ReplacementAuxSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -288,3 +292,5 @@ case class ReplacementAuxSpec () ) } + + From ec131dc6bbb139b8c859a8e6a4f3b3e91888e48e Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 22:07:15 +0100 Subject: [PATCH 55/71] Update processing order of Scala translator --- .../translator/extension/toscala/Package.scala | 4 ++-- .../extension/toscala/TranslatorToScala.soda | 4 ++-- .../soda/translator/io/DirectoryProcessor.soda | 18 +++++++++++------- .../scala/soda/translator/io/Package.scala | 18 +++++++++++------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index 2e7500fb..f0509dd4 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -751,7 +751,7 @@ trait TranslatorToScala ) private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = - _translate_append (pair.input_file_name) (pair.output_file_name) + _translate_append (pair.input_file_name) (pair.output_file_name) def get_input_output_file_names (input_name : String) : FileNamePair = if ( input_name.endsWith (_soda_extension) @@ -773,7 +773,7 @@ trait TranslatorToScala _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content = _translator.translate (input) + append_separation) + SimpleFileWriter_ ().append_file (output_file_name) (content = new_line + _translator.translate (input) + new_line) private def _read_input_with_prelude (input_file_name : String) : String = if ( _is_a_prelude_file (input_file_name) diff --git a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda index e228299f..1de115f5 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/TranslatorToScala.soda @@ -82,7 +82,7 @@ class TranslatorToScala ) _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = - _translate_append (pair.input_file_name) (pair.output_file_name) + _translate_append (pair.input_file_name) (pair.output_file_name) get_input_output_file_names (input_name : String) : FileNamePair = if input_name.endsWith (_soda_extension) @@ -104,7 +104,7 @@ class TranslatorToScala _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content := _translator.translate (input) + append_separation) + SimpleFileWriter_ ().append_file (output_file_name) (content := new_line + _translator.translate (input) + new_line) _read_input_with_prelude (input_file_name : String) : String = if _is_a_prelude_file (input_file_name) diff --git a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda index abd9cb1f..cdf2a811 100644 --- a/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda +++ b/translator/src/main/scala/soda/translator/io/DirectoryProcessor.soda @@ -22,27 +22,31 @@ class DirectoryProcessor package_file_name = "Package.soda" - _all_files = + _all_files : Seq [File] = DirectoryScanner_ ().get_all_files ( @new File (start)) - _all_soda_files = + _all_soda_files : Seq [File] = _all_files .filter ( lambda x --> x.isFile) .filter ( lambda x --> x.getName.endsWith (soda_suffix)) - _package_files = + _package_files : Seq [File] = _all_files .filter ( lambda x --> x.isFile) .filter ( lambda x --> x.getName == package_file_name) - _soda_non_package_files = + _sorted_package_files : Seq [File] = _package_files.sorted + + _soda_non_package_files : Seq [File] = _all_soda_files .filter ( lambda x --> not (x.getName == package_file_name) ) - _soda_files = - _package_files .++ (_soda_non_package_files) + _sorted_soda_non_package_files : Seq [File] = _soda_non_package_files.sorted + + _soda_files : Seq [File] = + _sorted_package_files .++ (_sorted_soda_non_package_files) - _lib_files = + _lib_files : Seq [File] = _all_files .filter ( lambda x --> x.isFile) .filter ( lambda file --> file.getName == LibraryDeployer_ ().library_marker_file) diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index d5da069f..70ffe4c3 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -71,27 +71,31 @@ trait DirectoryProcessor lazy val package_file_name = "Package.soda" - private lazy val _all_files = + private lazy val _all_files : Seq [File] = DirectoryScanner_ ().get_all_files ( new File (start)) - private lazy val _all_soda_files = + private lazy val _all_soda_files : Seq [File] = _all_files .filter ( x => x.isFile) .filter ( x => x.getName.endsWith (soda_suffix)) - private lazy val _package_files = + private lazy val _package_files : Seq [File] = _all_files .filter ( x => x.isFile) .filter ( x => x.getName == package_file_name) - private lazy val _soda_non_package_files = + private lazy val _sorted_package_files : Seq [File] = _package_files.sorted + + private lazy val _soda_non_package_files : Seq [File] = _all_soda_files .filter ( x => ! (x.getName == package_file_name) ) - private lazy val _soda_files = - _package_files .++ (_soda_non_package_files) + private lazy val _sorted_soda_non_package_files : Seq [File] = _soda_non_package_files.sorted + + private lazy val _soda_files : Seq [File] = + _sorted_package_files .++ (_sorted_soda_non_package_files) - private lazy val _lib_files = + private lazy val _lib_files : Seq [File] = _all_files .filter ( x => x.isFile) .filter ( file => file.getName == LibraryDeployer_ ().library_marker_file) From 8fb70c94bf6afeafe37d61304b822f9092d38916 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 15 Feb 2023 22:13:08 +0100 Subject: [PATCH 56/71] Update Package.scala files --- .../soda/example/algorithms/Package.scala | 158 +- .../ethicalissues/fairness/Package.scala | 2 +- .../ethicalissues/pricemonitor/Package.scala | 200 +-- .../example/forcoq/algorithms/Package.scala | 2 +- .../soda/example/forcoq/lib/Package.scala | 140 +- .../example/forcoq/mathematics/Package.scala | 44 +- .../soda/example/inanutshell/Package.scala | 2 +- .../soda/example/mathematics/Package.scala | 184 +- .../soda/example/miniexample/Package.scala | 2 +- .../soda/example/algorithms/Package.scala | 180 +- .../ethicalissues/fairness/Package.scala | 2 +- .../ethicalissues/pricemonitor/Package.scala | 2 +- .../example/forcoq/algorithms/Package.scala | 2 +- .../soda/example/forcoq/lib/Package.scala | 2 +- .../example/forcoq/mathematics/Package.scala | 42 +- .../soda/example/mathematics/Package.scala | 102 +- .../main/scala/soda/collection/Package.scala | 158 +- .../soda/collection/example/Package.scala | 90 +- .../test/scala/soda/collection/Package.scala | 2 +- .../soda/collection/example/Package.scala | 2 +- .../main/resources/lib/soda/lib/Package.scala | 326 ++-- .../src/main/scala/soda/lib/Package.scala | 330 ++-- .../scala/soda/translator/block/Package.scala | 218 +-- .../soda/translator/blocktr/Package.scala | 34 +- .../translator/extension/common/Package.scala | 2 +- .../translator/extension/help/Package.scala | 2 +- .../translator/extension/main/Package.scala | 2 +- .../translator/extension/tocoq/Package.scala | 1496 ++++++++-------- .../translator/extension/todoc/Package.scala | 218 +-- .../extension/toscala/Package.scala | 1566 ++++++++--------- .../scala/soda/translator/io/Package.scala | 78 +- .../soda/translator/parser/Package.scala | 324 ++-- .../parser/annotation/Package.scala | 398 ++--- .../soda/translator/replacement/Package.scala | 394 ++--- .../test/resources/soda/example/Package.scala | 2 +- .../soda/example/otherexample/Package.scala | 2 +- .../src/test/scala/soda/lib/Package.scala | 342 ++-- .../scala/soda/translator/block/Package.scala | 2 +- .../translator/extension/tocoq/Package.scala | 72 +- .../translator/extension/todoc/Package.scala | 88 +- .../extension/toscala/Package.scala | 670 +++---- .../scala/soda/translator/io/Package.scala | 2 +- .../soda/translator/parser/Package.scala | 2 +- .../parser/annotation/Package.scala | 316 ++-- .../soda/translator/replacement/Package.scala | 134 +- 45 files changed, 4169 insertions(+), 4169 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index 87165b78..98638761 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -6,7 +6,8 @@ package soda.example.algorithms */ trait Package -trait FizzBuzzPatternMatching + +trait FizzBuzz { lazy val fizz = "Fizz" @@ -21,72 +22,60 @@ trait FizzBuzzPatternMatching .map (_get_fizz_buzz_term) private def _get_fizz_buzz_term (n : Int) : String = - Tuple2 (n % 3, n % 5) match { - case Tuple2 (0, 0) => fizz + buzz - case Tuple2 (0, x) => fizz - case Tuple2 (x, 0) => buzz - case x => n.toString - } - -} - -case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching - - -trait SaladMaker -{ - - def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) + if ( _is_divisible_by (n) (15) ) fizz + buzz + else if ( _is_divisible_by (n) (3) ) fizz + else if ( _is_divisible_by (n) (5) ) buzz + else n.toString - import scala.annotation.tailrec - @tailrec final - private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = - if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) - ) salad_so_far - else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) + private def _is_divisible_by (n : Int) (k : Int) : Boolean = + n % k == 0 } -case class SaladMaker_ () extends SaladMaker +case class FizzBuzz_ () extends FizzBuzz -trait ScalaReservedWordEscaping +trait FizzBuzzPatternMatching { - private lazy val __soda__var = "var" - - private lazy val __soda__val = 1 - - private def __soda__def [A, B] (key : A) (value : B) : MyPair [A, B] = MyPair_ (key, value) - - private def __soda__while [A, B] (seq : Seq [A] ) (cond : A => Boolean) (funct : A => B) : Seq [B] = - seq.takeWhile (cond).map (funct) + lazy val fizz = "Fizz" - private lazy val __soda__protected = "protected" + lazy val buzz = "Buzz" - private lazy val __soda__private = "private" + private lazy val _range = soda.lib.Range_ () - def f (x : Int) (y : Int) : Int = x + y + lazy val apply : Seq [String] = + _range.apply (100) + .map ( (x : Int) => x + 1) + .map (_get_fizz_buzz_term) - lazy val cons : Int => Int => Int = - x => - y => - f (x) (y) + private def _get_fizz_buzz_term (n : Int) : String = + Tuple2 (n % 3, n % 5) match { + case Tuple2 (0, 0) => fizz + buzz + case Tuple2 (0, x) => fizz + case Tuple2 (x, 0) => buzz + case x => n.toString + } } -case class ScalaReservedWordEscaping_ () extends ScalaReservedWordEscaping +case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching -trait MyPair [A, B] + +trait Main { - def key : A - def value : B + def main (arguments : Array [String] ) : Unit = + println ("Hello world!") } -case class MyPair_ [A, B] (key : A, value : B) extends MyPair [A, B] +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main trait Parameter @@ -164,32 +153,60 @@ trait Triplet case class Triplet_ (x : Int, y : Int, z : Int) extends Triplet -trait FizzBuzz +trait SaladMaker { - lazy val fizz = "Fizz" + def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) - lazy val buzz = "Buzz" + import scala.annotation.tailrec + @tailrec final + private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) + ) salad_so_far + else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) - private lazy val _range = soda.lib.Range_ () +} - lazy val apply : Seq [String] = - _range.apply (100) - .map ( (x : Int) => x + 1) - .map (_get_fizz_buzz_term) +case class SaladMaker_ () extends SaladMaker - private def _get_fizz_buzz_term (n : Int) : String = - if ( _is_divisible_by (n) (15) ) fizz + buzz - else if ( _is_divisible_by (n) (3) ) fizz - else if ( _is_divisible_by (n) (5) ) buzz - else n.toString - private def _is_divisible_by (n : Int) (k : Int) : Boolean = - n % k == 0 +trait ScalaReservedWordEscaping +{ + + private lazy val __soda__var = "var" + + private lazy val __soda__val = 1 + + private def __soda__def [A, B] (key : A) (value : B) : MyPair [A, B] = MyPair_ (key, value) + + private def __soda__while [A, B] (seq : Seq [A] ) (cond : A => Boolean) (funct : A => B) : Seq [B] = + seq.takeWhile (cond).map (funct) + + private lazy val __soda__protected = "protected" + + private lazy val __soda__private = "private" + + def f (x : Int) (y : Int) : Int = x + y + + lazy val cons : Int => Int => Int = + x => + y => + f (x) (y) } -case class FizzBuzz_ () extends FizzBuzz +case class ScalaReservedWordEscaping_ () extends ScalaReservedWordEscaping + +trait MyPair [A, B] +{ + + def key : A + def value : B + +} + +case class MyPair_ [A, B] (key : A, value : B) extends MyPair [A, B] trait SortExample @@ -451,20 +468,3 @@ trait SwapExample case class SwapExample_ () extends SwapExample - -trait Main -{ - - def main (arguments : Array [String] ) : Unit = - println ("Hello world!") - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main - - diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala index e4c85eb8..c3bf47d5 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala @@ -7,6 +7,7 @@ package soda.example.ethicalissues.fairness trait Package + trait Applicant { @@ -54,4 +55,3 @@ trait Fairness case class Fairness_ (score_difference_tolerance : Double, ranking_difference_tolerance : Double, rank : Applicant => Double) extends Fairness - diff --git a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala index 2c8346b8..22ede3e6 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -5,114 +5,59 @@ package soda.example.ethicalissues.pricemonitor */ trait Package -trait Report3 + +trait Customer { - def compliant : Boolean - def price_of_flight : Int - def price_of_flight_by_segments : Int + def name : String + def ip_address : String } -case class Report3_ (compliant : Boolean, price_of_flight : Int, price_of_flight_by_segments : Int) extends Report3 +case class Customer_ (name : String, ip_address : String) extends Customer -trait Requirement3Monitor - extends - RequirementMonitor +trait PricingAgent { - def pricing_agent : PricingAgent - - def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report3 = - get_report_with ( - get_price (customer) (flight) (date_in_days) ) ( - get_price_of_flight_by_segments (customer) (flight) (date_in_days) - ) + import java.util.Date - def get_report_with (price_of_flight : Int) (price_of_flight_by_segments : Int) : Report3 = - Report3_ (price_of_flight <= price_of_flight_by_segments, price_of_flight, price_of_flight_by_segments) + /** get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int */ + def abs_get_price : Customer => Flight => Int => Int - def get_price_of_flight_by_segments (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - sum_prices (get_prices_of_segments (customer) (SegmentsForFlight_ (flight).segments) (date_in_days) ) + def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + abs_get_price (customer) (flight) (date_in_days) - def get_prices_of_segments (customer : Customer) (segments : Seq [Segment] ) (date_in_days : Int) : Seq [Int] = - segments.map ( segment => get_price (customer) (segment) (date_in_days) ) + lazy val milliseconds_per_day : Long = 24 * 60 * 60 * 1000 - def sum_prices (prices : Seq [Int] ) : Int = - prices.sum + def get_days_for (date : Date) : Int = + (date.getTime / milliseconds_per_day).toInt } -case class Requirement3Monitor_ (pricing_agent : PricingAgent) extends Requirement3Monitor +case class PricingAgent_ (abs_get_price : Customer => Flight => Int => Int) extends PricingAgent -trait Segment - extends - Flight +trait Flight { def start_airport : String + def intermediate_airports : Seq [String] def end_airport : String - lazy val intermediate_airports = Seq [String] () - -} - -case class Segment_ (start_airport : String, end_airport : String) extends Segment - -trait SegmentsForFlight -{ - - def flight : Flight - - lazy val segments : Seq [Segment] = - rec_segments_multi (flight.start_airport) (flight.intermediate_airports) (flight.end_airport) - - def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = - intermediate_stops match { - case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) - case x => Nil.+: (Segment_ (first_airport, last_airport) ) - } - -} - -case class SegmentsForFlight_ (flight : Flight) extends SegmentsForFlight - - -trait Report2 -{ - - def compliant : Boolean - def old_price : Int - def new_price : Int - } -case class Report2_ (compliant : Boolean, old_price : Int, new_price : Int) extends Report2 +case class Flight_ (start_airport : String, intermediate_airports : Seq [String], end_airport : String) extends Flight -trait Requirement2Monitor - extends - RequirementMonitor +trait RequirementMonitor { def pricing_agent : PricingAgent - lazy val acceptable_increase = 1.25 - - def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report2 = - get_report_with ( - old_price = get_price (customer) (flight) (get_a_year_before (date_in_days) ) ) ( - new_price = get_price (customer) (flight) (date_in_days) - ) - - def get_report_with (old_price : Int) (new_price : Int) : Report2 = - Report2_ (new_price <= old_price * acceptable_increase, old_price, new_price) - - def get_a_year_before (date_in_days : Int) : Int = - date_in_days - 365 + def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + pricing_agent.get_price (customer) (flight) (date_in_days) } -case class Requirement2Monitor_ (pricing_agent : PricingAgent) extends Requirement2Monitor +case class RequirementMonitor_ (pricing_agent : PricingAgent) extends RequirementMonitor trait Report1 @@ -166,57 +111,112 @@ trait Requirement1Monitor case class Requirement1Monitor_ (pricing_agent : PricingAgent) extends Requirement1Monitor -trait Customer +trait Report2 { - def name : String - def ip_address : String + def compliant : Boolean + def old_price : Int + def new_price : Int } -case class Customer_ (name : String, ip_address : String) extends Customer +case class Report2_ (compliant : Boolean, old_price : Int, new_price : Int) extends Report2 -trait PricingAgent +trait Requirement2Monitor + extends + RequirementMonitor { - import java.util.Date + def pricing_agent : PricingAgent - /** get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int */ - def abs_get_price : Customer => Flight => Int => Int + lazy val acceptable_increase = 1.25 - def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - abs_get_price (customer) (flight) (date_in_days) + def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report2 = + get_report_with ( + old_price = get_price (customer) (flight) (get_a_year_before (date_in_days) ) ) ( + new_price = get_price (customer) (flight) (date_in_days) + ) - lazy val milliseconds_per_day : Long = 24 * 60 * 60 * 1000 + def get_report_with (old_price : Int) (new_price : Int) : Report2 = + Report2_ (new_price <= old_price * acceptable_increase, old_price, new_price) - def get_days_for (date : Date) : Int = - (date.getTime / milliseconds_per_day).toInt + def get_a_year_before (date_in_days : Int) : Int = + date_in_days - 365 } -case class PricingAgent_ (abs_get_price : Customer => Flight => Int => Int) extends PricingAgent +case class Requirement2Monitor_ (pricing_agent : PricingAgent) extends Requirement2Monitor -trait Flight + +trait Report3 { - def start_airport : String - def intermediate_airports : Seq [String] - def end_airport : String + def compliant : Boolean + def price_of_flight : Int + def price_of_flight_by_segments : Int } -case class Flight_ (start_airport : String, intermediate_airports : Seq [String], end_airport : String) extends Flight +case class Report3_ (compliant : Boolean, price_of_flight : Int, price_of_flight_by_segments : Int) extends Report3 -trait RequirementMonitor +trait Requirement3Monitor + extends + RequirementMonitor { def pricing_agent : PricingAgent - def get_price (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = - pricing_agent.get_price (customer) (flight) (date_in_days) + def get_report (customer : Customer) (flight : Flight) (date_in_days : Int) : Report3 = + get_report_with ( + get_price (customer) (flight) (date_in_days) ) ( + get_price_of_flight_by_segments (customer) (flight) (date_in_days) + ) + + def get_report_with (price_of_flight : Int) (price_of_flight_by_segments : Int) : Report3 = + Report3_ (price_of_flight <= price_of_flight_by_segments, price_of_flight, price_of_flight_by_segments) + + def get_price_of_flight_by_segments (customer : Customer) (flight : Flight) (date_in_days : Int) : Int = + sum_prices (get_prices_of_segments (customer) (SegmentsForFlight_ (flight).segments) (date_in_days) ) + + def get_prices_of_segments (customer : Customer) (segments : Seq [Segment] ) (date_in_days : Int) : Seq [Int] = + segments.map ( segment => get_price (customer) (segment) (date_in_days) ) + + def sum_prices (prices : Seq [Int] ) : Int = + prices.sum } -case class RequirementMonitor_ (pricing_agent : PricingAgent) extends RequirementMonitor +case class Requirement3Monitor_ (pricing_agent : PricingAgent) extends Requirement3Monitor + +trait Segment + extends + Flight +{ + + def start_airport : String + def end_airport : String + + lazy val intermediate_airports = Seq [String] () + +} + +case class Segment_ (start_airport : String, end_airport : String) extends Segment + +trait SegmentsForFlight +{ + + def flight : Flight + lazy val segments : Seq [Segment] = + rec_segments_multi (flight.start_airport) (flight.intermediate_airports) (flight.end_airport) + + def rec_segments_multi (first_airport : String) (intermediate_stops : Seq [String] ) (last_airport : String) : Seq [Segment] = + intermediate_stops match { + case head :: tail => (rec_segments_multi (head) (tail) (last_airport) ).+: (Segment_ (first_airport, head) ) + case x => Nil.+: (Segment_ (first_airport, last_airport) ) + } + +} + +case class SegmentsForFlight_ (flight : Flight) extends SegmentsForFlight diff --git a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala index 1d5dc166..6667b9e5 100644 --- a/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/algorithms/Package.scala @@ -5,6 +5,7 @@ package soda.example.forcoq.algorithms */ trait Package + /** * This class contains tail recursive auxiliary functions. */ @@ -51,4 +52,3 @@ trait RecursionForCoq case class RecursionForCoq_ () extends RecursionForCoq - diff --git a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala index e9150371..5f6aff28 100644 --- a/examples/src/main/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/lib/Package.scala @@ -5,6 +5,76 @@ package soda.example.forcoq.lib */ trait Package + +trait list [A] +{ + +} + +case class list_ [A] () extends list [A] + +trait nil [A] + extends + list [A] +{ + +} + +case class nil_ [A] () extends nil [A] + +trait cons [A] + extends + list [A] +{ + + def e : A + def s : list [A] + +} + +case class cons_ [A] (e : A, s : list [A]) extends cons [A] + +trait SeqList +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = + a match { + case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) + case x => b + } + + def reverse [A] (s : list [A] ) : list [A] = + _tailrec_reverse [A] (s) (nil_ [A] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = + a match { + case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) + case x => b + } + + def from_Seq [A] (a : Seq [A] ) : list [A] = + reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = + a match { + case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) + case x => b + } + + def to_Seq [A] (a : list [A] ) : Seq [A] = + (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse + +} + +case class SeqList_ () extends SeqList + + trait nat { @@ -93,73 +163,3 @@ trait IntNat case class IntNat_ () extends IntNat - -trait list [A] -{ - -} - -case class list_ [A] () extends list [A] - -trait nil [A] - extends - list [A] -{ - -} - -case class nil_ [A] () extends nil [A] - -trait cons [A] - extends - list [A] -{ - - def e : A - def s : list [A] - -} - -case class cons_ [A] (e : A, s : list [A]) extends cons [A] - -trait SeqList -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_reverse [A] (a : list [A] ) (b : list [A] ) : list [A] = - a match { - case cons_ (e, s) => _tailrec_reverse (s) ( cons_ (e, b) ) - case x => b - } - - def reverse [A] (s : list [A] ) : list [A] = - _tailrec_reverse [A] (s) (nil_ [A] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_from_Seq [A] (a : Seq [A] ) (b : list [A] ) : list [A] = - a match { - case (e) :: (s) => _tailrec_from_Seq (s) (cons_ (e, b) ) - case x => b - } - - def from_Seq [A] (a : Seq [A] ) : list [A] = - reverse (_tailrec_from_Seq (a) ( nil_ [A] () ) ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_to_Seq [A] (a : list [A] ) (b : Seq [A] ) : Seq [A] = - a match { - case cons_ (e, s) => _tailrec_to_Seq (s) ( b .+: (e) ) - case x => b - } - - def to_Seq [A] (a : list [A] ) : Seq [A] = - (_tailrec_to_Seq (a) ( Seq [A]() ) ) .reverse - -} - -case class SeqList_ () extends SeqList - - diff --git a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala index 289d99e1..be1265af 100644 --- a/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/forcoq/mathematics/Package.scala @@ -5,28 +5,6 @@ package soda.example.forcoq.mathematics */ trait Package -trait TriangularNumberForCoq -{ - - import soda.example.forcoq.lib.O_ - import soda.example.forcoq.lib.S_ - import soda.example.forcoq.lib.nat - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_get_number (m : nat) (acc : nat) : nat = - m match { - case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) - case x => acc - } - - def get_number (n : nat) : nat = - _tailrec_get_number (n) ( O_ () ) - -} - -case class TriangularNumberForCoq_ () extends TriangularNumberForCoq - trait FactorialForCoq { @@ -75,3 +53,25 @@ trait FiboExampleInSodaForCoq case class FiboExampleInSodaForCoq_ () extends FiboExampleInSodaForCoq +trait TriangularNumberForCoq +{ + + import soda.example.forcoq.lib.O_ + import soda.example.forcoq.lib.S_ + import soda.example.forcoq.lib.nat + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_number (m : nat) (acc : nat) : nat = + m match { + case S_ (k) => _tailrec_get_number (k) (acc .add ( S_ (k) ) ) + case x => acc + } + + def get_number (n : nat) : nat = + _tailrec_get_number (n) ( O_ () ) + +} + +case class TriangularNumberForCoq_ () extends TriangularNumberForCoq + diff --git a/examples/src/main/scala/soda/example/inanutshell/Package.scala b/examples/src/main/scala/soda/example/inanutshell/Package.scala index 2d184d85..84a8b686 100644 --- a/examples/src/main/scala/soda/example/inanutshell/Package.scala +++ b/examples/src/main/scala/soda/example/inanutshell/Package.scala @@ -5,6 +5,7 @@ package soda.example.inanutshell */ trait Package + trait InANutshell { @@ -170,4 +171,3 @@ trait PersonName case class PersonName_ (name : String) extends PersonName - diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index 6c8e87aa..ef138cd8 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -6,6 +6,7 @@ package soda.example.mathematics */ trait Package + trait FactorialConcise { @@ -24,88 +25,54 @@ trait FactorialConcise case class FactorialConcise_ () extends FactorialConcise -trait Status +trait FactorialPatternMatching { - def r : BigInt - def n : Int - def q : BigInt - def t : BigInt - def l : Int - def k : Int + def apply (n : Int) : Int = + _tailrec_get_factorial (n) (1) - override - lazy val toString = " r=" + r + " n=" + n + " q=" + q + " t=" + t + " l=" + l + " k=" + k + import scala.annotation.tailrec + @tailrec final + private def _tailrec_get_factorial (n : Int) (product : Int) : Int = + n match { + case 0 => product + case x => _tailrec_get_factorial (x - 1) (x * product) + } } -case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : Int) extends Status - -trait PiIterator -{ - - def apply (n : Int) : Seq [Int] = - _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) - - private lazy val _initial_status = - Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) +case class FactorialPatternMatching_ () extends FactorialPatternMatching - import scala.annotation.tailrec - @tailrec final - private def _tailrec_compute_new_status (s : Status) : Status = - if ( (4 * s.q + s.r - s.t) < (s.n * s.t) - ) s - else - _tailrec_compute_new_status ( - Status_ ( - r = (2 * s.q + s.r) * s.l, - n = ( (s.q * (7 * s.k) + 2 + (s.r * s.l) ) / (s.t * s.l) ).toInt, - q = s.q * s.k, - t = s.t * s.l, - l = s.l + 2, - k = s.k + 1 - ) - ) - private def _compute_new_status (s : Status) : Status = - _tailrec_compute_new_status (s) +trait FactorialWithFold +{ - import scala.annotation.tailrec - @tailrec final - private def _tailrec_take (n : Int) (rev_seq : Seq [Int] ) (s : Status) (t : IntAndStatus) : Seq [Int] = - if ( n == 0 - ) rev_seq.reverse - else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) + private lazy val _fold = soda.lib.Fold_ () - private def _get_next (s : Status) : IntAndStatus = - _get_next_with_new_status (_compute_new_status (s) ) + private lazy val _range = soda.lib.Range_ () - private def _get_next_with_new_status (s : Status) : IntAndStatus = - IntAndStatus_ ( - s.n, - Status_ ( - r = 10 * (s.r - s.n * s.t), - n = ( ( (10 * (3 * s.q + s.r) ) / s.t) - (10 * s.n) ).toInt, - q = s.q * 10, - t = s.t, - l = s.l, - k = s.k - ) - ) + def apply (n : Int) : Int = + _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) } -case class PiIterator_ () extends PiIterator +case class FactorialWithFold_ () extends FactorialWithFold -trait IntAndStatus + +trait FiboExampleInSoda { - def digit : Int - def new_status : Status + def apply (n : Int) = + _rec (n) (0) (1) + + private def _rec (m : Int) (a : Int) (b : Int) : Int = + if ( m == 0 ) a + else if ( m == 1 ) b + else _rec (m - 1) (b) (a + b) } -case class IntAndStatus_ (digit : Int, new_status : Status) extends IntAndStatus +case class FiboExampleInSoda_ () extends FiboExampleInSoda trait InputPair [A, B] @@ -258,53 +225,86 @@ trait MemoizedFibonacci case class MemoizedFibonacci_ () extends MemoizedFibonacci -trait FactorialWithFold +trait Status { - private lazy val _fold = soda.lib.Fold_ () - - private lazy val _range = soda.lib.Range_ () + def r : BigInt + def n : Int + def q : BigInt + def t : BigInt + def l : Int + def k : Int - def apply (n : Int) : Int = - _fold.apply (_range.apply (n) ) (1) ( product => k => (product * (k + 1) ) ) + override + lazy val toString = " r=" + r + " n=" + n + " q=" + q + " t=" + t + " l=" + l + " k=" + k } -case class FactorialWithFold_ () extends FactorialWithFold - +case class Status_ (r : BigInt, n : Int, q : BigInt, t : BigInt, l : Int, k : Int) extends Status -trait FiboExampleInSoda +trait PiIterator { - def apply (n : Int) = - _rec (n) (0) (1) - - private def _rec (m : Int) (a : Int) (b : Int) : Int = - if ( m == 0 ) a - else if ( m == 1 ) b - else _rec (m - 1) (b) (a + b) - -} - -case class FiboExampleInSoda_ () extends FiboExampleInSoda + def apply (n : Int) : Seq [Int] = + _tailrec_take (n) (Seq () ) (_initial_status) (_get_next (_initial_status) ) + private lazy val _initial_status = + Status_ (r = 0, n = 3, q = 1, t = 1, l = 3, k = 1) -trait FactorialPatternMatching -{ + import scala.annotation.tailrec + @tailrec final + private def _tailrec_compute_new_status (s : Status) : Status = + if ( (4 * s.q + s.r - s.t) < (s.n * s.t) + ) s + else + _tailrec_compute_new_status ( + Status_ ( + r = (2 * s.q + s.r) * s.l, + n = ( (s.q * (7 * s.k) + 2 + (s.r * s.l) ) / (s.t * s.l) ).toInt, + q = s.q * s.k, + t = s.t * s.l, + l = s.l + 2, + k = s.k + 1 + ) + ) - def apply (n : Int) : Int = - _tailrec_get_factorial (n) (1) + private def _compute_new_status (s : Status) : Status = + _tailrec_compute_new_status (s) import scala.annotation.tailrec @tailrec final - private def _tailrec_get_factorial (n : Int) (product : Int) : Int = - n match { - case 0 => product - case x => _tailrec_get_factorial (x - 1) (x * product) - } + private def _tailrec_take (n : Int) (rev_seq : Seq [Int] ) (s : Status) (t : IntAndStatus) : Seq [Int] = + if ( n == 0 + ) rev_seq.reverse + else _tailrec_take (n - 1) (rev_seq.+: (t.digit) ) (t.new_status) (_get_next (t.new_status) ) + + private def _get_next (s : Status) : IntAndStatus = + _get_next_with_new_status (_compute_new_status (s) ) + + private def _get_next_with_new_status (s : Status) : IntAndStatus = + IntAndStatus_ ( + s.n, + Status_ ( + r = 10 * (s.r - s.n * s.t), + n = ( ( (10 * (3 * s.q + s.r) ) / s.t) - (10 * s.n) ).toInt, + q = s.q * 10, + t = s.t, + l = s.l, + k = s.k + ) + ) } -case class FactorialPatternMatching_ () extends FactorialPatternMatching +case class PiIterator_ () extends PiIterator + +trait IntAndStatus +{ + def digit : Int + def new_status : Status + +} + +case class IntAndStatus_ (digit : Int, new_status : Status) extends IntAndStatus diff --git a/examples/src/main/scala/soda/example/miniexample/Package.scala b/examples/src/main/scala/soda/example/miniexample/Package.scala index 2ad5d834..4b47fe6f 100644 --- a/examples/src/main/scala/soda/example/miniexample/Package.scala +++ b/examples/src/main/scala/soda/example/miniexample/Package.scala @@ -5,6 +5,7 @@ package soda.example.miniexample */ trait Package + trait MiniExample { @@ -35,4 +36,3 @@ object EntryPoint { case class Main_ () extends Main - diff --git a/examples/src/test/scala/soda/example/algorithms/Package.scala b/examples/src/test/scala/soda/example/algorithms/Package.scala index 1d6e83ed..8e9e558f 100644 --- a/examples/src/test/scala/soda/example/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/algorithms/Package.scala @@ -5,93 +5,45 @@ package soda.example.algorithms */ trait Package -case class SortExampleSpec () + +case class FizzBuzzSpec () extends org.scalatest.funsuite.AnyFunSuite { - import soda.lib.SomeSD_ - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val sorted_sequence = Seq (1, 3, 5, 5, 8, 9) - - lazy val unsorted_sequence = Seq (1, 3, 5, 4, 8, 9) - - test ("test sorted sequence with at") ( - check ( - obtained = SortExampleWithAt_ ().is_sorted (sorted_sequence) - ) ( - expected = true - ) - ) - - test ("test unsorted sequence with at") ( - check ( - obtained = SortExampleWithAt_ ().is_sorted (unsorted_sequence) - ) ( - expected = false - ) - ) - - test ("test sorted sequence with zip") ( - check ( - obtained = SortExampleWithZip_ ().is_sorted (sorted_sequence) - ) ( - expected = true - ) - ) - - test ("test unsorted sequence with zip") ( - check ( - obtained = SortExampleWithZip_ ().is_sorted (unsorted_sequence) - ) ( - expected = false - ) - ) - - test ("insert sorted simple") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 6, 8, 9) ) (5) - ) ( - expected = Seq (1, 2, 3, 5, 6, 8, 9) - ) + lazy val expected_result = Seq ( + "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", + "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", + "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", + "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", + "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", + "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", + "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", + "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", + "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", + "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" ) - test ("insert sorted with repetition") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 5, 6, 8, 9) ) (5) - ) ( - expected = Seq (1, 2, 3, 5, 5, 6, 8, 9) - ) - ) + private lazy val _fizz_buzz = FizzBuzz_ () - test ("sort unsorted sequence") ( - check ( - obtained = SortAlgorithmExampleWithFold_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) - ) ( - expected = Seq (1, 3, 4, 5, 8 ,9) - ) - ) + private lazy val _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () - test ("sort unsorted sequence applying constraints to verify correctness") ( + test ("first elements of FizzBuzz") ( check ( - obtained = ConstrainedSortAlgorithm_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) + obtained = _fizz_buzz.apply ) ( - expected = SomeSD_ (Seq (1, 3, 4, 5, 8 ,9) ) + expected = expected_result ) ) - test ("sort unsorted sequence with SortedSequenceBuilder") ( + test ("first elements of FizzBuzz with pattern matching") ( check ( - obtained = - SortedSequenceBuilder_ [Integer] () - .build ( Seq (3, 5, 1, 9, 8, 4).map ( x => Integer.valueOf (x) ) ) - .sequence - .map ( x => x.intValue) + obtained = _fizz_buzz_pattern_matching.apply ) ( - expected = Seq (1, 3, 4, 5, 8 ,9) + expected = expected_result ) ) @@ -221,47 +173,95 @@ case class SaladMakerSpec () } -case class FizzBuzzSpec () +case class SortExampleSpec () extends org.scalatest.funsuite.AnyFunSuite { + import soda.lib.SomeSD_ + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val expected_result = Seq ( - "1", "2", "Fizz", "4", "Buzz", "Fizz", "7", "8", "Fizz", "Buzz", - "11", "Fizz", "13", "14", "FizzBuzz", "16", "17", "Fizz", "19", "Buzz", - "Fizz", "22", "23", "Fizz", "Buzz", "26", "Fizz", "28", "29", "FizzBuzz", - "31", "32", "Fizz", "34", "Buzz", "Fizz", "37", "38", "Fizz", "Buzz", - "41", "Fizz", "43", "44", "FizzBuzz", "46", "47", "Fizz", "49", "Buzz", - "Fizz", "52", "53", "Fizz", "Buzz", "56", "Fizz", "58", "59", "FizzBuzz", - "61", "62", "Fizz", "64", "Buzz", "Fizz", "67", "68", "Fizz", "Buzz", - "71", "Fizz", "73", "74", "FizzBuzz", "76", "77", "Fizz", "79", "Buzz", - "Fizz", "82", "83", "Fizz", "Buzz", "86", "Fizz", "88", "89", "FizzBuzz", - "91", "92", "Fizz", "94", "Buzz", "Fizz", "97", "98", "Fizz", "Buzz" + lazy val sorted_sequence = Seq (1, 3, 5, 5, 8, 9) + + lazy val unsorted_sequence = Seq (1, 3, 5, 4, 8, 9) + + test ("test sorted sequence with at") ( + check ( + obtained = SortExampleWithAt_ ().is_sorted (sorted_sequence) + ) ( + expected = true + ) ) - private lazy val _fizz_buzz = FizzBuzz_ () + test ("test unsorted sequence with at") ( + check ( + obtained = SortExampleWithAt_ ().is_sorted (unsorted_sequence) + ) ( + expected = false + ) + ) - private lazy val _fizz_buzz_pattern_matching = FizzBuzzPatternMatching_ () + test ("test sorted sequence with zip") ( + check ( + obtained = SortExampleWithZip_ ().is_sorted (sorted_sequence) + ) ( + expected = true + ) + ) - test ("first elements of FizzBuzz") ( + test ("test unsorted sequence with zip") ( check ( - obtained = _fizz_buzz.apply + obtained = SortExampleWithZip_ ().is_sorted (unsorted_sequence) ) ( - expected = expected_result + expected = false ) ) - test ("first elements of FizzBuzz with pattern matching") ( + test ("insert sorted simple") ( check ( - obtained = _fizz_buzz_pattern_matching.apply + obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 6, 8, 9) ) (5) ) ( - expected = expected_result + expected = Seq (1, 2, 3, 5, 6, 8, 9) ) ) -} + test ("insert sorted with repetition") ( + check ( + obtained = SortAlgorithmExampleWithFold_ ().insert_sorted (Seq (1, 2, 3, 5, 6, 8, 9) ) (5) + ) ( + expected = Seq (1, 2, 3, 5, 5, 6, 8, 9) + ) + ) + test ("sort unsorted sequence") ( + check ( + obtained = SortAlgorithmExampleWithFold_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) + ) ( + expected = Seq (1, 3, 4, 5, 8 ,9) + ) + ) + + test ("sort unsorted sequence applying constraints to verify correctness") ( + check ( + obtained = ConstrainedSortAlgorithm_ ().sort (Seq (3, 5, 1, 9, 8, 4) ) + ) ( + expected = SomeSD_ (Seq (1, 3, 4, 5, 8 ,9) ) + ) + ) + + test ("sort unsorted sequence with SortedSequenceBuilder") ( + check ( + obtained = + SortedSequenceBuilder_ [Integer] () + .build ( Seq (3, 5, 1, 9, 8, 4).map ( x => Integer.valueOf (x) ) ) + .sequence + .map ( x => x.intValue) + ) ( + expected = Seq (1, 3, 4, 5, 8 ,9) + ) + ) + +} diff --git a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala index 614ded16..26327453 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/fairness/Package.scala @@ -5,6 +5,7 @@ package soda.example.ethicalissues.fairness */ trait Package + case class FairnessSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -41,4 +42,3 @@ case class FairnessSpec () } - diff --git a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala index 9ed46edb..4a24bcad 100644 --- a/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala +++ b/examples/src/test/scala/soda/example/ethicalissues/pricemonitor/Package.scala @@ -5,6 +5,7 @@ package soda.example.ethicalissues.pricemonitor */ trait Package + trait UnfairPricingAgent extends PricingAgent @@ -140,4 +141,3 @@ case class PriceMonitorSpec () } - diff --git a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala index a7765038..63d9f519 100644 --- a/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/algorithms/Package.scala @@ -5,6 +5,7 @@ package soda.example.forcoq.algorithms */ trait Package + case class RecursionForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -70,4 +71,3 @@ case class RecursionForCoqSpec () } - diff --git a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala index 9f861710..bd0dc4c9 100644 --- a/examples/src/test/scala/soda/example/forcoq/lib/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/lib/Package.scala @@ -5,6 +5,7 @@ package soda.example.forcoq.lib */ trait Package + case class ListSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -74,4 +75,3 @@ case class NatSpec () } - diff --git a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala index 07a1816c..b303d89d 100644 --- a/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/forcoq/mathematics/Package.scala @@ -5,6 +5,7 @@ package soda.example.forcoq.mathematics */ trait Package + case class FactorialForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -39,7 +40,7 @@ case class FactorialForCoqSpec () } -case class TriangularNumberForCoqSpec () +case class FiboExampleInSodaForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite { @@ -50,30 +51,30 @@ case class TriangularNumberForCoqSpec () def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val triangular_number_values : Seq [ Tuple2 [Int, Int] ] = Seq ( - (0, 0), (1, 1), (2, 3), (3, 6), (4, 10), (5, 15), (6, 21) + lazy val fibonacci_values : Seq [ Tuple2 [Int, Int] ] = Seq ( + (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) ) - lazy val triangular_number_with_nat : Seq [ Tuple2 [nat, nat] ] = - triangular_number_values + lazy val fibonacci_values_with_nat : Seq [ Tuple2 [nat, nat] ] = + fibonacci_values .map ( pair => - Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) + Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) ) - test ("should test the triangular for Coq") ( + test ("should test the fibonacci function for Coq") ( check ( - obtained = triangular_number_with_nat + obtained = fibonacci_values_with_nat .map ( pair => pair._1) - .map ( n => Tuple2 (n, TriangularNumberForCoq_ ().get_number (n) ) ) + .map ( n => Tuple2 (n, FiboExampleInSodaForCoq_ ().fib (n) ) ) ) ( - expected = triangular_number_with_nat + expected = fibonacci_values_with_nat ) ) } -case class FiboExampleInSodaForCoqSpec () +case class TriangularNumberForCoqSpec () extends org.scalatest.funsuite.AnyFunSuite { @@ -84,26 +85,25 @@ case class FiboExampleInSodaForCoqSpec () def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val fibonacci_values : Seq [ Tuple2 [Int, Int] ] = Seq ( - (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) + lazy val triangular_number_values : Seq [ Tuple2 [Int, Int] ] = Seq ( + (0, 0), (1, 1), (2, 3), (3, 6), (4, 10), (5, 15), (6, 21) ) - lazy val fibonacci_values_with_nat : Seq [ Tuple2 [nat, nat] ] = - fibonacci_values + lazy val triangular_number_with_nat : Seq [ Tuple2 [nat, nat] ] = + triangular_number_values .map ( pair => - Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) + Tuple2 ( IntNat_ ().from_non_negative (pair._1), IntNat_ ().from_non_negative (pair._2) ) ) - test ("should test the fibonacci function for Coq") ( + test ("should test the triangular for Coq") ( check ( - obtained = fibonacci_values_with_nat + obtained = triangular_number_with_nat .map ( pair => pair._1) - .map ( n => Tuple2 (n, FiboExampleInSodaForCoq_ ().fib (n) ) ) + .map ( n => Tuple2 (n, TriangularNumberForCoq_ ().get_number (n) ) ) ) ( - expected = fibonacci_values_with_nat + expected = triangular_number_with_nat ) ) } - diff --git a/examples/src/test/scala/soda/example/mathematics/Package.scala b/examples/src/test/scala/soda/example/mathematics/Package.scala index 8316f64e..8e3eb827 100644 --- a/examples/src/test/scala/soda/example/mathematics/Package.scala +++ b/examples/src/test/scala/soda/example/mathematics/Package.scala @@ -5,57 +5,6 @@ package soda.example.mathematics */ trait Package -case class PiIteratorSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" - - private lazy val _pi_iterator = PiIterator_ () - - lazy val pi_sequence = _pi_iterator.apply (128) - - test ("first digits of Pi") ( - check ( - obtained = "" + pi_sequence.head + "." + pi_sequence.tail.mkString ("") - ) ( - expected = pi_start - ) - ) - -} - - -case class FiboExampleSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val fibonacci_values = Seq ( - (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) - ) - - private lazy val _fibo_example_in_soda = FiboExampleInSoda_ () - - test ("should test the fibonacci function") ( - check ( - obtained = fibonacci_values - .map ( pair => pair._1) - .map ( n => Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) - ) ( - expected = fibonacci_values - ) - ) - -} - case class FactorialSpec () extends @@ -108,6 +57,33 @@ case class FactorialSpec () } +case class FiboExampleSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val fibonacci_values = Seq ( + (0, 0), (1, 1), (2, 1), (3, 2), (4, 3), (5, 5), (6, 8), (7, 13), (8, 21), (9, 34), (10, 55) + ) + + private lazy val _fibo_example_in_soda = FiboExampleInSoda_ () + + test ("should test the fibonacci function") ( + check ( + obtained = fibonacci_values + .map ( pair => pair._1) + .map ( n => Tuple2 (n, _fibo_example_in_soda.apply (n) ) ) + ) ( + expected = fibonacci_values + ) + ) + +} + + case class HardProblemSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -186,3 +162,27 @@ case class HardProblemSpec () } +case class PiIteratorSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val pi_start = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446" + + private lazy val _pi_iterator = PiIterator_ () + + lazy val pi_sequence = _pi_iterator.apply (128) + + test ("first digits of Pi") ( + check ( + obtained = "" + pi_sequence.head + "." + pi_sequence.tail.mkString ("") + ) ( + expected = pi_start + ) + ) + +} + diff --git a/library/src/main/scala/soda/collection/Package.scala b/library/src/main/scala/soda/collection/Package.scala index fe507499..3554295e 100644 --- a/library/src/main/scala/soda/collection/Package.scala +++ b/library/src/main/scala/soda/collection/Package.scala @@ -7,6 +7,85 @@ package soda.collection */ trait Package + +trait MSeq [A] +{ + + def isEmpty : Boolean + + def opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] => B) : B = + this match { + case NESeq_ (head, tail) => ifNonEmpty (NESeq_ (head, tail) ) + case x => ifEmpty + } + +} + +case class MSeq_ [A] (isEmpty : Boolean) extends MSeq [A] + +trait MSeqRec [A] +{ + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + sequence match { + case NESeq_ (head, tail) => + if ( ! condition (current_value) (head) + ) current_value + else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) + case x => current_value + } + + def fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = + _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) + +} + +case class MSeqRec_ [A] () extends MSeqRec [A] + +trait ESeq [A] + extends + MSeq [A] +{ + + lazy val isEmpty = true + +} + +case class ESeq_ [A] () extends ESeq [A] + +trait NEMSeq [A] + extends + MSeq [A] +{ + + def head0 : A + def tail0 : MSeq [A] + + lazy val isEmpty = false + +} + +case class NEMSeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NEMSeq [A] + +trait NESeq [A] + extends + NEMSeq [A] +{ + + def head0 : A + def tail0 : MSeq [A] + + lazy val head : A = head0 + + lazy val tail : MSeq [A] = tail0 + +} + +case class NESeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NESeq [A] + + trait MSeqTranslator [A] { @@ -424,82 +503,3 @@ trait SpanRevFoldTuple [A] case class SpanRevFoldTuple_ [A] (left : MSeq [A], right : MSeq [A], taking : Boolean, condition : A => Boolean) extends SpanRevFoldTuple [A] - -trait MSeq [A] -{ - - def isEmpty : Boolean - - def opt [B] (ifEmpty : B) (ifNonEmpty : NESeq [A] => B) : B = - this match { - case NESeq_ (head, tail) => ifNonEmpty (NESeq_ (head, tail) ) - case x => ifEmpty - } - -} - -case class MSeq_ [A] (isEmpty : Boolean) extends MSeq [A] - -trait MSeqRec [A] -{ - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [B] (sequence : MSeq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - sequence match { - case NESeq_ (head, tail) => - if ( ! condition (current_value) (head) - ) current_value - else _tailrec_fold_while (tail) (next_value_function (current_value) (head) ) (next_value_function) (condition) - case x => current_value - } - - def fold_while [B] (sequence : MSeq [A] ) (initial_value : B) (next_value : B => A => B) (condition : B => A => Boolean) : B = - _tailrec_fold_while (sequence) (initial_value) (next_value) (condition) - -} - -case class MSeqRec_ [A] () extends MSeqRec [A] - -trait ESeq [A] - extends - MSeq [A] -{ - - lazy val isEmpty = true - -} - -case class ESeq_ [A] () extends ESeq [A] - -trait NEMSeq [A] - extends - MSeq [A] -{ - - def head0 : A - def tail0 : MSeq [A] - - lazy val isEmpty = false - -} - -case class NEMSeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NEMSeq [A] - -trait NESeq [A] - extends - NEMSeq [A] -{ - - def head0 : A - def tail0 : MSeq [A] - - lazy val head : A = head0 - - lazy val tail : MSeq [A] = tail0 - -} - -case class NESeq_ [A] (head0 : A, tail0 : MSeq [A]) extends NESeq [A] - - diff --git a/library/src/main/scala/soda/collection/example/Package.scala b/library/src/main/scala/soda/collection/example/Package.scala index 9678e057..e30ccee4 100644 --- a/library/src/main/scala/soda/collection/example/Package.scala +++ b/library/src/main/scala/soda/collection/example/Package.scala @@ -5,51 +5,6 @@ package soda.collection.example */ trait Package -trait Main -{ - - lazy val e = ListExample_ () - - lazy val all_examples = - Seq ( - e.a_example, - e.b_example, - e.take_example, - e.takeRight_example, - e.takeWhile_example, - e.drop_example, - e.dropRight_example, - e.dropWhile_example, - e.splitAt_example, - e.indices_example, - e.zipWithIndex_example, - e.zip_example, - e.reverse_example, - e.prepended_example, - e.appended_example, - e.concat_example, - e.span_example, - e.map_example, - e.filter_example, - e.fold_example, - e.foldLeft_example, - e.foldRight_example - ) - .map ( pair => pair.name + " = " + pair.result.toString) - .mkString ("\n") - - def main (arguments : Array [String] ) : Unit = - println (all_examples) - -} - -object EntryPoint { - def main (args: Array [String]): Unit = Main_ ().main (args) -} - - -case class Main_ () extends Main - trait Pair [A] { @@ -145,3 +100,48 @@ trait ListExample case class ListExample_ () extends ListExample +trait Main +{ + + lazy val e = ListExample_ () + + lazy val all_examples = + Seq ( + e.a_example, + e.b_example, + e.take_example, + e.takeRight_example, + e.takeWhile_example, + e.drop_example, + e.dropRight_example, + e.dropWhile_example, + e.splitAt_example, + e.indices_example, + e.zipWithIndex_example, + e.zip_example, + e.reverse_example, + e.prepended_example, + e.appended_example, + e.concat_example, + e.span_example, + e.map_example, + e.filter_example, + e.fold_example, + e.foldLeft_example, + e.foldRight_example + ) + .map ( pair => pair.name + " = " + pair.result.toString) + .mkString ("\n") + + def main (arguments : Array [String] ) : Unit = + println (all_examples) + +} + +object EntryPoint { + def main (args: Array [String]): Unit = Main_ ().main (args) +} + + +case class Main_ () extends Main + diff --git a/library/src/test/scala/soda/collection/Package.scala b/library/src/test/scala/soda/collection/Package.scala index 4d3e8808..4f1e56ac 100644 --- a/library/src/test/scala/soda/collection/Package.scala +++ b/library/src/test/scala/soda/collection/Package.scala @@ -5,6 +5,7 @@ package soda.collection */ trait Package + case class MinSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -590,4 +591,3 @@ case class MinSpec () } - diff --git a/library/src/test/scala/soda/collection/example/Package.scala b/library/src/test/scala/soda/collection/example/Package.scala index d963bc7e..e0dc44e5 100644 --- a/library/src/test/scala/soda/collection/example/Package.scala +++ b/library/src/test/scala/soda/collection/example/Package.scala @@ -5,6 +5,7 @@ package soda.collection.example */ trait Package + case class ListExampleSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -191,4 +192,3 @@ case class ListExampleSpec () } - diff --git a/translator/src/main/resources/lib/soda/lib/Package.scala b/translator/src/main/resources/lib/soda/lib/Package.scala index a7279693..f4c7893e 100644 --- a/translator/src/main/resources/lib/soda/lib/Package.scala +++ b/translator/src/main/resources/lib/soda/lib/Package.scala @@ -13,71 +13,38 @@ package soda.lib trait Package + /* * This file is automatically generated. Do not edit. */ /** - * This is a Seq implemented without exceptions. + * This class contains auxiliary functions for combinations. */ -trait SeqSD [A] -{ - - def toSeq : Seq [A] - def reverse : SeqSD [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = - this match { - case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) - case x => ifEmpty - } - -} - -case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] - -trait EmptySeqSD [A] - extends - SeqSD [A] -{ - - lazy val toSeq : Seq [A] = Seq [A] () - - lazy val reverse : EmptySeqSD [A] = this - -} - -case class EmptySeqSD_ [A] () extends EmptySeqSD [A] - -trait NonEmptySeqSD [A] - extends - SeqSD [A] +trait CartesianProduct { - def toSeq : Seq [A] - - lazy val head : A = toSeq.head - - lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) - - lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) -} + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) -case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + private lazy val _fold = Fold_ () -trait SeqSDBuilder [A] -{ + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = + seq.map ( elem => Seq [A] (elem) ) - def build (seq : Seq [A] ) : SeqSD [A] = - if ( seq.isEmpty - ) EmptySeqSD_ [A] () - else NonEmptySeqSD_ [A] (seq) + private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = + seq_a.flatMap ( elem_a => + accum.map ( seq_b => seq_b.+: (elem_a) ) ) } -case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] +case class CartesianProduct_ () extends CartesianProduct /* @@ -85,90 +52,17 @@ case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] */ /** - * This class contains tail recursive auxiliary functions. + * All concrete classes extending this class need to have a 'doc' attribute. */ -trait FoldWhile -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - (condition : B => A => Boolean) - : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - -} - -case class FoldWhile_ () extends FoldWhile - -trait Fold -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = - if ( sequence.isEmpty - ) current_value - else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - -} - -case class Fold_ () extends Fold - -trait Range -{ - - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - -} - -case class Range_ () extends Range - -trait Recursion +trait Doc { - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) - - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _fold.apply (sequence) (initial_value) (next_value_function) - - def range (length : Int) : Seq [Int] = - _range.apply (length) + def doc : String } -case class Recursion_ () extends Recursion +case class Doc_ (doc : String) extends Doc /* @@ -199,39 +93,6 @@ trait Enum [A <: EnumConstant] case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains auxiliary functions for combinations. - */ - -trait CartesianProduct -{ - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - private lazy val _fold = Fold_ () - - private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = - seq.map ( elem => Seq [A] (elem) ) - - private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = - seq_a.flatMap ( elem_a => - accum.map ( seq_b => seq_b.+: (elem_a) ) ) - -} - -case class CartesianProduct_ () extends CartesianProduct - - /* * This file is automatically generated. Do not edit. */ @@ -371,16 +232,155 @@ case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] */ /** - * All concrete classes extending this class need to have a 'doc' attribute. + * This class contains tail recursive auxiliary functions. */ -trait Doc +trait FoldWhile { - def doc : String + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) + ) current_value + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) } -case class Doc_ (doc : String) extends Doc +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = + if ( sequence.isEmpty + ) current_value + else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) + +} + +case class Fold_ () extends Fold + +trait Range +{ + + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = + if ( n <= 0 + ) sequence + else _tailrec_range (n - 1) (sequence.+: (n - 1) ) + +} + +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + private lazy val _range = Range_ () + + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + +case class Recursion_ () extends Recursion + + +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a Seq implemented without exceptions. + */ + +trait SeqSD [A] +{ + + def toSeq : Seq [A] + def reverse : SeqSD [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = + this match { + case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty + } + +} + +case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] + +trait EmptySeqSD [A] + extends + SeqSD [A] +{ + + lazy val toSeq : Seq [A] = Seq [A] () + + lazy val reverse : EmptySeqSD [A] = this + +} + +case class EmptySeqSD_ [A] () extends EmptySeqSD [A] + +trait NonEmptySeqSD [A] + extends + SeqSD [A] +{ + + def toSeq : Seq [A] + + lazy val head : A = toSeq.head + + lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) + + lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + +} + +case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + +trait SeqSDBuilder [A] +{ + + def build (seq : Seq [A] ) : SeqSD [A] = + if ( seq.isEmpty + ) EmptySeqSD_ [A] () + else NonEmptySeqSD_ [A] (seq) + +} + +case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] diff --git a/translator/src/main/scala/soda/lib/Package.scala b/translator/src/main/scala/soda/lib/Package.scala index 2c4634f0..41ef2996 100644 --- a/translator/src/main/scala/soda/lib/Package.scala +++ b/translator/src/main/scala/soda/lib/Package.scala @@ -11,74 +11,38 @@ package soda.lib */ trait Package -/* Soda library */ - /* * This file is automatically generated. Do not edit. */ /** - * This is a Seq implemented without exceptions. + * This class contains auxiliary functions for combinations. */ -trait SeqSD [A] -{ - - def toSeq : Seq [A] - def reverse : SeqSD [A] - - def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = - this match { - case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) - case x => ifEmpty - } - -} - -case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] - -trait EmptySeqSD [A] - extends - SeqSD [A] -{ - - lazy val toSeq : Seq [A] = Seq [A] () - - lazy val reverse : EmptySeqSD [A] = this - -} - -case class EmptySeqSD_ [A] () extends EmptySeqSD [A] - -trait NonEmptySeqSD [A] - extends - SeqSD [A] +trait CartesianProduct { - def toSeq : Seq [A] - - lazy val head : A = toSeq.head - - lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) - - lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + if ( sequences.isEmpty + ) sequences + else _apply_recursion (sequences.reverse) -} + private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = + _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) -case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + private lazy val _fold = Fold_ () -trait SeqSDBuilder [A] -{ + private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = + seq.map ( elem => Seq [A] (elem) ) - def build (seq : Seq [A] ) : SeqSD [A] = - if ( seq.isEmpty - ) EmptySeqSD_ [A] () - else NonEmptySeqSD_ [A] (seq) + private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = + seq_a.flatMap ( elem_a => + accum.map ( seq_b => seq_b.+: (elem_a) ) ) } -case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] +case class CartesianProduct_ () extends CartesianProduct /* @@ -86,90 +50,17 @@ case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] */ /** - * This class contains tail recursive auxiliary functions. + * All concrete classes extending this class need to have a 'doc' attribute. */ -trait FoldWhile -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - (condition : B => A => Boolean) - : B = - _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) - ) current_value - else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) - -} - -case class FoldWhile_ () extends FoldWhile - -trait Fold -{ - - def apply [A, B] - (sequence : Seq [A] ) - (initial_value : B) - (next_value_function : B => A => B) - : B = - _tailrec_fold (sequence) (initial_value) (next_value_function) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = - if ( sequence.isEmpty - ) current_value - else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) - -} - -case class Fold_ () extends Fold - -trait Range -{ - - def apply (length : Int) : Seq [Int] = - _tailrec_range (length) (Seq [Int] () ) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = - if ( n <= 0 - ) sequence - else _tailrec_range (n - 1) (sequence.+: (n - 1) ) - -} - -case class Range_ () extends Range - -trait Recursion +trait Doc { - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = - _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) - - def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = - _fold.apply (sequence) (initial_value) (next_value_function) - - def range (length : Int) : Seq [Int] = - _range.apply (length) + def doc : String } -case class Recursion_ () extends Recursion +case class Doc_ (doc : String) extends Doc /* @@ -200,39 +91,6 @@ trait Enum [A <: EnumConstant] case class Enum_ [A <: EnumConstant] (values : Seq [A]) extends Enum [A] -/* - * This file is automatically generated. Do not edit. - */ - -/** - * This class contains auxiliary functions for combinations. - */ - -trait CartesianProduct -{ - - def apply [A] (sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - if ( sequences.isEmpty - ) sequences - else _apply_recursion (sequences.reverse) - - private def _apply_recursion [A] (rev_sequences : Seq [Seq [A] ] ) : Seq [Seq [A] ] = - _fold.apply (rev_sequences.tail) (_initial_value (rev_sequences.head) ) (_next_value [A] ) - - private lazy val _fold = Fold_ () - - private def _initial_value [A] (seq : Seq [A] ) : Seq [Seq [A] ] = - seq.map ( elem => Seq [A] (elem) ) - - private def _next_value [A] (accum : Seq [Seq [A] ] ) (seq_a : Seq [A] ) : Seq [Seq [A] ] = - seq_a.flatMap ( elem_a => - accum.map ( seq_b => seq_b.+: (elem_a) ) ) - -} - -case class CartesianProduct_ () extends CartesianProduct - - /* * This file is automatically generated. Do not edit. */ @@ -372,16 +230,158 @@ case class OptionSDBuilder_ [A] () extends OptionSDBuilder [A] */ /** - * All concrete classes extending this class need to have a 'doc' attribute. + * This class contains tail recursive auxiliary functions. */ -trait Doc +trait FoldWhile { - def doc : String + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + (condition : B => A => Boolean) + : B = + _tailrec_fold_while (sequence) (initial_value) (next_value_function) (condition) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold_while [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + if ( sequence.isEmpty || ( ! condition (current_value) (sequence.head) ) + ) current_value + else _tailrec_fold_while (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) (condition) } -case class Doc_ (doc : String) extends Doc +case class FoldWhile_ () extends FoldWhile + +trait Fold +{ + + def apply [A, B] + (sequence : Seq [A] ) + (initial_value : B) + (next_value_function : B => A => B) + : B = + _tailrec_fold (sequence) (initial_value) (next_value_function) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_fold [A, B] (sequence : Seq [A] ) (current_value : B) (next_value_function : B => A => B) : B = + if ( sequence.isEmpty + ) current_value + else _tailrec_fold (sequence.tail) (next_value_function (current_value) (sequence.head) ) (next_value_function) + +} + +case class Fold_ () extends Fold + +trait Range +{ + + def apply (length : Int) : Seq [Int] = + _tailrec_range (length) (Seq [Int] () ) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_range (n : Int) (sequence : Seq [Int] ) : Seq [Int] = + if ( n <= 0 + ) sequence + else _tailrec_range (n - 1) (sequence.+: (n - 1) ) + +} + +case class Range_ () extends Range + +trait Recursion +{ + + private lazy val _fold_while = FoldWhile_ () + + private lazy val _fold = Fold_ () + + private lazy val _range = Range_ () + def fold_while [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) (condition : B => A => Boolean) : B = + _fold_while.apply (sequence) (initial_value) (next_value_function) (condition) + + def fold [A, B] (sequence : Seq [A] ) (initial_value : B) (next_value_function : B => A => B) : B = + _fold.apply (sequence) (initial_value) (next_value_function) + + def range (length : Int) : Seq [Int] = + _range.apply (length) + +} + +case class Recursion_ () extends Recursion + + +/* + * This file is automatically generated. Do not edit. + */ + +/** + * This is a Seq implemented without exceptions. + */ + +trait SeqSD [A] +{ + + def toSeq : Seq [A] + def reverse : SeqSD [A] + + def opt [B] (ifEmpty : B) (ifNonEmpty : NonEmptySeqSD [A] => B) : B = + this match { + case NonEmptySeqSD_ (toSeq) => ifNonEmpty (NonEmptySeqSD_ (toSeq) ) + case x => ifEmpty + } + +} + +case class SeqSD_ [A] (toSeq : Seq [A], reverse : SeqSD [A]) extends SeqSD [A] + +trait EmptySeqSD [A] + extends + SeqSD [A] +{ + + lazy val toSeq : Seq [A] = Seq [A] () + + lazy val reverse : EmptySeqSD [A] = this + +} + +case class EmptySeqSD_ [A] () extends EmptySeqSD [A] + +trait NonEmptySeqSD [A] + extends + SeqSD [A] +{ + + def toSeq : Seq [A] + + lazy val head : A = toSeq.head + + lazy val tail : SeqSD [A] = SeqSDBuilder_ [A] ().build (toSeq.tail) + + lazy val reverse : NonEmptySeqSD [A] = NonEmptySeqSD_ (toSeq.reverse) + +} + +case class NonEmptySeqSD_ [A] (toSeq : Seq [A]) extends NonEmptySeqSD [A] + +trait SeqSDBuilder [A] +{ + + def build (seq : Seq [A] ) : SeqSD [A] = + if ( seq.isEmpty + ) EmptySeqSD_ [A] () + else NonEmptySeqSD_ [A] (seq) + +} + +case class SeqSDBuilder_ [A] () extends SeqSDBuilder [A] + + +/* Soda library */ diff --git a/translator/src/main/scala/soda/translator/block/Package.scala b/translator/src/main/scala/soda/translator/block/Package.scala index c1be2dd3..43290e14 100644 --- a/translator/src/main/scala/soda/translator/block/Package.scala +++ b/translator/src/main/scala/soda/translator/block/Package.scala @@ -7,115 +7,48 @@ package soda.translator.block trait Package -trait LineTranslator -{ - - def line : String - -} - -case class LineTranslator_ (line : String) extends LineTranslator - - -trait BlockSequenceTranslator -{ - - def translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] -} - -case class BlockSequenceTranslator_ (translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock]) extends BlockSequenceTranslator - -trait DefaultBlockSequenceTranslator +trait AnnotatedBlock extends - BlockSequenceTranslator -{ - - def translator : BlockTranslator - - lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = - block_sequence => - block_sequence.map ( block => translator.translate (block) ) - -} - -case class DefaultBlockSequenceTranslator_ (translator : BlockTranslator) extends DefaultBlockSequenceTranslator - - -trait PlainBlock + Block { - def lines : Seq [String] - - lazy val new_line = "\n" - - lazy val contents : String = - lines.mkString (new_line) + def annotated_lines : Seq [AnnotatedLine] + def block_annotation : BlockAnnotationId } -case class PlainBlock_ (lines : Seq [String]) extends PlainBlock +case class AnnotatedBlock_ (annotated_lines : Seq [AnnotatedLine], block_annotation : BlockAnnotationId) extends AnnotatedBlock -/** - * This models an abstract translator. - */ - -trait Translator +trait AnnotatedLine { - def translate : String => String - def keys : Seq [String] + def line : String + def is_comment : Boolean } -case class Translator_ (translate : String => String, keys : Seq [String]) extends Translator - +case class AnnotatedLine_ (line : String, is_comment : Boolean) extends AnnotatedLine -trait BlockTranslatorPipeline +trait Block extends - BlockTranslator -{ - - import soda.lib.Fold_ - - def pipeline : Seq [BlockTranslator] - - private lazy val _fold = Fold_ () - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _fold.apply (pipeline) (block) (_next_value_function) - - private def _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = - translator.translate (block) - -} - -case class BlockTranslatorPipeline_ (pipeline : Seq [BlockTranslator]) extends BlockTranslatorPipeline - - -trait BlockTranslator + PlainBlock { - def translate : AnnotatedBlock => AnnotatedBlock - -} - -case class BlockTranslator_ (translate : AnnotatedBlock => AnnotatedBlock) extends BlockTranslator + def annotated_lines : Seq [AnnotatedLine] -trait DefaultBlockTranslator - extends - BlockTranslator -{ + lazy val lines : Seq [String] = + annotated_lines + .map ( x => x.line) - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - block + lazy val readable_lines : Seq [AnnotatedLine] = + annotated_lines + .filter ( line => ! line.is_comment) } -case class DefaultBlockTranslator_ () extends DefaultBlockTranslator +case class Block_ (annotated_lines : Seq [AnnotatedLine]) extends Block trait BlockAnnotationId @@ -180,17 +113,75 @@ trait BlockAnnotationEnum case class BlockAnnotationEnum_ () extends BlockAnnotationEnum -trait AnnotatedBlock +trait BlockSequenceTranslator +{ + + def translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] + +} + +case class BlockSequenceTranslator_ (translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock]) extends BlockSequenceTranslator + +trait DefaultBlockSequenceTranslator extends - Block + BlockSequenceTranslator { - def annotated_lines : Seq [AnnotatedLine] - def block_annotation : BlockAnnotationId + def translator : BlockTranslator + + lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = + block_sequence => + block_sequence.map ( block => translator.translate (block) ) } -case class AnnotatedBlock_ (annotated_lines : Seq [AnnotatedLine], block_annotation : BlockAnnotationId) extends AnnotatedBlock +case class DefaultBlockSequenceTranslator_ (translator : BlockTranslator) extends DefaultBlockSequenceTranslator + + +trait BlockTranslator +{ + + def translate : AnnotatedBlock => AnnotatedBlock + +} + +case class BlockTranslator_ (translate : AnnotatedBlock => AnnotatedBlock) extends BlockTranslator + +trait DefaultBlockTranslator + extends + BlockTranslator +{ + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + block + +} + +case class DefaultBlockTranslator_ () extends DefaultBlockTranslator + + +trait BlockTranslatorPipeline + extends + BlockTranslator +{ + + import soda.lib.Fold_ + + def pipeline : Seq [BlockTranslator] + + private lazy val _fold = Fold_ () + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _fold.apply (pipeline) (block) (_next_value_function) + + private def _next_value_function (block : AnnotatedBlock) (translator : BlockTranslator) : AnnotatedBlock = + translator.translate (block) + +} + +case class BlockTranslatorPipeline_ (pipeline : Seq [BlockTranslator]) extends BlockTranslatorPipeline trait ConditionalBlockTranslator @@ -215,43 +206,52 @@ trait ConditionalBlockTranslator case class ConditionalBlockTranslator_ (accepted_annotations : Seq [BlockAnnotationId], translator : BlockTranslator) extends ConditionalBlockTranslator -trait AnnotatedLine +trait SingleLineProcessor { def line : String - def is_comment : Boolean } -case class AnnotatedLine_ (line : String, is_comment : Boolean) extends AnnotatedLine +case class SingleLineProcessor_ (line : String) extends SingleLineProcessor -trait Block - extends - PlainBlock + +trait LineTranslator { - def annotated_lines : Seq [AnnotatedLine] + def line : String - lazy val lines : Seq [String] = - annotated_lines - .map ( x => x.line) +} - lazy val readable_lines : Seq [AnnotatedLine] = - annotated_lines - .filter ( line => ! line.is_comment) +case class LineTranslator_ (line : String) extends LineTranslator + + +trait PlainBlock +{ + + def lines : Seq [String] + + lazy val new_line = "\n" + + lazy val contents : String = + lines.mkString (new_line) } -case class Block_ (annotated_lines : Seq [AnnotatedLine]) extends Block +case class PlainBlock_ (lines : Seq [String]) extends PlainBlock -trait SingleLineProcessor +/** + * This models an abstract translator. + */ + +trait Translator { - def line : String + def translate : String => String + def keys : Seq [String] } -case class SingleLineProcessor_ (line : String) extends SingleLineProcessor - +case class Translator_ (translate : String => String, keys : Seq [String]) extends Translator diff --git a/translator/src/main/scala/soda/translator/blocktr/Package.scala b/translator/src/main/scala/soda/translator/blocktr/Package.scala index 2df50c5a..ab682842 100644 --- a/translator/src/main/scala/soda/translator/blocktr/Package.scala +++ b/translator/src/main/scala/soda/translator/blocktr/Package.scala @@ -9,6 +9,7 @@ package soda.translator.blocktr trait Package + trait Table { @@ -37,6 +38,22 @@ trait TableTranslator case class TableTranslator_ (table : Seq [Tuple2 [String, String] ]) extends TableTranslator +trait TokenReplacement +{ + + import soda.translator.replacement.ReplacementWithTranslator_ + + def replace (table : Seq [ Tuple2 [String, String] ] ) : TokenizedBlockTranslator = + TokenizedBlockTranslator_ ( + token => + ReplacementWithTranslator_ (TableTranslator_ (table) ).replace (token.text) + ) + +} + +case class TokenReplacement_ () extends TokenReplacement + + trait TokenizedBlockTranslator extends soda.translator.block.BlockTranslator @@ -101,20 +118,3 @@ trait TokenizedBlockTranslator case class TokenizedBlockTranslator_ (replace_token : soda.translator.replacement.Token => String) extends TokenizedBlockTranslator - -trait TokenReplacement -{ - - import soda.translator.replacement.ReplacementWithTranslator_ - - def replace (table : Seq [ Tuple2 [String, String] ] ) : TokenizedBlockTranslator = - TokenizedBlockTranslator_ ( - token => - ReplacementWithTranslator_ (TableTranslator_ (table) ).replace (token.text) - ) - -} - -case class TokenReplacement_ () extends TokenReplacement - - diff --git a/translator/src/main/scala/soda/translator/extension/common/Package.scala b/translator/src/main/scala/soda/translator/extension/common/Package.scala index f353ae9d..6aa4af14 100644 --- a/translator/src/main/scala/soda/translator/extension/common/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/common/Package.scala @@ -7,6 +7,7 @@ package soda.translator.extension.common trait Package + trait Extension { @@ -16,4 +17,3 @@ trait Extension case class Extension_ (execute : Seq [String] => Boolean) extends Extension - diff --git a/translator/src/main/scala/soda/translator/extension/help/Package.scala b/translator/src/main/scala/soda/translator/extension/help/Package.scala index 7a3653d6..f11675e9 100644 --- a/translator/src/main/scala/soda/translator/extension/help/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/help/Package.scala @@ -7,6 +7,7 @@ package soda.translator.extension.help trait Package + trait AbstractHelp extends soda.translator.extension.common.Extension @@ -85,4 +86,3 @@ trait License case class License_ () extends License - diff --git a/translator/src/main/scala/soda/translator/extension/main/Package.scala b/translator/src/main/scala/soda/translator/extension/main/Package.scala index 3b3d76bc..8168e075 100644 --- a/translator/src/main/scala/soda/translator/extension/main/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/main/Package.scala @@ -8,6 +8,7 @@ package soda.translator.extension.main trait Package + /** * This is the main entry point. */ @@ -59,4 +60,3 @@ object EntryPoint { case class Main_ () extends Main - diff --git a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala index 31f49b59..b37658d4 100644 --- a/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/tocoq/Package.scala @@ -7,133 +7,136 @@ package soda.translator.extension.tocoq trait Package -/** - * A line containing the definition sign will be classified as a definition. - * The definitions need to be identified as 'val', 'def', or 'class'. - * - * 'class' is for class definition. - * It is detected if the 'class' reserved word is also in the same line. - * - * 'val' is for value definition. - * It is detected in three cases. - * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` - * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` - * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` - * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` - * - * 'def' is for function definition. - * If it does not fit in any of the 'val' cases. - * - * Formerly there was another case for 'val'. - * Deprecated Case: - * This was implemented simply as: - * `line.trim.startsWith (soda_opening_parenthesis)` - * This is no longer supported. - * - */ -trait DefinitionLineTranslator +trait CoqClassConstructorBlockTranslator extends - soda.translator.block.LineTranslator + soda.translator.block.BlockTranslator { - def line: String - - import soda.lib.OptionSD - import soda.lib.SomeSD_ + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ import soda.translator.parser.SodaConstant_ - import soda.translator.replacement.Replacement - import soda.translator.replacement.Replacement_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ private lazy val _sc = SodaConstant_ () private lazy val _tc = TranslationConstantToCoq_ () - private lazy val _trimmed_line = line.trim - - lazy val translation = - find_definition (line).opt (ifEmpty = line) (ifNonEmpty = position => _try_found_definition (position).line) - - private lazy val _is_class_definition = - get_index (line) (_sc.space + _sc.class_reserved_word + _sc.space).isDefined - - private lazy val _translation_of_class_definition = - if ( _condition_for_type_alias - ) Replacement_ (line) - else Replacement_ (line).replace_all (_sc.space + _sc.function_definition_symbol) ("") - - private lazy val _ends_with_equals = false - - private lazy val _ends_with_opening_brace = false - - private lazy val _contains_equals = - _trimmed_line.contains (_sc.function_definition_symbol) + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - private lazy val _condition_for_type_alias = - _contains_equals && ! (_ends_with_equals || _ends_with_opening_brace) + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) + case x => annotated_block + } - private lazy val _translation_of_val_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) + private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) - private lazy val _translation_of_def_definition = - Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) - private def _try_found_definition (position : Int) : Replacement = - if ( _is_class_definition - ) _translation_of_class_definition - else _decide_val_or_def_translation (position) + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) - private def _decide_val_or_def_translation (position : Int) : Replacement = - if ( _is_val_definition (position) - ) _translation_of_val_definition - else _translation_of_def_definition + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ ( + BlockBuilder_ ().build ( + Seq (_tc.coq_opening_comment).++ ( + block.lines.++ ( + Seq [String] ( + _tc.coq_closing_comment, + "", + _get_constructor_declaration (beginning) (_get_types_of_abstract_functions (block) ) + ) + ) + ) + ), + block.references + ) - private def _is_val_definition (initial_position : Int) = - _is_val_definition_case_1 || - _is_val_definition_case_2 (initial_position) || - _is_val_definition_case_3 || - _is_val_definition_case_4 + private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = + _get_initial_spaces (beginning) + + _tc.coq_inductive_reserved_word + + _tc.coq_space + + beginning.class_name + + _tc.coq_space + + _tc.coq_type_membership_symbol + + _tc.coq_space + + _tc.coq_type_reserved_word + + _tc.coq_space + + _tc.coq_function_definition_symbol + + _tc.coq_new_line + + _get_initial_spaces (beginning) + + _tc.coq_space + + _tc.coq_space + + _tc.coq_vertical_bar_symbol + + _tc.coq_space + + beginning.class_name + + _sc.constructor_suffix + + _tc.coq_space + + _tc.coq_opening_parenthesis + + _tc.coq_some_variable_name + + _tc.coq_space + + _tc.coq_type_membership_symbol + + _tc.coq_space + + abstract_functions.mkString (_tc.coq_space + _tc.coq_product_type_symbol + _tc.coq_space) + + _tc.coq_closing_parenthesis + + _tc.coq_new_line + + _get_initial_spaces (beginning) + + _tc.coq_inductive_end_symbol - private lazy val _position_of_first_opening_parenthesis = - get_index (line) (_sc.opening_parenthesis_symbol) + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption - private lazy val _is_val_definition_case_1 = - _position_of_first_opening_parenthesis.isEmpty + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } - private def _is_val_definition_case_2 (initial_position : Int) = - _position_of_first_opening_parenthesis.opt (false) ( position => (position > initial_position) ) + private def _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = + block.abstract_functions + .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) + .map ( line => _remove_variable (line) ) - private lazy val _is_val_definition_case_3 = - (get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => - _position_of_first_opening_parenthesis.opt (false) ( position => (position > other_position) ) - ) + private def _remove_variable (line : String) : String = + _remove_variable_with (line) (line.indexOf (_sc.type_membership_symbol) ) - private lazy val _is_val_definition_case_4 = - _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) + private def _remove_variable_with (line : String) (index : Int) : String = + if ( index < 0 + ) line + else line.substring (index + _sc.type_membership_symbol.length).trim - /** - * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. - * This function finds the first occurrence of the definition sign, if it is present. - * - * @param line line - * @return maybe the position of the definition sign - */ + private def _translate_type_symbols (line : String) : String = + line + .replaceAll (_sc.subtype_reserved_word, _tc.coq_subtype_symbol) + .replaceAll (_sc.supertype_reserved_word, _tc.coq_supertype_symbol) + .replaceAll (_sc.function_arrow_symbol, _tc.coq_function_arrow_symbol) - def find_definition (line : String) : OptionSD [Int] = - if ( line.endsWith (_sc.space + _sc.function_definition_symbol) - ) SomeSD_ (line.length - _sc.function_definition_symbol.length) - else get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) + private def _get_initial_spaces (block : AnnotatedBlock) : String = + _get_initial_spaces_with (_get_first_line (block) ) - def get_index (line : String) (pattern : String) : OptionSD [Int] = - get_index_from (line) (pattern) (0) + private def _get_initial_spaces_with (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) - def get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = - SomeSD_ (line.indexOf (pattern, start) ) - .filter ( position => ! (position == -1) ) + private def _get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") } -case class DefinitionLineTranslator_ (line: String) extends DefinitionLineTranslator +case class CoqClassConstructorBlockTranslator_ () extends CoqClassConstructorBlockTranslator trait CoqClassDeclarationBlockTranslator @@ -234,82 +237,82 @@ trait CoqClassDeclarationBlockTranslator case class CoqClassDeclarationBlockTranslator_ () extends CoqClassDeclarationBlockTranslator -trait CoqImportDeclarationBlockTranslator +trait CoqClassEndBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ImportDeclarationAnnotation - import soda.translator.parser.annotation.ImportDeclarationAnnotation_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ private lazy val _tc = TranslationConstantToCoq_ () - lazy val coq_import_declaration_pattern = - _tc.coq_import_reserved_word + _tc.coq_space - lazy val translate : AnnotatedBlock => AnnotatedBlock = block => translate_for (block) def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = annotated_block match { - case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) case x => annotated_block } - private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = - ImportDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - coq_import_declaration_pattern) ( - block.imported_items - .filter( annotated_line => ! annotated_line.is_comment) - .map ( annotated_line => AnnotatedLine_ (annotated_line.line + _tc.coq_space + _tc.coq_end_symbol, false) ) - ) - ) - - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - BlockBuilder_ ().build ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) - ) - - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = - if ( annotated_line.is_comment - ) annotated_line.line - else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) - - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile ( ch => ch.isSpaceChar) - .length + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) -} + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) -case class CoqImportDeclarationBlockTranslator_ () extends CoqImportDeclarationBlockTranslator + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _tc.coq_module_end_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol, + "", + _tc.coq_import_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol + ) + ), + block.references + ) + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } -trait CoqClassConstructorBlockTranslator +} + +case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator + + +trait CoqDefinitionBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - - private lazy val _sc = SodaConstant_ () + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ private lazy val _tc = TranslationConstantToCoq_ () @@ -319,550 +322,380 @@ trait CoqClassConstructorBlockTranslator def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = annotated_block match { - case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) + case FunctionDefinitionAnnotation_ (block) => _translate_definition_block (FunctionDefinitionAnnotation_ (block) ) case x => annotated_block } - private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) + private def _translate_definition_block (block : FunctionDefinitionAnnotation) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) + private def _translate_block (block : FunctionDefinitionAnnotation) : Block = + if ( is_a_recursive_definition (block) + ) _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) + else _translate_non_recursive_definition (block) - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - if ( beginning.is_concrete - ) block - else _translate_block_with_abstract_beginning (beginning) (block) + private def _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = + if ( is_a_definition (block) + ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) + else block - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ ( - BlockBuilder_ ().build ( - Seq (_tc.coq_opening_comment).++ ( - block.lines.++ ( - Seq [String] ( - _tc.coq_closing_comment, - "", - _get_constructor_declaration (beginning) (_get_types_of_abstract_functions (block) ) - ) - ) - ) - ), - block.references + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq[String] (prefix + block.lines.head) ++ block.lines.tail ) - private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = - _get_initial_spaces (beginning) + - _tc.coq_inductive_reserved_word + - _tc.coq_space + - beginning.class_name + - _tc.coq_space + - _tc.coq_type_membership_symbol + - _tc.coq_space + - _tc.coq_type_reserved_word + - _tc.coq_space + - _tc.coq_function_definition_symbol + - _tc.coq_new_line + - _get_initial_spaces (beginning) + - _tc.coq_space + - _tc.coq_space + - _tc.coq_vertical_bar_symbol + - _tc.coq_space + - beginning.class_name + - _sc.constructor_suffix + - _tc.coq_space + - _tc.coq_opening_parenthesis + - _tc.coq_some_variable_name + - _tc.coq_space + - _tc.coq_type_membership_symbol + - _tc.coq_space + - abstract_functions.mkString (_tc.coq_space + _tc.coq_product_type_symbol + _tc.coq_space) + - _tc.coq_closing_parenthesis + - _tc.coq_new_line + - _get_initial_spaces (beginning) + - _tc.coq_inductive_end_symbol - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - - private def _get_types_of_abstract_functions (block : AbstractDeclarationAnnotation) : Seq [String] = - block.abstract_functions - .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) - .map ( line => _remove_variable (line) ) - - private def _remove_variable (line : String) : String = - _remove_variable_with (line) (line.indexOf (_sc.type_membership_symbol) ) - - private def _remove_variable_with (line : String) (index : Int) : String = - if ( index < 0 - ) line - else line.substring (index + _sc.type_membership_symbol.length).trim - - private def _translate_type_symbols (line : String) : String = - line - .replaceAll (_sc.subtype_reserved_word, _tc.coq_subtype_symbol) - .replaceAll (_sc.supertype_reserved_word, _tc.coq_supertype_symbol) - .replaceAll (_sc.function_arrow_symbol, _tc.coq_function_arrow_symbol) + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) - private def _get_initial_spaces (block : AnnotatedBlock) : String = - _get_initial_spaces_with (_get_first_line (block) ) + def is_a_recursive_definition (block : Block) : Boolean = + _tc.coq_recursive_function_prefixes.exists ( prefix => first_line (block).startsWith (prefix) ) - private def _get_initial_spaces_with (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) + def first_line (block : Block) : String = + block.lines.headOption.getOrElse ("").trim - private def _get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") + def is_a_definition (block : Block) : Boolean = + ! is_a_recursive_definition (block) && + ! _tc.non_definition_block_prefixes.exists ( prefix => block.contents.trim.startsWith (prefix) ) } -case class CoqClassConstructorBlockTranslator_ () extends CoqClassConstructorBlockTranslator - +case class CoqDefinitionBlockTranslator_ () extends CoqDefinitionBlockTranslator -/** - * This class translates Soda snippets into Coq snippets. - */ -trait MicroTranslatorToCoq +trait CoqImportDeclarationBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ImportDeclarationAnnotation + import soda.translator.parser.annotation.ImportDeclarationAnnotation_ private lazy val _tc = TranslationConstantToCoq_ () - private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - - private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - - lazy val functions_and_tests = Seq (_function_definition, _test_declaration) + lazy val coq_import_declaration_pattern = + _tc.coq_import_reserved_word + _tc.coq_space lazy val translate : AnnotatedBlock => AnnotatedBlock = block => - _translation_pipeline.translate (block) + translate_for (block) - lazy val try_definition : Token => String = - token => - DefinitionLineTranslator_ (token.text).translation + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) + case x => annotated_block + } - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - MatchCaseBlockTranslator_ (), - CoqDefinitionBlockTranslator_ (), - CoqClassConstructorBlockTranslator_ (), - CoqClassDeclarationBlockTranslator_ (), - CoqPackageDeclarationBlockTranslator_ (), - CoqClassEndBlockTranslator_ (), - CoqImportDeclarationBlockTranslator_ (), - CoqTheoremBlockTranslator_ (), - CoqProofBlockTranslator_ (), - ConditionalBlockTranslator_ (functions_and_tests, TokenizedBlockTranslator_ (try_definition) ), - ConditionalBlockTranslator_ (functions_and_tests, TokenReplacement_ ().replace (_tc.function_symbols_translation) ) + private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = + ImportDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + coq_import_declaration_pattern) ( + block.imported_items + .filter( annotated_line => ! annotated_line.is_comment) + .map ( annotated_line => AnnotatedLine_ (annotated_line.line + _tc.coq_space + _tc.coq_end_symbol, false) ) ) ) -} + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + BlockBuilder_ ().build ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) -case class MicroTranslatorToCoq_ () extends MicroTranslatorToCoq + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile ( ch => ch.isSpaceChar) + .length -/** - * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. - */ + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") -trait TranslationConstantToCoq -{ +} - import soda.translator.parser.SodaConstant_ +case class CoqImportDeclarationBlockTranslator_ () extends CoqImportDeclarationBlockTranslator - lazy val soda_constant = SodaConstant_ () - lazy val coq_space = " " +trait CoqPackageDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ - lazy val coq_new_line = "\n" + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.PackageDeclarationAnnotation + import soda.translator.parser.annotation.PackageDeclarationAnnotation_ - lazy val coq_function_definition_symbol = ":=" + private lazy val _tc = TranslationConstantToCoq_ () - lazy val coq_type_membership_symbol = ":" + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - lazy val coq_subtype_symbol = "<:" + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case PackageDeclarationAnnotation_ (block) => _translate_block (PackageDeclarationAnnotation_ (block) ) + case x => annotated_block + } - lazy val coq_supertype_symbol = ">:" + private def _translate_block (block : PackageDeclarationAnnotation) : PackageDeclarationAnnotation = + PackageDeclarationAnnotation_ ( + _comment_block ( + block + ) + ) - lazy val coq_function_arrow_symbol = "->" + private def _comment_block (block : Block) : Block = + BlockBuilder_ ().build ( + ( (Seq (_tc.coq_opening_comment).++ (block.lines) ).++ (Seq (_tc.coq_closing_comment) ) ).++ (_tc.coq_prelude) + ) - lazy val coq_empty_string = "" +} - lazy val coq_vertical_bar_symbol = "|" +case class CoqPackageDeclarationBlockTranslator_ () extends CoqPackageDeclarationBlockTranslator - lazy val coq_match_end_translation = "end" - lazy val coq_opening_parenthesis = "(" +trait CoqProofBlockTranslator + extends + soda.translator.block.BlockTranslator +{ - lazy val coq_closing_parenthesis = ")" + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ProofBlockAnnotation + import soda.translator.parser.annotation.ProofBlockAnnotation_ - lazy val coq_opening_comment = "(*" + private lazy val _tc = TranslationConstantToCoq_ () - lazy val coq_closing_comment = "*)" + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - lazy val coq_opening_documentation = "(**" + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ProofBlockAnnotation_ (block) => _translate_block (ProofBlockAnnotation_ (block) ) + case x => annotated_block + } - lazy val coq_closing_documentation = "*)" + private def _translate_block (block : ProofBlockAnnotation) : ProofBlockAnnotation = + ProofBlockAnnotation_ ( + _append ( + _tc.coq_proof_end_reserved_word) ( + _replace_first_line (_tc.coq_proof_begin_reserved_word) (block) + ) + ) - lazy val coq_some_variable_name = "x" + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) - lazy val coq_opening_brace = "{" + private def _replace_first_line (first_line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq (first_line) .++ (_get_tail_or_empty (block.lines) ) + ) - lazy val coq_closing_brace = "}" + private def _get_tail_or_empty (sequence : Seq [String] ) : Seq [String] = + if ( sequence.isEmpty + ) sequence + else sequence.tail - lazy val coq_product_type_symbol = "*" +} - lazy val coq_lambda_reserved_word = "fun" +case class CoqProofBlockTranslator_ () extends CoqProofBlockTranslator - lazy val coq_lambda_arrow_symbol = "=>" - lazy val coq_case_arrow_symbol = "=>" +trait CoqTheoremBlockTranslator + extends + soda.translator.block.BlockTranslator +{ - lazy val coq_case_translation = coq_vertical_bar_symbol + coq_space + import soda.translator.block.AnnotatedBlock + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.TheoremBlockAnnotation + import soda.translator.parser.annotation.TheoremBlockAnnotation_ - lazy val coq_not_reserved_word = "notb" + private lazy val _tc = TranslationConstantToCoq_ () - lazy val coq_and_reserved_word = "andb" + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - lazy val coq_or_reserved_word = "orb" + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case TheoremBlockAnnotation_ (block) => _translate_block (TheoremBlockAnnotation_ (block) ) + case x => annotated_block + } - lazy val coq_end_symbol = "." + private def _translate_block (block : TheoremBlockAnnotation) : TheoremBlockAnnotation = + TheoremBlockAnnotation_ ( + _append ( + _tc.coq_theorem_end_symbol) (_prepend ( + _tc.coq_theorem_begin_reserved_word) (_remove_first_line (block) + ) + ) + ) - lazy val coq_definition_reserved_word : String = "Definition" + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq[String] (prefix + block.lines.head).++ (block.lines.tail) + ) - lazy val coq_inductive_reserved_word : String = "Inductive" + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) + ) - lazy val coq_set_reserved_word : String = "Set" + private def _remove_first_line (block : Block) : Block = + if ( block.lines.isEmpty + ) block + else BlockBuilder_ ().build (block.lines.tail) - lazy val coq_type_reserved_word : String = "Type" +} - lazy val coq_module_reserved_word : String = "Module" +case class CoqTheoremBlockTranslator_ () extends CoqTheoremBlockTranslator - lazy val coq_module_end_reserved_word : String = "End" - lazy val coq_import_reserved_word : String = "Import" +/** + * A line containing the definition sign will be classified as a definition. + * The definitions need to be identified as 'val', 'def', or 'class'. + * + * 'class' is for class definition. + * It is detected if the 'class' reserved word is also in the same line. + * + * 'val' is for value definition. + * It is detected in three cases. + * Case 1: The line does not have a opening parenthesis, e.g. `a = 1` + * Case 2: The first opening parenthesis is after the definition sign, e.g. `x = f (y)` + * Case 3: The first opening parenthesis is after a colon, e.g. `x : (A, B) -> C = (x, y) -> f (x, y)` + * Case 4: The first non-blank character of a line is an opening parenthesis, e.g. `(x, y) = (0, 1)` + * + * 'def' is for function definition. + * If it does not fit in any of the 'val' cases. + * + * Formerly there was another case for 'val'. + * Deprecated Case: + * This was implemented simply as: + * `line.trim.startsWith (soda_opening_parenthesis)` + * This is no longer supported. + * + */ - lazy val coq_recursive_definition_reserved_word : String = "Fixpoint" +trait DefinitionLineTranslator + extends + soda.translator.block.LineTranslator +{ - lazy val coq_inductive_end_symbol : String = coq_end_symbol + def line: String - lazy val coq_definition_end_symbol : String = coq_end_symbol + import soda.lib.OptionSD + import soda.lib.SomeSD_ + import soda.translator.parser.SodaConstant_ + import soda.translator.replacement.Replacement + import soda.translator.replacement.Replacement_ - lazy val coq_recursive_definition_end_symbol : String = coq_end_symbol + private lazy val _sc = SodaConstant_ () - lazy val coq_with_reserved_word : String = "with" + private lazy val _tc = TranslationConstantToCoq_ () - lazy val coq_theorem_begin_reserved_word : String = "Theorem" + private lazy val _trimmed_line = line.trim - lazy val coq_theorem_end_symbol : String = coq_end_symbol + lazy val translation = + find_definition (line).opt (ifEmpty = line) (ifNonEmpty = position => _try_found_definition (position).line) - lazy val coq_proof_begin_reserved_word : String = "Proof." + private lazy val _is_class_definition = + get_index (line) (_sc.space + _sc.class_reserved_word + _sc.space).isDefined - lazy val coq_proof_end_reserved_word : String = "Qed." + private lazy val _translation_of_class_definition = + if ( _condition_for_type_alias + ) Replacement_ (line) + else Replacement_ (line).replace_all (_sc.space + _sc.function_definition_symbol) ("") - lazy val coq_prelude : Seq [String] = - Seq ( - "", - "Require Import Coq.ZArith.BinInt .", - "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", - "", - "Require Import Coq.Lists.List .", - "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", - "", - "Notation Int := Z .", - "" - ) + private lazy val _ends_with_equals = false - lazy val coq_recursive_function_prefixes : Seq [String] = - Seq ( - "rec_", - "_rec_", - "tailrec_", - "_tailrec_", - "@tailrec" - ) + private lazy val _ends_with_opening_brace = false - lazy val non_definition_block_prefixes : Seq [String] = - Seq ( - soda_constant.package_reserved_word, - soda_constant.import_reserved_word, - soda_constant.class_end_reserved_word, - soda_constant.class_reserved_word, - soda_constant.comment_opening_symbol - ) + private lazy val _contains_equals = + _trimmed_line.contains (_sc.function_definition_symbol) - lazy val coq_reserved_words = - coq_1 ++ coq_2 ++ coq_3 ++ coq_4 + private lazy val _condition_for_type_alias = + _contains_equals && ! (_ends_with_equals || _ends_with_opening_brace) - lazy val coq_1 : Seq [String] = - Seq ( - "as", - "else", - "end", - "forall", - "fun", - "if", - "in", - "let", - "match", - "then", - "with" - ) + private lazy val _translation_of_val_definition = + Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) - lazy val coq_2 : Seq [String] = - Seq ( - "Admitted", - "Arguments", - "Check", - "Constructors", - "End", - "Eval", - "Export", - "Hint", - "Implicit", - "Import", - "Module", - "Notation", - "Print", - "Proof", - "Qed", - "Require", - "Resolve", - "Section", - "Set", - "Type", - "Unset" - ) - - lazy val coq_3 : Seq [String] = - Seq ( - "admit", - "apply", - "assert", - "auto", - "case", - "compute", - "destruct", - "discriminate", - "elim", - "exact", - "induction", - "intros", - "pose", - "refine", - "rewrite", - "simpl", - "specialize", - "unfold" - ) - - lazy val coq_4 : Seq [String] = - Seq ( - "CoFixpoint", - "CoInductive", - "Definition", - "Example", - "Fixpoint", - "Global", - "Hypothesis", - "Inductive", - "Instance", - "Lemma", - "Ltac", - "Parameter", - "Theorem", - "Variable" - ) - - lazy val type_symbols_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.subtype_reserved_word, coq_subtype_symbol), - Tuple2 (soda_constant.supertype_reserved_word, coq_supertype_symbol), - Tuple2 (soda_constant.function_arrow_symbol, coq_function_arrow_symbol) - ) - - lazy val function_symbols_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), - Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), - Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), - Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), - Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), - Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), - Tuple2 (soda_constant.and_reserved_word, coq_and_reserved_word ), - Tuple2 (soda_constant.or_reserved_word, coq_or_reserved_word ) - ) - - lazy val type_translation : Seq [ Tuple2 [String, String] ] = - Seq ( - Tuple2 ("Boolean", "bool"), - Tuple2 ("Nat", "nat"), - Tuple2 ("Option", "option"), - Tuple2 ("List", "list"), - Tuple2 ("String", "string"), - Tuple2 ("BigInt", "Z") - ) - - lazy val prefix_coq_non_soda : String = "__soda__" - - lazy val coq_non_soda : Seq [Tuple2 [String, String] ] = - coq_reserved_words - .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) - .map ( x => Tuple2 (x, prefix_coq_non_soda + x) ) - - def is_coq_word (word : String) : Boolean = - coq_reserved_words.contains (word) - - def is_soda_word (word : String) : Boolean = - soda_constant.soda_reserved_words.contains (word) - -} - -case class TranslationConstantToCoq_ () extends TranslationConstantToCoq - - -/** - * This translates Soda source code to Coq source code. - */ - -trait TranslatorToCoq - extends - soda.translator.extension.common.Extension -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File - - private lazy val _soda_extension : String = ".soda" - - private lazy val _coq_extension : String = ".v" - - private lazy val _default_argument = "." - - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToCoq_ () - ) - ) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) + private lazy val _translation_of_def_definition = + Replacement_ (line).add_after_spaces_or_pattern (_tc.coq_space) (_tc.coq_space) - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => _translate (arguments (0) ) (arguments (1) ) - case x => false - } + private def _try_found_definition (position : Int) : Replacement = + if ( _is_class_definition + ) _translation_of_class_definition + else _decide_val_or_def_translation (position) - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () + private def _decide_val_or_def_translation (position : Int) : Replacement = + if ( _is_val_definition (position) + ) _translation_of_val_definition + else _translation_of_def_definition - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + private def _is_val_definition (initial_position : Int) = + _is_val_definition_case_1 || + _is_val_definition_case_2 (initial_position) || + _is_val_definition_case_3 || + _is_val_definition_case_4 - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) + private lazy val _position_of_first_opening_parenthesis = + get_index (line) (_sc.opening_parenthesis_symbol) - private def _get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _coq_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _coq_extension) + private lazy val _is_val_definition_case_1 = + _position_of_first_opening_parenthesis.isEmpty - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) + private def _is_val_definition_case_2 (initial_position : Int) = + _position_of_first_opening_parenthesis.opt (false) ( position => (position > initial_position) ) - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content = _translator.translate (input) + private lazy val _is_val_definition_case_3 = + (get_index (line) (_sc.type_membership_symbol) ).opt (ifEmpty = false) (ifNonEmpty = other_position => + _position_of_first_opening_parenthesis.opt (false) ( position => (position > other_position) ) ) -} - -case class TranslatorToCoq_ () extends TranslatorToCoq - -trait FileNamePair -{ - - def input_file_name : String - def output_file_name : String - -} - -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair - - -trait CoqPackageDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.PackageDeclarationAnnotation - import soda.translator.parser.annotation.PackageDeclarationAnnotation_ - - private lazy val _tc = TranslationConstantToCoq_ () + private lazy val _is_val_definition_case_4 = + _trimmed_line.startsWith (_sc.opening_parenthesis_symbol) - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + /** + * A line is a definition when its main operator is "=" (the equals sign), which in this context is also called the definition sign. + * This function finds the first occurrence of the definition sign, if it is present. + * + * @param line line + * @return maybe the position of the definition sign + */ - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case PackageDeclarationAnnotation_ (block) => _translate_block (PackageDeclarationAnnotation_ (block) ) - case x => annotated_block - } + def find_definition (line : String) : OptionSD [Int] = + if ( line.endsWith (_sc.space + _sc.function_definition_symbol) + ) SomeSD_ (line.length - _sc.function_definition_symbol.length) + else get_index (line) (_sc.space + _sc.function_definition_symbol + _sc.space) - private def _translate_block (block : PackageDeclarationAnnotation) : PackageDeclarationAnnotation = - PackageDeclarationAnnotation_ ( - _comment_block ( - block - ) - ) + def get_index (line : String) (pattern : String) : OptionSD [Int] = + get_index_from (line) (pattern) (0) - private def _comment_block (block : Block) : Block = - BlockBuilder_ ().build ( - ( (Seq (_tc.coq_opening_comment).++ (block.lines) ).++ (Seq (_tc.coq_closing_comment) ) ).++ (_tc.coq_prelude) - ) + def get_index_from (line : String) (pattern : String) (start : Int) : OptionSD [Int] = + SomeSD_ (line.indexOf (pattern, start) ) + .filter ( position => ! (position == -1) ) } -case class CoqPackageDeclarationBlockTranslator_ () extends CoqPackageDeclarationBlockTranslator +case class DefinitionLineTranslator_ (line: String) extends DefinitionLineTranslator trait MatchCaseBlockTranslator @@ -951,233 +784,400 @@ trait MatchCaseBlockTranslator case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator -trait CoqDefinitionBlockTranslator +/** + * This class translates Soda snippets into Coq snippets. + */ + +trait MicroTranslatorToCoq extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token private lazy val _tc = TranslationConstantToCoq_ () - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_definition_block (FunctionDefinitionAnnotation_ (block) ) - case x => annotated_block - } + private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - private def _translate_definition_block (block : FunctionDefinitionAnnotation) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) + lazy val functions_and_tests = Seq (_function_definition, _test_declaration) - private def _translate_block (block : FunctionDefinitionAnnotation) : Block = - if ( is_a_recursive_definition (block) - ) _append (_tc.coq_recursive_definition_end_symbol) (_prepend (_tc.coq_recursive_definition_reserved_word + _tc.coq_space) (block) ) - else _translate_non_recursive_definition (block) + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) - private def _translate_non_recursive_definition (block : FunctionDefinitionAnnotation) : Block = - if ( is_a_definition (block) - ) _append (_tc.coq_definition_end_symbol) (_prepend (_tc.coq_definition_reserved_word + _tc.coq_space) (block) ) - else block + lazy val try_definition : Token => String = + token => + DefinitionLineTranslator_ (token.text).translation - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq[String] (prefix + block.lines.head) ++ block.lines.tail + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + MatchCaseBlockTranslator_ (), + CoqDefinitionBlockTranslator_ (), + CoqClassConstructorBlockTranslator_ (), + CoqClassDeclarationBlockTranslator_ (), + CoqPackageDeclarationBlockTranslator_ (), + CoqClassEndBlockTranslator_ (), + CoqImportDeclarationBlockTranslator_ (), + CoqTheoremBlockTranslator_ (), + CoqProofBlockTranslator_ (), + ConditionalBlockTranslator_ (functions_and_tests, TokenizedBlockTranslator_ (try_definition) ), + ConditionalBlockTranslator_ (functions_and_tests, TokenReplacement_ ().replace (_tc.function_symbols_translation) ) + ) ) - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) +} - def is_a_recursive_definition (block : Block) : Boolean = - _tc.coq_recursive_function_prefixes.exists ( prefix => first_line (block).startsWith (prefix) ) +case class MicroTranslatorToCoq_ () extends MicroTranslatorToCoq - def first_line (block : Block) : String = - block.lines.headOption.getOrElse ("").trim - def is_a_definition (block : Block) : Boolean = - ! is_a_recursive_definition (block) && - ! _tc.non_definition_block_prefixes.exists ( prefix => block.contents.trim.startsWith (prefix) ) +/** + * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Coq. + */ -} +trait TranslationConstantToCoq +{ -case class CoqDefinitionBlockTranslator_ () extends CoqDefinitionBlockTranslator + import soda.translator.parser.SodaConstant_ + lazy val soda_constant = SodaConstant_ () -trait CoqTheoremBlockTranslator - extends - soda.translator.block.BlockTranslator -{ + lazy val coq_space = " " - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.TheoremBlockAnnotation - import soda.translator.parser.annotation.TheoremBlockAnnotation_ + lazy val coq_new_line = "\n" - private lazy val _tc = TranslationConstantToCoq_ () + lazy val coq_function_definition_symbol = ":=" - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + lazy val coq_type_membership_symbol = ":" - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case TheoremBlockAnnotation_ (block) => _translate_block (TheoremBlockAnnotation_ (block) ) - case x => annotated_block - } + lazy val coq_subtype_symbol = "<:" - private def _translate_block (block : TheoremBlockAnnotation) : TheoremBlockAnnotation = - TheoremBlockAnnotation_ ( - _append ( - _tc.coq_theorem_end_symbol) (_prepend ( - _tc.coq_theorem_begin_reserved_word) (_remove_first_line (block) - ) - ) - ) + lazy val coq_supertype_symbol = ">:" - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq[String] (prefix + block.lines.head).++ (block.lines.tail) - ) + lazy val coq_function_arrow_symbol = "->" - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) + lazy val coq_empty_string = "" - private def _remove_first_line (block : Block) : Block = - if ( block.lines.isEmpty - ) block - else BlockBuilder_ ().build (block.lines.tail) + lazy val coq_vertical_bar_symbol = "|" -} + lazy val coq_match_end_translation = "end" -case class CoqTheoremBlockTranslator_ () extends CoqTheoremBlockTranslator + lazy val coq_opening_parenthesis = "(" + lazy val coq_closing_parenthesis = ")" -trait CoqClassEndBlockTranslator - extends - soda.translator.block.BlockTranslator -{ + lazy val coq_opening_comment = "(*" - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ + lazy val coq_closing_comment = "*)" - private lazy val _tc = TranslationConstantToCoq_ () + lazy val coq_opening_documentation = "(**" - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + lazy val coq_closing_documentation = "*)" - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } + lazy val coq_some_variable_name = "x" - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) + lazy val coq_opening_brace = "{" - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) + lazy val coq_closing_brace = "}" - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( beginning.is_concrete - ) block - else _translate_block_with_abstract_beginning (beginning) (block) + lazy val coq_product_type_symbol = "*" - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - Seq [String] ( - _tc.coq_module_end_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol, - "", - _tc.coq_import_reserved_word + _tc.coq_space + beginning.class_name + _tc.coq_space + _tc.coq_end_symbol - ) - ), - block.references + lazy val coq_lambda_reserved_word = "fun" + + lazy val coq_lambda_arrow_symbol = "=>" + + lazy val coq_case_arrow_symbol = "=>" + + lazy val coq_case_translation = coq_vertical_bar_symbol + coq_space + + lazy val coq_not_reserved_word = "notb" + + lazy val coq_and_reserved_word = "andb" + + lazy val coq_or_reserved_word = "orb" + + lazy val coq_end_symbol = "." + + lazy val coq_definition_reserved_word : String = "Definition" + + lazy val coq_inductive_reserved_word : String = "Inductive" + + lazy val coq_set_reserved_word : String = "Set" + + lazy val coq_type_reserved_word : String = "Type" + + lazy val coq_module_reserved_word : String = "Module" + + lazy val coq_module_end_reserved_word : String = "End" + + lazy val coq_import_reserved_word : String = "Import" + + lazy val coq_recursive_definition_reserved_word : String = "Fixpoint" + + lazy val coq_inductive_end_symbol : String = coq_end_symbol + + lazy val coq_definition_end_symbol : String = coq_end_symbol + + lazy val coq_recursive_definition_end_symbol : String = coq_end_symbol + + lazy val coq_with_reserved_word : String = "with" + + lazy val coq_theorem_begin_reserved_word : String = "Theorem" + + lazy val coq_theorem_end_symbol : String = coq_end_symbol + + lazy val coq_proof_begin_reserved_word : String = "Proof." + + lazy val coq_proof_end_reserved_word : String = "Qed." + + lazy val coq_prelude : Seq [String] = + Seq ( + "", + "Require Import Coq.ZArith.BinInt .", + "(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *)", + "", + "Require Import Coq.Lists.List .", + "(* https://coq.inria.fr/library/Coq.Lists.List.html *)", + "", + "Notation Int := Z .", + "" ) - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption + lazy val coq_recursive_function_prefixes : Seq [String] = + Seq ( + "rec_", + "_rec_", + "tailrec_", + "_tailrec_", + "@tailrec" + ) - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } + lazy val non_definition_block_prefixes : Seq [String] = + Seq ( + soda_constant.package_reserved_word, + soda_constant.import_reserved_word, + soda_constant.class_end_reserved_word, + soda_constant.class_reserved_word, + soda_constant.comment_opening_symbol + ) + + lazy val coq_reserved_words = + coq_1 ++ coq_2 ++ coq_3 ++ coq_4 + + lazy val coq_1 : Seq [String] = + Seq ( + "as", + "else", + "end", + "forall", + "fun", + "if", + "in", + "let", + "match", + "then", + "with" + ) + + lazy val coq_2 : Seq [String] = + Seq ( + "Admitted", + "Arguments", + "Check", + "Constructors", + "End", + "Eval", + "Export", + "Hint", + "Implicit", + "Import", + "Module", + "Notation", + "Print", + "Proof", + "Qed", + "Require", + "Resolve", + "Section", + "Set", + "Type", + "Unset" + ) + + lazy val coq_3 : Seq [String] = + Seq ( + "admit", + "apply", + "assert", + "auto", + "case", + "compute", + "destruct", + "discriminate", + "elim", + "exact", + "induction", + "intros", + "pose", + "refine", + "rewrite", + "simpl", + "specialize", + "unfold" + ) + + lazy val coq_4 : Seq [String] = + Seq ( + "CoFixpoint", + "CoInductive", + "Definition", + "Example", + "Fixpoint", + "Global", + "Hypothesis", + "Inductive", + "Instance", + "Lemma", + "Ltac", + "Parameter", + "Theorem", + "Variable" + ) + + lazy val type_symbols_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.subtype_reserved_word, coq_subtype_symbol), + Tuple2 (soda_constant.supertype_reserved_word, coq_supertype_symbol), + Tuple2 (soda_constant.function_arrow_symbol, coq_function_arrow_symbol) + ) + + lazy val function_symbols_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.function_definition_symbol, coq_function_definition_symbol), + Tuple2 (soda_constant.lambda_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.any_reserved_word, coq_lambda_reserved_word), + Tuple2 (soda_constant.lambda_arrow_symbol, coq_lambda_arrow_symbol), + Tuple2 (soda_constant.case_arrow_symbol, coq_case_arrow_symbol), + Tuple2 (soda_constant.not_reserved_word, coq_not_reserved_word ), + Tuple2 (soda_constant.and_reserved_word, coq_and_reserved_word ), + Tuple2 (soda_constant.or_reserved_word, coq_or_reserved_word ) + ) + + lazy val type_translation : Seq [ Tuple2 [String, String] ] = + Seq ( + Tuple2 ("Boolean", "bool"), + Tuple2 ("Nat", "nat"), + Tuple2 ("Option", "option"), + Tuple2 ("List", "list"), + Tuple2 ("String", "string"), + Tuple2 ("BigInt", "Z") + ) + + lazy val prefix_coq_non_soda : String = "__soda__" + + lazy val coq_non_soda : Seq [Tuple2 [String, String] ] = + coq_reserved_words + .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) + .map ( x => Tuple2 (x, prefix_coq_non_soda + x) ) + + def is_coq_word (word : String) : Boolean = + coq_reserved_words.contains (word) + + def is_soda_word (word : String) : Boolean = + soda_constant.soda_reserved_words.contains (word) } -case class CoqClassEndBlockTranslator_ () extends CoqClassEndBlockTranslator +case class TranslationConstantToCoq_ () extends TranslationConstantToCoq -trait CoqProofBlockTranslator +/** + * This translates Soda source code to Coq source code. + */ + +trait TranslatorToCoq extends - soda.translator.block.BlockTranslator + soda.translator.extension.common.Extension { - import soda.translator.block.AnnotatedBlock - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ProofBlockAnnotation - import soda.translator.parser.annotation.ProofBlockAnnotation_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File - private lazy val _tc = TranslationConstantToCoq_ () + private lazy val _soda_extension : String = ".soda" - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + private lazy val _coq_extension : String = ".v" - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ProofBlockAnnotation_ (block) => _translate_block (ProofBlockAnnotation_ (block) ) - case x => annotated_block - } + private lazy val _default_argument = "." - private def _translate_block (block : ProofBlockAnnotation) : ProofBlockAnnotation = - ProofBlockAnnotation_ ( - _append ( - _tc.coq_proof_end_reserved_word) ( - _replace_first_line (_tc.coq_proof_begin_reserved_word) (block) + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToCoq_ () ) ) - private def _append (suffix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - block.lines.:+ (suffix) - ) + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) - private def _replace_first_line (first_line : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq (first_line) .++ (_get_tail_or_empty (block.lines) ) + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } + + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () + + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) + + private def _get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, + input_name.substring (0, input_name.length - _soda_extension.length) + _coq_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _coq_extension) + + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( + SimpleFileReader_ ().read_file (input_file_name) ) ( + output_file_name ) - private def _get_tail_or_empty (sequence : Seq [String] ) : Seq [String] = - if ( sequence.isEmpty - ) sequence - else sequence.tail + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file ( + output_file_name) ( + content = _translator.translate (input) + ) } -case class CoqProofBlockTranslator_ () extends CoqProofBlockTranslator +case class TranslatorToCoq_ () extends TranslatorToCoq + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String +} + +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index e92ef407..c56501f1 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -7,46 +7,6 @@ package soda.translator.extension.todoc trait Package -/** - * This class generates documentation from Soda snippets. - */ - -trait MicroTranslatorToDoc - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token - - private lazy val _tc = TranslationConstantToDoc_ () - - private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - - private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - - lazy val functions_and_tests = Seq (_function_definition, _test_declaration) - - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _translation_pipeline.translate (block) - - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - DocBlockTranslator_ () - ) - ) - -} - -case class MicroTranslatorToDoc_ () extends MicroTranslatorToDoc - trait DocBlockTranslator extends @@ -149,91 +109,44 @@ case class DocBlockTranslator_ () extends DocBlockTranslator /** - * This generates documentation from Soda source code. + * This class generates documentation from Soda snippets. */ -trait TranslatorToDoc +trait MicroTranslatorToDoc extends - soda.translator.extension.common.Extension + soda.translator.block.BlockTranslator { - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File - - private lazy val _soda_extension : String = ".soda" - - private lazy val _doc_extension : String = ".tex" - - private lazy val _default_argument = "." + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token private lazy val _tc = TranslationConstantToDoc_ () - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToDoc_ () - ) - ) - - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => _translate (arguments (0) ) (arguments (1) ) - case x => false - } - - def translate_content (input : String) : String = - _tc.doc_header + _translator.translate (input) + _tc.doc_footer - - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () - - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) + private lazy val _test_declaration = BlockAnnotationEnum_ ().test_declaration - private def _get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, - input_name.substring (0, input_name.length - _soda_extension.length) + _doc_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _doc_extension) + lazy val functions_and_tests = Seq (_function_definition, _test_declaration) - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( - SimpleFileReader_ ().read_file (input_file_name) ) ( - output_file_name - ) + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file ( - output_file_name) ( - content = translate_content (input) + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + DocBlockTranslator_ () + ) ) } -case class TranslatorToDoc_ () extends TranslatorToDoc - -trait FileNamePair -{ - - def input_file_name : String - def output_file_name : String - -} - -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair +case class MicroTranslatorToDoc_ () extends MicroTranslatorToDoc /** @@ -347,3 +260,90 @@ trait TranslationConstantToDoc case class TranslationConstantToDoc_ () extends TranslationConstantToDoc +/** + * This generates documentation from Soda source code. + */ + +trait TranslatorToDoc + extends + soda.translator.extension.common.Extension +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File + + private lazy val _soda_extension : String = ".soda" + + private lazy val _doc_extension : String = ".tex" + + private lazy val _default_argument = "." + + private lazy val _tc = TranslationConstantToDoc_ () + + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToDoc_ () + ) + ) + + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) + + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => _translate (arguments (0) ) (arguments (1) ) + case x => false + } + + def translate_content (input : String) : String = + _tc.doc_header + _translator.translate (input) + _tc.doc_footer + + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () + + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (_get_input_output_file_names (file.getAbsolutePath) ) + + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) + + private def _get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, + input_name.substring (0, input_name.length - _soda_extension.length) + _doc_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _doc_extension) + + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( + SimpleFileReader_ ().read_file (input_file_name) ) ( + output_file_name + ) + + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file ( + output_file_name) ( + content = translate_content (input) + ) + +} + +case class TranslatorToDoc_ () extends TranslatorToDoc + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String + +} + +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair + diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index f0509dd4..e76e04c0 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -7,16 +7,85 @@ package soda.translator.extension.toscala trait Package -trait ClassEndBlockTranslator + +trait AbstractDeclarationBlockTranslator + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.Block + import soda.translator.block.Block_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + + private lazy val _tc = TranslationConstantToScala_ () + + lazy val scala_abstract_function_declaration_pattern = + _tc.scala_abstract_function_declaration + _tc.scala_space + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) + case x => annotated_block + } + + private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + scala_abstract_function_declaration_pattern) ( + block.abstract_functions_with_comments + ), + block.references + ) + + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + Block_ ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) + + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : AnnotatedLine = + if ( annotated_line.is_comment + ) annotated_line + else AnnotatedLine_ (annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index), annotated_line.is_comment) + + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile (ch => ch.isSpaceChar) + .length + + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") + +} + +case class AbstractDeclarationBlockTranslator_ () extends AbstractDeclarationBlockTranslator + + +trait ClassConstructorBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ import soda.translator.parser.annotation.ClassEndAnnotation import soda.translator.parser.annotation.ClassEndAnnotation_ + private lazy val _sc = SodaConstant_ () + private lazy val _tc = TranslationConstantToScala_ () lazy val translate : AnnotatedBlock => AnnotatedBlock = @@ -30,19 +99,83 @@ trait ClassEndBlockTranslator } private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + _translate_block_with (_get_class_beginning (block.references) ) (block) + + private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( maybe_beginning.isEmpty + ) block + else _translate_block_with_beginning (maybe_beginning.get) (block) + + private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( beginning.is_concrete + ) block + else _translate_block_with_abstract_beginning (beginning) (block) + + private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = ClassEndAnnotation_ ( BlockBuilder_ ().build ( - Seq [String] ( - _get_translation (block) + block.lines.++ ( + Seq [String] ( + "", + _get_constructor_declaration (beginning) (_get_abstract_functions (block.references) ) + ) ) ), block.references ) - private def _get_translation (block : ClassEndAnnotation) : String = - _get_initial_spaces (block) + _tc.scala_class_end_symbol + private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = + _get_initial_spaces (beginning) + + _tc.class_declaration_translation_at_beginning_with_paren + + _tc.scala_space + + beginning.class_name + + _sc.constructor_suffix + + _translate_type_symbols (_get_as_parameter_list (beginning.type_parameters_and_bounds) ) + + _tc.scala_space + + _tc.scala_opening_parenthesis + + abstract_functions.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + + _tc.scala_closing_parenthesis + + _tc.scala_space + + _tc.scala_extends_translation + + _tc.scala_space + + beginning.class_name + + _get_as_parameter_list (beginning.type_parameters) - private def _get_initial_spaces (block : ClassEndAnnotation) : String = + private def _get_as_parameter_list (parameters : Seq [String] ) : String = + if ( parameters.isEmpty + ) "" + else _tc.scala_space + _tc.scala_opening_bracket + parameters.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + _tc.scala_closing_bracket + + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption + + private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + annotated_block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } + + private def _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = + references + .flatMap ( block => _get_as_abstract_declaration_annotation (block) ) + .flatMap ( block => block.abstract_functions) + .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) + + private def _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = + block match { + case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) + case x => None + } + + private def _translate_type_symbols (line : String) : String = + line + .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) + .replaceAll (_sc.supertype_reserved_word, _tc.scala_supertype_symbol) + .replaceAll (_sc.function_arrow_symbol, _tc.scala_function_arrow_symbol) + + private def _get_initial_spaces (block : AnnotatedBlock) : String = _get_initial_spaces_with (_get_first_line (block) ) private def _get_initial_spaces_with (line : String) : String = @@ -53,522 +186,276 @@ trait ClassEndBlockTranslator } -case class ClassEndBlockTranslator_ () extends ClassEndBlockTranslator +case class ClassConstructorBlockTranslator_ () extends ClassConstructorBlockTranslator -trait TheoremAndProofBlockTranslator +trait ClassDeclarationBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock import soda.translator.block.Block + import soda.translator.block.Translator + import soda.translator.blocktr.TableTranslator_ import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ProofBlockAnnotation - import soda.translator.parser.annotation.ProofBlockAnnotation_ - import soda.translator.parser.annotation.TheoremBlockAnnotation - import soda.translator.parser.annotation.TheoremBlockAnnotation_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassAliasAnnotation + import soda.translator.parser.annotation.ClassAliasAnnotation_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () private lazy val _tc = TranslationConstantToScala_ () + lazy val soda_space : String = _sc.space + lazy val translate : AnnotatedBlock => AnnotatedBlock = block => translate_for (block) def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = annotated_block match { - case TheoremBlockAnnotation_ (block) => _translate_theorem_block (TheoremBlockAnnotation_ (block) ) - case ProofBlockAnnotation_ (block) => _translate_proof_block (ProofBlockAnnotation_ (block) ) + case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) + case ClassAliasAnnotation_ (block) => _translate_class_alias_block (ClassAliasAnnotation_ (block) ) case x => annotated_block } - private def _translate_theorem_block (block : AnnotatedBlock) : TheoremBlockAnnotation = - TheoremBlockAnnotation_ (_translate_block (block) ) + private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = + ClassBeginningAnnotation_ (_translate_block (block) ) - private def _translate_proof_block (block : AnnotatedBlock) : ProofBlockAnnotation = - ProofBlockAnnotation_ (_translate_block (block) ) + private def _translate_class_alias_block (block : ClassAliasAnnotation) : ClassAliasAnnotation = + ClassAliasAnnotation_ (_translate_block (block) ) private def _translate_block (block : AnnotatedBlock) : Block = - _append (_tc.scala_comment_closing_symbol) (_prepend (_tc.scala_comment_opening_symbol) (block) ) - - private def _prepend (prefix : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) - ) - - private def _append (suffix : String) (block : Block) : Block = BlockBuilder_ ().build ( - block.lines.:+ (suffix) + if ( (has_condition_for_type_alias (get_first_line (block) ) ) + ) _process_head (block) ++ _process_tail (block) + else _process_head (block) ++ _process_tail (block) ++ Seq [String] (get_initial_spaces (block) + _tc.scala_class_begin_symbol) ) -} - -case class TheoremAndProofBlockTranslator_ () extends TheoremAndProofBlockTranslator + private def _process_head (block : Block) : Seq [String] = + _process_head_with (get_first_line (block) ) (block) + private def _process_head_with (line : String) (block : Block) : Seq [String] = + Seq [String] (Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) ) -/** - * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. - */ + private def _process_tail (block : Block) : Seq [String] = + _process_if_extends (remove_first_line (block) ) -trait TranslationConstantToScala -{ + private def _process_if_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim == _sc.extends_reserved_word) + ) Seq [String] (get_initial_spaces (block) + _tc.scala_extends_translation) ++ _process_after_extends (remove_first_line (block) ) + else block.lines - import soda.translator.parser.SodaConstant_ + def get_table_translator (line : String) : Translator = + TableTranslator_ ( + Seq (Tuple2 (_sc.class_reserved_word, get_class_declaration_translation (line) ) ) + ) - lazy val soda_constant = SodaConstant_ () + def get_class_declaration_translation (line : String) : String = + if ( line.contains (_sc.opening_parenthesis_symbol) + ) _tc.class_declaration_translation_at_beginning_with_paren + else + if ( has_condition_for_type_alias (line) + ) _tc.class_declaration_translation_at_beginning_without_paren_for_type_alias + else _tc.class_declaration_translation_at_beginning_without_paren - lazy val scala_3_class_definition = ":" + private def _process_after_extends (block : Block) : Seq [String] = + if ( (get_first_line (block).trim.nonEmpty) + ) Seq [String] (get_first_line (block) ) ++ remove_first_line (block).lines.map ( line => get_initial_spaces_for (line) + _tc.scala_with_translation + _tc.scala_space + line.trim) + else Seq [String] () - lazy val scala_match_translation = " match " + def remove_first_line (block : Block) : Block = + BlockBuilder_ ().build ( + if ( block.lines.isEmpty + ) block.lines + else block.lines.tail + ) - lazy val scala_space = " " + def get_first_line (block : Block) : String = + block.lines.headOption.getOrElse ("") - lazy val scala_empty_string = "" + def get_initial_spaces (block : Block) : String = + get_initial_spaces_for (get_first_line (block) ) - lazy val scala_comma = "," + def get_initial_spaces_for (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) - lazy val scala_parameter_separator_symbol = "," + def ends_with_equals (line : String) : Boolean = false - lazy val scala_lambda_arrow_symbol = "=>" + def ends_with_opening_brace (line : String) : Boolean = false - lazy val scala_case_arrow_symbol = "=>" + def contains_equals (line : String) : Boolean = + line.trim.contains (_sc.function_definition_symbol) - lazy val scala_parameter_definition_symbol = "=" + def has_condition_for_type_alias (line : String) : Boolean = + contains_equals (line) - lazy val scala_match_end_translation = "}" +} - lazy val scala_opening_parenthesis = "(" +case class ClassDeclarationBlockTranslator_ () extends ClassDeclarationBlockTranslator - lazy val scala_closing_parenthesis = ")" - lazy val scala_opening_bracket = "[" - - lazy val scala_closing_bracket = "]" - - lazy val scala_opening_brace = "{" - - lazy val scala_closing_brace = "}" - - lazy val scala_class_begin_symbol = "{" - - lazy val scala_class_end_symbol = "}" - - lazy val scala_comment_opening_symbol = "/*" - - lazy val scala_comment_closing_symbol = "*/" - - lazy val scala_if_translation = "if (" - - lazy val scala_then_translation = ")" - - lazy val scala_abstract_function_declaration = "def" - - lazy val scala_definition = "def" - - lazy val scala_value = "lazy val" - - lazy val scala_import_declaration = "import" - - lazy val scala_with_translation = "with" - - lazy val scala_extends_translation = "extends" - - lazy val scala_function_arrow_symbol = "=>" - - lazy val scala_subtype_symbol = "<:" - - lazy val scala_supertype_symbol = ">:" - - lazy val scala_not_symbol = "!" - - lazy val scala_and_symbol = "&&" - - lazy val scala_or_symbol = "||" - - lazy val scala_tail_recursion_annotation_translation = "import scala.annotation.tailrec\n @tailrec final" - - lazy val scala_override_annotation_translation = "override" - - lazy val scala_new_annotation_translation = "new" - - lazy val soda_main_class_name = "Main" - - lazy val scala_entry_point = "object EntryPoint {\n def main (args: Array [String]): Unit = Main_ ().main (args)\n}\n" - - lazy val scala_private_reserved_word = "private" - - /** - * Scala 3 keywords: - * https://dotty.epfl.ch/docs/internals/syntax.html - * Scala 2 keywords: - * https://www.scala-lang.org/files/archive/spec/2.13/01-lexical-syntax.html - */ - lazy val scala_reserved_words = - scala_3_regular_keywords ++ scala_3_soft_keywords ++ scala_2_extra_keywords +trait ClassEndBlockTranslator + extends + soda.translator.block.BlockTranslator +{ - lazy val scala_3_regular_keywords = - Seq ( - "abstract", - "case", - "catch", - "class", - "def", - "do", - "else", - "enum", - "export", - "extends", - "false", - "final", - "finally", - "for", - "given", - "if", - "implicit", - "import", - "lazy", - "match", - "new", - "null", - "object", - "override", - "package", - "private", - "protected", - "return", - "sealed", - "super", - "then", - "throw", - "trait", - "true", - "try", - "type", - "val", - "var", - "while", - "with", - "yield", - ":", - "=", - "<-", - "=>", - "<:", - ">:", - "#", - "@", - "=>>", - "?=>" - ) + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ - lazy val scala_3_soft_keywords = - Seq ( - "as", - "derives", - "end", - "extension", - "infix", - "inline", - "opaque", - "open", - "transparent", - "using", - "|", - "*", - "+", - "-" - ) + private lazy val _tc = TranslationConstantToScala_ () - lazy val scala_2_extra_keywords = - Seq ( - "forSome", - "macro", - "this", - "_", - "<%", - "\u21D2", - "\u2190" - ) + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - lazy val type_symbol_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.subtype_reserved_word, scala_subtype_symbol), - Tuple2 (soda_constant.supertype_reserved_word, scala_supertype_symbol), - Tuple2 (soda_constant.function_arrow_symbol, scala_function_arrow_symbol) - ) + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } - lazy val function_symbol_translation : Seq [Tuple2 [String, String] ] = - Seq ( - Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), - Tuple2 (soda_constant.any_reserved_word, scala_empty_string), - Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), - Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), - Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), - Tuple2 (soda_constant.and_reserved_word, scala_and_symbol), - Tuple2 (soda_constant.or_reserved_word, scala_or_symbol), - Tuple2 (soda_constant.if_reserved_word, scala_if_translation), - Tuple2 (soda_constant.then_reserved_word, scala_then_translation), - Tuple2 (soda_constant.parameter_definition_symbol, scala_parameter_definition_symbol), - Tuple2 (soda_constant.tail_recursion_annotation, scala_tail_recursion_annotation_translation), - Tuple2 (soda_constant.override_annotation, scala_override_annotation_translation), - Tuple2 (soda_constant.new_annotation, scala_new_annotation_translation) + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _get_translation (block) + ) + ), + block.references ) - lazy val all_translations : Seq [Tuple2 [String, String] ] = - type_symbol_translation.++ (function_symbol_translation) - - lazy val class_declaration_translation_at_beginning_with_paren = "case class" - - lazy val class_declaration_translation_at_beginning_without_paren_for_type_alias = "type" - - lazy val class_declaration_translation_at_beginning_without_paren = "trait" - - lazy val prefix_scala_non_soda = "__soda__" + private def _get_translation (block : ClassEndAnnotation) : String = + _get_initial_spaces (block) + _tc.scala_class_end_symbol - lazy val scala_non_soda : Seq [Tuple2 [String, String] ] = - scala_reserved_words - .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) - .map ( x => Tuple2 (x, prefix_scala_non_soda + x) ) + private def _get_initial_spaces (block : ClassEndAnnotation) : String = + _get_initial_spaces_with (_get_first_line (block) ) - def is_scala_word (word : String) : Boolean = - scala_reserved_words.contains (word) + private def _get_initial_spaces_with (line : String) : String = + line.takeWhile ( ch => ch.isSpaceChar) - def is_soda_word (word : String) : Boolean = - soda_constant.soda_reserved_words.contains (word) + private def _get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") } -case class TranslationConstantToScala_ () extends TranslationConstantToScala +case class ClassEndBlockTranslator_ () extends ClassEndBlockTranslator -trait ClassDeclarationBlockTranslator +trait FunctionDefinitionBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedLine_ import soda.translator.block.Block - import soda.translator.block.Translator - import soda.translator.blocktr.TableTranslator_ + import soda.translator.block.Block_ import soda.translator.parser.BlockBuilder_ import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassAliasAnnotation - import soda.translator.parser.annotation.ClassAliasAnnotation_ + import soda.translator.parser.annotation.FunctionDefinitionAnnotation + import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ import soda.translator.replacement.Replacement_ private lazy val _sc = SodaConstant_ () private lazy val _tc = TranslationConstantToScala_ () - lazy val soda_space : String = _sc.space - lazy val translate : AnnotatedBlock => AnnotatedBlock = block => translate_for (block) def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = annotated_block match { - case ClassBeginningAnnotation_ (block) => _translate_class_beginning_block (ClassBeginningAnnotation_ (block) ) - case ClassAliasAnnotation_ (block) => _translate_class_alias_block (ClassAliasAnnotation_ (block) ) + case FunctionDefinitionAnnotation_ (block) => _translate_function_definition_block (block) case x => annotated_block } - private def _translate_class_beginning_block (block : ClassBeginningAnnotation) : ClassBeginningAnnotation = - ClassBeginningAnnotation_ (_translate_block (block) ) - - private def _translate_class_alias_block (block : ClassAliasAnnotation) : ClassAliasAnnotation = - ClassAliasAnnotation_ (_translate_block (block) ) + private def _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = + FunctionDefinitionAnnotation_ (_translate_block (block) ) - private def _translate_block (block : AnnotatedBlock) : Block = - BlockBuilder_ ().build ( - if ( (has_condition_for_type_alias (get_first_line (block) ) ) - ) _process_head (block) ++ _process_tail (block) - else _process_head (block) ++ _process_tail (block) ++ Seq [String] (get_initial_spaces (block) + _tc.scala_class_begin_symbol) - ) + private def _translate_block (block : Block) : Block = + if ( block.readable_lines.isEmpty + ) block + else _translate_block_with (block.readable_lines.head) (block) - private def _process_head (block : Block) : Seq [String] = - _process_head_with (get_first_line (block) ) (block) - - private def _process_head_with (line : String) (block : Block) : Seq [String] = - Seq [String] (Replacement_ (_sc.space + line).replace_at_beginning (0) (get_table_translator (line) ).line.substring (_sc.space.length) ) + private def _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = + if ( _is_annotation (first_line.line) + ) _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) + else _translate_main_block (block) - private def _process_tail (block : Block) : Seq [String] = - _process_if_extends (remove_first_line (block) ) + private def _translate_main_block (block : Block) : Block = + _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) - private def _process_if_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim == _sc.extends_reserved_word) - ) Seq [String] (get_initial_spaces (block) + _tc.scala_extends_translation) ++ _process_after_extends (remove_first_line (block) ) - else block.lines + private def _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = + detector.detect match { + case detector.val_detected => _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case detector.def_detected => _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) + case x => block + } - def get_table_translator (line : String) : Translator = - TableTranslator_ ( - Seq (Tuple2 (_sc.class_reserved_word, get_class_declaration_translation (line) ) ) + private def _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) ) - def get_class_declaration_translation (line : String) : String = - if ( line.contains (_sc.opening_parenthesis_symbol) - ) _tc.class_declaration_translation_at_beginning_with_paren - else - if ( has_condition_for_type_alias (line) - ) _tc.class_declaration_translation_at_beginning_without_paren_for_type_alias - else _tc.class_declaration_translation_at_beginning_without_paren - - private def _process_after_extends (block : Block) : Seq [String] = - if ( (get_first_line (block).trim.nonEmpty) - ) Seq [String] (get_first_line (block) ) ++ remove_first_line (block).lines.map ( line => get_initial_spaces_for (line) + _tc.scala_with_translation + _tc.scala_space + line.trim) - else Seq [String] () - - def remove_first_line (block : Block) : Block = - BlockBuilder_ ().build ( - if ( block.lines.isEmpty - ) block.lines - else block.lines.tail + private def _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = + Block_ ( + initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) ) - def get_first_line (block : Block) : String = - block.lines.headOption.getOrElse ("") - - def get_initial_spaces (block : Block) : String = - get_initial_spaces_for (get_first_line (block) ) - - def get_initial_spaces_for (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) - - def ends_with_equals (line : String) : Boolean = false - - def ends_with_opening_brace (line : String) : Boolean = false - - def contains_equals (line : String) : Boolean = - line.trim.contains (_sc.function_definition_symbol) - - def has_condition_for_type_alias (line : String) : Boolean = - contains_equals (line) - -} - -case class ClassDeclarationBlockTranslator_ () extends ClassDeclarationBlockTranslator - - -trait ClassConstructorBlockTranslator - extends - soda.translator.block.BlockTranslator -{ - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - private lazy val _sc = SodaConstant_ () + private def _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.takeWhile ( annotated_line => annotated_line.is_comment ) - private lazy val _tc = TranslationConstantToScala_ () + private def _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = + lines.dropWhile ( annotated_line => annotated_line.is_comment ) - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + private def _translate_val_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) + .line - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } + private def _translate_def_definition (line : String) : String = + Replacement_ (line) + .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) + .line - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - _translate_block_with (_get_class_beginning (block.references) ) (block) + private def _private_prefix_if_necessary (line : String) : String = + if ( line.trim.startsWith (_sc.private_function_prefix) + ) _tc.scala_private_reserved_word + _tc.scala_space + else "" - private def _translate_block_with (maybe_beginning : Option [ClassBeginningAnnotation] ) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( maybe_beginning.isEmpty - ) block - else _translate_block_with_beginning (maybe_beginning.get) (block) + private def _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = + if ( lines.isEmpty + ) Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) + else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) - private def _translate_block_with_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( beginning.is_concrete + private def _remove_first_line_if_possible (block : Block) : Block = + if ( block.lines.isEmpty ) block - else _translate_block_with_abstract_beginning (beginning) (block) + else BlockBuilder_ ().build (block.lines.tail) - private def _translate_block_with_abstract_beginning (beginning : ClassBeginningAnnotation) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - block.lines.++ ( - Seq [String] ( - "", - _get_constructor_declaration (beginning) (_get_abstract_functions (block.references) ) - ) - ) - ), - block.references + private def _prepend_line (line : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (line) .++ (block.lines) ) - private def _get_constructor_declaration (beginning : ClassBeginningAnnotation) (abstract_functions : Seq [String] ) : String = - _get_initial_spaces (beginning) + - _tc.class_declaration_translation_at_beginning_with_paren + - _tc.scala_space + - beginning.class_name + - _sc.constructor_suffix + - _translate_type_symbols (_get_as_parameter_list (beginning.type_parameters_and_bounds) ) + - _tc.scala_space + - _tc.scala_opening_parenthesis + - abstract_functions.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + - _tc.scala_closing_parenthesis + - _tc.scala_space + - _tc.scala_extends_translation + - _tc.scala_space + - beginning.class_name + - _get_as_parameter_list (beginning.type_parameters) - - private def _get_as_parameter_list (parameters : Seq [String] ) : String = - if ( parameters.isEmpty - ) "" - else _tc.scala_space + _tc.scala_opening_bracket + parameters.mkString (_tc.scala_parameter_separator_symbol + _tc.scala_space) + _tc.scala_closing_bracket - - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption - - private def _get_as_class_beginning_annotation (annotated_block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - annotated_block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } - - private def _get_abstract_functions (references : Seq [AnnotatedBlock] ) : Seq [String] = - references - .flatMap ( block => _get_as_abstract_declaration_annotation (block) ) - .flatMap ( block => block.abstract_functions) - .map ( annotated_line => _translate_type_symbols (annotated_line.line).trim ) - - private def _get_as_abstract_declaration_annotation (block : AnnotatedBlock) : Option [AbstractDeclarationAnnotation] = - block match { - case AbstractDeclarationAnnotation_ (b, references) => Some (AbstractDeclarationAnnotation_ (b, references) ) - case x => None - } - - private def _translate_type_symbols (line : String) : String = - line - .replaceAll (_sc.subtype_reserved_word, _tc.scala_subtype_symbol) - .replaceAll (_sc.supertype_reserved_word, _tc.scala_supertype_symbol) - .replaceAll (_sc.function_arrow_symbol, _tc.scala_function_arrow_symbol) - - private def _get_initial_spaces (block : AnnotatedBlock) : String = - _get_initial_spaces_with (_get_first_line (block) ) - - private def _get_initial_spaces_with (line : String) : String = - line.takeWhile ( ch => ch.isSpaceChar) + private def _flatten_block (block : Block) : String = + block.lines.mkString (_sc.space) - private def _get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") + private def _is_annotation (line : String) : Boolean = + (line.trim == _sc.tail_recursion_annotation) || (line.trim == _sc.override_annotation) } -case class ClassConstructorBlockTranslator_ () extends ClassConstructorBlockTranslator +case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator /** @@ -667,152 +554,124 @@ trait FunctionDefinitionLineDetector case class FunctionDefinitionLineDetector_ (line: String) extends FunctionDefinitionLineDetector -/** - * This translates Soda source code to Scala source code. - */ - -trait TranslatorToScala +trait ImportDeclarationBlockTranslator extends - soda.translator.extension.common.Extension + soda.translator.block.BlockTranslator { - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.io.DirectoryProcessor_ - import soda.translator.io.SimpleFileReader_ - import soda.translator.io.SimpleFileWriter_ - import soda.translator.parser.BlockProcessor_ - import java.io.File + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedLine + import soda.translator.block.Block + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.annotation.ImportDeclarationAnnotation + import soda.translator.parser.annotation.ImportDeclarationAnnotation_ - private lazy val _soda_extension : String = ".soda" + private lazy val _tc = TranslationConstantToScala_ () - private lazy val _scala_extension : String = ".scala" + lazy val scala_import_declaration_pattern = + _tc.scala_import_declaration + _tc.scala_space - private lazy val _default_argument = "." + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - lazy val package_file_prefix : String = "Package" + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) + case x => annotated_block + } - lazy val package_file_name : String = package_file_prefix + _soda_extension + private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = + ImportDeclarationAnnotation_ ( + prepend_to_lines_aligned_at ( + get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( + scala_import_declaration_pattern) ( + block.imported_items + ) + ) - lazy val package_scala_file_name : String = package_file_prefix + _scala_extension + def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = + BlockBuilder_ ().build ( + annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + ) - lazy val file_separator : String = File.separator - - lazy val default_prelude : String = "" - - lazy val new_line : String = "\n" - - lazy val append_separation : String = new_line + new_line + def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = + if ( annotated_line.is_comment + ) annotated_line.line + else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) - lazy val prelude_file_body : String = new_line + "trait Package" + append_separation + def get_number_of_spaces_at_beginning (line : String) : Int = + line + .takeWhile ( ch => ch.isSpaceChar) + .length - lazy val package_option_1 = "-p" + def get_first_line (block : AnnotatedBlock) : String = + block.lines.headOption.getOrElse ("") - lazy val package_option_2 = "--package" +} - private lazy val _translator = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) +case class ImportDeclarationBlockTranslator_ () extends ImportDeclarationBlockTranslator - lazy val execute : Seq [String] => Boolean = - arguments => - execute_for (arguments) - def execute_for (arguments : Seq [String] ) : Boolean = - arguments.length match { - case 0 => _process_directory (_default_argument) - case 1 => _process_directory (arguments (0) ) - case 2 => - if ( _is_package_option (arguments (0) ) - ) _process_directory_with_package_option (arguments (1) ) - else _translate (arguments (0) ) (arguments (1) ) - case x => false - } +trait MainClassBlockTranslator + extends + soda.translator.block.BlockTranslator +{ - private def _process_directory (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file).process () + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.SodaConstant_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ - private def _process_soda_file (file : File) : Boolean = - _process_soda_file_with (get_input_output_file_names (file.getAbsolutePath) ) + private lazy val _tc = TranslationConstantToScala_ () - private def _process_soda_file_with (pair : FileNamePair) : Boolean = - _translate (pair.input_file_name) (pair.output_file_name) + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) - private def _process_directory_with_package_option (start : String) : Boolean = - DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () + def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = + annotated_block match { + case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) + case x => annotated_block + } - private def _process_soda_file_with_package_option (file : File) : Boolean = - if ( file.getName == package_file_name - ) _process_soda_file (file) - else _process_soda_file_with_package_option_with ( - get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) + private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = + if ( _get_class_name (block.references) == _tc.soda_main_class_name ) + ClassEndAnnotation_ ( + BlockBuilder_ ().build ( + Seq [String] ( + _tc.scala_class_end_symbol, + "", + _tc.scala_entry_point + ) + ), + block.references + ) + else block - private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = - _translate_append (pair.input_file_name) (pair.output_file_name) - - def get_input_output_file_names (input_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) - else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) - - def get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = - if ( input_name.endsWith (_soda_extension) - ) FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) - else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) - - private def _translate (input_file_name : String) (output_file_name : String) : Boolean = - _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) - - private def _translate_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) - - private def _translate_append (input_file_name : String) (output_file_name : String) : Boolean = - _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) - - private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = - SimpleFileWriter_ ().append_file (output_file_name) (content = new_line + _translator.translate (input) + new_line) - - private def _read_input_with_prelude (input_file_name : String) : String = - if ( _is_a_prelude_file (input_file_name) - ) _read_input (input_file_name) + prelude_file_body - else _get_prelude (input_file_name) + _read_input (input_file_name) - - private def _read_input (input_file_name : String) : String = - SimpleFileReader_ ().read_file (input_file_name) - - private def _get_prelude (input_file_name : String) : String = - _get_prelude_with (_get_prelude_file (input_file_name) ) - - private def _get_prelude_with (prelude_file : File) : String = - if ( prelude_file.exists - ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + append_separation - else default_prelude - - private def _get_prelude_file (input_file_name : String) : File = - new File ( new File (input_file_name) .getParentFile , package_file_name ) - - private def _is_a_prelude_file (input_file_name : String) : Boolean = - package_file_name == ( ( new File (input_file_name) ) .getName) - - private def _is_package_option (s : String) : Boolean = - (s == package_option_1) || (s == package_option_2) - -} - -case class TranslatorToScala_ () extends TranslatorToScala + private def _get_class_name (references : Seq [AnnotatedBlock] ) : String = + _get_class_beginning (references) + .map ( x => x.class_name) + .getOrElse ("") -trait FileNamePair -{ + private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = + references + .flatMap ( block => _get_as_class_beginning_annotation (block) ) + .headOption - def input_file_name : String - def output_file_name : String + private def _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = + block match { + case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) + case x => None + } } -case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair +case class MainClassBlockTranslator_ () extends MainClassBlockTranslator trait MatchCaseBlockTranslator @@ -895,23 +754,75 @@ trait MatchCaseBlockTranslator case class MatchCaseBlockTranslator_ () extends MatchCaseBlockTranslator -trait FunctionDefinitionBlockTranslator +/** + * This class translates Soda source code into Scala source code. + */ + +trait MicroTranslatorToScala + extends + soda.translator.block.BlockTranslator +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockTranslatorPipeline_ + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.ConditionalBlockTranslator_ + import soda.translator.blocktr.TokenReplacement_ + import soda.translator.blocktr.TokenizedBlockTranslator_ + import soda.translator.replacement.Token + + private lazy val _tc = TranslationConstantToScala_ () + + private lazy val _ba = BlockAnnotationEnum_ () + + private lazy val _functions_and_tests = + Seq (_ba.function_definition, _ba.test_declaration) + + private lazy val _class_declarations = + Seq (_ba.class_alias, _ba.class_beginning, _ba.abstract_declaration) + + private lazy val _definitions_and_declarations = + _functions_and_tests.++ (_class_declarations) + + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + _translation_pipeline.translate (block) + + private lazy val _translation_pipeline = + BlockTranslatorPipeline_ ( + Seq ( + MatchCaseBlockTranslator_ (), + ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), + ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), + ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), + ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), + ClassDeclarationBlockTranslator_ (), + ImportDeclarationBlockTranslator_ (), + AbstractDeclarationBlockTranslator_ (), + TheoremAndProofBlockTranslator_ (), + ClassEndBlockTranslator_ (), + MainClassBlockTranslator_ (), + ClassConstructorBlockTranslator_ () + ) + ) + +} + +case class MicroTranslatorToScala_ () extends MicroTranslatorToScala + + +trait TheoremAndProofBlockTranslator extends soda.translator.block.BlockTranslator { import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ import soda.translator.block.Block - import soda.translator.block.Block_ import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.FunctionDefinitionAnnotation - import soda.translator.parser.annotation.FunctionDefinitionAnnotation_ - import soda.translator.replacement.Replacement_ - - private lazy val _sc = SodaConstant_ () + import soda.translator.parser.annotation.ProofBlockAnnotation + import soda.translator.parser.annotation.ProofBlockAnnotation_ + import soda.translator.parser.annotation.TheoremBlockAnnotation + import soda.translator.parser.annotation.TheoremBlockAnnotation_ private lazy val _tc = TranslationConstantToScala_ () @@ -921,325 +832,414 @@ trait FunctionDefinitionBlockTranslator def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = annotated_block match { - case FunctionDefinitionAnnotation_ (block) => _translate_function_definition_block (block) + case TheoremBlockAnnotation_ (block) => _translate_theorem_block (TheoremBlockAnnotation_ (block) ) + case ProofBlockAnnotation_ (block) => _translate_proof_block (ProofBlockAnnotation_ (block) ) case x => annotated_block } - private def _translate_function_definition_block (block : Block) : FunctionDefinitionAnnotation = - FunctionDefinitionAnnotation_ (_translate_block (block) ) + private def _translate_theorem_block (block : AnnotatedBlock) : TheoremBlockAnnotation = + TheoremBlockAnnotation_ (_translate_block (block) ) - private def _translate_block (block : Block) : Block = - if ( block.readable_lines.isEmpty - ) block - else _translate_block_with (block.readable_lines.head) (block) + private def _translate_proof_block (block : AnnotatedBlock) : ProofBlockAnnotation = + ProofBlockAnnotation_ (_translate_block (block) ) - private def _translate_block_with (first_line : AnnotatedLine) (block : Block) : Block = - if ( _is_annotation (first_line.line) - ) _prepend_line (first_line.line) (_translate_main_block (_remove_first_line_if_possible (block) ) ) - else _translate_main_block (block) + private def _translate_block (block : AnnotatedBlock) : Block = + _append (_tc.scala_comment_closing_symbol) (_prepend (_tc.scala_comment_opening_symbol) (block) ) - private def _translate_main_block (block : Block) : Block = - _translate_main_block_with (block) ( FunctionDefinitionLineDetector_ (_flatten_block (block) ) ) + private def _prepend (prefix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + Seq [String] (prefix + block.lines.head) .++ (block.lines.tail) + ) - private def _translate_main_block_with (block : Block) (detector : FunctionDefinitionLineDetector) : Block = - detector.detect match { - case detector.val_detected => _replace_on_val_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) - case detector.def_detected => _replace_on_def_block (_get_initial_comment (block.annotated_lines) ) (_get_part_without_initial_comment (block.annotated_lines) ) - case x => block - } - - private def _replace_on_val_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = - Block_ ( - initial_comments .++ (_replace_first_line (main_block) (_translate_val_definition (main_block.head.line) ) ) + private def _append (suffix : String) (block : Block) : Block = + BlockBuilder_ ().build ( + block.lines.:+ (suffix) ) - private def _replace_on_def_block (initial_comments : Seq [AnnotatedLine] ) (main_block : Seq [AnnotatedLine] ) : Block = - Block_ ( - initial_comments .++ (_replace_first_line (main_block) (_translate_def_definition (main_block.head.line) ) ) - ) +} - private def _get_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = - lines.takeWhile ( annotated_line => annotated_line.is_comment ) +case class TheoremAndProofBlockTranslator_ () extends TheoremAndProofBlockTranslator - private def _get_part_without_initial_comment (lines : Seq [AnnotatedLine] ) : Seq [AnnotatedLine] = - lines.dropWhile ( annotated_line => annotated_line.is_comment ) - private def _translate_val_definition (line : String) : String = - Replacement_ (line) - .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_value + _tc.scala_space) - .line +/** + * This class contains constants that are specific for the Soda translator, like reserved words for Soda and Scala. + */ - private def _translate_def_definition (line : String) : String = - Replacement_ (line) - .add_after_spaces_or_pattern (_tc.scala_space) (_private_prefix_if_necessary (line) + _tc.scala_definition + _tc.scala_space) - .line +trait TranslationConstantToScala +{ - private def _private_prefix_if_necessary (line : String) : String = - if ( line.trim.startsWith (_sc.private_function_prefix) - ) _tc.scala_private_reserved_word + _tc.scala_space - else "" + import soda.translator.parser.SodaConstant_ - private def _replace_first_line (lines : Seq [AnnotatedLine] ) (new_first_line : String) : Seq [AnnotatedLine] = - if ( lines.isEmpty - ) Seq [AnnotatedLine] () .+: ( AnnotatedLine_ (new_first_line, false) ) - else lines.tail .+: ( AnnotatedLine_ (new_first_line, false) ) + lazy val soda_constant = SodaConstant_ () - private def _remove_first_line_if_possible (block : Block) : Block = - if ( block.lines.isEmpty - ) block - else BlockBuilder_ ().build (block.lines.tail) + lazy val scala_3_class_definition = ":" - private def _prepend_line (line : String) (block : Block) : Block = - BlockBuilder_ ().build ( - Seq [String] (line) .++ (block.lines) - ) + lazy val scala_match_translation = " match " - private def _flatten_block (block : Block) : String = - block.lines.mkString (_sc.space) + lazy val scala_space = " " - private def _is_annotation (line : String) : Boolean = - (line.trim == _sc.tail_recursion_annotation) || (line.trim == _sc.override_annotation) + lazy val scala_empty_string = "" -} + lazy val scala_comma = "," -case class FunctionDefinitionBlockTranslator_ () extends FunctionDefinitionBlockTranslator + lazy val scala_parameter_separator_symbol = "," + lazy val scala_lambda_arrow_symbol = "=>" -trait ImportDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ + lazy val scala_case_arrow_symbol = "=>" - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.Block - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.annotation.ImportDeclarationAnnotation - import soda.translator.parser.annotation.ImportDeclarationAnnotation_ + lazy val scala_parameter_definition_symbol = "=" - private lazy val _tc = TranslationConstantToScala_ () + lazy val scala_match_end_translation = "}" - lazy val scala_import_declaration_pattern = - _tc.scala_import_declaration + _tc.scala_space + lazy val scala_opening_parenthesis = "(" - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + lazy val scala_closing_parenthesis = ")" - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ImportDeclarationAnnotation_ (block) => _translate_block (ImportDeclarationAnnotation_ (block) ) - case x => annotated_block - } + lazy val scala_opening_bracket = "[" - private def _translate_block (block : ImportDeclarationAnnotation) : ImportDeclarationAnnotation = - ImportDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - scala_import_declaration_pattern) ( - block.imported_items - ) + lazy val scala_closing_bracket = "]" + + lazy val scala_opening_brace = "{" + + lazy val scala_closing_brace = "}" + + lazy val scala_class_begin_symbol = "{" + + lazy val scala_class_end_symbol = "}" + + lazy val scala_comment_opening_symbol = "/*" + + lazy val scala_comment_closing_symbol = "*/" + + lazy val scala_if_translation = "if (" + + lazy val scala_then_translation = ")" + + lazy val scala_abstract_function_declaration = "def" + + lazy val scala_definition = "def" + + lazy val scala_value = "lazy val" + + lazy val scala_import_declaration = "import" + + lazy val scala_with_translation = "with" + + lazy val scala_extends_translation = "extends" + + lazy val scala_function_arrow_symbol = "=>" + + lazy val scala_subtype_symbol = "<:" + + lazy val scala_supertype_symbol = ">:" + + lazy val scala_not_symbol = "!" + + lazy val scala_and_symbol = "&&" + + lazy val scala_or_symbol = "||" + + lazy val scala_tail_recursion_annotation_translation = "import scala.annotation.tailrec\n @tailrec final" + + lazy val scala_override_annotation_translation = "override" + + lazy val scala_new_annotation_translation = "new" + + lazy val soda_main_class_name = "Main" + + lazy val scala_entry_point = "object EntryPoint {\n def main (args: Array [String]): Unit = Main_ ().main (args)\n}\n" + + lazy val scala_private_reserved_word = "private" + + /** + * Scala 3 keywords: + * https://dotty.epfl.ch/docs/internals/syntax.html + * Scala 2 keywords: + * https://www.scala-lang.org/files/archive/spec/2.13/01-lexical-syntax.html + */ + lazy val scala_reserved_words = + scala_3_regular_keywords ++ scala_3_soft_keywords ++ scala_2_extra_keywords + + lazy val scala_3_regular_keywords = + Seq ( + "abstract", + "case", + "catch", + "class", + "def", + "do", + "else", + "enum", + "export", + "extends", + "false", + "final", + "finally", + "for", + "given", + "if", + "implicit", + "import", + "lazy", + "match", + "new", + "null", + "object", + "override", + "package", + "private", + "protected", + "return", + "sealed", + "super", + "then", + "throw", + "trait", + "true", + "try", + "type", + "val", + "var", + "while", + "with", + "yield", + ":", + "=", + "<-", + "=>", + "<:", + ">:", + "#", + "@", + "=>>", + "?=>" ) - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - BlockBuilder_ ().build ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) + lazy val scala_3_soft_keywords = + Seq ( + "as", + "derives", + "end", + "extension", + "infix", + "inline", + "opaque", + "open", + "transparent", + "using", + "|", + "*", + "+", + "-" ) - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : String = - if ( annotated_line.is_comment - ) annotated_line.line - else annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index) + lazy val scala_2_extra_keywords = + Seq ( + "forSome", + "macro", + "this", + "_", + "<%", + "\u21D2", + "\u2190" + ) + + lazy val type_symbol_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.subtype_reserved_word, scala_subtype_symbol), + Tuple2 (soda_constant.supertype_reserved_word, scala_supertype_symbol), + Tuple2 (soda_constant.function_arrow_symbol, scala_function_arrow_symbol) + ) + + lazy val function_symbol_translation : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (soda_constant.lambda_reserved_word, scala_empty_string), + Tuple2 (soda_constant.any_reserved_word, scala_empty_string), + Tuple2 (soda_constant.lambda_arrow_symbol, scala_lambda_arrow_symbol), + Tuple2 (soda_constant.case_arrow_symbol, scala_case_arrow_symbol), + Tuple2 (soda_constant.not_reserved_word, scala_not_symbol), + Tuple2 (soda_constant.and_reserved_word, scala_and_symbol), + Tuple2 (soda_constant.or_reserved_word, scala_or_symbol), + Tuple2 (soda_constant.if_reserved_word, scala_if_translation), + Tuple2 (soda_constant.then_reserved_word, scala_then_translation), + Tuple2 (soda_constant.parameter_definition_symbol, scala_parameter_definition_symbol), + Tuple2 (soda_constant.tail_recursion_annotation, scala_tail_recursion_annotation_translation), + Tuple2 (soda_constant.override_annotation, scala_override_annotation_translation), + Tuple2 (soda_constant.new_annotation, scala_new_annotation_translation) + ) + + lazy val all_translations : Seq [Tuple2 [String, String] ] = + type_symbol_translation.++ (function_symbol_translation) + + lazy val class_declaration_translation_at_beginning_with_paren = "case class" + + lazy val class_declaration_translation_at_beginning_without_paren_for_type_alias = "type" + + lazy val class_declaration_translation_at_beginning_without_paren = "trait" + + lazy val prefix_scala_non_soda = "__soda__" + + lazy val scala_non_soda : Seq [Tuple2 [String, String] ] = + scala_reserved_words + .filter ( x => ! soda_constant.soda_reserved_words.contains (x)) + .map ( x => Tuple2 (x, prefix_scala_non_soda + x) ) - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile ( ch => ch.isSpaceChar) - .length + def is_scala_word (word : String) : Boolean = + scala_reserved_words.contains (word) - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") + def is_soda_word (word : String) : Boolean = + soda_constant.soda_reserved_words.contains (word) } -case class ImportDeclarationBlockTranslator_ () extends ImportDeclarationBlockTranslator +case class TranslationConstantToScala_ () extends TranslationConstantToScala -trait MainClassBlockTranslator +/** + * This translates Soda source code to Scala source code. + */ + +trait TranslatorToScala extends - soda.translator.block.BlockTranslator + soda.translator.extension.common.Extension { - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.io.DirectoryProcessor_ + import soda.translator.io.SimpleFileReader_ + import soda.translator.io.SimpleFileWriter_ + import soda.translator.parser.BlockProcessor_ + import java.io.File - private lazy val _tc = TranslationConstantToScala_ () + private lazy val _soda_extension : String = ".soda" - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + private lazy val _scala_extension : String = ".scala" - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case ClassEndAnnotation_ (block, references) => _translate_block (ClassEndAnnotation_ (block, references) ) - case x => annotated_block - } + private lazy val _default_argument = "." - private def _translate_block (block : ClassEndAnnotation) : ClassEndAnnotation = - if ( _get_class_name (block.references) == _tc.soda_main_class_name - ) - ClassEndAnnotation_ ( - BlockBuilder_ ().build ( - Seq [String] ( - _tc.scala_class_end_symbol, - "", - _tc.scala_entry_point - ) - ), - block.references - ) - else block + lazy val package_file_prefix : String = "Package" - private def _get_class_name (references : Seq [AnnotatedBlock] ) : String = - _get_class_beginning (references) - .map ( x => x.class_name) - .getOrElse ("") + lazy val package_file_name : String = package_file_prefix + _soda_extension - private def _get_class_beginning (references : Seq [AnnotatedBlock] ) : Option [ClassBeginningAnnotation] = - references - .flatMap ( block => _get_as_class_beginning_annotation (block) ) - .headOption + lazy val package_scala_file_name : String = package_file_prefix + _scala_extension - private def _get_as_class_beginning_annotation (block : AnnotatedBlock) : Option [ClassBeginningAnnotation] = - block match { - case ClassBeginningAnnotation_ (b) => Some (ClassBeginningAnnotation_ (b) ) - case x => None - } + lazy val file_separator : String = File.separator -} + lazy val default_prelude : String = "" -case class MainClassBlockTranslator_ () extends MainClassBlockTranslator + lazy val new_line : String = "\n" + lazy val append_separation : String = new_line + new_line -/** - * This class translates Soda source code into Scala source code. - */ + lazy val prelude_file_body : String = new_line + "trait Package" + append_separation -trait MicroTranslatorToScala - extends - soda.translator.block.BlockTranslator -{ + lazy val package_option_1 = "-p" - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token + lazy val package_option_2 = "--package" - private lazy val _tc = TranslationConstantToScala_ () + private lazy val _translator = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) - private lazy val _ba = BlockAnnotationEnum_ () + lazy val execute : Seq [String] => Boolean = + arguments => + execute_for (arguments) - private lazy val _functions_and_tests = - Seq (_ba.function_definition, _ba.test_declaration) + def execute_for (arguments : Seq [String] ) : Boolean = + arguments.length match { + case 0 => _process_directory (_default_argument) + case 1 => _process_directory (arguments (0) ) + case 2 => + if ( _is_package_option (arguments (0) ) + ) _process_directory_with_package_option (arguments (1) ) + else _translate (arguments (0) ) (arguments (1) ) + case x => false + } - private lazy val _class_declarations = - Seq (_ba.class_alias, _ba.class_beginning, _ba.abstract_declaration) + private def _process_directory (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file).process () - private lazy val _definitions_and_declarations = - _functions_and_tests.++ (_class_declarations) + private def _process_soda_file (file : File) : Boolean = + _process_soda_file_with (get_input_output_file_names (file.getAbsolutePath) ) - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - _translation_pipeline.translate (block) + private def _process_soda_file_with (pair : FileNamePair) : Boolean = + _translate (pair.input_file_name) (pair.output_file_name) - private lazy val _translation_pipeline = - BlockTranslatorPipeline_ ( - Seq ( - MatchCaseBlockTranslator_ (), - ConditionalBlockTranslator_ (_definitions_and_declarations, TokenReplacement_ ().replace (_tc.scala_non_soda) ), - ConditionalBlockTranslator_ (_functions_and_tests, FunctionDefinitionBlockTranslator_ () ), - ConditionalBlockTranslator_ (_class_declarations, TokenReplacement_ ().replace (_tc.type_symbol_translation) ), - ConditionalBlockTranslator_ (_functions_and_tests, TokenReplacement_ ().replace (_tc.all_translations) ), - ClassDeclarationBlockTranslator_ (), - ImportDeclarationBlockTranslator_ (), - AbstractDeclarationBlockTranslator_ (), - TheoremAndProofBlockTranslator_ (), - ClassEndBlockTranslator_ (), - MainClassBlockTranslator_ (), - ClassConstructorBlockTranslator_ () - ) + private def _process_directory_with_package_option (start : String) : Boolean = + DirectoryProcessor_ (start, _process_soda_file_with_package_option).process () + + private def _process_soda_file_with_package_option (file : File) : Boolean = + if ( file.getName == package_file_name + ) _process_soda_file (file) + else _process_soda_file_with_package_option_with ( + get_input_output_file_names_with_package_option (file.getAbsolutePath) (file.getParent) ) -} + private def _process_soda_file_with_package_option_with (pair : FileNamePair) : Boolean = + _translate_append (pair.input_file_name) (pair.output_file_name) -case class MicroTranslatorToScala_ () extends MicroTranslatorToScala + def get_input_output_file_names (input_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name, input_name.substring (0, input_name.length - _soda_extension.length) + _scala_extension) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) + def get_input_output_file_names_with_package_option (input_name : String) (parent_name : String) : FileNamePair = + if ( input_name.endsWith (_soda_extension) + ) FileNamePair_ (input_name , parent_name + file_separator + package_scala_file_name ) + else FileNamePair_ (input_name + _soda_extension, input_name + _scala_extension) -trait AbstractDeclarationBlockTranslator - extends - soda.translator.block.BlockTranslator -{ + private def _translate (input_file_name : String) (output_file_name : String) : Boolean = + _translate_with_input ( _read_input_with_prelude (input_file_name) ) (output_file_name) - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedLine - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.Block - import soda.translator.block.Block_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + private def _translate_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().write_file (output_file_name) (content = _translator.translate (input) ) - private lazy val _tc = TranslationConstantToScala_ () + private def _translate_append (input_file_name : String) (output_file_name : String) : Boolean = + _translate_append_with_input ( _read_input (input_file_name) ) (output_file_name) - lazy val scala_abstract_function_declaration_pattern = - _tc.scala_abstract_function_declaration + _tc.scala_space + private def _translate_append_with_input (input : String) (output_file_name : String) : Boolean = + SimpleFileWriter_ ().append_file (output_file_name) (content = new_line + _translator.translate (input) + new_line) - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + private def _read_input_with_prelude (input_file_name : String) : String = + if ( _is_a_prelude_file (input_file_name) + ) _read_input (input_file_name) + prelude_file_body + else _get_prelude (input_file_name) + _read_input (input_file_name) - def translate_for (annotated_block : AnnotatedBlock) : AnnotatedBlock = - annotated_block match { - case AbstractDeclarationAnnotation_ (block, references) => _translate_block (AbstractDeclarationAnnotation_ (block, references) ) - case x => annotated_block - } + private def _read_input (input_file_name : String) : String = + SimpleFileReader_ ().read_file (input_file_name) - private def _translate_block (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ ( - prepend_to_lines_aligned_at ( - get_number_of_spaces_at_beginning (get_first_line (block) ) ) ( - scala_abstract_function_declaration_pattern) ( - block.abstract_functions_with_comments - ), - block.references - ) + private def _get_prelude (input_file_name : String) : String = + _get_prelude_with (_get_prelude_file (input_file_name) ) - def prepend_to_lines_aligned_at (number_of_spaces : Int) (prefix : String) (annotated_lines : Seq [AnnotatedLine] ) : Block = - Block_ ( - annotated_lines.map ( annotated_line => prepend_aligned_non_comment (number_of_spaces) (prefix) (annotated_line) ) - ) + private def _get_prelude_with (prelude_file : File) : String = + if ( prelude_file.exists + ) (SimpleFileReader_ ().read_file (prelude_file.getAbsolutePath) ) + append_separation + else default_prelude - def prepend_aligned_non_comment (index : Int) (prefix : String) (annotated_line : AnnotatedLine) : AnnotatedLine = - if ( annotated_line.is_comment - ) annotated_line - else AnnotatedLine_ (annotated_line.line.substring (0, index) + prefix + annotated_line.line.substring (index), annotated_line.is_comment) + private def _get_prelude_file (input_file_name : String) : File = + new File ( new File (input_file_name) .getParentFile , package_file_name ) - def get_number_of_spaces_at_beginning (line : String) : Int = - line - .takeWhile (ch => ch.isSpaceChar) - .length + private def _is_a_prelude_file (input_file_name : String) : Boolean = + package_file_name == ( ( new File (input_file_name) ) .getName) - def get_first_line (block : AnnotatedBlock) : String = - block.lines.headOption.getOrElse ("") + private def _is_package_option (s : String) : Boolean = + (s == package_option_1) || (s == package_option_2) } -case class AbstractDeclarationBlockTranslator_ () extends AbstractDeclarationBlockTranslator +case class TranslatorToScala_ () extends TranslatorToScala + +trait FileNamePair +{ + + def input_file_name : String + def output_file_name : String + +} +case class FileNamePair_ (input_file_name : String, output_file_name : String) extends FileNamePair diff --git a/translator/src/main/scala/soda/translator/io/Package.scala b/translator/src/main/scala/soda/translator/io/Package.scala index 70ffe4c3..f0b0e56f 100644 --- a/translator/src/main/scala/soda/translator/io/Package.scala +++ b/translator/src/main/scala/soda/translator/io/Package.scala @@ -8,44 +8,6 @@ package soda.translator.io trait Package -/** - * This class is used to scan files in a given directory. - */ - -trait DirectoryScanner -{ - - import java.io.File - - def get_all_files (start : File) : Seq [File] = - if ( start.isFile - ) Seq (start) - else _scan (Seq () ) (start.listFiles ().toSeq) - - import scala.annotation.tailrec - @tailrec final - private def _tailrec_scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = - if ( to_scan.isEmpty - ) found - else _tailrec_scan (found.+: (to_scan.head) ) (_get_files_to_scan (to_scan) ) - - private def _scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = - _tailrec_scan (found) (to_scan) - - private def _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = - if ( to_scan.isEmpty - ) to_scan - else _get_files_to_scan_with (to_scan.head) (to_scan.tail) - - private def _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = - if ( to_scan_head.isDirectory - ) to_scan_tail.++ (to_scan_head.listFiles () ) - else to_scan_tail - -} - -case class DirectoryScanner_ () extends DirectoryScanner - trait AbstractDirectoryProcessor { @@ -111,6 +73,45 @@ trait DirectoryProcessor case class DirectoryProcessor_ (start : String, process_soda_file : java.io.File => Boolean) extends DirectoryProcessor +/** + * This class is used to scan files in a given directory. + */ + +trait DirectoryScanner +{ + + import java.io.File + + def get_all_files (start : File) : Seq [File] = + if ( start.isFile + ) Seq (start) + else _scan (Seq () ) (start.listFiles ().toSeq) + + import scala.annotation.tailrec + @tailrec final + private def _tailrec_scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = + if ( to_scan.isEmpty + ) found + else _tailrec_scan (found.+: (to_scan.head) ) (_get_files_to_scan (to_scan) ) + + private def _scan (found : Seq [File] ) (to_scan : Seq [File] ) : Seq [File] = + _tailrec_scan (found) (to_scan) + + private def _get_files_to_scan (to_scan : Seq [File] ) : Seq [File] = + if ( to_scan.isEmpty + ) to_scan + else _get_files_to_scan_with (to_scan.head) (to_scan.tail) + + private def _get_files_to_scan_with (to_scan_head : File) (to_scan_tail : Seq [File] ) : Seq [File] = + if ( to_scan_head.isDirectory + ) to_scan_tail.++ (to_scan_head.listFiles () ) + else to_scan_tail + +} + +case class DirectoryScanner_ () extends DirectoryScanner + + trait LibraryDeployer { @@ -217,4 +218,3 @@ trait SimpleFileWriter case class SimpleFileWriter_ () extends SimpleFileWriter - diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index a59c34dd..d8db6963 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -7,6 +7,7 @@ package soda.translator.parser trait Package + trait BlockBuilder { @@ -75,6 +76,167 @@ trait CurrentAndNewCommentState case class CurrentAndNewCommentState_ (current_state : Boolean, new_comment_state : Boolean) extends CurrentAndNewCommentState +/** + * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. + */ + +trait BlockProcessor +{ + + def translator : soda.translator.block.BlockSequenceTranslator + + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.annotation.AnnotationFactory_ + + lazy val new_line = "\n" + + lazy val double_new_line = new_line + new_line + + lazy val translator_with_preprocessor = PreprocessorSequenceTranslator_ (translator) + + def translate (program : String) : String = + join_translated_blocks ( + translator_with_preprocessor.translate ( + split_blocks (program) + ) + ) + + def split_blocks (program : String) : Seq [AnnotatedBlock] = + program + .split (double_new_line) + .toIndexedSeq + .map ( paragraph => make_block (paragraph) ) + + def make_block (paragraph : String) : AnnotatedBlock = + AnnotationFactory_ ().annotate ( + BlockBuilder_ ().build ( + remove_empty_lines (paragraph.split (new_line).toIndexedSeq) + ) + ) + + def join_translated_blocks (blocks : Seq [AnnotatedBlock] ) : String = + blocks + .map ( x => x.contents) + .mkString (double_new_line) + new_line + + def remove_empty_lines (lines : Seq [String] ) : Seq [String] = + lines + .filter ( line => line.trim.nonEmpty) + +} + +case class BlockProcessor_ (translator : soda.translator.block.BlockSequenceTranslator) extends BlockProcessor + + +trait PreprocessorSequenceTranslator + extends + soda.translator.block.BlockSequenceTranslator +{ + + def translator : soda.translator.block.BlockSequenceTranslator + + import soda.lib.Fold_ + import soda.translator.block.AnnotatedLine_ + import soda.translator.block.AnnotatedBlock + import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.parser.annotation.AbstractDeclarationAnnotation + import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ + import soda.translator.parser.annotation.ClassBeginningAnnotation + import soda.translator.parser.annotation.ClassBeginningAnnotation_ + import soda.translator.parser.annotation.ClassEndAnnotation + import soda.translator.parser.annotation.ClassEndAnnotation_ + + lazy val block_annotator = AnnotationFactory_ () + + lazy val ba = soda.translator.block.BlockAnnotationEnum_ () + + lazy val sc = SodaConstant_ () + + private lazy val _fold = Fold_ () + + lazy val empty_line = AnnotatedLine_ ("", true) + + lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = + block_sequence => + translate_for (block_sequence) + + def translate_for (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + translator.translate ( + _get_second_pass ( + _get_first_pass (block_sequence) + ) + ) + + private def _get_first_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + block_sequence.map ( block => block_annotator.translate (block) ) + + private def _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = + _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) + .accumulated + .reverse + + private def _get_second_pass_initial_value (block_sequence : Seq [AnnotatedBlock] ) : AuxiliaryTuple = + AuxiliaryTuple_ ( + block_sequence = block_sequence, + accumulated = Seq [AnnotatedBlock] (), + references = Seq [Seq [AnnotatedBlock] ] () + ) + + private def _get_second_pass_next_value_function (current : AuxiliaryTuple) (index : Int) : AuxiliaryTuple = + _pass_next_step (current) (index) (_get_additional_information (current) (index) ) + + private def _get_additional_information (current : AuxiliaryTuple) (index : Int) : AnnotatedBlock = + current.block_sequence.apply (index) match { + case AbstractDeclarationAnnotation_ (block, references) => _get_abstract_declaration_updated_block (current) (AbstractDeclarationAnnotation_ (block, references) ) + case ClassEndAnnotation_ (block, references) => _get_class_end_updated_block (current) (ClassEndAnnotation_ (block, references) ) + case x => x + } + + private def _get_abstract_declaration_updated_block (current : AuxiliaryTuple) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = + AbstractDeclarationAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) + + private def _get_class_end_updated_block (current : AuxiliaryTuple) (block : ClassEndAnnotation) : ClassEndAnnotation = + ClassEndAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) + + private def _pass_next_step (current : AuxiliaryTuple) (index : Int) (updated_block : AnnotatedBlock ) : AuxiliaryTuple = + AuxiliaryTuple_ ( + block_sequence = current.block_sequence, + accumulated = current.accumulated.+: (updated_block), + references = _update_references (current) (index) + ) + + private def _update_references (current : AuxiliaryTuple) (index : Int) : Seq [Seq [AnnotatedBlock] ] = + current.block_sequence.apply (index) match { + case ClassBeginningAnnotation_ (b) => current.references.+: (Seq [AnnotatedBlock] (ClassBeginningAnnotation_ (b) ) ) + case AbstractDeclarationAnnotation_ (b, references) => _update_first_element (current.references) (AbstractDeclarationAnnotation_ (b, references) ) + case ClassEndAnnotation_ (b, references) => _tail_non_empty (current.references) + case x => current.references + } + + private def _update_first_element (s : Seq [Seq [AnnotatedBlock] ] ) (b : AnnotatedBlock) : Seq [Seq [AnnotatedBlock] ] = + _tail_non_empty (s).+: (s.headOption.getOrElse (Seq [AnnotatedBlock] () ).+: (b) ) + + private def _tail_non_empty [A] (s : Seq [A] ) : Seq [A] = + if ( s.isEmpty + ) s + else s.tail + +} + +case class PreprocessorSequenceTranslator_ (translator : soda.translator.block.BlockSequenceTranslator) extends PreprocessorSequenceTranslator + +trait AuxiliaryTuple +{ + + def block_sequence : Seq [soda.translator.block.AnnotatedBlock] + def accumulated : Seq [soda.translator.block.AnnotatedBlock] + def references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ] + +} + +case class AuxiliaryTuple_ (block_sequence : Seq [soda.translator.block.AnnotatedBlock], accumulated : Seq [soda.translator.block.AnnotatedBlock], references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ]) extends AuxiliaryTuple + + trait SodaConstant { @@ -241,165 +403,3 @@ trait SodaConstant case class SodaConstant_ () extends SodaConstant - -trait PreprocessorSequenceTranslator - extends - soda.translator.block.BlockSequenceTranslator -{ - - def translator : soda.translator.block.BlockSequenceTranslator - - import soda.lib.Fold_ - import soda.translator.block.AnnotatedLine_ - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.annotation.AnnotationFactory_ - import soda.translator.parser.annotation.AbstractDeclarationAnnotation - import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation - import soda.translator.parser.annotation.ClassBeginningAnnotation_ - import soda.translator.parser.annotation.ClassEndAnnotation - import soda.translator.parser.annotation.ClassEndAnnotation_ - - lazy val block_annotator = AnnotationFactory_ () - - lazy val ba = soda.translator.block.BlockAnnotationEnum_ () - - lazy val sc = SodaConstant_ () - - private lazy val _fold = Fold_ () - - lazy val empty_line = AnnotatedLine_ ("", true) - - lazy val translate : Seq [AnnotatedBlock] => Seq [AnnotatedBlock] = - block_sequence => - translate_for (block_sequence) - - def translate_for (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - translator.translate ( - _get_second_pass ( - _get_first_pass (block_sequence) - ) - ) - - private def _get_first_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - block_sequence.map ( block => block_annotator.translate (block) ) - - private def _get_second_pass (block_sequence : Seq [AnnotatedBlock] ) : Seq [AnnotatedBlock] = - _fold.apply (block_sequence.indices) (_get_second_pass_initial_value (block_sequence) ) (_get_second_pass_next_value_function) - .accumulated - .reverse - - private def _get_second_pass_initial_value (block_sequence : Seq [AnnotatedBlock] ) : AuxiliaryTuple = - AuxiliaryTuple_ ( - block_sequence = block_sequence, - accumulated = Seq [AnnotatedBlock] (), - references = Seq [Seq [AnnotatedBlock] ] () - ) - - private def _get_second_pass_next_value_function (current : AuxiliaryTuple) (index : Int) : AuxiliaryTuple = - _pass_next_step (current) (index) (_get_additional_information (current) (index) ) - - private def _get_additional_information (current : AuxiliaryTuple) (index : Int) : AnnotatedBlock = - current.block_sequence.apply (index) match { - case AbstractDeclarationAnnotation_ (block, references) => _get_abstract_declaration_updated_block (current) (AbstractDeclarationAnnotation_ (block, references) ) - case ClassEndAnnotation_ (block, references) => _get_class_end_updated_block (current) (ClassEndAnnotation_ (block, references) ) - case x => x - } - - private def _get_abstract_declaration_updated_block (current : AuxiliaryTuple) (block : AbstractDeclarationAnnotation) : AbstractDeclarationAnnotation = - AbstractDeclarationAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) - - private def _get_class_end_updated_block (current : AuxiliaryTuple) (block : ClassEndAnnotation) : ClassEndAnnotation = - ClassEndAnnotation_ (block.block, block.references.++ (current.references.headOption.getOrElse (Seq [AnnotatedBlock] () ) ) ) - - private def _pass_next_step (current : AuxiliaryTuple) (index : Int) (updated_block : AnnotatedBlock ) : AuxiliaryTuple = - AuxiliaryTuple_ ( - block_sequence = current.block_sequence, - accumulated = current.accumulated.+: (updated_block), - references = _update_references (current) (index) - ) - - private def _update_references (current : AuxiliaryTuple) (index : Int) : Seq [Seq [AnnotatedBlock] ] = - current.block_sequence.apply (index) match { - case ClassBeginningAnnotation_ (b) => current.references.+: (Seq [AnnotatedBlock] (ClassBeginningAnnotation_ (b) ) ) - case AbstractDeclarationAnnotation_ (b, references) => _update_first_element (current.references) (AbstractDeclarationAnnotation_ (b, references) ) - case ClassEndAnnotation_ (b, references) => _tail_non_empty (current.references) - case x => current.references - } - - private def _update_first_element (s : Seq [Seq [AnnotatedBlock] ] ) (b : AnnotatedBlock) : Seq [Seq [AnnotatedBlock] ] = - _tail_non_empty (s).+: (s.headOption.getOrElse (Seq [AnnotatedBlock] () ).+: (b) ) - - private def _tail_non_empty [A] (s : Seq [A] ) : Seq [A] = - if ( s.isEmpty - ) s - else s.tail - -} - -case class PreprocessorSequenceTranslator_ (translator : soda.translator.block.BlockSequenceTranslator) extends PreprocessorSequenceTranslator - -trait AuxiliaryTuple -{ - - def block_sequence : Seq [soda.translator.block.AnnotatedBlock] - def accumulated : Seq [soda.translator.block.AnnotatedBlock] - def references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ] - -} - -case class AuxiliaryTuple_ (block_sequence : Seq [soda.translator.block.AnnotatedBlock], accumulated : Seq [soda.translator.block.AnnotatedBlock], references : Seq [ Seq [soda.translator.block.AnnotatedBlock] ]) extends AuxiliaryTuple - - -/** - * An instance of this class splits a String in blocks, applies a translator to them, and joins them again in a String. - */ - -trait BlockProcessor -{ - - def translator : soda.translator.block.BlockSequenceTranslator - - import soda.translator.block.AnnotatedBlock - import soda.translator.parser.annotation.AnnotationFactory_ - - lazy val new_line = "\n" - - lazy val double_new_line = new_line + new_line - - lazy val translator_with_preprocessor = PreprocessorSequenceTranslator_ (translator) - - def translate (program : String) : String = - join_translated_blocks ( - translator_with_preprocessor.translate ( - split_blocks (program) - ) - ) - - def split_blocks (program : String) : Seq [AnnotatedBlock] = - program - .split (double_new_line) - .toIndexedSeq - .map ( paragraph => make_block (paragraph) ) - - def make_block (paragraph : String) : AnnotatedBlock = - AnnotationFactory_ ().annotate ( - BlockBuilder_ ().build ( - remove_empty_lines (paragraph.split (new_line).toIndexedSeq) - ) - ) - - def join_translated_blocks (blocks : Seq [AnnotatedBlock] ) : String = - blocks - .map ( x => x.contents) - .mkString (double_new_line) + new_line - - def remove_empty_lines (lines : Seq [String] ) : Seq [String] = - lines - .filter ( line => line.trim.nonEmpty) - -} - -case class BlockProcessor_ (translator : soda.translator.block.BlockSequenceTranslator) extends BlockProcessor - - diff --git a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala index 74f4d3dd..b0f9deb1 100644 --- a/translator/src/main/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/annotation/Package.scala @@ -5,147 +5,105 @@ package soda.translator.parser.annotation */ trait Package -trait ProofBlockAnnotation - extends - BlockAnnotationParser -{ - def block : soda.translator.block.Block - - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().proof_block - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) - -} - -case class ProofBlockAnnotation_ (block : soda.translator.block.Block) extends ProofBlockAnnotation - - -trait FunctionDefinitionAnnotation +trait AbstractDeclarationAnnotation extends BlockAnnotationParser { def block : soda.translator.block.Block + def references : Seq [soda.translator.block.AnnotatedBlock] + import soda.translator.block.AnnotatedLine import soda.translator.block.BlockAnnotationEnum_ import soda.translator.parser.SodaConstant_ - import soda.translator.replacement.ParserStateEnum_ - import soda.translator.replacement.Tokenizer_ - - lazy val identifier = BlockAnnotationEnum_ ().function_definition - lazy val sc = SodaConstant_ () - - private lazy val _symbol_at_the_end : String = - sc.space + - sc.function_definition_symbol - - private lazy val _symbol_in_the_middle : String = - sc.space + - sc.function_definition_symbol + - sc.space - - private lazy val _plain_state = ParserStateEnum_ ().plain + lazy val identifier = BlockAnnotationEnum_ ().abstract_declaration lazy val applies : Boolean = - ! is_a_theorem && - ! is_a_proof && - ! is_a_class_declaration && - (contains_the_equals_symbol || _starts_with_valid_annotation) - - lazy val contains_the_equals_symbol : Boolean = - block.readable_lines.nonEmpty && - block.readable_lines - .filter ( annotated_line => ! annotated_line.is_comment) - .exists ( annotated_line => _contains_the_equals_symbol_in_line (annotated_line.line) ) - - private def _contains_the_equals_symbol_in_line (line : String) : Boolean = - Tokenizer_ (line) - .tokens - .exists ( token => - token.parser_state == _plain_state && - _contains_the_equals_symbol_in_token (token.text) - ) - - private def _contains_the_equals_symbol_in_token (token_text : String) : Boolean = - ( - (token_text.contains (_symbol_in_the_middle) ) || - (token_text.endsWith (_symbol_at_the_end) ) - ) - - private lazy val _starts_with_valid_annotation : Boolean = block.readable_lines.nonEmpty && - _starts_with_valid_annotation_with (block.readable_lines.head.line.trim) - - private def _starts_with_valid_annotation_with (first_line_trimmed : String) : Boolean = - ( first_line_trimmed == sc.tail_recursion_annotation || - first_line_trimmed == sc.override_annotation ) - - lazy val is_a_class_declaration : Boolean = - starts_with_prefix_and_space (sc.class_reserved_word) + (block.readable_lines.head.line.trim == SodaConstant_ ().abstract_reserved_word) - lazy val is_a_theorem : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + lazy val abstract_functions_with_comments : Seq [AnnotatedLine] = + content_lines - lazy val is_a_proof : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) + lazy val abstract_functions : Seq [AnnotatedLine] = + abstract_functions_with_comments + .filter ( line => ! line.is_comment) } -case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation +case class AbstractDeclarationAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends AbstractDeclarationAnnotation -trait ImportDeclarationAnnotation +trait AnnotationFactory extends - BlockAnnotationParser + soda.translator.block.BlockTranslator { - def block : soda.translator.block.Block - - import soda.translator.block.AnnotatedLine + import soda.translator.block.AnnotatedBlock + import soda.translator.block.AnnotatedBlock_ + import soda.translator.block.Block import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - lazy val identifier = BlockAnnotationEnum_ ().import_declaration - - lazy val applies : Boolean = - block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().import_reserved_word) - - lazy val imported_items : Seq [AnnotatedLine] = - content_lines - -} - -case class ImportDeclarationAnnotation_ (block : soda.translator.block.Block) extends ImportDeclarationAnnotation + lazy val translate : AnnotatedBlock => AnnotatedBlock = + block => + translate_for (block) + def translate_for (block : AnnotatedBlock) : AnnotatedBlock = + if ( block.block_annotation == BlockAnnotationEnum_ ().undefined + ) annotate (block) + else block -trait PackageDeclarationAnnotation - extends - BlockAnnotationParser -{ + def annotate (block : Block) : AnnotatedBlock = + block match { + case AnnotatedBlock_ (annotated_lines, block_annotation) => AnnotatedBlock_ (annotated_lines, block_annotation) + case x => _get_first_or_undefined (_find_candidates (x) ) (x) + } - def block : soda.translator.block.Block + def update_block (original_content : AnnotatedBlock) (new_content : Block) : AnnotatedBlock = + original_content match { + case FunctionDefinitionAnnotation_ (b) => FunctionDefinitionAnnotation_ (new_content) + case ClassBeginningAnnotation_ (b) => ClassBeginningAnnotation_ (new_content) + case ClassEndAnnotation_ (b, references) => ClassEndAnnotation_ (new_content, references) + case AbstractDeclarationAnnotation_ (b, references) => AbstractDeclarationAnnotation_ (new_content, references) + case ImportDeclarationAnnotation_ (b) => ImportDeclarationAnnotation_ (new_content) + case PackageDeclarationAnnotation_ (b) => PackageDeclarationAnnotation_ (new_content) + case ClassAliasAnnotation_ (b) => ClassAliasAnnotation_ (new_content) + case TheoremBlockAnnotation_ (b) => TheoremBlockAnnotation_ (new_content) + case ProofBlockAnnotation_ (b) => ProofBlockAnnotation_ (new_content) + case CommentAnnotation_ (b) => CommentAnnotation_ (new_content) + case TestDeclarationAnnotation_ (b) => TestDeclarationAnnotation_ (new_content) + case x => AnnotatedBlock_ (new_content.annotated_lines, x.block_annotation) + } - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ + private def _detectors (block : Block) : Seq [BlockAnnotationParser] = + Seq ( + FunctionDefinitionAnnotation_ (block), + ClassBeginningAnnotation_ (block), + ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), + AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), + ImportDeclarationAnnotation_ (block), + PackageDeclarationAnnotation_ (block), + ClassAliasAnnotation_ (block), + TheoremBlockAnnotation_ (block), + ProofBlockAnnotation_ (block), + CommentAnnotation_ (block), + TestDeclarationAnnotation_ (block) + ) - lazy val identifier = BlockAnnotationEnum_ ().package_declaration + private def _find_candidates (block : Block) : Seq [BlockAnnotationParser] = + _detectors (block) + .filter ( detector => detector.applies) - lazy val applies : Boolean = - starts_with_prefix_and_space (SodaConstant_ ().package_reserved_word) + private def _get_first_or_undefined (candidates : Seq [BlockAnnotationParser] ) (block : Block) : AnnotatedBlock = + if ( candidates.length == 1 + ) candidates.head + else AnnotatedBlock_ (block.annotated_lines, BlockAnnotationEnum_ ().undefined ) } -case class PackageDeclarationAnnotation_ (block : soda.translator.block.Block) extends PackageDeclarationAnnotation +case class AnnotationFactory_ () extends AnnotationFactory trait BlockAnnotationParser @@ -208,6 +166,32 @@ trait BlockAnnotationParser case class BlockAnnotationParser_ (block : soda.translator.block.Block, applies : Boolean, identifier : soda.translator.block.BlockAnnotationId) extends BlockAnnotationParser +trait ClassAliasAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().class_alias + + lazy val sc = SodaConstant_ () + + lazy val applies : Boolean = + starts_with_prefix_and_space (sc.class_reserved_word) && + _contains_the_equals_symbol + + private lazy val _contains_the_equals_symbol : Boolean = + FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol + +} + +case class ClassAliasAnnotation_ (block : soda.translator.block.Block) extends ClassAliasAnnotation + + trait ClassBeginningAnnotation extends BlockAnnotationParser @@ -265,7 +249,7 @@ trait ClassBeginningAnnotation case class ClassBeginningAnnotation_ (block : soda.translator.block.Block) extends ClassBeginningAnnotation -trait AbstractDeclarationAnnotation +trait ClassEndAnnotation extends BlockAnnotationParser { @@ -273,29 +257,21 @@ trait AbstractDeclarationAnnotation def block : soda.translator.block.Block def references : Seq [soda.translator.block.AnnotatedBlock] - import soda.translator.block.AnnotatedLine import soda.translator.block.BlockAnnotationEnum_ import soda.translator.parser.SodaConstant_ - lazy val identifier = BlockAnnotationEnum_ ().abstract_declaration + lazy val identifier = BlockAnnotationEnum_ ().class_end lazy val applies : Boolean = block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().abstract_reserved_word) - - lazy val abstract_functions_with_comments : Seq [AnnotatedLine] = - content_lines - - lazy val abstract_functions : Seq [AnnotatedLine] = - abstract_functions_with_comments - .filter ( line => ! line.is_comment) + (block.readable_lines.head.line.trim == SodaConstant_ ().class_end_reserved_word) } -case class AbstractDeclarationAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends AbstractDeclarationAnnotation +case class ClassEndAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends ClassEndAnnotation -trait ClassAliasAnnotation +trait CommentAnnotation extends BlockAnnotationParser { @@ -303,116 +279,122 @@ trait ClassAliasAnnotation def block : soda.translator.block.Block import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.parser.SodaConstant_ - - lazy val identifier = BlockAnnotationEnum_ ().class_alias - lazy val sc = SodaConstant_ () + lazy val identifier = BlockAnnotationEnum_ ().comment lazy val applies : Boolean = - starts_with_prefix_and_space (sc.class_reserved_word) && - _contains_the_equals_symbol - - private lazy val _contains_the_equals_symbol : Boolean = - FunctionDefinitionAnnotation_ (block).contains_the_equals_symbol + block + .annotated_lines + .forall ( annotated_line => annotated_line.is_comment) } -case class ClassAliasAnnotation_ (block : soda.translator.block.Block) extends ClassAliasAnnotation +case class CommentAnnotation_ (block : soda.translator.block.Block) extends CommentAnnotation -trait AnnotationFactory +trait FunctionDefinitionAnnotation extends - soda.translator.block.BlockTranslator + BlockAnnotationParser { - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedBlock_ - import soda.translator.block.Block + def block : soda.translator.block.Block + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + import soda.translator.replacement.ParserStateEnum_ + import soda.translator.replacement.Tokenizer_ - lazy val translate : AnnotatedBlock => AnnotatedBlock = - block => - translate_for (block) + lazy val identifier = BlockAnnotationEnum_ ().function_definition - def translate_for (block : AnnotatedBlock) : AnnotatedBlock = - if ( block.block_annotation == BlockAnnotationEnum_ ().undefined - ) annotate (block) - else block + lazy val sc = SodaConstant_ () - def annotate (block : Block) : AnnotatedBlock = - block match { - case AnnotatedBlock_ (annotated_lines, block_annotation) => AnnotatedBlock_ (annotated_lines, block_annotation) - case x => _get_first_or_undefined (_find_candidates (x) ) (x) - } + private lazy val _symbol_at_the_end : String = + sc.space + + sc.function_definition_symbol - def update_block (original_content : AnnotatedBlock) (new_content : Block) : AnnotatedBlock = - original_content match { - case FunctionDefinitionAnnotation_ (b) => FunctionDefinitionAnnotation_ (new_content) - case ClassBeginningAnnotation_ (b) => ClassBeginningAnnotation_ (new_content) - case ClassEndAnnotation_ (b, references) => ClassEndAnnotation_ (new_content, references) - case AbstractDeclarationAnnotation_ (b, references) => AbstractDeclarationAnnotation_ (new_content, references) - case ImportDeclarationAnnotation_ (b) => ImportDeclarationAnnotation_ (new_content) - case PackageDeclarationAnnotation_ (b) => PackageDeclarationAnnotation_ (new_content) - case ClassAliasAnnotation_ (b) => ClassAliasAnnotation_ (new_content) - case TheoremBlockAnnotation_ (b) => TheoremBlockAnnotation_ (new_content) - case ProofBlockAnnotation_ (b) => ProofBlockAnnotation_ (new_content) - case CommentAnnotation_ (b) => CommentAnnotation_ (new_content) - case TestDeclarationAnnotation_ (b) => TestDeclarationAnnotation_ (new_content) - case x => AnnotatedBlock_ (new_content.annotated_lines, x.block_annotation) - } + private lazy val _symbol_in_the_middle : String = + sc.space + + sc.function_definition_symbol + + sc.space - private def _detectors (block : Block) : Seq [BlockAnnotationParser] = - Seq ( - FunctionDefinitionAnnotation_ (block), - ClassBeginningAnnotation_ (block), - ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), - AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), - ImportDeclarationAnnotation_ (block), - PackageDeclarationAnnotation_ (block), - ClassAliasAnnotation_ (block), - TheoremBlockAnnotation_ (block), - ProofBlockAnnotation_ (block), - CommentAnnotation_ (block), - TestDeclarationAnnotation_ (block) + private lazy val _plain_state = ParserStateEnum_ ().plain + + lazy val applies : Boolean = + ! is_a_theorem && + ! is_a_proof && + ! is_a_class_declaration && + (contains_the_equals_symbol || _starts_with_valid_annotation) + + lazy val contains_the_equals_symbol : Boolean = + block.readable_lines.nonEmpty && + block.readable_lines + .filter ( annotated_line => ! annotated_line.is_comment) + .exists ( annotated_line => _contains_the_equals_symbol_in_line (annotated_line.line) ) + + private def _contains_the_equals_symbol_in_line (line : String) : Boolean = + Tokenizer_ (line) + .tokens + .exists ( token => + token.parser_state == _plain_state && + _contains_the_equals_symbol_in_token (token.text) + ) + + private def _contains_the_equals_symbol_in_token (token_text : String) : Boolean = + ( + (token_text.contains (_symbol_in_the_middle) ) || + (token_text.endsWith (_symbol_at_the_end) ) ) - private def _find_candidates (block : Block) : Seq [BlockAnnotationParser] = - _detectors (block) - .filter ( detector => detector.applies) + private lazy val _starts_with_valid_annotation : Boolean = + block.readable_lines.nonEmpty && + _starts_with_valid_annotation_with (block.readable_lines.head.line.trim) - private def _get_first_or_undefined (candidates : Seq [BlockAnnotationParser] ) (block : Block) : AnnotatedBlock = - if ( candidates.length == 1 - ) candidates.head - else AnnotatedBlock_ (block.annotated_lines, BlockAnnotationEnum_ ().undefined ) + private def _starts_with_valid_annotation_with (first_line_trimmed : String) : Boolean = + ( first_line_trimmed == sc.tail_recursion_annotation || + first_line_trimmed == sc.override_annotation ) + + lazy val is_a_class_declaration : Boolean = + starts_with_prefix_and_space (sc.class_reserved_word) + + lazy val is_a_theorem : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().theorem_reserved_word) + + lazy val is_a_proof : Boolean = + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) } -case class AnnotationFactory_ () extends AnnotationFactory +case class FunctionDefinitionAnnotation_ (block : soda.translator.block.Block) extends FunctionDefinitionAnnotation -trait CommentAnnotation +trait ImportDeclarationAnnotation extends BlockAnnotationParser { def block : soda.translator.block.Block + import soda.translator.block.AnnotatedLine import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ - lazy val identifier = BlockAnnotationEnum_ ().comment + lazy val identifier = BlockAnnotationEnum_ ().import_declaration lazy val applies : Boolean = - block - .annotated_lines - .forall ( annotated_line => annotated_line.is_comment) + block.readable_lines.nonEmpty && + (block.readable_lines.head.line.trim == SodaConstant_ ().import_reserved_word) + + lazy val imported_items : Seq [AnnotatedLine] = + content_lines } -case class CommentAnnotation_ (block : soda.translator.block.Block) extends CommentAnnotation +case class ImportDeclarationAnnotation_ (block : soda.translator.block.Block) extends ImportDeclarationAnnotation -trait TestDeclarationAnnotation +trait PackageDeclarationAnnotation extends BlockAnnotationParser { @@ -422,36 +404,55 @@ trait TestDeclarationAnnotation import soda.translator.block.BlockAnnotationEnum_ import soda.translator.parser.SodaConstant_ - lazy val identifier = BlockAnnotationEnum_ ().test_declaration + lazy val identifier = BlockAnnotationEnum_ ().package_declaration lazy val applies : Boolean = - starts_with_prefix_and_space (SodaConstant_ ().test_special_function) + starts_with_prefix_and_space (SodaConstant_ ().package_reserved_word) } -case class TestDeclarationAnnotation_ (block : soda.translator.block.Block) extends TestDeclarationAnnotation +case class PackageDeclarationAnnotation_ (block : soda.translator.block.Block) extends PackageDeclarationAnnotation -trait ClassEndAnnotation +trait ProofBlockAnnotation extends BlockAnnotationParser { def block : soda.translator.block.Block - def references : Seq [soda.translator.block.AnnotatedBlock] import soda.translator.block.BlockAnnotationEnum_ import soda.translator.parser.SodaConstant_ - lazy val identifier = BlockAnnotationEnum_ ().class_end + lazy val identifier = BlockAnnotationEnum_ ().proof_block lazy val applies : Boolean = block.readable_lines.nonEmpty && - (block.readable_lines.head.line.trim == SodaConstant_ ().class_end_reserved_word) + (block.readable_lines.head.line.trim == SodaConstant_ ().proof_reserved_word) } -case class ClassEndAnnotation_ (block : soda.translator.block.Block, references : Seq [soda.translator.block.AnnotatedBlock]) extends ClassEndAnnotation +case class ProofBlockAnnotation_ (block : soda.translator.block.Block) extends ProofBlockAnnotation + + +trait TestDeclarationAnnotation + extends + BlockAnnotationParser +{ + + def block : soda.translator.block.Block + + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.parser.SodaConstant_ + + lazy val identifier = BlockAnnotationEnum_ ().test_declaration + + lazy val applies : Boolean = + starts_with_prefix_and_space (SodaConstant_ ().test_special_function) + +} + +case class TestDeclarationAnnotation_ (block : soda.translator.block.Block) extends TestDeclarationAnnotation trait TheoremBlockAnnotation @@ -474,4 +475,3 @@ trait TheoremBlockAnnotation case class TheoremBlockAnnotation_ (block : soda.translator.block.Block) extends TheoremBlockAnnotation - diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index f29b6648..a4860274 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -8,102 +8,181 @@ package soda.translator.replacement trait Package + /** - * A token is a piece of code, that can contain one or more words combined with symbols. + * This is to classify characters. */ -trait Token +trait CharType + extends + soda.lib.EnumConstant { - def text : String - def parser_state : ParserState - def index : Int + def ordinal : Int + def name : String } -case class Token_ (text : String, parser_state : ParserState, index : Int) extends Token +case class CharType_ (ordinal : Int, name : String) extends CharType /** - * This class processes a line to divide it into tokens. + * This is an enumeration for all types of characters. */ -trait Tokenizer +trait CharTypeEnum extends - soda.translator.block.SingleLineProcessor + soda.lib.Enum [CharType] { - def line : String + lazy val undefined_type = CharType_ (0, "undefined_type") - import soda.lib.Fold_ - import soda.lib.Range_ + lazy val quotes_type = CharType_ (1, "quotes_type") - private lazy val _fold = Fold_ () + lazy val apostrophe_type = CharType_ (2, "apostrophe_type") - private lazy val _range = Range_ () + lazy val backslash_type = CharType_ (3, "backslash_type") - lazy val tokens : Seq [Token] = - _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) + lazy val plain_type = CharType_ (4, "plain_type") - private lazy val _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) + lazy val values = Seq (undefined_type, quotes_type, apostrophe_type, backslash_type, plain_type) - private def _postprocess (tuple : TokenizerFoldTuple) : Seq [Token] = - (tuple.rev_tokens.+: (Token_ (line.substring (tuple.last_index), tuple.parser_state, tuple.last_index) ) ) - .reverse + lazy val backslash_char = '\\' - private def _next_value_function (tuple : TokenizerFoldTuple) (current_index : Int) : TokenizerFoldTuple = - _new_value_function_with (tuple) (current_index) (_new_parser_state (tuple) (current_index) ) + lazy val quotes_char = '\"' - private def _new_value_function_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = - if ( ParserStateEnum_ ().is_same_class (new_parser_state) (tuple.parser_state) - ) TokenizerFoldTuple_ (tuple.last_index, new_parser_state, tuple.rev_tokens) - else _next_value_function_of_different_class (tuple) (current_index) (new_parser_state) + lazy val apostrophe_char = '\'' - private def _new_parser_state (tuple : TokenizerFoldTuple) (current_index : Int) : ParserState = - ParserTransition_ () - .next_parser_state ( - tuple.parser_state) ( - CharTypeEnum_ ().get_char_type (line.charAt (current_index) ) - ) + lazy val underscore_char = '_' - private def _next_value_function_of_different_class (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = - _next_value_function_of_different_class_with ( - tuple) ( - current_index) ( - new_parser_state) ( - _get_new_current_index (tuple) (current_index) + lazy val symbol_chars : Seq [Char] = + Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + + lazy val simple_char_type_map : Map [Char , CharType] = + Map ( + Tuple2 ( quotes_char , quotes_type ), + Tuple2 ( apostrophe_char , apostrophe_type ), + Tuple2 ( backslash_char, backslash_type ) ) - private def _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = - if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || - tuple.parser_state == ParserStateEnum_ ().apostrophe_state - ) current_index + 1 - else current_index + def get_char_type (ch : Char) : CharType = + simple_char_type_map + .getOrElse (ch, _get_char_type_if_plain (ch) ) - private def _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = - TokenizerFoldTuple_ (index, new_parser_state, - tuple.rev_tokens.+: ( - Token_ ( - line.substring (tuple.last_index, index), - tuple.parser_state, - tuple.last_index - ) - ) - ) + private def _get_char_type_if_plain (ch : Char) : CharType = + if ( _is_plain (ch) + ) plain_type + else undefined_type + + private def _is_plain (ch : Char) : Boolean = + _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) + + private def _is_whitespace (ch : Char) : Boolean = + ch.isWhitespace + + private def _is_letter_or_digit_or_underscore (ch : Char) : Boolean = + ch.isLetterOrDigit || ch == underscore_char + + private def _is_symbol (ch : Char) : Boolean = + symbol_chars.contains (ch) } -case class Tokenizer_ (line : String) extends Tokenizer +case class CharTypeEnum_ () extends CharTypeEnum -trait TokenizerFoldTuple + +/** + * This models all the possible states that the parser can be. + */ + +trait ParserState + extends + soda.lib.EnumConstant { - def last_index : Int - def parser_state : ParserState - def rev_tokens : Seq [Token] + def ordinal : Int + def name : String } -case class TokenizerFoldTuple_ (last_index : Int, parser_state : ParserState, rev_tokens : Seq [Token]) extends TokenizerFoldTuple +case class ParserState_ (ordinal : Int, name : String) extends ParserState + +/** + * This is an enumeration of all the parser states. + */ + +trait ParserStateEnum + extends + soda.lib.Enum [ParserState] +{ + + lazy val undefined_state = ParserState_ (0, "undefined_state") + + lazy val quotes_state = ParserState_ (1, "quotes_state") + + lazy val apostrophe_state = ParserState_ (2, "apostrophe_state") + + lazy val quotes_backslash_state = ParserState_ (3, "quotes_backslash_state") + + lazy val apostrophe_backslash_state = ParserState_ (4, "apostrophe_backslash_state") + + lazy val plain = ParserState_ (5, "plain") + + lazy val values = Seq (undefined_state, quotes_state, apostrophe_state, quotes_backslash_state, apostrophe_backslash_state, plain) + + def is_same_class (x : ParserState) (y : ParserState) : Boolean = + (x == y) || _is_like (x) (y) || _is_like (y) (x) + + private def _is_like (x : ParserState) (y : ParserState) : Boolean = + (x == quotes_state && y == quotes_backslash_state) || + (x == apostrophe_state && y == apostrophe_backslash_state) + +} + +case class ParserStateEnum_ () extends ParserStateEnum + +trait ParserTransition +{ + + lazy val ps = ParserStateEnum_ () + + lazy val ct = CharTypeEnum_ () + + lazy val transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = + Map ( + /* */ + Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), + Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), + /* */ + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), + Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), + /* */ + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), + /* */ + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), + /* */ + Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), + Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), + Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), + Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), + Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) + ) + + def next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = + transitions_that_change_states.getOrElse ( Tuple2 (parser_state, char_type), parser_state) + +} + +case class ParserTransition_ () extends ParserTransition /** @@ -335,178 +414,99 @@ case class ReplacerFoldTuple_ (replaced_text_rev : Seq [String], start_index : I /** - * This is to classify characters. + * A token is a piece of code, that can contain one or more words combined with symbols. */ -trait CharType - extends - soda.lib.EnumConstant +trait Token { - def ordinal : Int - def name : String + def text : String + def parser_state : ParserState + def index : Int } -case class CharType_ (ordinal : Int, name : String) extends CharType +case class Token_ (text : String, parser_state : ParserState, index : Int) extends Token /** - * This is an enumeration for all types of characters. + * This class processes a line to divide it into tokens. */ -trait CharTypeEnum +trait Tokenizer extends - soda.lib.Enum [CharType] + soda.translator.block.SingleLineProcessor { - lazy val undefined_type = CharType_ (0, "undefined_type") - - lazy val quotes_type = CharType_ (1, "quotes_type") + def line : String - lazy val apostrophe_type = CharType_ (2, "apostrophe_type") + import soda.lib.Fold_ + import soda.lib.Range_ - lazy val backslash_type = CharType_ (3, "backslash_type") + private lazy val _fold = Fold_ () - lazy val plain_type = CharType_ (4, "plain_type") + private lazy val _range = Range_ () - lazy val values = Seq (undefined_type, quotes_type, apostrophe_type, backslash_type, plain_type) + lazy val tokens : Seq [Token] = + _postprocess (_fold.apply (_range.apply (line.length) ) (_initial_value) (_next_value_function) ) - lazy val backslash_char = '\\' + private lazy val _initial_value : TokenizerFoldTuple = TokenizerFoldTuple_ (0, ParserStateEnum_ ().plain, Seq () ) - lazy val quotes_char = '\"' + private def _postprocess (tuple : TokenizerFoldTuple) : Seq [Token] = + (tuple.rev_tokens.+: (Token_ (line.substring (tuple.last_index), tuple.parser_state, tuple.last_index) ) ) + .reverse - lazy val apostrophe_char = '\'' + private def _next_value_function (tuple : TokenizerFoldTuple) (current_index : Int) : TokenizerFoldTuple = + _new_value_function_with (tuple) (current_index) (_new_parser_state (tuple) (current_index) ) - lazy val underscore_char = '_' + private def _new_value_function_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = + if ( ParserStateEnum_ ().is_same_class (new_parser_state) (tuple.parser_state) + ) TokenizerFoldTuple_ (tuple.last_index, new_parser_state, tuple.rev_tokens) + else _next_value_function_of_different_class (tuple) (current_index) (new_parser_state) - lazy val symbol_chars : Seq [Char] = - Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') + private def _new_parser_state (tuple : TokenizerFoldTuple) (current_index : Int) : ParserState = + ParserTransition_ () + .next_parser_state ( + tuple.parser_state) ( + CharTypeEnum_ ().get_char_type (line.charAt (current_index) ) + ) - lazy val simple_char_type_map : Map [Char , CharType] = - Map ( - Tuple2 ( quotes_char , quotes_type ), - Tuple2 ( apostrophe_char , apostrophe_type ), - Tuple2 ( backslash_char, backslash_type ) + private def _next_value_function_of_different_class (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) : TokenizerFoldTuple = + _next_value_function_of_different_class_with ( + tuple) ( + current_index) ( + new_parser_state) ( + _get_new_current_index (tuple) (current_index) ) - def get_char_type (ch : Char) : CharType = - simple_char_type_map - .getOrElse (ch, _get_char_type_if_plain (ch) ) - - private def _get_char_type_if_plain (ch : Char) : CharType = - if ( _is_plain (ch) - ) plain_type - else undefined_type - - private def _is_plain (ch : Char) : Boolean = - _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) - - private def _is_whitespace (ch : Char) : Boolean = - ch.isWhitespace - - private def _is_letter_or_digit_or_underscore (ch : Char) : Boolean = - ch.isLetterOrDigit || ch == underscore_char - - private def _is_symbol (ch : Char) : Boolean = - symbol_chars.contains (ch) - -} - -case class CharTypeEnum_ () extends CharTypeEnum - - -/** - * This models all the possible states that the parser can be. - */ - -trait ParserState - extends - soda.lib.EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class ParserState_ (ordinal : Int, name : String) extends ParserState - -/** - * This is an enumeration of all the parser states. - */ - -trait ParserStateEnum - extends - soda.lib.Enum [ParserState] -{ - - lazy val undefined_state = ParserState_ (0, "undefined_state") - - lazy val quotes_state = ParserState_ (1, "quotes_state") - - lazy val apostrophe_state = ParserState_ (2, "apostrophe_state") - - lazy val quotes_backslash_state = ParserState_ (3, "quotes_backslash_state") - - lazy val apostrophe_backslash_state = ParserState_ (4, "apostrophe_backslash_state") - - lazy val plain = ParserState_ (5, "plain") - - lazy val values = Seq (undefined_state, quotes_state, apostrophe_state, quotes_backslash_state, apostrophe_backslash_state, plain) - - def is_same_class (x : ParserState) (y : ParserState) : Boolean = - (x == y) || _is_like (x) (y) || _is_like (y) (x) + private def _get_new_current_index (tuple : TokenizerFoldTuple) (current_index : Int) : Int = + if ( tuple.parser_state == ParserStateEnum_ ().quotes_state || + tuple.parser_state == ParserStateEnum_ ().apostrophe_state + ) current_index + 1 + else current_index - private def _is_like (x : ParserState) (y : ParserState) : Boolean = - (x == quotes_state && y == quotes_backslash_state) || - (x == apostrophe_state && y == apostrophe_backslash_state) + private def _next_value_function_of_different_class_with (tuple : TokenizerFoldTuple) (current_index : Int) (new_parser_state : ParserState) (index : Int) : TokenizerFoldTuple = + TokenizerFoldTuple_ (index, new_parser_state, + tuple.rev_tokens.+: ( + Token_ ( + line.substring (tuple.last_index, index), + tuple.parser_state, + tuple.last_index + ) + ) + ) } -case class ParserStateEnum_ () extends ParserStateEnum +case class Tokenizer_ (line : String) extends Tokenizer -trait ParserTransition +trait TokenizerFoldTuple { - lazy val ps = ParserStateEnum_ () - - lazy val ct = CharTypeEnum_ () - - lazy val transitions_that_change_states : Map [ Tuple2 [ParserState, CharType], ParserState] = - Map ( - /* */ - Tuple2 ( Tuple2 (ps.quotes_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.quotes_state, ct.quotes_type), ps.plain), - Tuple2 ( Tuple2 (ps.quotes_state, ct.backslash_type), ps.quotes_backslash_state), - /* */ - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.apostrophe_type), ps.plain), - Tuple2 ( Tuple2 (ps.apostrophe_state, ct.backslash_type), ps.apostrophe_backslash_state), - /* */ - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.quotes_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.apostrophe_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.backslash_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.quotes_backslash_state, ct.plain_type), ps.quotes_state), - /* */ - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.quotes_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.apostrophe_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.backslash_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.apostrophe_backslash_state, ct.plain_type), ps.apostrophe_state), - /* */ - Tuple2 ( Tuple2 (ps.plain, ct.undefined_type), ps.undefined_state), - Tuple2 ( Tuple2 (ps.plain, ct.quotes_type), ps.quotes_state), - Tuple2 ( Tuple2 (ps.plain, ct.apostrophe_type), ps.apostrophe_state), - Tuple2 ( Tuple2 (ps.plain, ct.backslash_type), ps.plain), - Tuple2 ( Tuple2 (ps.plain, ct.plain_type), ps.plain) - ) - - def next_parser_state (parser_state : ParserState) (char_type : CharType) : ParserState = - transitions_that_change_states.getOrElse ( Tuple2 (parser_state, char_type), parser_state) + def last_index : Int + def parser_state : ParserState + def rev_tokens : Seq [Token] } -case class ParserTransition_ () extends ParserTransition - +case class TokenizerFoldTuple_ (last_index : Int, parser_state : ParserState, rev_tokens : Seq [Token]) extends TokenizerFoldTuple diff --git a/translator/src/test/resources/soda/example/Package.scala b/translator/src/test/resources/soda/example/Package.scala index c13885b1..91a014c7 100644 --- a/translator/src/test/resources/soda/example/Package.scala +++ b/translator/src/test/resources/soda/example/Package.scala @@ -4,9 +4,9 @@ package soda.example * This package is just a minimal example. */ trait Package + case class Example() { } - diff --git a/translator/src/test/resources/soda/example/otherexample/Package.scala b/translator/src/test/resources/soda/example/otherexample/Package.scala index fe43d823..e4144433 100644 --- a/translator/src/test/resources/soda/example/otherexample/Package.scala +++ b/translator/src/test/resources/soda/example/otherexample/Package.scala @@ -5,9 +5,9 @@ package soda.example.otherexample */ trait Package + case class OtherExample() { } - diff --git a/translator/src/test/scala/soda/lib/Package.scala b/translator/src/test/scala/soda/lib/Package.scala index 19815933..8dc829c0 100644 --- a/translator/src/test/scala/soda/lib/Package.scala +++ b/translator/src/test/scala/soda/lib/Package.scala @@ -5,6 +5,145 @@ package soda.lib */ trait Package + +case class CartesianProductSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val int_seq_a = Seq (10, 20) + + lazy val int_seq_b = Seq (100, 200, 300) + + lazy val str_seq_a = Seq ("A", "B") + + lazy val str_seq_b = Seq ("0", "1", "2") + + lazy val str_seq_c = Seq ("a", "b", "c", "d") + + lazy val instance = CartesianProduct_ () + + test ("Cartesian product of two sequences") ( + check ( + obtained = instance.apply (Seq (int_seq_a, int_seq_b) ) + ) ( + expected = Seq ( + Seq (10, 100), Seq (10, 200), Seq (10, 300), + Seq (20, 100), Seq (20, 200), Seq (20, 300) + ) + ) + ) + + test ("Cartesian product of an empty sequence") ( + check ( + obtained = instance.apply (Seq () ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product of only empty sequences") ( + check ( + obtained = instance.apply (Seq (Seq (), Seq (), Seq () ) ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product with at least one empty sequence") ( + check ( + obtained = instance.apply (Seq (Seq ("A"), Seq () ) ) + ) ( + expected = Seq () + ) + ) + + test ("Cartesian product of three sequences") ( + check ( + obtained = instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) + ) ( + expected = Seq ( + Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), + Seq ("A", "1", "a"), Seq ("A", "1", "b"), Seq ("A", "1", "c"), Seq ("A", "1", "d"), + Seq ("A", "2", "a"), Seq ("A", "2", "b"), Seq ("A", "2", "c"), Seq ("A", "2", "d"), + Seq ("B", "0", "a"), Seq ("B", "0", "b"), Seq ("B", "0", "c"), Seq ("B", "0", "d"), + Seq ("B", "1", "a"), Seq ("B", "1", "b"), Seq ("B", "1", "c"), Seq ("B", "1", "d"), + Seq ("B", "2", "a"), Seq ("B", "2", "b"), Seq ("B", "2", "c"), Seq ("B", "2", "d") + ) + ) + ) + +} + + +trait DayOfTheWeek + extends + EnumConstant +{ + + def ordinal : Int + def name : String + +} + +case class DayOfTheWeek_ (ordinal : Int, name : String) extends DayOfTheWeek + +trait DayOfTheWeekConstant +{ + + lazy val sunday = DayOfTheWeek_ (0, "Sunday") + + lazy val monday = DayOfTheWeek_ (1, "Monday") + + lazy val tuesday = DayOfTheWeek_ (2, "Tuesday") + + lazy val wednesday = DayOfTheWeek_ (3, "Wednesday") + + lazy val thursday = DayOfTheWeek_ (4, "Thursday") + + lazy val friday = DayOfTheWeek_ (5, "Friday") + + lazy val saturday = DayOfTheWeek_ (6, "Saturday") + + lazy val DayOfTheWeek_values = Seq (sunday, monday, tuesday, wednesday, thursday, friday, saturday) + +} + +case class DayOfTheWeekConstant_ () extends DayOfTheWeekConstant + +trait DayOfTheWeekEnum + extends + DayOfTheWeekConstant +{ + + lazy val values = DayOfTheWeek_values + +} + +case class DayOfTheWeekEnum_ () extends DayOfTheWeekEnum + +case class EnumSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("the names of the elements in enumerations") ( + check ( + obtained = DayOfTheWeekEnum_ ().values.map ( x => x.toString) + ) ( + expected = Seq ("DayOfTheWeek_(0,Sunday)", "DayOfTheWeek_(1,Monday)", "DayOfTheWeek_(2,Tuesday)", "DayOfTheWeek_(3,Wednesday)", "DayOfTheWeek_(4,Thursday)", "DayOfTheWeek_(5,Friday)", "DayOfTheWeek_(6,Saturday)") + ) + ) + +} + + case class OptionSDSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -221,7 +360,7 @@ case class OptionSDSpec () } -case class CartesianProductSpec () +case class RecursionSpec () extends org.scalatest.funsuite.AnyFunSuite { @@ -229,65 +368,64 @@ case class CartesianProductSpec () def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val int_seq_a = Seq (10, 20) - - lazy val int_seq_b = Seq (100, 200, 300) - - lazy val str_seq_a = Seq ("A", "B") + lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) - lazy val str_seq_b = Seq ("0", "1", "2") + private lazy val _fold_while = FoldWhile_ () - lazy val str_seq_c = Seq ("a", "b", "c", "d") + private lazy val _fold = Fold_ () - lazy val instance = CartesianProduct_ () + private lazy val _range = Range_ () - test ("Cartesian product of two sequences") ( + test ("fold left while with Seq") ( check ( - obtained = instance.apply (Seq (int_seq_a, int_seq_b) ) + obtained = _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) ) ( - expected = Seq ( - Seq (10, 100), Seq (10, 200), Seq (10, 300), - Seq (20, 100), Seq (20, 200), Seq (20, 300) - ) + expected = Seq ("103", "102", "101", "101", "100") ) ) - test ("Cartesian product of an empty sequence") ( + private lazy val _fold0_initial_value = Seq [String] () + + private lazy val _fold0_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String]) => (e : Int) => (s.+: ("" + (e + 100) ) ) + + private lazy val _fold0_condition : Seq [String] => Int => Boolean = + (s : Seq [String] ) => (e : Int) => (e < 5) + + test ("fold left with Seq") ( check ( - obtained = instance.apply (Seq () ) + obtained = _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) ) ( - expected = Seq () + expected = Seq ("108", "105", "103", "102", "101", "101", "100") ) ) - test ("Cartesian product of only empty sequences") ( + private lazy val _fold1_initial_value = Seq [String] () + + private lazy val _fold1_next_value_function : Seq [String] => Int => Seq [String] = + (s : Seq [String] ) => (e : Int) => (s.+: ("" + (e + 100) ) ) + + test ("range with positive number") ( check ( - obtained = instance.apply (Seq (Seq (), Seq (), Seq () ) ) + obtained = _range.apply (8) ) ( - expected = Seq () + expected = Seq (0, 1, 2, 3, 4, 5, 6, 7) ) ) - test ("Cartesian product with at least one empty sequence") ( + test ("range with zero size") ( check ( - obtained = instance.apply (Seq (Seq ("A"), Seq () ) ) + obtained = _range.apply (-1) ) ( expected = Seq () ) ) - test ("Cartesian product of three sequences") ( + test ("range with negative number") ( check ( - obtained = instance.apply (Seq (str_seq_a, str_seq_b, str_seq_c) ) + obtained = _range.apply (-1) ) ( - expected = Seq ( - Seq ("A", "0", "a"), Seq ("A", "0", "b"), Seq ("A", "0", "c"), Seq ("A", "0", "d"), - Seq ("A", "1", "a"), Seq ("A", "1", "b"), Seq ("A", "1", "c"), Seq ("A", "1", "d"), - Seq ("A", "2", "a"), Seq ("A", "2", "b"), Seq ("A", "2", "c"), Seq ("A", "2", "d"), - Seq ("B", "0", "a"), Seq ("B", "0", "b"), Seq ("B", "0", "c"), Seq ("B", "0", "d"), - Seq ("B", "1", "a"), Seq ("B", "1", "b"), Seq ("B", "1", "c"), Seq ("B", "1", "d"), - Seq ("B", "2", "a"), Seq ("B", "2", "b"), Seq ("B", "2", "c"), Seq ("B", "2", "d") - ) + expected = Seq () ) ) @@ -364,141 +502,3 @@ case class SeqSDSpec () } - -trait DayOfTheWeek - extends - EnumConstant -{ - - def ordinal : Int - def name : String - -} - -case class DayOfTheWeek_ (ordinal : Int, name : String) extends DayOfTheWeek - -trait DayOfTheWeekConstant -{ - - lazy val sunday = DayOfTheWeek_ (0, "Sunday") - - lazy val monday = DayOfTheWeek_ (1, "Monday") - - lazy val tuesday = DayOfTheWeek_ (2, "Tuesday") - - lazy val wednesday = DayOfTheWeek_ (3, "Wednesday") - - lazy val thursday = DayOfTheWeek_ (4, "Thursday") - - lazy val friday = DayOfTheWeek_ (5, "Friday") - - lazy val saturday = DayOfTheWeek_ (6, "Saturday") - - lazy val DayOfTheWeek_values = Seq (sunday, monday, tuesday, wednesday, thursday, friday, saturday) - -} - -case class DayOfTheWeekConstant_ () extends DayOfTheWeekConstant - -trait DayOfTheWeekEnum - extends - DayOfTheWeekConstant -{ - - lazy val values = DayOfTheWeek_values - -} - -case class DayOfTheWeekEnum_ () extends DayOfTheWeekEnum - -case class EnumSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("the names of the elements in enumerations") ( - check ( - obtained = DayOfTheWeekEnum_ ().values.map ( x => x.toString) - ) ( - expected = Seq ("DayOfTheWeek_(0,Sunday)", "DayOfTheWeek_(1,Monday)", "DayOfTheWeek_(2,Tuesday)", "DayOfTheWeek_(3,Wednesday)", "DayOfTheWeek_(4,Thursday)", "DayOfTheWeek_(5,Friday)", "DayOfTheWeek_(6,Saturday)") - ) - ) - -} - - -case class RecursionSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_seq : Seq [Int] = Seq (0, 1, 1, 2, 3, 5, 8) - - private lazy val _fold_while = FoldWhile_ () - - private lazy val _fold = Fold_ () - - private lazy val _range = Range_ () - - test ("fold left while with Seq") ( - check ( - obtained = _fold_while.apply (example_seq) (_fold0_initial_value) (_fold0_next_value_function) (_fold0_condition) - ) ( - expected = Seq ("103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold0_initial_value = Seq [String] () - - private lazy val _fold0_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String]) => (e : Int) => (s.+: ("" + (e + 100) ) ) - - private lazy val _fold0_condition : Seq [String] => Int => Boolean = - (s : Seq [String] ) => (e : Int) => (e < 5) - - test ("fold left with Seq") ( - check ( - obtained = _fold.apply (example_seq) (_fold1_initial_value) (_fold1_next_value_function) - ) ( - expected = Seq ("108", "105", "103", "102", "101", "101", "100") - ) - ) - - private lazy val _fold1_initial_value = Seq [String] () - - private lazy val _fold1_next_value_function : Seq [String] => Int => Seq [String] = - (s : Seq [String] ) => (e : Int) => (s.+: ("" + (e + 100) ) ) - - test ("range with positive number") ( - check ( - obtained = _range.apply (8) - ) ( - expected = Seq (0, 1, 2, 3, 4, 5, 6, 7) - ) - ) - - test ("range with zero size") ( - check ( - obtained = _range.apply (-1) - ) ( - expected = Seq () - ) - ) - - test ("range with negative number") ( - check ( - obtained = _range.apply (-1) - ) ( - expected = Seq () - ) - ) - -} - - diff --git a/translator/src/test/scala/soda/translator/block/Package.scala b/translator/src/test/scala/soda/translator/block/Package.scala index b3bc5e17..6cbc0620 100644 --- a/translator/src/test/scala/soda/translator/block/Package.scala +++ b/translator/src/test/scala/soda/translator/block/Package.scala @@ -4,6 +4,7 @@ package soda.translator.block * This package contains tests for block translators. */ trait Package + trait BlockTranslator00 extends BlockTranslator @@ -117,4 +118,3 @@ case class BlockTranslatorPipelineSpec () } - diff --git a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala index 257466d3..67cc2b0d 100644 --- a/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/tocoq/Package.scala @@ -4,42 +4,6 @@ package soda.translator.extension.tocoq * This package contains test for the translator to Coq. */ trait Package -case class MicroTranslatorToCoqSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToCoq_ () - ) - ) - - test ("Coq translation of a constant") ( - check ( - obtained = instance.translate ("x = 0") - ) ( - expected = " Definition x := 0\n.\n" - ) - ) - - test ("Coq translation of a function") ( - check ( - obtained = instance.translate ("f (a: nat) = 0") - ) ( - expected = " Definition f (a: nat) := 0\n.\n" - ) - ) - -} - case class CoqFullTranslationSpec () extends @@ -98,3 +62,39 @@ case class CoqFullTranslationSpec () } +case class MicroTranslatorToCoqSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToCoq_ () + ) + ) + + test ("Coq translation of a constant") ( + check ( + obtained = instance.translate ("x = 0") + ) ( + expected = " Definition x := 0\n.\n" + ) + ) + + test ("Coq translation of a function") ( + check ( + obtained = instance.translate ("f (a: nat) = 0") + ) ( + expected = " Definition f (a: nat) := 0\n.\n" + ) + ) + +} + diff --git a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala index 07a3c0c4..9b2085e9 100644 --- a/translator/src/test/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/todoc/Package.scala @@ -4,50 +4,6 @@ package soda.translator.extension.todoc * This package contains tests for the translator to documents. */ trait Package -case class MicroTranslatorToDocSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val instance = - BlockProcessor_ ( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToDoc_ () - ) - ) - - lazy val original_snippet = "" + - "/*" + - "\n * This is an example" + - "\n*/" + - "\n" - - lazy val translated_snippet = "" + - "\n\\end{lstlisting}" + - "\n" + - "\nThis is an example" + - "\n" + - "\n" + - "\n\\begin{lstlisting}" + - "\n" + - "\n" - - test ("Document generation of a snippet") ( - check ( - obtained = instance.translate (original_snippet) - ) ( - expected = translated_snippet - ) - ) - -} - case class DocFullTranslationSpec () extends @@ -95,3 +51,47 @@ case class DocFullTranslationSpec () } +case class MicroTranslatorToDocSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = + BlockProcessor_ ( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToDoc_ () + ) + ) + + lazy val original_snippet = "" + + "/*" + + "\n * This is an example" + + "\n*/" + + "\n" + + lazy val translated_snippet = "" + + "\n\\end{lstlisting}" + + "\n" + + "\nThis is an example" + + "\n" + + "\n" + + "\n\\begin{lstlisting}" + + "\n" + + "\n" + + test ("Document generation of a snippet") ( + check ( + obtained = instance.translate (original_snippet) + ) ( + expected = translated_snippet + ) + ) + +} + diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala index 6663e9a4..8f31adfc 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -4,83 +4,32 @@ package soda.translator.extension.toscala * This package contains tests for the translator to Scala. */ trait Package -case class MultiLineSpec () + +case class BeautifierSpec () extends org.scalatest.funsuite.AnyFunSuite { - import soda.translator.block.AnnotatedBlock - import soda.translator.block.BlockAnnotationEnum_ - import soda.translator.block.DefaultBlockTranslator_ import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.annotation.AnnotationFactory_ - import soda.translator.parser.BlockBuilder_ import soda.translator.parser.BlockProcessor_ def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val bp = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - lazy val mt = MicroTranslatorToScala_ () - - lazy val original_input = - " value = 1\n" + - " sequence = Seq(1 ,\n" + - " 2, \n" + - " 3)\n" + - " f( x: Int,\t\n" + - " y: Int,\n" + - " z: Int) =\n" + - " x * x + y * y + z * z\n" - - lazy val original_input_lines = Seq( - " value = 1", - " sequence = Seq(1 ,", - " 2, ", - " 3)", - " f( x: Int,\t", - " y: Int,", - " z: Int) =", - " x * x + y * y + z * z") - - lazy val joined_comma_lines = Seq( - " value = 1", - " sequence = Seq(1 , 2, 3)", - " f( x: Int,\t y: Int, z: Int) =", - " x * x + y * y + z * z") - - lazy val joined_output = - " value = 1\n" + - " sequence = Seq(1 ," + - " 2, " + - " 3)\n" + - " f( x: Int,\t" + - " y: Int," + - " z: Int) =\n" + - " x * x + y * y + z * z" - - def build_block (lines: Seq [String]): AnnotatedBlock = - AnnotationFactory_ ().annotate (BlockBuilder_ ().build (lines) ) - - test ("should split a program in multiple lines") ( - check ( - obtained = bp.make_block (original_input) - ) ( - expected = build_block (original_input_lines ) - ) - ) + lazy val original = " beautify_this ( original : String ) : String = \n" + + " original . replaceAll(\" \" , \" \") \n" - test ("should join the translated lines of a program") ( + test ("the translated source code should respect unnecessary spaces") ( check ( - obtained = build_block (joined_comma_lines) + obtained = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_() + ) + ).translate (original) ) ( - expected = bp.make_block (joined_output) + expected = " def beautify_this ( original : String ) : String = \n" + + " original . replaceAll(\" \" , \" \") \n" ) ) @@ -216,98 +165,6 @@ case class ClassConstructorBlockTranslatorSpec () } -/** - * This tests how translation is done for Scala reserved words that are not Soda reserved words. - */ - -case class ScalaNonSodaSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val bp = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) - ) - - test ("Scala reserved words are replaced") ( - check ( - obtained = bp.translate ("" + - "\nval x =" + - "\n while (x != 0)" - ) - ) ( - expected = "" + - "private lazy val __soda__val x =" + - "\n __soda__while (x != 0)" + - "\n" - ) - ) - - test ("some synonyms are Scala reserved words") ( - check ( - obtained = bp.translate ("" + - "\nclass A0 [B0 <: C0]" + - "\n" + - "\nend" + - "\n" + - "\nclass C0 [D0 >: E0]" + - "\n" + - "\nend" + - "\n" + - "\nclass A1 [B1 subtype C1]" + - "\n" + - "\nend" + - "\n" + - "\nclass C1 [D1 supertype E1]" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = "" + - "trait A0 [B0 <: C0]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class A0_ [B0 <: C0] () extends A0 [B0]" + - "\n" + - "\ntrait C0 [D0 >: E0]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class C0_ [D0 >: E0] () extends C0 [D0]" + - "\n" + - "\ntrait A1 [B1 <: C1]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class A1_ [B1 <: C1] () extends A1 [B1]" + - "\n" + - "\ntrait C1 [D1 >: E1]" + - "\n{" + - "\n" + - "\n}" + - "\n" + - "\ncase class C1_ [D1 >: E1] () extends C1 [D1]" + - "\n" - ) - ) - -} - - case class FullTranslationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -409,186 +266,80 @@ case class FullTranslationSpec () } -case class UpperAndLowerBoundDeclarationSpec () +trait ExampleWithWrongOrder +{ + + lazy val this_is_null_but = constant_defined_later + + lazy val constant_defined_later = "Success!" + +} + +case class ExampleWithWrongOrder_ () extends ExampleWithWrongOrder + +trait ExampleWithRightOrder +{ + + lazy val constant_defined_before = "Success!" + + lazy val this_is_not_null = constant_defined_before + +} + +case class ExampleWithRightOrder_ () extends ExampleWithRightOrder + +trait ExampleWithEmptyParentheses +{ + + def this_is_not_null () = constant_defined_later + + lazy val constant_defined_later = "Success!" + +} + +case class ExampleWithEmptyParentheses_ () extends ExampleWithEmptyParentheses + +trait AnotherExampleWithEmptyParentheses +{ + + lazy val this_is_not_null = constant_function_defined_later () + + def constant_function_defined_later () = "Success!" + +} + +case class AnotherExampleWithEmptyParentheses_ () extends AnotherExampleWithEmptyParentheses + +/** + * In Soda constants cannot be defined as 'lazy val'. + * These tests detect and test this problem, and test work-arounds. + */ + +case class LazySyntaxSpec () extends org.scalatest.funsuite.AnyFunSuite { - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val instance = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_ () - ) + test ("should show what happens when constants are defined in the wrong order") ( + check ( + obtained = ExampleWithWrongOrder_ ().this_is_null_but + ) ( + expected = "Success!" ) + ) - test ("should translate a single upper bound") ( + test ("should show what happens when constants are defined in the right order") ( check ( - obtained = instance.translate ("class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A subtype AbstractInput]" + - "\n" + - "\nend" + - "\n" - ) + obtained = ExampleWithRightOrder_ ().this_is_not_null ) ( - expected = - "case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A <: AbstractInput]" + - "\n{" + - "\n" + - "\n}" + - "\n" + expected = "Success!" ) ) - test ("should translate multiple upper bounds") ( - check ( - obtained = instance.translate ( " class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A subtype AbstractInput]" + - "\n AbstractDevice[B subtype AbstractDeviceInput]" + - "\n" + - "\n end" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A <: AbstractInput]" + - "\n with AbstractDevice[B <: AbstractDeviceInput]" + - "\n {" + - "\n" + - "\n }" + - "\n" - ) - ) - - test ("should translate a single lower bound") ( - check ( - obtained = instance.translate (" class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A supertype (AbstractInput)]" + - "\n" + - "\n end" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A >: (AbstractInput)]" + - "\n {" + - "\n" + - "\n }" + - "\n" - ) - ) - - test ("should translate multiple lower bounds") ( - check ( - obtained = instance.translate (" class BlackBox()" + - "\n extends " + - "\n AbstractBlackBox[A supertype (AbstractInput)]" + - "\n AbstractDevice[B supertype (AbstractDeviceInput)]" + - "\n" + - "\nend" + - "\n" - ) - ) ( - expected = " case class BlackBox()" + - "\n extends" + - "\n AbstractBlackBox[A >: (AbstractInput)]" + - "\n with AbstractDevice[B >: (AbstractDeviceInput)]" + - "\n {" + - "\n" + - "\n}" + - "\n" - ) - ) - -} - - -trait ExampleWithWrongOrder -{ - - lazy val this_is_null_but = constant_defined_later - - lazy val constant_defined_later = "Success!" - -} - -case class ExampleWithWrongOrder_ () extends ExampleWithWrongOrder - -trait ExampleWithRightOrder -{ - - lazy val constant_defined_before = "Success!" - - lazy val this_is_not_null = constant_defined_before - -} - -case class ExampleWithRightOrder_ () extends ExampleWithRightOrder - -trait ExampleWithEmptyParentheses -{ - - def this_is_not_null () = constant_defined_later - - lazy val constant_defined_later = "Success!" - -} - -case class ExampleWithEmptyParentheses_ () extends ExampleWithEmptyParentheses - -trait AnotherExampleWithEmptyParentheses -{ - - lazy val this_is_not_null = constant_function_defined_later () - - def constant_function_defined_later () = "Success!" - -} - -case class AnotherExampleWithEmptyParentheses_ () extends AnotherExampleWithEmptyParentheses - -/** - * In Soda constants cannot be defined as 'lazy val'. - * These tests detect and test this problem, and test work-arounds. - */ - -case class LazySyntaxSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should show what happens when constants are defined in the wrong order") ( - check ( - obtained = ExampleWithWrongOrder_ ().this_is_null_but - ) ( - expected = "Success!" - ) - ) - - test ("should show what happens when constants are defined in the right order") ( - check ( - obtained = ExampleWithRightOrder_ ().this_is_not_null - ) ( - expected = "Success!" - ) - ) - - test ("should show what happens when one work-around is used") ( + test ("should show what happens when one work-around is used") ( check ( obtained = ExampleWithEmptyParentheses_ ().this_is_not_null () ) ( @@ -910,6 +661,181 @@ case class MicroTranslatorToScalaSpec () } +case class MultiLineSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.AnnotatedBlock + import soda.translator.block.BlockAnnotationEnum_ + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.parser.BlockBuilder_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val bp = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + lazy val mt = MicroTranslatorToScala_ () + + lazy val original_input = + " value = 1\n" + + " sequence = Seq(1 ,\n" + + " 2, \n" + + " 3)\n" + + " f( x: Int,\t\n" + + " y: Int,\n" + + " z: Int) =\n" + + " x * x + y * y + z * z\n" + + lazy val original_input_lines = Seq( + " value = 1", + " sequence = Seq(1 ,", + " 2, ", + " 3)", + " f( x: Int,\t", + " y: Int,", + " z: Int) =", + " x * x + y * y + z * z") + + lazy val joined_comma_lines = Seq( + " value = 1", + " sequence = Seq(1 , 2, 3)", + " f( x: Int,\t y: Int, z: Int) =", + " x * x + y * y + z * z") + + lazy val joined_output = + " value = 1\n" + + " sequence = Seq(1 ," + + " 2, " + + " 3)\n" + + " f( x: Int,\t" + + " y: Int," + + " z: Int) =\n" + + " x * x + y * y + z * z" + + def build_block (lines: Seq [String]): AnnotatedBlock = + AnnotationFactory_ ().annotate (BlockBuilder_ ().build (lines) ) + + test ("should split a program in multiple lines") ( + check ( + obtained = bp.make_block (original_input) + ) ( + expected = build_block (original_input_lines ) + ) + ) + + test ("should join the translated lines of a program") ( + check ( + obtained = build_block (joined_comma_lines) + ) ( + expected = bp.make_block (joined_output) + ) + ) + +} + + +/** + * This tests how translation is done for Scala reserved words that are not Soda reserved words. + */ + +case class ScalaNonSodaSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val bp = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) + + test ("Scala reserved words are replaced") ( + check ( + obtained = bp.translate ("" + + "\nval x =" + + "\n while (x != 0)" + ) + ) ( + expected = "" + + "private lazy val __soda__val x =" + + "\n __soda__while (x != 0)" + + "\n" + ) + ) + + test ("some synonyms are Scala reserved words") ( + check ( + obtained = bp.translate ("" + + "\nclass A0 [B0 <: C0]" + + "\n" + + "\nend" + + "\n" + + "\nclass C0 [D0 >: E0]" + + "\n" + + "\nend" + + "\n" + + "\nclass A1 [B1 subtype C1]" + + "\n" + + "\nend" + + "\n" + + "\nclass C1 [D1 supertype E1]" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = "" + + "trait A0 [B0 <: C0]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class A0_ [B0 <: C0] () extends A0 [B0]" + + "\n" + + "\ntrait C0 [D0 >: E0]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class C0_ [D0 >: E0] () extends C0 [D0]" + + "\n" + + "\ntrait A1 [B1 <: C1]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class A1_ [B1 <: C1] () extends A1 [B1]" + + "\n" + + "\ntrait C1 [D1 >: E1]" + + "\n{" + + "\n" + + "\n}" + + "\n" + + "\ncase class C1_ [D1 >: E1] () extends C1 [D1]" + + "\n" + ) + ) + +} + + case class MainSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -939,7 +865,7 @@ case class MainSpec () } -case class BeautifierSpec () +case class UpperAndLowerBoundDeclarationSpec () extends org.scalatest.funsuite.AnyFunSuite { @@ -950,23 +876,97 @@ case class BeautifierSpec () def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = assert (obtained == expected) - lazy val original = " beautify_this ( original : String ) : String = \n" + - " original . replaceAll(\" \" , \" \") \n" + lazy val instance = + BlockProcessor_( + DefaultBlockSequenceTranslator_ ( + MicroTranslatorToScala_ () + ) + ) - test ("the translated source code should respect unnecessary spaces") ( + test ("should translate a single upper bound") ( check ( - obtained = - BlockProcessor_( - DefaultBlockSequenceTranslator_ ( - MicroTranslatorToScala_() - ) - ).translate (original) + obtained = instance.translate ("class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A subtype AbstractInput]" + + "\n" + + "\nend" + + "\n" + ) ) ( - expected = " def beautify_this ( original : String ) : String = \n" + - " original . replaceAll(\" \" , \" \") \n" + expected = + "case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A <: AbstractInput]" + + "\n{" + + "\n" + + "\n}" + + "\n" ) ) -} + test ("should translate multiple upper bounds") ( + check ( + obtained = instance.translate ( " class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A subtype AbstractInput]" + + "\n AbstractDevice[B subtype AbstractDeviceInput]" + + "\n" + + "\n end" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A <: AbstractInput]" + + "\n with AbstractDevice[B <: AbstractDeviceInput]" + + "\n {" + + "\n" + + "\n }" + + "\n" + ) + ) + test ("should translate a single lower bound") ( + check ( + obtained = instance.translate (" class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A supertype (AbstractInput)]" + + "\n" + + "\n end" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A >: (AbstractInput)]" + + "\n {" + + "\n" + + "\n }" + + "\n" + ) + ) + + test ("should translate multiple lower bounds") ( + check ( + obtained = instance.translate (" class BlackBox()" + + "\n extends " + + "\n AbstractBlackBox[A supertype (AbstractInput)]" + + "\n AbstractDevice[B supertype (AbstractDeviceInput)]" + + "\n" + + "\nend" + + "\n" + ) + ) ( + expected = " case class BlackBox()" + + "\n extends" + + "\n AbstractBlackBox[A >: (AbstractInput)]" + + "\n with AbstractDevice[B >: (AbstractDeviceInput)]" + + "\n {" + + "\n" + + "\n}" + + "\n" + ) + ) + +} diff --git a/translator/src/test/scala/soda/translator/io/Package.scala b/translator/src/test/scala/soda/translator/io/Package.scala index e834e2d6..2d485be8 100644 --- a/translator/src/test/scala/soda/translator/io/Package.scala +++ b/translator/src/test/scala/soda/translator/io/Package.scala @@ -5,6 +5,7 @@ package soda.translator.io */ trait Package + case class DirectoryScannerSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -49,4 +50,3 @@ case class DirectoryScannerSpec () } - diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index 01e9b988..253ae077 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -5,6 +5,7 @@ package soda.translator.parser */ trait Package + case class BlockSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -124,4 +125,3 @@ case class PreprocessorSequenceTranslatorSpec () } - diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala index e7bf8aba..e0ae5f20 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala @@ -5,6 +5,164 @@ package soda.translator.parser.annotation */ trait Package + +case class BlockAnnotationSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.block.Block + import soda.translator.block.DefaultBlockTranslator_ + import soda.translator.block.DefaultBlockSequenceTranslator_ + import soda.translator.parser.BlockProcessor_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val example_blocks = + ExampleProgram_ ().example_blocks + + def detectors (block: Block): Seq [BlockAnnotationParser] = + Seq ( + FunctionDefinitionAnnotation_ (block), + ClassBeginningAnnotation_ (block), + ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), + AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), + ImportDeclarationAnnotation_ (block), + PackageDeclarationAnnotation_ (block), + ClassAliasAnnotation_ (block), + TheoremBlockAnnotation_ (block), + ProofBlockAnnotation_ (block), + CommentAnnotation_ (block), + TestDeclarationAnnotation_ (block) + ) + + def apply_detectors (block : Block) : Seq [Boolean] = + detectors (block).map ( detector => detector.applies) + + test ("should detect a package declaration") ( + check ( + obtained = apply_detectors (example_blocks (0) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, true, false, false, false, false, false) + ) + ) + + test ("should detect a comment") ( + check ( + obtained = apply_detectors (example_blocks (1) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, true, false) + ) + ) + + test ("should detect a class beginning") ( + check ( + obtained = apply_detectors (example_blocks (2) ) + ) ( + expected = Seq [Boolean] (false, true, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect an abstract block declaration") ( + check ( + obtained = apply_detectors (example_blocks (3) ) + ) ( + expected = Seq [Boolean] (false, false, false, true, false, false, false, false, false, false, false) + ) + ) + + test ("should detect an import declaration") ( + check ( + obtained = apply_detectors (example_blocks (4) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, true, false, false, false, false, false, false) + ) + ) + + test ("should detect a constant declaration") ( + check ( + obtained = apply_detectors (example_blocks (5) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a function declaration") ( + check ( + obtained = apply_detectors (example_blocks (6) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect another function declaration") ( + check ( + obtained = apply_detectors (example_blocks (7) ) + ) ( + expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a test declaration") ( + check ( + obtained = apply_detectors (example_blocks (8) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) + ) + ) + + test ("should detect a theorem block") ( + check ( + obtained = apply_detectors (example_blocks (9) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) + ) + ) + + test ("should detect a proof block") ( + check ( + obtained = apply_detectors (example_blocks (10) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) + ) + ) + + test ("should detect a class end") ( + check ( + obtained = apply_detectors (example_blocks (11) ) + ) ( + expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) + ) + ) + + test ("should detect a class alias") ( + check ( + obtained = apply_detectors (example_blocks (12) ) + ) ( + expected = Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) + ) + ) + + test ("should find only 13 blocks") ( + check ( + obtained = example_blocks.length + ) ( + expected = 13 + ) + ) + + test ("should be ordered by the identifier ordinal") ( + check ( + obtained = detectors (example_blocks (0) ).map ( detector => detector.identifier.ordinal) + ) ( + expected = Seq [Int] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) + ) + ) + +} + + case class ClassBeginningAnnotationSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -198,163 +356,6 @@ case class ClassBeginningAnnotationSpec () } -case class BlockAnnotationSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - import soda.translator.block.Block - import soda.translator.block.DefaultBlockTranslator_ - import soda.translator.block.DefaultBlockSequenceTranslator_ - import soda.translator.parser.BlockProcessor_ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - lazy val example_blocks = - ExampleProgram_ ().example_blocks - - def detectors (block: Block): Seq [BlockAnnotationParser] = - Seq ( - FunctionDefinitionAnnotation_ (block), - ClassBeginningAnnotation_ (block), - ClassEndAnnotation_ (block, Seq [BlockAnnotationParser] () ), - AbstractDeclarationAnnotation_ (block, Seq [BlockAnnotationParser] () ), - ImportDeclarationAnnotation_ (block), - PackageDeclarationAnnotation_ (block), - ClassAliasAnnotation_ (block), - TheoremBlockAnnotation_ (block), - ProofBlockAnnotation_ (block), - CommentAnnotation_ (block), - TestDeclarationAnnotation_ (block) - ) - - def apply_detectors (block : Block) : Seq [Boolean] = - detectors (block).map ( detector => detector.applies) - - test ("should detect a package declaration") ( - check ( - obtained = apply_detectors (example_blocks (0) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, true, false, false, false, false, false) - ) - ) - - test ("should detect a comment") ( - check ( - obtained = apply_detectors (example_blocks (1) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, true, false) - ) - ) - - test ("should detect a class beginning") ( - check ( - obtained = apply_detectors (example_blocks (2) ) - ) ( - expected = Seq [Boolean] (false, true, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect an abstract block declaration") ( - check ( - obtained = apply_detectors (example_blocks (3) ) - ) ( - expected = Seq [Boolean] (false, false, false, true, false, false, false, false, false, false, false) - ) - ) - - test ("should detect an import declaration") ( - check ( - obtained = apply_detectors (example_blocks (4) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, true, false, false, false, false, false, false) - ) - ) - - test ("should detect a constant declaration") ( - check ( - obtained = apply_detectors (example_blocks (5) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a function declaration") ( - check ( - obtained = apply_detectors (example_blocks (6) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect another function declaration") ( - check ( - obtained = apply_detectors (example_blocks (7) ) - ) ( - expected = Seq [Boolean] (true, false, false, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a test declaration") ( - check ( - obtained = apply_detectors (example_blocks (8) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, false, false, true) - ) - ) - - test ("should detect a theorem block") ( - check ( - obtained = apply_detectors (example_blocks (9) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, true, false, false, false) - ) - ) - - test ("should detect a proof block") ( - check ( - obtained = apply_detectors (example_blocks (10) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, false, false, true, false, false) - ) - ) - - test ("should detect a class end") ( - check ( - obtained = apply_detectors (example_blocks (11) ) - ) ( - expected = Seq [Boolean] (false, false, true, false, false, false, false, false, false, false, false) - ) - ) - - test ("should detect a class alias") ( - check ( - obtained = apply_detectors (example_blocks (12) ) - ) ( - expected = Seq [Boolean] (false, false, false, false, false, false, true, false, false, false, false) - ) - ) - - test ("should find only 13 blocks") ( - check ( - obtained = example_blocks.length - ) ( - expected = 13 - ) - ) - - test ("should be ordered by the identifier ordinal") ( - check ( - obtained = detectors (example_blocks (0) ).map ( detector => detector.identifier.ordinal) - ) ( - expected = Seq [Int] (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11) - ) - ) - -} - - trait ExampleProgram { @@ -426,4 +427,3 @@ trait ExampleProgram case class ExampleProgram_ () extends ExampleProgram - diff --git a/translator/src/test/scala/soda/translator/replacement/Package.scala b/translator/src/test/scala/soda/translator/replacement/Package.scala index a21a15e6..781197f5 100644 --- a/translator/src/test/scala/soda/translator/replacement/Package.scala +++ b/translator/src/test/scala/soda/translator/replacement/Package.scala @@ -5,6 +5,7 @@ package soda.translator.replacement */ trait Package + case class CharTypeSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -60,73 +61,6 @@ case class CharTypeSpec () } -case class TokenizerSpec () - extends - org.scalatest.funsuite.AnyFunSuite -{ - - def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = - assert (obtained == expected) - - test ("should tokenize a small example") ( - check ( - obtained = Tokenizer_ (" val Constant = \"my text\"").tokens - ) ( - expected = Seq ( - Token_ (" val Constant = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"my text\"", ParserStateEnum_ ().quotes_state, 19), - Token_ ("", ParserStateEnum_ ().plain, 28) - ) - ) - ) - - test ("should tokenize a common tab in a string") ( - check ( - obtained = Tokenizer_ (" x = \"abc\tde\"").tokens - ) ( - expected = Seq ( - Token_ (" x = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"abc\tde\"", ParserStateEnum_ ().quotes_state, 6), - Token_ ("", ParserStateEnum_ ().plain, 14) - ) - ) - ) - - test ("should tokenize an escaped tab in a string") ( - check ( - obtained = Tokenizer_ (" x = \"abc\\tde\"").tokens - ) ( - expected = Seq ( - Token_ (" x = ", ParserStateEnum_ ().plain, 0), - Token_ ("\"abc\\tde\"", ParserStateEnum_ ().quotes_state, 6), - Token_ ("", ParserStateEnum_ ().plain, 15) - ) - ) - ) - - test ("should tokenize a single function definition") ( - check ( - obtained = Tokenizer_ ("def f (x: Int): Int = x").tokens - ) ( - expected = Seq ( - Token_ ("def f (x: Int): Int = x", ParserStateEnum_ ().plain, 0) - ) - ) - ) - - test ("should tokenize a function call") ( - check ( - obtained = Tokenizer_ ("\tas_digits (5 * number)").tokens - ) ( - expected = Seq ( - Token_ ("\tas_digits (5 * number)", ParserStateEnum_ ().plain, 0) - ) - ) - ) - -} - - case class ReplacementAuxSpec () extends org.scalatest.funsuite.AnyFunSuite @@ -294,3 +228,69 @@ case class ReplacementAuxSpec () } +case class TokenizerSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + test ("should tokenize a small example") ( + check ( + obtained = Tokenizer_ (" val Constant = \"my text\"").tokens + ) ( + expected = Seq ( + Token_ (" val Constant = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"my text\"", ParserStateEnum_ ().quotes_state, 19), + Token_ ("", ParserStateEnum_ ().plain, 28) + ) + ) + ) + + test ("should tokenize a common tab in a string") ( + check ( + obtained = Tokenizer_ (" x = \"abc\tde\"").tokens + ) ( + expected = Seq ( + Token_ (" x = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"abc\tde\"", ParserStateEnum_ ().quotes_state, 6), + Token_ ("", ParserStateEnum_ ().plain, 14) + ) + ) + ) + + test ("should tokenize an escaped tab in a string") ( + check ( + obtained = Tokenizer_ (" x = \"abc\\tde\"").tokens + ) ( + expected = Seq ( + Token_ (" x = ", ParserStateEnum_ ().plain, 0), + Token_ ("\"abc\\tde\"", ParserStateEnum_ ().quotes_state, 6), + Token_ ("", ParserStateEnum_ ().plain, 15) + ) + ) + ) + + test ("should tokenize a single function definition") ( + check ( + obtained = Tokenizer_ ("def f (x: Int): Int = x").tokens + ) ( + expected = Seq ( + Token_ ("def f (x: Int): Int = x", ParserStateEnum_ ().plain, 0) + ) + ) + ) + + test ("should tokenize a function call") ( + check ( + obtained = Tokenizer_ ("\tas_digits (5 * number)").tokens + ) ( + expected = Seq ( + Token_ ("\tas_digits (5 * number)", ParserStateEnum_ ().plain, 0) + ) + ) + ) + +} + From f91e511bb7c08ffb93f5185a43f92a13db759dc7 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 16 Feb 2023 13:26:02 +0100 Subject: [PATCH 57/71] Update example --- .../scala/soda/example/algorithms/SaladMaker.soda | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda index a53329de..c04b7652 100644 --- a/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda +++ b/examples/src/main/scala/soda/example/algorithms/SaladMaker.soda @@ -1,11 +1,21 @@ class SaladMaker - apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + apply [Ingredient, Salad] + (list_of_ingredients : Seq [Ingredient] ) + (initial_bowl : Salad) + (next_ingredient_function : Salad -> Ingredient -> Salad) + (condition_to_continue : Salad -> Ingredient -> Boolean) + : Salad = _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) @tailrec - _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + _tailrec_prepare_salad [Ingredient, Salad] + (ingredients_so_far : Seq [Ingredient] ) + (salad_so_far : Salad) + (next_ingredient_function : Salad -> Ingredient -> Salad) + (condition_to_continue : Salad -> Ingredient -> Boolean) + : Salad = if ingredients_so_far.isEmpty or ( not condition_to_continue (salad_so_far) (ingredients_so_far.head) ) then salad_so_far else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) From d677e889d87dadb38005a26b0ef6b5fcbbeac7de Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Fri, 17 Feb 2023 11:06:26 +0100 Subject: [PATCH 58/71] Update documentation --- docs/README.md | 46 +++++-------------- docs/RELEASE-NOTES.md | 2 +- .../src/site/tex/common/language.tex | 22 +++++++-- .../soda/translator/documentation/help.txt | 28 +++++++---- 4 files changed, 47 insertions(+), 51 deletions(-) diff --git a/docs/README.md b/docs/README.md index fda607e1..bc46ed38 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,47 +15,24 @@ The reserved words are: - `->` (type mapping symbol) - `=` (definition symbol) - `:=` (parameter definition symbol) -- `lambda` -- `any` (synonym of `lambda`) -- `-->` (lambda symbol) -- `if` -- `then` -- `else` -- `match` -- `case` -- `==>` (implication symbol in pattern matching) -- `class` -- `extends` -- `abstract` -- `end` -- `this` -- `subtype` -- `supertype` -- `false` -- `true` -- `not` -- `and` -- `or` -- `package` -- `import` -- `theorem` -- `proof` +- `lambda`, `any` (synonym of `lambda`), `-->` (lambda symbol) +- `if`, `then`, `else` +- `match`, `case`, `==>` (implication symbol in pattern matching) +- `class`, `extends`, `abstract`, `end` +- `this`, `subtype`, `supertype` +- `false`, `true` , `not`, `and`, `or` +- `package`, `import` +- `theorem`, `proof` ## Other Symbols In addition, the language has: - - `(` and `)` (parentheses) for parameters and operator precedence -- `[` and `]` (square brackets) for types +- `[` and `]` (square brackets) for parametric types The main arithmetic operators are: - -- `+` -- `-` -- `*` -- `/` -- `%` +- `+`, `-`, `*`, `/`, `%` (modulus) Comments are marked with `/*` and `*/`. Scaladoc / Javadoc markers are `/**` and `*/`. @@ -76,8 +53,7 @@ Special names: In this language, variables cannot change their value. Therefore, there is no equivalent to `var`. -For example, it is not possible to write `x = x + 1`. Loops can be managed with `range` and `fold` functions, tail -recursion, or directly using streams. +For example, it is not possible to write `x = x + 1`. Loops can be managed with `range` and `fold` functions, tail recursion, or directly using streams. The language does not provide `throw`, `try`, and `catch`, because those commands do not follow the functional style. diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index d6399501..a58eb6fb 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -4,7 +4,7 @@ - build: sbt '++ 3.2.0' clean compile test package assembly - release: target/scala-3.2.0/soda-0.17.0.jar - new_features: - - includes an option to translate a whole Soda package into a single Scala file + - includes an option to translate a whole Soda package into a single Scala file - reads `Package.soda` as prelude for a Soda file in the same directory - accepts reserved word `any` as a synonym for `lambda` - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure diff --git a/documentation/src/site/tex/common/language.tex b/documentation/src/site/tex/common/language.tex index d78ecbdd..011b91ed 100644 --- a/documentation/src/site/tex/common/language.tex +++ b/documentation/src/site/tex/common/language.tex @@ -1,7 +1,7 @@ \usepackage{listings} \lstdefinelanguage{Soda}{ - morekeywords={lambda, if, then, else, match, case, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @new, @tailrec, @override}, + morekeywords={lambda, any, if, then, else, match, case, class, extends, abstract, end, this, subtype, supertype, false, true, not, and, or, package, import, theorem, proof, @new, @tailrec, @override}, sensitive=true, morecomment=[s]{/*}{*/}, morestring=[b]" @@ -43,11 +43,13 @@ \newcommand{\sodadef}{\srccode{=}\xspace} \newcommand{\sodacolon}{\srccode{:}\xspace} \newcommand{\sodaarrow}{{-\textgreater}\xspace} -\newcommand{\sodalambdaarrow}{{---\textgreater}\xspace} \newcommand{\sodaimplies}{{==\textgreater}\xspace} \newcommand{\sodadefparam}{\srccode{:=}\xspace} +\newcommand{\sodalambdaarrow}{\ensuremath{\longrightarrow}\xspace} +\newcommand{\sodacasearrow}{\ensuremath{\Longrightarrow}\xspace} \newcommand{\sodalambda}{\reservedWordSoda{lambda}} +\newcommand{\sodaany}{\reservedWordSoda{any}} \newcommand{\sodaif}{\reservedWordSoda{if}} \newcommand{\sodathen}{\reservedWordSoda{then}} @@ -55,7 +57,6 @@ \newcommand{\sodamatch}{\reservedWordSoda{match}} \newcommand{\sodacase}{\reservedWordSoda{case}} -\newcommand{\sodaendmatch}{\reservedWordSoda{end}} \newcommand{\sodaclass}{\reservedWordSoda{class}} \newcommand{\sodaextends}{\reservedWordSoda{extends}} @@ -74,6 +75,9 @@ \newcommand{\sodapackage}{\reservedWordSoda{package}} \newcommand{\sodaimport}{\reservedWordSoda{import}} +\newcommand{\sodatheorem}{\reservedWordSoda{theorem}} +\newcommand{\sodaproof}{\reservedWordSoda{proof}} + \newcommand{\sodanew}{\annotation{@new}} \newcommand{\sodatailrec}{\annotation{@tailrec}} \newcommand{\sodaoverride}{\annotation{@override}} @@ -120,11 +124,19 @@ \newcommand{\coqmatch}{\reservedWordCoq{match}} \newcommand{\coqwith}{\reservedWordCoq{with}} -\newcommand{\coqbar}{\reservedWordCoq{|}} -\newcommand{\coqend}{\reservedWordCoq{end}} +\newcommand{\coqcasebar}{\reservedWordCoq{|}} +\newcommand{\coqcasearrow}{\ensuremath{\Rightarrow}\xspace} +\newcommand{\coqendmatch}{\reservedWordCoq{end}} \newcommand{\coqDefinition}{\reservedWordCoq{Definition}} +\newcommand{\coqNotation}{\reservedWordCoq{Notation}} +\newcommand{\coqInductive}{\reservedWordCoq{Inductive}} \newcommand{\coqFixpoint}{\reservedWordCoq{Fixpoint}} +\newcommand{\coqRequire}{\reservedWordCoq{Require}} +\newcommand{\coqImport}{\reservedWordCoq{Import}} \newcommand{\coqModule}{\reservedWordCoq{Module}} \newcommand{\coqEnd}{\reservedWordCoq{End}} +\newcommand{\coqTheorem}{\reservedWordCoq{Theorem}} +\newcommand{\coqProof}{\reservedWordCoq{Proof}} +\newcommand{\coqQed}{\reservedWordCoq{Qed}} diff --git a/translator/src/main/resources/soda/translator/documentation/help.txt b/translator/src/main/resources/soda/translator/documentation/help.txt index e7768a68..e9c0f2a8 100644 --- a/translator/src/main/resources/soda/translator/documentation/help.txt +++ b/translator/src/main/resources/soda/translator/documentation/help.txt @@ -2,6 +2,8 @@ Soda - Symbolic Objective Descriptive Analysis Copyright 2020--2023 Julian Alfredo Mendez +https://github.com/julianmendez/soda + Soda is an object-oriented purely-functional language for descriptions. Usage: @@ -10,25 +12,25 @@ Usage: where EXTENSION can be: - scala calls the Soda-to-Scala translator + scala calls the Soda-to-Scala translator - coq calls the Soda-to-Coq translator (only for snippets) + coq calls the Soda-to-Coq translator (only for snippets) - doc creates LaTeX documents based on Soda files + doc creates LaTeX documents based on Soda files - manual outputs the manual, which is written in Soda + manual outputs the manual, which is written in Soda - license outputs the license + license outputs the license - help shows this help + help shows this help - . calls the Soda-to-Scala translator + . calls the Soda-to-Scala translator --- Soda-to-Scala translator Usage: - soda scala SODA_SCALA_INPUT + soda scala [OPTION] SODA_SCALA_INPUT or soda scala SODA_INPUT SCALA_OUTPUT @@ -36,8 +38,8 @@ where SODA_SCALA_INPUT is used to create the Soda input file and Scala output file. If it is a directory, it scans recursively the directory to translate Soda files. -If the extension is .soda, the output file has extension .scala. -Otherwise, the extension .soda and .scala are appended to create the input and output files respectively. +If the extension is .soda, the output file has extension .scala . +Otherwise, the extension .soda and .scala are appended to the input and output files respectively. SODA_INPUT is the Soda input file, regardless of the extension @@ -45,6 +47,12 @@ Otherwise, the extension .soda and .scala are appended to create the input and o SCALA_OUTPUT is the Scala output file, regardless of the extension +OPTION: + + -p, --package + visit each Soda package and for each package, translate all Soda source files into a single Package.scala file. + + --- Soda-to-Coq translator From d0e12bc65eebcc75ec437f29d83ec17a58f84672 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 23 Feb 2023 17:49:30 +0100 Subject: [PATCH 59/71] Update package dependencies --- .../scala/soda/example/algorithms/Package.scala | 14 ++++++++++++-- .../extension/todoc/MicroTranslatorToDoc.soda | 6 ------ .../soda/translator/extension/todoc/Package.scala | 6 ------ .../toscala/MainClassBlockTranslator.soda | 1 - .../extension/toscala/MicroTranslatorToScala.soda | 2 -- .../translator/extension/toscala/Package.scala | 3 --- .../scala/soda/translator/parser/BlockBuilder.soda | 2 -- .../scala/soda/translator/parser/Package.scala | 3 --- .../parser/PreprocessorSequenceTranslator.soda | 1 - 9 files changed, 12 insertions(+), 26 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index 98638761..60948330 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -156,12 +156,22 @@ case class Triplet_ (x : Int, y : Int, z : Int) extends Triplet trait SaladMaker { - def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + def apply [Ingredient, Salad] + (list_of_ingredients : Seq [Ingredient] ) + (initial_bowl : Salad) + (next_ingredient_function : Salad => Ingredient => Salad) + (condition_to_continue : Salad => Ingredient => Boolean) + : Salad = _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) import scala.annotation.tailrec @tailrec final - private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + private def _tailrec_prepare_salad [Ingredient, Salad] + (ingredients_so_far : Seq [Ingredient] ) + (salad_so_far : Salad) + (next_ingredient_function : Salad => Ingredient => Salad) + (condition_to_continue : Salad => Ingredient => Boolean) + : Salad = if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) ) salad_so_far else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) diff --git a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda index b761c14d..4085e38e 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda +++ b/translator/src/main/scala/soda/translator/extension/todoc/MicroTranslatorToDoc.soda @@ -11,12 +11,6 @@ class MicroTranslatorToDoc soda.translator.block.AnnotatedBlock soda.translator.block.BlockAnnotationEnum_ soda.translator.block.BlockTranslatorPipeline_ - soda.translator.block.ConditionalBlockTranslator_ - soda.translator.blocktr.TokenReplacement_ - soda.translator.blocktr.TokenizedBlockTranslator_ - soda.translator.replacement.Token - - _tc = TranslationConstantToDoc_ () _function_definition = BlockAnnotationEnum_ ().function_definition diff --git a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala index c56501f1..75b064ec 100644 --- a/translator/src/main/scala/soda/translator/extension/todoc/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/todoc/Package.scala @@ -120,12 +120,6 @@ trait MicroTranslatorToDoc import soda.translator.block.AnnotatedBlock import soda.translator.block.BlockAnnotationEnum_ import soda.translator.block.BlockTranslatorPipeline_ - import soda.translator.block.ConditionalBlockTranslator_ - import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token - - private lazy val _tc = TranslationConstantToDoc_ () private lazy val _function_definition = BlockAnnotationEnum_ ().function_definition diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda index b736502b..1e52a5b6 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MainClassBlockTranslator.soda @@ -6,7 +6,6 @@ class MainClassBlockTranslator import soda.translator.block.AnnotatedBlock soda.translator.parser.BlockBuilder_ - soda.translator.parser.SodaConstant_ soda.translator.parser.annotation.ClassBeginningAnnotation soda.translator.parser.annotation.ClassBeginningAnnotation_ soda.translator.parser.annotation.ClassEndAnnotation diff --git a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda index 5e413547..2ba6d0aa 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda +++ b/translator/src/main/scala/soda/translator/extension/toscala/MicroTranslatorToScala.soda @@ -13,8 +13,6 @@ class MicroTranslatorToScala soda.translator.block.BlockAnnotationEnum_ soda.translator.block.ConditionalBlockTranslator_ soda.translator.blocktr.TokenReplacement_ - soda.translator.blocktr.TokenizedBlockTranslator_ - soda.translator.replacement.Token _tc = TranslationConstantToScala_ () diff --git a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala index e76e04c0..d532a543 100644 --- a/translator/src/main/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/main/scala/soda/translator/extension/toscala/Package.scala @@ -620,7 +620,6 @@ trait MainClassBlockTranslator import soda.translator.block.AnnotatedBlock import soda.translator.parser.BlockBuilder_ - import soda.translator.parser.SodaConstant_ import soda.translator.parser.annotation.ClassBeginningAnnotation import soda.translator.parser.annotation.ClassBeginningAnnotation_ import soda.translator.parser.annotation.ClassEndAnnotation @@ -768,8 +767,6 @@ trait MicroTranslatorToScala import soda.translator.block.BlockAnnotationEnum_ import soda.translator.block.ConditionalBlockTranslator_ import soda.translator.blocktr.TokenReplacement_ - import soda.translator.blocktr.TokenizedBlockTranslator_ - import soda.translator.replacement.Token private lazy val _tc = TranslationConstantToScala_ () diff --git a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda index 6d6eca6f..e094b242 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockBuilder.soda @@ -5,8 +5,6 @@ class BlockBuilder soda.lib.Fold_ soda.translator.block.AnnotatedLine soda.translator.block.AnnotatedLine_ - soda.translator.block.AnnotatedBlock - soda.translator.block.AnnotatedBlock_ soda.translator.block.Block soda.translator.block.Block_ diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index d8db6963..ba7b7761 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -14,8 +14,6 @@ trait BlockBuilder import soda.lib.Fold_ import soda.translator.block.AnnotatedLine import soda.translator.block.AnnotatedLine_ - import soda.translator.block.AnnotatedBlock - import soda.translator.block.AnnotatedBlock_ import soda.translator.block.Block import soda.translator.block.Block_ @@ -141,7 +139,6 @@ trait PreprocessorSequenceTranslator import soda.translator.parser.annotation.AnnotationFactory_ import soda.translator.parser.annotation.AbstractDeclarationAnnotation import soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - import soda.translator.parser.annotation.ClassBeginningAnnotation import soda.translator.parser.annotation.ClassBeginningAnnotation_ import soda.translator.parser.annotation.ClassEndAnnotation import soda.translator.parser.annotation.ClassEndAnnotation_ diff --git a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda index a570b04f..752a36bd 100644 --- a/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda +++ b/translator/src/main/scala/soda/translator/parser/PreprocessorSequenceTranslator.soda @@ -13,7 +13,6 @@ class PreprocessorSequenceTranslator soda.translator.parser.annotation.AnnotationFactory_ soda.translator.parser.annotation.AbstractDeclarationAnnotation soda.translator.parser.annotation.AbstractDeclarationAnnotation_ - soda.translator.parser.annotation.ClassBeginningAnnotation soda.translator.parser.annotation.ClassBeginningAnnotation_ soda.translator.parser.annotation.ClassEndAnnotation soda.translator.parser.annotation.ClassEndAnnotation_ From fe941ea2b9a4c6d4549b079560c45e36a900fabd Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 23 Feb 2023 18:17:01 +0100 Subject: [PATCH 60/71] Add processing of Soda Unicode symbols --- docs/RELEASE-NOTES.md | 3 +- .../translator/parser/BlockProcessor.soda | 35 +++++++++++- .../soda/translator/parser/Package.scala | 53 ++++++++++++++++++- .../soda/translator/parser/SodaConstant.soda | 18 +++++++ .../soda/translator/replacement/CharType.soda | 7 ++- .../soda/translator/replacement/Package.scala | 13 +++-- .../translator/replacement/Replacement.soda | 6 --- .../soda/translator/parser/Package.scala | 30 ++++++++--- .../PreprocessorSequenceTranslatorSpec.soda | 30 ++++++++--- .../ClassBeginningAnnotationSpec.soda | 6 ++- .../parser/annotation/ExampleProgram.soda | 4 +- .../parser/annotation/Package.scala | 10 ++-- .../soda/translator/replacement/Package.scala | 50 +++++++++++++++++ .../replacement/ReplacementSpec.soda | 50 +++++++++++++++++ 14 files changed, 274 insertions(+), 41 deletions(-) create mode 100644 translator/src/test/scala/soda/translator/replacement/ReplacementSpec.soda diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index a58eb6fb..f815e6bd 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -6,9 +6,10 @@ - new_features: - includes an option to translate a whole Soda package into a single Scala file - reads `Package.soda` as prelude for a Soda file in the same directory - - accepts reserved word `any` as a synonym for `lambda` - requires `match`-`case` structures to be used at most once in a function definition, and cannot be nested in another structure - improves function definition by allowing multiple lines in its signature + - accepts reserved word `any` as a synonym for `lambda` + - accepts Unicode characters for reserved words, like the letter lambda for `lambda` and right arrows for `->`, `-->`, and `==>` - includes a Bash script (`makeall.sh`) to build the project and create the binary file - deprecated_features: - the `end` reserved word for `match`-`case` is no longer used diff --git a/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda b/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda index b1023ad2..b01377b9 100644 --- a/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda +++ b/translator/src/main/scala/soda/translator/parser/BlockProcessor.soda @@ -11,6 +11,14 @@ class BlockProcessor import soda.translator.block.AnnotatedBlock soda.translator.parser.annotation.AnnotationFactory_ + soda.translator.replacement.ParserStateEnum_ + soda.translator.replacement.Token + soda.translator.replacement.Tokenizer_ + soda.translator.replacement.Replacement_ + + _sc = SodaConstant_ () + + fold = soda.lib.Fold_ () new_line = "\n" @@ -22,14 +30,37 @@ class BlockProcessor join_translated_blocks ( translator_with_preprocessor.translate ( split_blocks (program) + .map ( lambda block --> process_unicode_symbols_in_block (block) ) + .map ( lambda block --> make_block (block) ) ) ) - split_blocks (program : String) : Seq [AnnotatedBlock] = + split_blocks (program : String) : Seq [String] = program .split (double_new_line) .toIndexedSeq - .map ( lambda paragraph --> make_block (paragraph) ) + + process_unicode_symbols_in_block (block : String) : String = + Tokenizer_ (block) + .tokens + .map ( lambda token --> process_unicode_symbols_in_token (token) ) + .mkString + + process_unicode_symbols_in_token (token : Token) : String = + if (token.parser_state == ParserStateEnum_ ().plain) + then replace_unicode_symbols_in_string (token.text) + else token.text + + replace_unicode_symbols_in_string (text : String) : String = + fold (_sc.soda_unicode_symbols) (text) (_replace_one_unicode_symbol) + + _replace_one_unicode_symbol (text : String) (symbol_pair : Tuple2 [String , String] ) : String = + Replacement_ (text) + .replace_all (symbol_pair._1) (symbol_pair._2) + .line + + make_blocks (blocks: Seq [String] ) : Seq[AnnotatedBlock] = + blocks.map ( lambda paragraph --> make_block (paragraph) ) make_block (paragraph : String) : AnnotatedBlock = AnnotationFactory_ ().annotate ( diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index ba7b7761..4a7f13df 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -85,6 +85,14 @@ trait BlockProcessor import soda.translator.block.AnnotatedBlock import soda.translator.parser.annotation.AnnotationFactory_ + import soda.translator.replacement.ParserStateEnum_ + import soda.translator.replacement.Token + import soda.translator.replacement.Tokenizer_ + import soda.translator.replacement.Replacement_ + + private lazy val _sc = SodaConstant_ () + + lazy val fold = soda.lib.Fold_ () lazy val new_line = "\n" @@ -96,14 +104,37 @@ trait BlockProcessor join_translated_blocks ( translator_with_preprocessor.translate ( split_blocks (program) + .map ( block => process_unicode_symbols_in_block (block) ) + .map ( block => make_block (block) ) ) ) - def split_blocks (program : String) : Seq [AnnotatedBlock] = + def split_blocks (program : String) : Seq [String] = program .split (double_new_line) .toIndexedSeq - .map ( paragraph => make_block (paragraph) ) + + def process_unicode_symbols_in_block (block : String) : String = + Tokenizer_ (block) + .tokens + .map ( token => process_unicode_symbols_in_token (token) ) + .mkString + + def process_unicode_symbols_in_token (token : Token) : String = + if ( (token.parser_state == ParserStateEnum_ ().plain) + ) replace_unicode_symbols_in_string (token.text) + else token.text + + def replace_unicode_symbols_in_string (text : String) : String = + fold (_sc.soda_unicode_symbols) (text) (_replace_one_unicode_symbol) + + private def _replace_one_unicode_symbol (text : String) (symbol_pair : Tuple2 [String , String] ) : String = + Replacement_ (text) + .replace_all (symbol_pair._1) (symbol_pair._2) + .line + + def make_blocks (blocks: Seq [String] ) : Seq[AnnotatedBlock] = + blocks.map ( paragraph => make_block (paragraph) ) def make_block (paragraph : String) : AnnotatedBlock = AnnotationFactory_ ().annotate ( @@ -247,16 +278,26 @@ trait SodaConstant lazy val function_arrow_symbol = "->" + lazy val function_arrow_unicode_symbol = "\u2192" + lazy val lambda_arrow_symbol = "-->" + lazy val lambda_arrow_unicode_symbol = "\u27F6" + lazy val case_arrow_symbol = "==>" + lazy val case_arrow_unicode_symbol = "\u27F9" + lazy val parameter_definition_symbol = ":=" + lazy val parameter_definition_unicode_symbol = "\u2254" + lazy val lambda_reserved_word = "lambda" lazy val any_reserved_word = "any" + lazy val lambda_unicode_symbol = "\u03BB" + lazy val if_reserved_word = "if" lazy val then_reserved_word = "then" @@ -396,6 +437,14 @@ trait SodaConstant lazy val soda_reserved_words : Seq [String] = soda_reserved_words_words_only.++ (soda_reserved_words_symbols_only.++ (soda_reserved_words_annotations_only) ) + lazy val soda_unicode_symbols : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (lambda_unicode_symbol, lambda_reserved_word), + Tuple2 (lambda_arrow_unicode_symbol, lambda_arrow_symbol), + Tuple2 (function_arrow_unicode_symbol, function_arrow_symbol), + Tuple2 (case_arrow_unicode_symbol, case_arrow_symbol) + ) + } case class SodaConstant_ () extends SodaConstant diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index d8f30098..49081b9a 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -11,16 +11,26 @@ class SodaConstant function_arrow_symbol = "->" + function_arrow_unicode_symbol = "\u2192" + lambda_arrow_symbol = "-->" + lambda_arrow_unicode_symbol = "\u27F6" + case_arrow_symbol = "==>" + case_arrow_unicode_symbol = "\u27F9" + parameter_definition_symbol = ":=" + parameter_definition_unicode_symbol = "\u2254" + lambda_reserved_word = "lambda" any_reserved_word = "any" + lambda_unicode_symbol = "\u03BB" + if_reserved_word = "if" then_reserved_word = "then" @@ -160,5 +170,13 @@ class SodaConstant soda_reserved_words : Seq [String] = soda_reserved_words_words_only.++ (soda_reserved_words_symbols_only.++ (soda_reserved_words_annotations_only) ) + soda_unicode_symbols : Seq [Tuple2 [String, String] ] = + Seq ( + Tuple2 (lambda_unicode_symbol, lambda_reserved_word), + Tuple2 (lambda_arrow_unicode_symbol, lambda_arrow_symbol), + Tuple2 (function_arrow_unicode_symbol, function_arrow_symbol), + Tuple2 (case_arrow_unicode_symbol, case_arrow_symbol) + ) + end diff --git a/translator/src/main/scala/soda/translator/replacement/CharType.soda b/translator/src/main/scala/soda/translator/replacement/CharType.soda index 1a746b75..257ead88 100644 --- a/translator/src/main/scala/soda/translator/replacement/CharType.soda +++ b/translator/src/main/scala/soda/translator/replacement/CharType.soda @@ -41,6 +41,8 @@ class CharTypeEnum underscore_char = '_' + last_standard_symbol : Char = 0x7F + symbol_chars : Seq [Char] = Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') @@ -61,7 +63,7 @@ class CharTypeEnum else undefined_type _is_plain (ch : Char) : Boolean = - _is_whitespace (ch) or _is_letter_or_digit_or_underscore (ch) or _is_symbol (ch) + _is_whitespace (ch) or _is_letter_or_digit_or_underscore (ch) or _is_symbol (ch) or _is_extended_character (ch) _is_whitespace (ch : Char) : Boolean = ch.isWhitespace @@ -72,5 +74,8 @@ class CharTypeEnum _is_symbol (ch : Char) : Boolean = symbol_chars.contains (ch) + _is_extended_character (ch: Char): Boolean = + ch > last_standard_symbol + end diff --git a/translator/src/main/scala/soda/translator/replacement/Package.scala b/translator/src/main/scala/soda/translator/replacement/Package.scala index a4860274..06b752b9 100644 --- a/translator/src/main/scala/soda/translator/replacement/Package.scala +++ b/translator/src/main/scala/soda/translator/replacement/Package.scala @@ -54,6 +54,8 @@ trait CharTypeEnum lazy val underscore_char = '_' + lazy val last_standard_symbol : Char = 0x7F + lazy val symbol_chars : Seq [Char] = Seq ('!', '#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', ']', '^', '`', '{', '|', '}', '~') @@ -74,7 +76,7 @@ trait CharTypeEnum else undefined_type private def _is_plain (ch : Char) : Boolean = - _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) + _is_whitespace (ch) || _is_letter_or_digit_or_underscore (ch) || _is_symbol (ch) || _is_extended_character (ch) private def _is_whitespace (ch : Char) : Boolean = ch.isWhitespace @@ -85,6 +87,9 @@ trait CharTypeEnum private def _is_symbol (ch : Char) : Boolean = symbol_chars.contains (ch) + private def _is_extended_character (ch: Char): Boolean = + ch > last_standard_symbol + } case class CharTypeEnum_ () extends CharTypeEnum @@ -333,12 +338,6 @@ trait ReplacementWithTranslator aux.replace_if_found (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) - def replace_regex (line : String) : String = - _fold.apply (translator.keys) (initial_value = line) (next_value_function = _next_replace_regex) - - private def _next_replace_regex (line : String) (regex : String) : String = - line.replaceAll (regex, translator.translate (regex) ) - } case class ReplacementWithTranslator_ (translator : soda.translator.block.Translator) extends ReplacementWithTranslator diff --git a/translator/src/main/scala/soda/translator/replacement/Replacement.soda b/translator/src/main/scala/soda/translator/replacement/Replacement.soda index 3ed40c2d..b77ba2c4 100644 --- a/translator/src/main/scala/soda/translator/replacement/Replacement.soda +++ b/translator/src/main/scala/soda/translator/replacement/Replacement.soda @@ -144,11 +144,5 @@ class ReplacementWithTranslator aux.replace_if_found (line) ( soda_space + reserved_word + soda_space) (scala_space + translator.translate (reserved_word) + scala_space) - replace_regex (line : String) : String = - _fold.apply (translator.keys) (initial_value := line) (next_value_function := _next_replace_regex) - - _next_replace_regex (line : String) (regex : String) : String = - line.replaceAll (regex, translator.translate (regex) ) - end diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index 253ae077..136a2db4 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -71,14 +71,21 @@ case class PreprocessorSequenceTranslatorSpec () "\n soda.lib.Enum" + "\n" + "\n abstract" + - "\n number: Int" + - "\n name: String" + + "\n number : Int" + + "\n name : String" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function (f : Int \u2192 Int) (x : Int) : Int =" + + "\n f (x)" + + "\n" + + "\n process (sequence : Seq [Int]) : Seq [Int] =" + + "\n sequence" + + "\n .map ( \u03BB elem \u27F6 my_function (elem) (my_constant) )" + + "\n" + "\nend" + "\n" + "\n") @@ -97,14 +104,21 @@ case class PreprocessorSequenceTranslatorSpec () "\n soda.lib.Enum" + "\n" + "\n abstract" + - "\n number: Int" + - "\n name: String" + + "\n number : Int" + + "\n name : String" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function (f : Int -> Int) (x : Int) : Int =" + + "\n f (x)" + + "\n" + + "\n process (sequence : Seq [Int]) : Seq [Int] =" + + "\n sequence" + + "\n .map ( lambda elem --> my_function (elem) (my_constant) )" + + "\n" + "\nend" + "\n") diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index 28000751..a9e166e4 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -24,14 +24,21 @@ class PreprocessorSequenceTranslatorSpec () "\n soda.lib.Enum" + "\n" + "\n abstract" + - "\n number: Int" + - "\n name: String" + + "\n number : Int" + + "\n name : String" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function (f : Int \u2192 Int) (x : Int) : Int =" + + "\n f (x)" + + "\n" + + "\n process (sequence : Seq [Int]) : Seq [Int] =" + + "\n sequence" + + "\n .map ( \u03BB elem \u27F6 my_function (elem) (my_constant) )" + + "\n" + "\nend" + "\n" + "\n") @@ -50,14 +57,21 @@ class PreprocessorSequenceTranslatorSpec () "\n soda.lib.Enum" + "\n" + "\n abstract" + - "\n number: Int" + - "\n name: String" + + "\n number : Int" + + "\n name : String" + "\n" + - "\n my_constant: Int = 0" + + "\n my_constant : Int = 0" + "\n" + - "\n my_function (x: Int, y: Int): Int =" + + "\n my_function (x : Int) (y : Int) : Int =" + "\n x + y" + "\n" + + "\n another_function (f : Int -> Int) (x : Int) : Int =" + + "\n f (x)" + + "\n" + + "\n process (sequence : Seq [Int]) : Seq [Int] =" + + "\n sequence" + + "\n .map ( lambda elem --> my_function (elem) (my_constant) )" + + "\n" + "\nend" + "\n") diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda index 547d0f37..e133d678 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ClassBeginningAnnotationSpec.soda @@ -20,8 +20,10 @@ class ClassBeginningAnnotationSpec () get_as_block (text: String): Block = default_block_processor - .split_blocks (text) - .head + .make_blocks( + default_block_processor + .split_blocks (text) + ).head example_1 = get_as_block ( diff --git a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda index f55115d8..630e67dc 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda +++ b/translator/src/test/scala/soda/translator/parser/annotation/ExampleProgram.soda @@ -64,7 +64,9 @@ class ExampleProgram ) example_blocks : Seq [Block] = - default_block_processor.split_blocks (example_program) + default_block_processor.make_blocks( + default_block_processor.split_blocks (example_program) + ) end diff --git a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala index e0ae5f20..4737ccf7 100644 --- a/translator/src/test/scala/soda/translator/parser/annotation/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/annotation/Package.scala @@ -184,8 +184,10 @@ case class ClassBeginningAnnotationSpec () def get_as_block (text: String): Block = default_block_processor - .split_blocks (text) - .head + .make_blocks( + default_block_processor + .split_blocks (text) + ).head lazy val example_1 = get_as_block ( @@ -421,7 +423,9 @@ trait ExampleProgram ) lazy val example_blocks : Seq [Block] = - default_block_processor.split_blocks (example_program) + default_block_processor.make_blocks( + default_block_processor.split_blocks (example_program) + ) } diff --git a/translator/src/test/scala/soda/translator/replacement/Package.scala b/translator/src/test/scala/soda/translator/replacement/Package.scala index 781197f5..1d7ba888 100644 --- a/translator/src/test/scala/soda/translator/replacement/Package.scala +++ b/translator/src/test/scala/soda/translator/replacement/Package.scala @@ -228,6 +228,56 @@ case class ReplacementAuxSpec () } +case class ReplacementSpec () + extends + org.scalatest.funsuite.AnyFunSuite +{ + + import soda.translator.parser.SodaConstant_ + + def check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + lazy val instance = ReplacementAux_ () + + private lazy val _sc = SodaConstant_ () + + test ("Unicode replacements 1") ( + check ( + obtained = + Replacement_ ("\u03BB") + .replace_all ("\u03BB") (_sc.lambda_reserved_word) + .line + ) ( + expected = "lambda" + ) + ) + + test ("Unicode replacement 2") ( + check ( + obtained = + Replacement_ ("\u2192") + .replace_all ("\u2192") ("->") + .line + ) ( + expected = "->" + ) + ) + + test ("Unicode replacement 3") ( + check ( + obtained = + Replacement_ (_sc.case_arrow_unicode_symbol) + .replace_all (_sc.case_arrow_unicode_symbol) (_sc.case_reserved_word) + .line + ) ( + expected = _sc.case_reserved_word + ) + ) + +} + + case class TokenizerSpec () extends org.scalatest.funsuite.AnyFunSuite diff --git a/translator/src/test/scala/soda/translator/replacement/ReplacementSpec.soda b/translator/src/test/scala/soda/translator/replacement/ReplacementSpec.soda new file mode 100644 index 00000000..d8bb4bd2 --- /dev/null +++ b/translator/src/test/scala/soda/translator/replacement/ReplacementSpec.soda @@ -0,0 +1,50 @@ + +class ReplacementSpec () + extends + org.scalatest.funsuite.AnyFunSuite + + import + soda.translator.parser.SodaConstant_ + + check [A] (obtained : A) (expected : A) : org.scalatest.compatible.Assertion = + assert (obtained == expected) + + instance = ReplacementAux_ () + + _sc = SodaConstant_ () + + test ("Unicode replacements 1") ( + check ( + obtained := + Replacement_ ("\u03BB") + .replace_all ("\u03BB") (_sc.lambda_reserved_word) + .line + ) ( + expected := "lambda" + ) + ) + + test ("Unicode replacement 2") ( + check ( + obtained := + Replacement_ ("\u2192") + .replace_all ("\u2192") ("->") + .line + ) ( + expected := "->" + ) + ) + + test ("Unicode replacement 3") ( + check ( + obtained := + Replacement_ (_sc.case_arrow_unicode_symbol) + .replace_all (_sc.case_arrow_unicode_symbol) (_sc.case_reserved_word) + .line + ) ( + expected := _sc.case_reserved_word + ) + ) + +end + From e1a736d6d3bdaa43141ea3aa6784f278bad1a608 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Thu, 23 Feb 2023 21:35:33 +0100 Subject: [PATCH 61/71] Add some Soda Unicode symbols --- .../soda/translator/parser/Package.scala | 34 +++++++++++++++---- .../soda/translator/parser/SodaConstant.soda | 34 +++++++++++++++---- .../soda/translator/parser/Package.scala | 26 +++++++++++--- .../PreprocessorSequenceTranslatorSpec.soda | 26 +++++++++++--- 4 files changed, 100 insertions(+), 20 deletions(-) diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index 4a7f13df..fa10e264 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -292,10 +292,10 @@ trait SodaConstant lazy val parameter_definition_unicode_symbol = "\u2254" - lazy val lambda_reserved_word = "lambda" - lazy val any_reserved_word = "any" + lazy val lambda_reserved_word = "lambda" + lazy val lambda_unicode_symbol = "\u03BB" lazy val if_reserved_word = "if" @@ -310,12 +310,16 @@ trait SodaConstant lazy val class_reserved_word = "class" + lazy val class_proposed_unicode_symbol = "\u23BE" + lazy val extends_reserved_word = "extends" lazy val abstract_reserved_word = "abstract" lazy val class_end_reserved_word = "end" + lazy val class_end_proposed_unicode_symbol = "\u23BF" + lazy val this_reserved_word = "this" lazy val subtype_reserved_word = "subtype" @@ -324,14 +328,24 @@ trait SodaConstant lazy val false_reserved_word = "false" + lazy val false_unicode_symbol = "\u22A5" + lazy val true_reserved_word = "true" + lazy val true_unicode_symbol = "\u22A4" + lazy val not_reserved_word = "not" + lazy val not_unicode_symbol = "\u00AC" + lazy val and_reserved_word = "and" + lazy val and_unicode_symbol = "\u2227" + lazy val or_reserved_word = "or" + lazy val or_unicode_symbol = "\u2228" + lazy val package_reserved_word = "package" lazy val import_reserved_word = "import" @@ -439,10 +453,18 @@ trait SodaConstant lazy val soda_unicode_symbols : Seq [Tuple2 [String, String] ] = Seq ( - Tuple2 (lambda_unicode_symbol, lambda_reserved_word), - Tuple2 (lambda_arrow_unicode_symbol, lambda_arrow_symbol), - Tuple2 (function_arrow_unicode_symbol, function_arrow_symbol), - Tuple2 (case_arrow_unicode_symbol, case_arrow_symbol) + Tuple2 (lambda_unicode_symbol , lambda_reserved_word), + Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol), + Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol), + Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol), + Tuple2 (false_unicode_symbol , false_reserved_word), + Tuple2 (true_unicode_symbol , true_reserved_word), + Tuple2 (not_unicode_symbol , not_reserved_word), + Tuple2 (and_unicode_symbol , and_reserved_word), + Tuple2 (or_unicode_symbol , or_reserved_word), + Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), + Tuple2 (class_proposed_unicode_symbol , class_reserved_word), + Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) ) } diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index 49081b9a..42e38d83 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -25,10 +25,10 @@ class SodaConstant parameter_definition_unicode_symbol = "\u2254" - lambda_reserved_word = "lambda" - any_reserved_word = "any" + lambda_reserved_word = "lambda" + lambda_unicode_symbol = "\u03BB" if_reserved_word = "if" @@ -43,12 +43,16 @@ class SodaConstant class_reserved_word = "class" + class_proposed_unicode_symbol = "\u23BE" + extends_reserved_word = "extends" abstract_reserved_word = "abstract" class_end_reserved_word = "end" + class_end_proposed_unicode_symbol = "\u23BF" + this_reserved_word = "this" subtype_reserved_word = "subtype" @@ -57,14 +61,24 @@ class SodaConstant false_reserved_word = "false" + false_unicode_symbol = "\u22A5" + true_reserved_word = "true" + true_unicode_symbol = "\u22A4" + not_reserved_word = "not" + not_unicode_symbol = "\u00AC" + and_reserved_word = "and" + and_unicode_symbol = "\u2227" + or_reserved_word = "or" + or_unicode_symbol = "\u2228" + package_reserved_word = "package" import_reserved_word = "import" @@ -172,10 +186,18 @@ class SodaConstant soda_unicode_symbols : Seq [Tuple2 [String, String] ] = Seq ( - Tuple2 (lambda_unicode_symbol, lambda_reserved_word), - Tuple2 (lambda_arrow_unicode_symbol, lambda_arrow_symbol), - Tuple2 (function_arrow_unicode_symbol, function_arrow_symbol), - Tuple2 (case_arrow_unicode_symbol, case_arrow_symbol) + Tuple2 (lambda_unicode_symbol , lambda_reserved_word), + Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol), + Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol), + Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol), + Tuple2 (false_unicode_symbol , false_reserved_word), + Tuple2 (true_unicode_symbol , true_reserved_word), + Tuple2 (not_unicode_symbol , not_reserved_word), + Tuple2 (and_unicode_symbol , and_reserved_word), + Tuple2 (or_unicode_symbol , or_reserved_word), + Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), + Tuple2 (class_proposed_unicode_symbol , class_reserved_word), + Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) ) end diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index 136a2db4..e4c41c64 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -62,9 +62,10 @@ case class PreprocessorSequenceTranslatorSpec () "\n" + "\n/**" + "\n * Example class for testing." + + "\n * '\u03BB' in a comment is not replaced." + "\n */" + "\n" + - "\nclass Example" + + "\n\u23BE Example" + "\n" + "\n import" + "\n soda.lib.Fold_" + @@ -84,9 +85,17 @@ case class PreprocessorSequenceTranslatorSpec () "\n" + "\n process (sequence : Seq [Int]) : Seq [Int] =" + "\n sequence" + - "\n .map ( \u03BB elem \u27F6 my_function (elem) (my_constant) )" + + "\n .map ( \u03BB elem \u27F6 my_function (x \u2254 elem) (y \u2254 my_constant) )" + "\n" + - "\nend" + + "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + + "\n (x \u2228 y) \u2227 \u00AC (x \u2227 y)" + + "\n" + + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + + "\n match b" + + "\n case \u22A4 \u27F9 x" + + "\n case \u22A5 \u27F9 y" + + "\n" + + "\n\u23BF" + "\n" + "\n") @@ -95,6 +104,7 @@ case class PreprocessorSequenceTranslatorSpec () "\n" + "\n/**" + "\n * Example class for testing." + + "\n * '\u03BB' in a comment is not replaced." + "\n */" + "\n" + "\nclass Example" + @@ -117,7 +127,15 @@ case class PreprocessorSequenceTranslatorSpec () "\n" + "\n process (sequence : Seq [Int]) : Seq [Int] =" + "\n sequence" + - "\n .map ( lambda elem --> my_function (elem) (my_constant) )" + + "\n .map ( lambda elem --> my_function (x := elem) (y := my_constant) )" + + "\n" + + "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + + "\n (x or y) and not (x and y)" + + "\n" + + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + + "\n match b" + + "\n case true ==> x" + + "\n case false ==> y" + "\n" + "\nend" + "\n") diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index a9e166e4..beceb325 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -15,9 +15,10 @@ class PreprocessorSequenceTranslatorSpec () "\n" + "\n/**" + "\n * Example class for testing." + + "\n * '\u03BB' in a comment is not replaced." + "\n */" + "\n" + - "\nclass Example" + + "\n\u23BE Example" + "\n" + "\n import" + "\n soda.lib.Fold_" + @@ -37,9 +38,17 @@ class PreprocessorSequenceTranslatorSpec () "\n" + "\n process (sequence : Seq [Int]) : Seq [Int] =" + "\n sequence" + - "\n .map ( \u03BB elem \u27F6 my_function (elem) (my_constant) )" + + "\n .map ( \u03BB elem \u27F6 my_function (x \u2254 elem) (y \u2254 my_constant) )" + "\n" + - "\nend" + + "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + + "\n (x \u2228 y) \u2227 \u00AC (x \u2227 y)" + + "\n" + + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + + "\n match b" + + "\n case \u22A4 \u27F9 x" + + "\n case \u22A5 \u27F9 y" + + "\n" + + "\n\u23BF" + "\n" + "\n") @@ -48,6 +57,7 @@ class PreprocessorSequenceTranslatorSpec () "\n" + "\n/**" + "\n * Example class for testing." + + "\n * '\u03BB' in a comment is not replaced." + "\n */" + "\n" + "\nclass Example" + @@ -70,7 +80,15 @@ class PreprocessorSequenceTranslatorSpec () "\n" + "\n process (sequence : Seq [Int]) : Seq [Int] =" + "\n sequence" + - "\n .map ( lambda elem --> my_function (elem) (my_constant) )" + + "\n .map ( lambda elem --> my_function (x := elem) (y := my_constant) )" + + "\n" + + "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + + "\n (x or y) and not (x and y)" + + "\n" + + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + + "\n match b" + + "\n case true ==> x" + + "\n case false ==> y" + "\n" + "\nend" + "\n") From 62d64a7109656c451cb2043f7ecf8919626a9598 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 27 Feb 2023 11:39:18 +0100 Subject: [PATCH 62/71] Add example in Unicode --- .../example/algorithms/FizzBuzzUnicode.soda | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda new file mode 100644 index 00000000..25069192 --- /dev/null +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda @@ -0,0 +1,21 @@ +⎾ FizzBuzzPatternUnicode + + fizz = "Fizz" + + buzz = "Buzz" + + _range = soda.lib.Range_ () + + apply : Seq [String] = + _range.apply (100) + .map ( λ x ⟶ x + 1) + .map (_get_fizz_buzz_term) + + _get_fizz_buzz_term (n : Int) : String = + match Tuple2 (n % 3 , n % 5) + case Tuple2 (0 , 0) ⟹ fizz + buzz + case Tuple2 (0 , x) ⟹ fizz + case Tuple2 (x , 0) ⟹ buzz + case x ⟹ n.toString + +⎿ From 9c93cf4cf977b11e0c3feb6cea1cf07142caa194 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 27 Feb 2023 11:40:47 +0100 Subject: [PATCH 63/71] Update unit tests for translation --- .../soda/example/algorithms/Package.scala | 27 +++++++++++++++++++ .../example/algorithms/FizzBuzzUnicode.scala | 25 +++++++++++++++++ .../example/algorithms/FizzBuzzUnicode.soda | 21 +++++++++++++++ .../example/algorithms/SaladMaker.scala | 14 ++++++++-- .../example/algorithms/SaladMaker.soda | 14 ++++++++-- .../ethicalissues/fairness/Fairness.scala | 2 +- .../ethicalissues/fairness/Fairness.soda | 2 +- .../pricemonitor/PriceMonitor.scala | 1 - .../pricemonitor/PriceMonitor.soda | 1 - .../pricemonitor/Requirement1Monitor.scala | 1 - .../pricemonitor/Requirement1Monitor.soda | 1 - .../pricemonitor/Requirement2Monitor.scala | 1 - .../pricemonitor/Requirement2Monitor.soda | 1 - .../pricemonitor/Requirement3Monitor.scala | 1 - .../pricemonitor/Requirement3Monitor.soda | 1 - .../forcoq/algorithms/RecursionForCoq.soda | 1 - .../translator/example/forcoq/lib/List.soda | 1 - .../translator/example/forcoq/lib/Nat.soda | 1 - .../forcoq/mathematics/FactorialForCoq.soda | 1 - .../mathematics/FiboExampleInSodaForCoq.soda | 1 - .../mathematics/TriangularNumberForCoq.soda | 1 - .../mathematics/TriangularNumberForCoq.v | 13 --------- .../example/inanutshell/InANutshell.scala | 2 -- .../example/inanutshell/InANutshell.soda | 1 - .../example/miniexample/MiniExample.soda | 1 - .../toscala/FullTranslationSpec.soda | 13 +++++++++ .../extension/toscala/Package.scala | 12 +++++++++ 27 files changed, 124 insertions(+), 37 deletions(-) create mode 100644 translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.scala create mode 100644 translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda diff --git a/examples/src/main/scala/soda/example/algorithms/Package.scala b/examples/src/main/scala/soda/example/algorithms/Package.scala index 60948330..6f740332 100644 --- a/examples/src/main/scala/soda/example/algorithms/Package.scala +++ b/examples/src/main/scala/soda/example/algorithms/Package.scala @@ -62,6 +62,33 @@ trait FizzBuzzPatternMatching case class FizzBuzzPatternMatching_ () extends FizzBuzzPatternMatching +trait FizzBuzzPatternUnicode +{ + + lazy val fizz = "Fizz" + + lazy val buzz = "Buzz" + + private lazy val _range = soda.lib.Range_ () + + lazy val apply : Seq [String] = + _range.apply (100) + .map ( x => x + 1) + .map (_get_fizz_buzz_term) + + private def _get_fizz_buzz_term (n : Int) : String = + Tuple2 (n % 3 , n % 5) match { + case Tuple2 (0 , 0) => fizz + buzz + case Tuple2 (0 , x) => fizz + case Tuple2 (x , 0) => buzz + case x => n.toString + } + +} + +case class FizzBuzzPatternUnicode_ () extends FizzBuzzPatternUnicode + + trait Main { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.scala b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.scala new file mode 100644 index 00000000..2763aebc --- /dev/null +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.scala @@ -0,0 +1,25 @@ +trait FizzBuzzPatternUnicode +{ + + lazy val fizz = "Fizz" + + lazy val buzz = "Buzz" + + private lazy val _range = soda.lib.Range_ () + + lazy val apply : Seq [String] = + _range.apply (100) + .map ( x => x + 1) + .map (_get_fizz_buzz_term) + + private def _get_fizz_buzz_term (n : Int) : String = + Tuple2 (n % 3 , n % 5) match { + case Tuple2 (0 , 0) => fizz + buzz + case Tuple2 (0 , x) => fizz + case Tuple2 (x , 0) => buzz + case x => n.toString + } + +} + +case class FizzBuzzPatternUnicode_ () extends FizzBuzzPatternUnicode diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda new file mode 100644 index 00000000..25069192 --- /dev/null +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda @@ -0,0 +1,21 @@ +⎾ FizzBuzzPatternUnicode + + fizz = "Fizz" + + buzz = "Buzz" + + _range = soda.lib.Range_ () + + apply : Seq [String] = + _range.apply (100) + .map ( λ x ⟶ x + 1) + .map (_get_fizz_buzz_term) + + _get_fizz_buzz_term (n : Int) : String = + match Tuple2 (n % 3 , n % 5) + case Tuple2 (0 , 0) ⟹ fizz + buzz + case Tuple2 (0 , x) ⟹ fizz + case Tuple2 (x , 0) ⟹ buzz + case x ⟹ n.toString + +⎿ diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala index 0de8d911..5978c48e 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.scala @@ -1,12 +1,22 @@ trait SaladMaker { - def apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + def apply [Ingredient, Salad] + (list_of_ingredients : Seq [Ingredient] ) + (initial_bowl : Salad) + (next_ingredient_function : Salad => Ingredient => Salad) + (condition_to_continue : Salad => Ingredient => Boolean) + : Salad = _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) import scala.annotation.tailrec @tailrec final - private def _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad => Ingredient => Salad) (condition_to_continue : Salad => Ingredient => Boolean) : Salad = + private def _tailrec_prepare_salad [Ingredient, Salad] + (ingredients_so_far : Seq [Ingredient] ) + (salad_so_far : Salad) + (next_ingredient_function : Salad => Ingredient => Salad) + (condition_to_continue : Salad => Ingredient => Boolean) + : Salad = if ( ingredients_so_far.isEmpty || ( ! condition_to_continue (salad_so_far) (ingredients_so_far.head) ) ) salad_so_far else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) diff --git a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda index a53329de..c04b7652 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/SaladMaker.soda @@ -1,11 +1,21 @@ class SaladMaker - apply [Ingredient, Salad] (list_of_ingredients : Seq [Ingredient] ) (initial_bowl : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + apply [Ingredient, Salad] + (list_of_ingredients : Seq [Ingredient] ) + (initial_bowl : Salad) + (next_ingredient_function : Salad -> Ingredient -> Salad) + (condition_to_continue : Salad -> Ingredient -> Boolean) + : Salad = _tailrec_prepare_salad (list_of_ingredients) (initial_bowl) (next_ingredient_function) (condition_to_continue) @tailrec - _tailrec_prepare_salad [Ingredient, Salad] (ingredients_so_far : Seq [Ingredient] ) (salad_so_far : Salad) (next_ingredient_function : Salad -> Ingredient -> Salad) (condition_to_continue : Salad -> Ingredient -> Boolean) : Salad = + _tailrec_prepare_salad [Ingredient, Salad] + (ingredients_so_far : Seq [Ingredient] ) + (salad_so_far : Salad) + (next_ingredient_function : Salad -> Ingredient -> Salad) + (condition_to_continue : Salad -> Ingredient -> Boolean) + : Salad = if ingredients_so_far.isEmpty or ( not condition_to_continue (salad_so_far) (ingredients_so_far.head) ) then salad_so_far else _tailrec_prepare_salad (ingredients_so_far.tail) (next_ingredient_function (salad_so_far) (ingredients_so_far.head) ) (next_ingredient_function) (condition_to_continue) diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala index ee94b89b..a356edfd 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala @@ -1,4 +1,4 @@ -package soda.example.ethicalissues.fairness + trait Applicant { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda index eb623ec1..1a187f03 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda @@ -1,4 +1,4 @@ -package soda.example.ethicalissues.fairness + class Applicant diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala index 05c3229f..82532963 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor trait Customer { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.soda index c79501cb..0607bf30 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Customer diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index 730db703..6d2b8d8f 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor trait Report1 { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda index b8256a5e..75a8b4a6 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report1 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala index ea835c13..4fd98a8d 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor trait Report2 { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.soda index 620b7c58..82e3b3e1 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report2 diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 03940a9b..42461fc9 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor trait Report3 { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda index 8e345fad..bf157075 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.soda @@ -1,4 +1,3 @@ -package soda.example.ethicalissues.pricemonitor class Report3 diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda index 5ecca244..eb562420 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.algorithms /** * This class contains tail recursive auxiliary functions. diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda index 099fb620..a2cad06a 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class list [A] diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda index 88b9e767..d6207e48 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.lib class nat diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda index f6fd39d2..fdda5183 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FactorialForCoq diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda index 94e8793d..4b8e9fbd 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class FiboExampleInSodaForCoq diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda index b6f3aa3f..92de56a9 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.soda @@ -1,4 +1,3 @@ -package soda.example.forcoq.mathematics class TriangularNumberForCoq diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v index 906e8f88..3003fa2f 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.v @@ -1,16 +1,3 @@ -(* -package soda.example.forcoq.mathematics -*) - -Require Import Coq.ZArith.BinInt . -(* https://coq.inria.fr/library/Coq.ZArith.BinInt.html *) - -Require Import Coq.Lists.List . -(* https://coq.inria.fr/library/Coq.Lists.List.html *) - -Notation Int := Z . - - Module TriangularNumberForCoq . Import soda.example.forcoq.lib.O_ . diff --git a/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.scala b/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.scala index 1aeeee01..c3ec94d2 100644 --- a/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.scala +++ b/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.scala @@ -1,5 +1,3 @@ -package soda.example.inanutshell - trait InANutshell { diff --git a/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.soda b/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.soda index e8459852..fc647d38 100644 --- a/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.soda +++ b/translator/src/test/resources/soda/translator/example/inanutshell/InANutshell.soda @@ -1,4 +1,3 @@ -package soda.example.inanutshell class InANutshell diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda index 9f2f55ec..6732873a 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.soda @@ -1,4 +1,3 @@ -package soda.example.miniexample class MiniExample diff --git a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda index bb669c42..f1f9425f 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda @@ -31,6 +31,10 @@ class FullTranslationSpec () PiIterator = "mathematics/PiIterator" + SaladMaker = "algorithms/SaladMaker" + + FizzBuzzUnicode = "algorithms/FizzBuzzUnicode" + ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" InANutshell = "inanutshell/InANutshell" @@ -85,6 +89,15 @@ class FullTranslationSpec () test_translation (PiIterator) ) + test ("should translate the Salad Maker example") ( + test_translation (SaladMaker) + ) + + test ("should translate the FizzBuzz Unicode example") ( + test_translation (FizzBuzzUnicode) + ) + + test ("should translated Soda code that uses Scala reserved words as variables and functions") ( test_translation (ScalaReservedWordEscaping) ) diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala index 8f31adfc..60cea78c 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -197,6 +197,10 @@ case class FullTranslationSpec () lazy val PiIterator = "mathematics/PiIterator" + lazy val SaladMaker = "algorithms/SaladMaker" + + lazy val FizzBuzzUnicode = "algorithms/FizzBuzzUnicode" + lazy val ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" lazy val InANutshell = "inanutshell/InANutshell" @@ -251,6 +255,14 @@ case class FullTranslationSpec () test_translation (PiIterator) ) + test ("should translate the Salad Maker example") ( + test_translation (SaladMaker) + ) + + test ("should translate the FizzBuzz Unicode example") ( + test_translation (FizzBuzzUnicode) + ) + test ("should translated Soda code that uses Scala reserved words as variables and functions") ( test_translation (ScalaReservedWordEscaping) ) From cf85316072ed4b8da283292cfd2c66ea8c408485 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Mon, 27 Feb 2023 13:32:11 +0100 Subject: [PATCH 64/71] Add Unicode symbols for <= and >= --- .../soda/translator/parser/Package.scala | 21 +++++++++++++++++++ .../soda/translator/parser/SodaConstant.soda | 21 +++++++++++++++++++ .../soda/translator/parser/Package.scala | 6 ++++++ .../PreprocessorSequenceTranslatorSpec.soda | 6 ++++++ 4 files changed, 54 insertions(+) diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index fa10e264..e4a5f1a8 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -382,6 +382,20 @@ trait SodaConstant lazy val modulo_symbol = "%" + lazy val equals_symbol = "==" + + lazy val less_than_symbol = "<" + + lazy val less_than_or_equal_to_symbol = "<=" + + lazy val less_than_or_equal_to_unicode_symbol = "\u2264" + + lazy val greater_than_symbol = ">" + + lazy val greater_than_or_equal_to_symbol = ">=" + + lazy val greater_than_or_equal_to_unicode_symbol = "\u2265" + lazy val documentation_comment_opening_symbol = "/**" lazy val comment_opening_symbol = "/*" @@ -437,6 +451,11 @@ trait SodaConstant multiplication_symbol, division_symbol, modulo_symbol, + equals_symbol, + less_than_symbol, + less_than_or_equal_to_symbol, + greater_than_symbol, + greater_than_or_equal_to_symbol, subtype_abbreviation, supertype_abbreviation ) @@ -462,6 +481,8 @@ trait SodaConstant Tuple2 (not_unicode_symbol , not_reserved_word), Tuple2 (and_unicode_symbol , and_reserved_word), Tuple2 (or_unicode_symbol , or_reserved_word), + Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol), + Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol), Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), Tuple2 (class_proposed_unicode_symbol , class_reserved_word), Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index 42e38d83..bb3f7a43 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -115,6 +115,20 @@ class SodaConstant modulo_symbol = "%" + equals_symbol = "==" + + less_than_symbol = "<" + + less_than_or_equal_to_symbol = "<=" + + less_than_or_equal_to_unicode_symbol = "\u2264" + + greater_than_symbol = ">" + + greater_than_or_equal_to_symbol = ">=" + + greater_than_or_equal_to_unicode_symbol = "\u2265" + documentation_comment_opening_symbol = "/**" comment_opening_symbol = "/*" @@ -170,6 +184,11 @@ class SodaConstant multiplication_symbol, division_symbol, modulo_symbol, + equals_symbol, + less_than_symbol, + less_than_or_equal_to_symbol, + greater_than_symbol, + greater_than_or_equal_to_symbol, subtype_abbreviation, supertype_abbreviation ) @@ -195,6 +214,8 @@ class SodaConstant Tuple2 (not_unicode_symbol , not_reserved_word), Tuple2 (and_unicode_symbol , and_reserved_word), Tuple2 (or_unicode_symbol , or_reserved_word), + Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol), + Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol), Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), Tuple2 (class_proposed_unicode_symbol , class_reserved_word), Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index e4c41c64..3483807d 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -90,6 +90,9 @@ case class PreprocessorSequenceTranslatorSpec () "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + "\n (x \u2228 y) \u2227 \u00AC (x \u2227 y)" + "\n" + + "\n are_equal (x : Int) (y : Int) : Boolean =" + + "\n (x \u2264 y) \u2227 (x \u2265 y)" + + "\n" + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + "\n match b" + "\n case \u22A4 \u27F9 x" + @@ -132,6 +135,9 @@ case class PreprocessorSequenceTranslatorSpec () "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + "\n (x or y) and not (x and y)" + "\n" + + "\n are_equal (x : Int) (y : Int) : Boolean =" + + "\n (x <= y) and (x >= y)" + + "\n" + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + "\n match b" + "\n case true ==> x" + diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index beceb325..1eb2622b 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -43,6 +43,9 @@ class PreprocessorSequenceTranslatorSpec () "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + "\n (x \u2228 y) \u2227 \u00AC (x \u2227 y)" + "\n" + + "\n are_equal (x : Int) (y : Int) : Boolean =" + + "\n (x \u2264 y) \u2227 (x \u2265 y)" + + "\n" + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + "\n match b" + "\n case \u22A4 \u27F9 x" + @@ -85,6 +88,9 @@ class PreprocessorSequenceTranslatorSpec () "\n my_xor (x : Boolean) (y : Boolean) : Boolean =" + "\n (x or y) and not (x and y)" + "\n" + + "\n are_equal (x : Int) (y : Int) : Boolean =" + + "\n (x <= y) and (x >= y)" + + "\n" + "\n if_true_else (b : Boolean) (x : Int) (y : Int) : Int =" + "\n match b" + "\n case true ==> x" + From 66215b665802b451ec39392dc3cf046e8c18c2da Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 28 Feb 2023 10:56:59 +0100 Subject: [PATCH 65/71] Add proposed Unicode symbols --- .../mathematics/FiboUnicodeExample.soda | 13 +++++++ .../soda/example/mathematics/Package.scala | 16 ++++++++ .../soda/translator/parser/Package.scala | 37 ++++++++++++------- .../soda/translator/parser/SodaConstant.soda | 37 ++++++++++++------- .../mathematics/FiboUnicodeExample.scala | 15 ++++++++ .../mathematics/FiboUnicodeExample.soda | 13 +++++++ .../toscala/FullTranslationSpec.soda | 2 + .../extension/toscala/Package.scala | 2 + .../soda/translator/parser/Package.scala | 10 +++++ .../PreprocessorSequenceTranslatorSpec.soda | 10 +++++ 10 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 examples/src/main/scala/soda/example/mathematics/FiboUnicodeExample.soda create mode 100644 translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala create mode 100644 translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.soda diff --git a/examples/src/main/scala/soda/example/mathematics/FiboUnicodeExample.soda b/examples/src/main/scala/soda/example/mathematics/FiboUnicodeExample.soda new file mode 100644 index 00000000..5085cb98 --- /dev/null +++ b/examples/src/main/scala/soda/example/mathematics/FiboUnicodeExample.soda @@ -0,0 +1,13 @@ + +⎾ FiboUnicodeExample + + apply (n : Int) = + _rec (n) (0) (1) + + _rec (m : Int) (a : Int) (b : Int) : Int = + ⧩ m == 0 ▶ a + ▷ ⧩ m == 1 ▶ b + ▷ _rec (m - 1) (b) (a + b) + +⎿ + diff --git a/examples/src/main/scala/soda/example/mathematics/Package.scala b/examples/src/main/scala/soda/example/mathematics/Package.scala index ef138cd8..49eaa783 100644 --- a/examples/src/main/scala/soda/example/mathematics/Package.scala +++ b/examples/src/main/scala/soda/example/mathematics/Package.scala @@ -75,6 +75,22 @@ trait FiboExampleInSoda case class FiboExampleInSoda_ () extends FiboExampleInSoda +trait FiboUnicodeExample +{ + + def apply (n : Int) = + _rec (n) (0) (1) + + private def _rec (m : Int) (a : Int) (b : Int) : Int = + if ( m == 0 ) a + else if ( m == 1 ) b + else _rec (m - 1) (b) (a + b) + +} + +case class FiboUnicodeExample_ () extends FiboUnicodeExample + + trait InputPair [A, B] { diff --git a/translator/src/main/scala/soda/translator/parser/Package.scala b/translator/src/main/scala/soda/translator/parser/Package.scala index e4a5f1a8..ff3e58f8 100644 --- a/translator/src/main/scala/soda/translator/parser/Package.scala +++ b/translator/src/main/scala/soda/translator/parser/Package.scala @@ -300,10 +300,16 @@ trait SodaConstant lazy val if_reserved_word = "if" + lazy val if_proposed_unicode_symbol = "\u29E9" + lazy val then_reserved_word = "then" + lazy val then_proposed_unicode_symbol = "\u25B6" + lazy val else_reserved_word = "else" + lazy val else_proposed_unicode_symbol = "\u25B7" + lazy val match_reserved_word = "match" lazy val case_reserved_word = "case" @@ -472,20 +478,23 @@ trait SodaConstant lazy val soda_unicode_symbols : Seq [Tuple2 [String, String] ] = Seq ( - Tuple2 (lambda_unicode_symbol , lambda_reserved_word), - Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol), - Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol), - Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol), - Tuple2 (false_unicode_symbol , false_reserved_word), - Tuple2 (true_unicode_symbol , true_reserved_word), - Tuple2 (not_unicode_symbol , not_reserved_word), - Tuple2 (and_unicode_symbol , and_reserved_word), - Tuple2 (or_unicode_symbol , or_reserved_word), - Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol), - Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol), - Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), - Tuple2 (class_proposed_unicode_symbol , class_reserved_word), - Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) + Tuple2 (lambda_unicode_symbol , lambda_reserved_word) , + Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol) , + Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol) , + Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol) , + Tuple2 (false_unicode_symbol , false_reserved_word) , + Tuple2 (true_unicode_symbol , true_reserved_word) , + Tuple2 (not_unicode_symbol , not_reserved_word) , + Tuple2 (and_unicode_symbol , and_reserved_word) , + Tuple2 (or_unicode_symbol , or_reserved_word) , + Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol) , + Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol) , + Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol) , + Tuple2 (class_proposed_unicode_symbol , class_reserved_word) , + Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) , + Tuple2 (if_proposed_unicode_symbol , if_reserved_word) , + Tuple2 (then_proposed_unicode_symbol , then_reserved_word) , + Tuple2 (else_proposed_unicode_symbol , else_reserved_word) ) } diff --git a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda index bb3f7a43..41508ddf 100644 --- a/translator/src/main/scala/soda/translator/parser/SodaConstant.soda +++ b/translator/src/main/scala/soda/translator/parser/SodaConstant.soda @@ -33,10 +33,16 @@ class SodaConstant if_reserved_word = "if" + if_proposed_unicode_symbol = "\u29E9" + then_reserved_word = "then" + then_proposed_unicode_symbol = "\u25B6" + else_reserved_word = "else" + else_proposed_unicode_symbol = "\u25B7" + match_reserved_word = "match" case_reserved_word = "case" @@ -205,20 +211,23 @@ class SodaConstant soda_unicode_symbols : Seq [Tuple2 [String, String] ] = Seq ( - Tuple2 (lambda_unicode_symbol , lambda_reserved_word), - Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol), - Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol), - Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol), - Tuple2 (false_unicode_symbol , false_reserved_word), - Tuple2 (true_unicode_symbol , true_reserved_word), - Tuple2 (not_unicode_symbol , not_reserved_word), - Tuple2 (and_unicode_symbol , and_reserved_word), - Tuple2 (or_unicode_symbol , or_reserved_word), - Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol), - Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol), - Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol), - Tuple2 (class_proposed_unicode_symbol , class_reserved_word), - Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) + Tuple2 (lambda_unicode_symbol , lambda_reserved_word) , + Tuple2 (lambda_arrow_unicode_symbol , lambda_arrow_symbol) , + Tuple2 (function_arrow_unicode_symbol , function_arrow_symbol) , + Tuple2 (case_arrow_unicode_symbol , case_arrow_symbol) , + Tuple2 (false_unicode_symbol , false_reserved_word) , + Tuple2 (true_unicode_symbol , true_reserved_word) , + Tuple2 (not_unicode_symbol , not_reserved_word) , + Tuple2 (and_unicode_symbol , and_reserved_word) , + Tuple2 (or_unicode_symbol , or_reserved_word) , + Tuple2 (less_than_or_equal_to_unicode_symbol , less_than_or_equal_to_symbol) , + Tuple2 (greater_than_or_equal_to_unicode_symbol , greater_than_or_equal_to_symbol) , + Tuple2 (parameter_definition_unicode_symbol , parameter_definition_symbol) , + Tuple2 (class_proposed_unicode_symbol , class_reserved_word) , + Tuple2 (class_end_proposed_unicode_symbol , class_end_reserved_word) , + Tuple2 (if_proposed_unicode_symbol , if_reserved_word) , + Tuple2 (then_proposed_unicode_symbol , then_reserved_word) , + Tuple2 (else_proposed_unicode_symbol , else_reserved_word) ) end diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala new file mode 100644 index 00000000..26a8b6f7 --- /dev/null +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala @@ -0,0 +1,15 @@ + +trait FiboUnicodeExample +{ + + def apply (n : Int) = + _rec (n) (0) (1) + + private def _rec (m : Int) (a : Int) (b : Int) : Int = + if ( m == 0 ) a + else if ( m == 1 ) b + else _rec (m - 1) (b) (a + b) + +} + +case class FiboUnicodeExample_ () extends FiboUnicodeExample diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.soda b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.soda new file mode 100644 index 00000000..5085cb98 --- /dev/null +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.soda @@ -0,0 +1,13 @@ + +⎾ FiboUnicodeExample + + apply (n : Int) = + _rec (n) (0) (1) + + _rec (m : Int) (a : Int) (b : Int) : Int = + ⧩ m == 0 ▶ a + ▷ ⧩ m == 1 ▶ b + ▷ _rec (m - 1) (b) (a + b) + +⎿ + diff --git a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda index f1f9425f..be943e2e 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda +++ b/translator/src/test/scala/soda/translator/extension/toscala/FullTranslationSpec.soda @@ -35,6 +35,8 @@ class FullTranslationSpec () FizzBuzzUnicode = "algorithms/FizzBuzzUnicode" + FiboUnicodeExample = "mathematics/FiboUnicodeExample" + ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" InANutshell = "inanutshell/InANutshell" diff --git a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala index 60cea78c..f78bab5d 100644 --- a/translator/src/test/scala/soda/translator/extension/toscala/Package.scala +++ b/translator/src/test/scala/soda/translator/extension/toscala/Package.scala @@ -201,6 +201,8 @@ case class FullTranslationSpec () lazy val FizzBuzzUnicode = "algorithms/FizzBuzzUnicode" + lazy val FiboUnicodeExample = "mathematics/FiboUnicodeExample" + lazy val ScalaReservedWordEscaping = "algorithms/ScalaReservedWordEscaping" lazy val InANutshell = "inanutshell/InANutshell" diff --git a/translator/src/test/scala/soda/translator/parser/Package.scala b/translator/src/test/scala/soda/translator/parser/Package.scala index 3483807d..dc948be2 100644 --- a/translator/src/test/scala/soda/translator/parser/Package.scala +++ b/translator/src/test/scala/soda/translator/parser/Package.scala @@ -98,6 +98,11 @@ case class PreprocessorSequenceTranslatorSpec () "\n case \u22A4 \u27F9 x" + "\n case \u22A5 \u27F9 y" + "\n" + + "\n my_min (x : Int) (y : Int) : Int =" + + "\n \u29E9 x < y" + + "\n \u25B6 x" + + "\n \u25B7 y" + + "\n" + "\n\u23BF" + "\n" + "\n") @@ -143,6 +148,11 @@ case class PreprocessorSequenceTranslatorSpec () "\n case true ==> x" + "\n case false ==> y" + "\n" + + "\n my_min (x : Int) (y : Int) : Int =" + + "\n if x < y" + + "\n then x" + + "\n else y" + + "\n" + "\nend" + "\n") diff --git a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda index 1eb2622b..ef55823a 100644 --- a/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda +++ b/translator/src/test/scala/soda/translator/parser/PreprocessorSequenceTranslatorSpec.soda @@ -51,6 +51,11 @@ class PreprocessorSequenceTranslatorSpec () "\n case \u22A4 \u27F9 x" + "\n case \u22A5 \u27F9 y" + "\n" + + "\n my_min (x : Int) (y : Int) : Int =" + + "\n \u29E9 x < y" + + "\n \u25B6 x" + + "\n \u25B7 y" + + "\n" + "\n\u23BF" + "\n" + "\n") @@ -96,6 +101,11 @@ class PreprocessorSequenceTranslatorSpec () "\n case true ==> x" + "\n case false ==> y" + "\n" + + "\n my_min (x : Int) (y : Int) : Int =" + + "\n if x < y" + + "\n then x" + + "\n else y" + + "\n" + "\nend" + "\n") From 348e56b5919699a8753295ee7a2bf394e46ef9f6 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 28 Feb 2023 14:55:21 +0100 Subject: [PATCH 66/71] Use sbt 1.8.2 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index cfb87626..aeedd7eb 100644 --- a/project/build.properties +++ b/project/build.properties @@ -7,5 +7,5 @@ # [https://repo1.maven.org/maven2/org/scala-sbt/sbt-launch/] # [https://repo.scala-sbt.org/scalasbt/maven-releases/org/scala-sbt/sbt-launch/] # -sbt.version=1.7.1 +sbt.version=1.8.2 From 6679dbc37f13c41428178f74d6c674fef43286cb Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 28 Feb 2023 14:57:20 +0100 Subject: [PATCH 67/71] Use sbt-assembly 2.1.1 --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 487b15a3..9bfe034d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -4,7 +4,7 @@ * [[https://github.com/sbt/sbt-assembly]] * [[https://repo1.maven.org/maven2/com/eed3si9n/sbt-assembly_2.12_1.0/]] */ -addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.2.0") +addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1") /** * scalastyle-sbt-plugin From 015efbae94af29ff5350dd89c3f6d797975f15bd Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 28 Feb 2023 15:00:49 +0100 Subject: [PATCH 68/71] Use Scala 3.2.2 --- .github/workflows/ci.yml | 4 ++-- build.sbt | 6 +++--- docs/RELEASE-NOTES.md | 4 ++-- makeall.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d955a3e1..a38517cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,8 +19,8 @@ jobs: scala: - 2.11.12 - 2.12.17 - - 2.13.8 - - 3.2.0 + - 2.13.10 + - 3.2.2 steps: - name: Check out uses: actions/checkout@v3 diff --git a/build.sbt b/build.sbt index 13085ca0..f2f83ec3 100644 --- a/build.sbt +++ b/build.sbt @@ -4,9 +4,9 @@ lazy val scala2_11 = "2.11.12" lazy val scala2_12 = "2.12.17" -lazy val scala2_13 = "2.13.8" +lazy val scala2_13 = "2.13.10" -lazy val scala3_2 = "3.2.0" +lazy val scala3_2 = "3.2.2" lazy val commonSettings = Seq( @@ -36,7 +36,7 @@ lazy val commonSettings = * [[https://github.com/scalatest/scalatest]] * [[https://repo1.maven.org/maven2/org/scalatest/]] */ - libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.13" % "test", + libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.15" % "test", resolvers += Resolver.mavenLocal, publishTo := Some(Resolver.mavenLocal), publishMavenStyle := true, diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index f815e6bd..f6bcf485 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -1,8 +1,8 @@ --- - - version: v0.17.0 - date: unreleased - - build: sbt '++ 3.2.0' clean compile test package assembly - - release: target/scala-3.2.0/soda-0.17.0.jar + - build: sbt '++ 3.2.2' clean compile test package assembly + - release: target/scala-3.2.2/soda-0.17.0.jar - new_features: - includes an option to translate a whole Soda package into a single Scala file - reads `Package.soda` as prelude for a Soda file in the same directory diff --git a/makeall.sh b/makeall.sh index b6f7b123..b8b8ce78 100644 --- a/makeall.sh +++ b/makeall.sh @@ -9,7 +9,7 @@ sbt scalaVersion sbtVersion version clean compile test package assembly executableStub="exec java -jar \$0 \"\$@\" ; exit" sodaFile="soda" -scalaVersion="3.2.0" +scalaVersion="3.2.2" jarFile="target/scala-${scalaVersion}/soda-*.jar" echo ${executableStub} >${sodaFile} From 43136bec6addb060bbc1f48894d2bee9fb6ffadd Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Tue, 28 Feb 2023 16:15:36 +0100 Subject: [PATCH 69/71] Make minor changes in examples --- .../src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda | 1 + .../scala/soda/example/ethicalissues/fairness/Fairness.soda | 1 - .../scala/soda/example/ethicalissues/fairness/Package.scala | 2 -- .../soda/translator/example/algorithms/FizzBuzzUnicode.soda | 1 + .../translator/example/ethicalissues/fairness/Fairness.scala | 2 -- .../translator/example/ethicalissues/fairness/Fairness.soda | 1 - .../example/ethicalissues/pricemonitor/PriceMonitor.scala | 1 - .../ethicalissues/pricemonitor/Requirement1Monitor.scala | 1 - .../ethicalissues/pricemonitor/Requirement2Monitor.scala | 1 - .../ethicalissues/pricemonitor/Requirement3Monitor.scala | 1 - .../translator/example/forcoq/algorithms/RecursionForCoq.scala | 2 -- .../resources/soda/translator/example/forcoq/lib/List.scala | 2 -- .../test/resources/soda/translator/example/forcoq/lib/Nat.scala | 2 -- .../translator/example/forcoq/mathematics/FactorialForCoq.scala | 2 -- .../example/forcoq/mathematics/FiboExampleInSodaForCoq.scala | 2 -- .../example/forcoq/mathematics/TriangularNumberForCoq.scala | 2 -- .../translator/example/mathematics/FiboUnicodeExample.scala | 1 - .../soda/translator/example/miniexample/MiniExample.scala | 2 -- 18 files changed, 2 insertions(+), 25 deletions(-) diff --git a/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda b/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda index 25069192..2913a29b 100644 --- a/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda +++ b/examples/src/main/scala/soda/example/algorithms/FizzBuzzUnicode.soda @@ -1,3 +1,4 @@ + ⎾ FizzBuzzPatternUnicode fizz = "Fizz" diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda index 1a187f03..5994ca09 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Fairness.soda @@ -1,5 +1,4 @@ - class Applicant abstract diff --git a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala index c3bf47d5..bb5d82e3 100644 --- a/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala +++ b/examples/src/main/scala/soda/example/ethicalissues/fairness/Package.scala @@ -6,8 +6,6 @@ package soda.example.ethicalissues.fairness trait Package - - trait Applicant { diff --git a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda index 25069192..2913a29b 100644 --- a/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda +++ b/translator/src/test/resources/soda/translator/example/algorithms/FizzBuzzUnicode.soda @@ -1,3 +1,4 @@ + ⎾ FizzBuzzPatternUnicode fizz = "Fizz" diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala index a356edfd..945ff789 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.scala @@ -1,5 +1,3 @@ - - trait Applicant { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda index 1a187f03..5994ca09 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/fairness/Fairness.soda @@ -1,5 +1,4 @@ - class Applicant abstract diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala index 82532963..8b3f5942 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/PriceMonitor.scala @@ -1,4 +1,3 @@ - trait Customer { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala index 6d2b8d8f..8d517a31 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement1Monitor.scala @@ -1,4 +1,3 @@ - trait Report1 { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala index 4fd98a8d..871cfe02 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement2Monitor.scala @@ -1,4 +1,3 @@ - trait Report2 { diff --git a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala index 42461fc9..2d996777 100644 --- a/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala +++ b/translator/src/test/resources/soda/translator/example/ethicalissues/pricemonitor/Requirement3Monitor.scala @@ -1,4 +1,3 @@ - trait Report3 { diff --git a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala index f17155c8..eb396439 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/algorithms/RecursionForCoq.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.algorithms - /** * This class contains tail recursive auxiliary functions. */ diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala index d08bfdd5..9129eb5b 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/List.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.lib - trait list [A] { diff --git a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala index 435fbd5b..9ed0568f 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/lib/Nat.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.lib - trait nat { diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala index 36f039b6..c7896aec 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FactorialForCoq.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.mathematics - trait FactorialForCoq { diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala index f9345f4f..0b27f9ec 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/FiboExampleInSodaForCoq.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.mathematics - trait FiboExampleInSodaForCoq { diff --git a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala index 19db2a1a..eaa5d4f8 100644 --- a/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala +++ b/translator/src/test/resources/soda/translator/example/forcoq/mathematics/TriangularNumberForCoq.scala @@ -1,5 +1,3 @@ -package soda.example.forcoq.mathematics - trait TriangularNumberForCoq { diff --git a/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala index 26a8b6f7..b895b1b6 100644 --- a/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala +++ b/translator/src/test/resources/soda/translator/example/mathematics/FiboUnicodeExample.scala @@ -1,4 +1,3 @@ - trait FiboUnicodeExample { diff --git a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala index 70d61712..2319b36d 100644 --- a/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala +++ b/translator/src/test/resources/soda/translator/example/miniexample/MiniExample.scala @@ -1,5 +1,3 @@ -package soda.example.miniexample - trait MiniExample { From faf18da6e09bd908cdc0ac988f17435cb16e7b0d Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 1 Mar 2023 08:43:48 +0100 Subject: [PATCH 70/71] Update documentation --- documentation/src/site/tex/manual/appendix-01-reservedwords.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/src/site/tex/manual/appendix-01-reservedwords.tex b/documentation/src/site/tex/manual/appendix-01-reservedwords.tex index fa68ae33..fbcac876 100644 --- a/documentation/src/site/tex/manual/appendix-01-reservedwords.tex +++ b/documentation/src/site/tex/manual/appendix-01-reservedwords.tex @@ -13,7 +13,7 @@ \chapter{Reserved Words} \hline \sodaif $b$ \sodathen $e_{0}$ \sodaelse $e_{1}$ & expression if $b$ is true, then $e_{0}$, else $e_{1}$ \\ \hline - \sodamatch $x$ \sodacase $p_{i}$ \sodaimplies $e_{i}$ \sodaendmatch & pattern matching from $p_{i}$ to $e_{i}$ for $1 \leq i \leq n$ \\ + \sodamatch $x$ \sodacase $p_{i}$ \sodaimplies $e_{i}$ & pattern matching from $p_{i}$ to $e_{i}$ for $1 \leq i \leq n$ \\ \hline \sodaclass $B$ \sodaextends $A_{1} \ldots A_{n}$ & class $B$ extends classes $A_{0}$ and $A_{1}$ \\ \sodaclass $B$ [$A_{0}$ \sodasubtype $A_{1}$ ] & class $B$ requires a class $A_{0}$ which extends $A_{1}$ \\ From fa67fd0384a2b648694ebdf4812ef4f90cd873d6 Mon Sep 17 00:00:00 2001 From: Julian Mendez Date: Wed, 1 Mar 2023 19:58:47 +0100 Subject: [PATCH 71/71] Update version to 0.17.0 --- build.sbt | 2 +- docs/RELEASE-NOTES.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index f2f83ec3..ce99e0e1 100644 --- a/build.sbt +++ b/build.sbt @@ -11,7 +11,7 @@ lazy val scala3_2 = "3.2.2" lazy val commonSettings = Seq( organization := "se.umu.cs.rai.soda", - version := "0.17.0-SNAPSHOT", + version := "0.17.0", description := "Functional language to describe ethical problems", homepage := Some(url("https://bitbucket.org/mendezjulian/soda")), startYear := Some(2020), diff --git a/docs/RELEASE-NOTES.md b/docs/RELEASE-NOTES.md index f6bcf485..dfacbba6 100644 --- a/docs/RELEASE-NOTES.md +++ b/docs/RELEASE-NOTES.md @@ -1,6 +1,6 @@ --- - - version: v0.17.0 - - date: unreleased + - date: '2023-03-01' - build: sbt '++ 3.2.2' clean compile test package assembly - release: target/scala-3.2.2/soda-0.17.0.jar - new_features: