diff --git a/.github/workflows/ghc.yml b/.github/workflows/ghc.yml index b53026bda..2fa57511a 100644 --- a/.github/workflows/ghc.yml +++ b/.github/workflows/ghc.yml @@ -27,10 +27,24 @@ jobs: uses: actions/checkout@v4 - name: 🧰 Setup Stack - uses: freckle/stack-action@v4 + # FIXME use freckle/stack-action@v4 when https://github.com/freckle/stack-action/pull/31 is merged + uses: deemp/stack-action@main with: fast: ${{ github.ref_name != 'master' }} + - uses: actions/setup-node@v4 + with: + node-version: 20 + + - uses: actions/setup-java@v4 + with: + distribution: "zulu" + java-version: 21 + + - run: npm install -g eolang@0.15.1 + + - run: ./pipeline.sh + haddock: needs: [build] if: ${{ github.ref_name == 'master' }} diff --git a/.gitignore b/.gitignore index fc587c5eb..8a188c2b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.eoc +before.txt +after.txt +app.eo *.bak eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.hs eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.hs diff --git a/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf b/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf index be9180219..36ce7fb2d 100644 --- a/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf +++ b/eo-phi-normalizer/grammar/EO/Phi/Syntax.cf @@ -4,7 +4,7 @@ -- -- This is a non-ambiguous grammar for φ-programs. -token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])* {"--"}) ; +token Bytes ({"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] {"-"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ({"-"} ["0123456789ABCDEF"] ["0123456789ABCDEF"])+) ; token Function upper (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; token LabelId lower (char - [" \r\n\t,.|':;!-?][}{)(⟧⟦"])* ; token AlphaIndex ({"α0"} | {"α"} (digit - ["0"]) (digit)* ) ; diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs index 04444019a..ae634d48b 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Abs.hs @@ -1,4 +1,4 @@ --- File generated by the BNF Converter (bnfc 2.9.6). +-- File generated by the BNF Converter (bnfc 2.9.5). {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt index 6b3ef07d2..5bdd30af9 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Doc.txt @@ -1,87 +1,87 @@ -The Language Syntax -BNF Converter - - -%Process by txt2tags to generate html or latex - - - -This document was automatically generated by the //BNF-Converter//. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place). - -==The lexical structure of Syntax== - -===Literals=== - - - - - -Bytes literals are recognized by the regular expression -`````{"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ('-' ["0123456789ABCDEF"] ["0123456789ABCDEF"])* {"--"}````` - -Function literals are recognized by the regular expression -`````upper (char - [" - !'(),-.:;?[]{|}⟦⟧"])*````` - -LabelId literals are recognized by the regular expression -`````lower (char - [" - !'(),-.:;?[]{|}⟦⟧"])*````` - -AlphaIndex literals are recognized by the regular expression -`````{"α0"} | 'α' (digit - '0') digit*````` - - -===Reserved words and symbols=== -The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions. - -The reserved words used in Syntax are the following: - | ``Δ`` | ``Φ`` | ``λ`` | ``ν`` - | ``ξ`` | ``ρ`` | ``σ`` | ``φ`` - -The symbols used in Syntax are the following: - | { | } | ⟦ | ⟧ - | ( | ) | . | ⊥ - | ↦ | ∅ | ⤍ | , - -===Comments=== -There are no single-line comments in the grammar.There are no multiple-line comments in the grammar. - -==The syntactic structure of Syntax== -Non-terminals are enclosed between < and >. -The symbols -> (production), **|** (union) -and **eps** (empty rule) belong to the BNF notation. -All other symbols are terminals. - - | //Program// | -> | ``{`` //[Binding]// ``}`` - | //Object// | -> | ``⟦`` //[Binding]// ``⟧`` - | | **|** | //Object// ``(`` //[Binding]// ``)`` - | | **|** | //Object// ``.`` //Attribute// - | | **|** | ``Φ`` ``.`` //Attribute// - | | **|** | ``ξ`` ``.`` //Attribute// - | | **|** | ``⊥`` - | //Binding// | -> | //Attribute// ``↦`` //Object// - | | **|** | //Attribute// ``↦`` ``∅`` - | | **|** | ``Δ`` ``⤍`` //Bytes// - | | **|** | ``λ`` ``⤍`` //Function// - | //[Binding]// | -> | **eps** - | | **|** | //Binding// - | | **|** | //Binding// ``,`` //[Binding]// - | //Attribute// | -> | ``φ`` - | | **|** | ``ρ`` - | | **|** | ``σ`` - | | **|** | ``ν`` - | | **|** | //LabelId// - | | **|** | //AlphaIndex// - | //PeeledObject// | -> | //ObjectHead// //[ObjectAction]// - | //ObjectHead// | -> | ``{`` //[Binding]// ``}`` - | | **|** | ``Φ`` - | | **|** | ``ξ`` - | | **|** | ``⊥`` - | //ObjectAction// | -> | ``{`` //[Binding]// ``}`` - | | **|** | ``.`` //Attribute// - | //[ObjectAction]// | -> | **eps** - | | **|** | //ObjectAction// //[ObjectAction]// - - - -%% File generated by the BNF Converter (bnfc 2.9.6). +The Language Syntax +BNF Converter + + +%Process by txt2tags to generate html or latex + + + +This document was automatically generated by the //BNF-Converter//. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place). + +==The lexical structure of Syntax== + +===Literals=== + + + + + +Bytes literals are recognized by the regular expression +`````{"--"} | ["0123456789ABCDEF"] ["0123456789ABCDEF"] '-' | ["0123456789ABCDEF"] ["0123456789ABCDEF"] ('-' ["0123456789ABCDEF"] ["0123456789ABCDEF"])+````` + +Function literals are recognized by the regular expression +`````upper (char - [" + !'(),-.:;?[]{|}⟦⟧"])*````` + +LabelId literals are recognized by the regular expression +`````lower (char - [" + !'(),-.:;?[]{|}⟦⟧"])*````` + +AlphaIndex literals are recognized by the regular expression +`````{"α0"} | 'α' (digit - '0') digit*````` + + +===Reserved words and symbols=== +The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions. + +The reserved words used in Syntax are the following: + | ``Δ`` | ``Φ`` | ``λ`` | ``ν`` + | ``ξ`` | ``ρ`` | ``σ`` | ``φ`` + +The symbols used in Syntax are the following: + | { | } | ⟦ | ⟧ + | ( | ) | . | ⊥ + | ↦ | ∅ | ⤍ | , + +===Comments=== +There are no single-line comments in the grammar.There are no multiple-line comments in the grammar. + +==The syntactic structure of Syntax== +Non-terminals are enclosed between < and >. +The symbols -> (production), **|** (union) +and **eps** (empty rule) belong to the BNF notation. +All other symbols are terminals. + + | //Program// | -> | ``{`` //[Binding]// ``}`` + | //Object// | -> | ``⟦`` //[Binding]// ``⟧`` + | | **|** | //Object// ``(`` //[Binding]// ``)`` + | | **|** | //Object// ``.`` //Attribute// + | | **|** | ``Φ`` ``.`` //Attribute// + | | **|** | ``ξ`` ``.`` //Attribute// + | | **|** | ``⊥`` + | //Binding// | -> | //Attribute// ``↦`` //Object// + | | **|** | //Attribute// ``↦`` ``∅`` + | | **|** | ``Δ`` ``⤍`` //Bytes// + | | **|** | ``λ`` ``⤍`` //Function// + | //[Binding]// | -> | **eps** + | | **|** | //Binding// + | | **|** | //Binding// ``,`` //[Binding]// + | //Attribute// | -> | ``φ`` + | | **|** | ``ρ`` + | | **|** | ``σ`` + | | **|** | ``ν`` + | | **|** | //LabelId// + | | **|** | //AlphaIndex// + | //PeeledObject// | -> | //ObjectHead// //[ObjectAction]// + | //ObjectHead// | -> | ``{`` //[Binding]// ``}`` + | | **|** | ``Φ`` + | | **|** | ``ξ`` + | | **|** | ``⊥`` + | //ObjectAction// | -> | ``{`` //[Binding]// ``}`` + | | **|** | ``.`` //Attribute// + | //[ObjectAction]// | -> | **eps** + | | **|** | //ObjectAction// //[ObjectAction]// + + + +%% File generated by the BNF Converter (bnfc 2.9.5). diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x index f71d65948..c59d9fa5a 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Lex.x @@ -1,4 +1,4 @@ --- -*- haskell -*- File generated by the BNF Converter (bnfc 2.9.6). +-- -*- haskell -*- File generated by the BNF Converter (bnfc 2.9.5). -- Lexer definition for use with Alex 3 { @@ -40,7 +40,7 @@ $white+ ; { tok (eitherResIdent TV) } -- token Bytes -\- \- | [0 1 2 3 4 5 6 7 8 9 A B C D E F][0 1 2 3 4 5 6 7 8 9 A B C D E F](\- [0 1 2 3 4 5 6 7 8 9 A B C D E F][0 1 2 3 4 5 6 7 8 9 A B C D E F]) * (\- \-) +\- \- | [0 1 2 3 4 5 6 7 8 9 A B C D E F][0 1 2 3 4 5 6 7 8 9 A B C D E F]\- | [0 1 2 3 4 5 6 7 8 9 A B C D E F][0 1 2 3 4 5 6 7 8 9 A B C D E F](\- [0 1 2 3 4 5 6 7 8 9 A B C D E F][0 1 2 3 4 5 6 7 8 9 A B C D E F]) + { tok (eitherResIdent T_Bytes) } -- token Function diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y index 1fba42102..3964497f3 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Par.y @@ -1,4 +1,4 @@ --- -*- haskell -*- File generated by the BNF Converter (bnfc 2.9.6). +-- -*- haskell -*- File generated by the BNF Converter (bnfc 2.9.5). -- Parser definition for use with Happy { diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs index a12f4ab9f..62bc11297 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Syntax/Print.hs @@ -1,4 +1,4 @@ --- File generated by the BNF Converter (bnfc 2.9.6). +-- File generated by the BNF Converter (bnfc 2.9.5). {-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} diff --git a/flake.lock b/flake.lock index 9669d63dd..bb01383d7 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,28 @@ { "nodes": { + "eoc": { + "flake": false, + "locked": { + "lastModified": 1704732261, + "narHash": "sha256-UOwwOpbVQjVraZebqQbq4BPitCKpwcL6s3ywjAfGCaw=", + "owner": "deemp", + "repo": "eoc", + "rev": "c338c36db124212efbb85f31d12e04e04bcde450", + "type": "github" + }, + "original": { + "owner": "deemp", + "repo": "eoc", + "type": "github" + } + }, "flakes": { "locked": { - "lastModified": 1703248027, - "narHash": "sha256-kq2J/wLaUL3KY/OwgZEAZ7/QZ5alrol9ERBWqxJshiA=", + "lastModified": 1704589266, + "narHash": "sha256-iuqS9ieLQYcTIKT7GHrqBf89yNU6rdYp+ge08ww5zC0=", "owner": "deemp", "repo": "flakes", - "rev": "8b4c8ae507d591ad41e239e70a9c2d226b7eaa45", + "rev": "dcb6e49b7c7df2dd381d204a9316572d7087c373", "type": "github" }, "original": { @@ -15,9 +31,23 @@ "type": "github" } }, + "maven-wrapper-jar": { + "flake": false, + "locked": { + "narHash": "sha256-O6tlCRB5YmX0T0F240jGhiln1jwkKO8XgyCvtHSq40A=", + "type": "file", + "url": "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + }, + "original": { + "type": "file", + "url": "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar" + } + }, "root": { "inputs": { - "flakes": "flakes" + "eoc": "eoc", + "flakes": "flakes", + "maven-wrapper-jar": "maven-wrapper-jar" } } }, diff --git a/flake.nix b/flake.nix index c4b3fa919..c63ea5751 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,24 @@ { - inputs.flakes.url = "github:deemp/flakes"; + inputs = { + flakes.url = "github:deemp/flakes"; + eoc = { + url = "github:deemp/eoc"; + flake = false; + }; + # should be synchronized with + # https://github.com/objectionary/eoc/blob/116286a11aa538705c0f2b794abbdbcc6dec33ef/mvnw/.mvn/wrapper/maven-wrapper.properties#L18 + maven-wrapper-jar = { + flake = false; + url = "https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar"; + }; + }; outputs = inputs: inputs.flakes.makeFlake { inputs = { inherit (inputs.flakes.all) - haskell-tools codium drv-tools devshell - flakes-tools nixpkgs formatter workflows lima; + haskell-tools drv-tools devshell + flakes-tools nixpkgs formatter + slimlock; + inherit (inputs) eoc maven-wrapper-jar; }; perSystem = { inputs, system }: let @@ -14,8 +28,9 @@ # --- Imports --- pkgs = inputs.nixpkgs.legacyPackages.${system}; + inherit (pkgs) lib; inherit (inputs.devshell.lib.${system}) mkCommands mkRunCommands mkShell; - inherit (inputs.drv-tools.lib.${system}) withAttrs withMan withDescription mkShellApp man; + inherit (inputs.drv-tools.lib.${system}) mkShellApps; inherit (inputs.flakes-tools.lib.${system}) mkFlakesTools; inherit (inputs.haskell-tools.lib.${system}) toolsGHC; @@ -69,7 +84,7 @@ packages = ps: [ ps.${packageName} ]; }) hls cabal fourmolu justStaticExecutable - ghcid haskellPackages hpack stack; + ghcid ghc haskellPackages hpack stack; # --- Tools --- @@ -80,6 +95,7 @@ fourmolu cabal stack + pkgs.gh # `cabal` already has a `ghc` on its `PATH`, # so you may remove `ghc` from this list. # Then, you can access `ghc` like `cabal exec -- ghc --version`. @@ -93,7 +109,30 @@ # --- Packages --- - packages = { + packages = mkShellApps { + eoc = pkgs.buildNpmPackage rec { + name = ""; + version = "0.15.1"; + src = inputs.eoc; + npmDepsHash = "sha256-j6lfte6RhxRY5cRHcrtIHfZDe0lP1ovEukgHbHsGPb0="; + npmInstallFlags = [ "--omit=dev" ]; + dontNpmBuild = true; + + postPatch = + let path = "mvnw/.mvn/wrapper/maven-wrapper.jar"; in + '' + cp ${inputs.maven-wrapper-jar} ${path} + chmod +x ${path} + ''; + meta = with pkgs.lib; { + description = "EO compiler"; + homepage = "https://github.com/objectionary/eoc"; + license = licenses.mit; + }; + }; + + # + # --- Haskell package --- # This is a static executable with given runtime dependencies. @@ -104,6 +143,17 @@ }; "${packageName}" = haskellPackages."${packageName}"; + + pipeline = { + runtimeInputs = [ stack pkgs.jdk21 packages.eoc pkgs.maven ]; + text = '' + JAVA_HOME="${pkgs.jdk21.home}" + export JAVA_HOME + ${builtins.readFile ./pipeline.sh} + ''; + description = "Run pipeline"; + excludeShellChecks = [ "SC2139" ]; + }; }; # --- Devshells --- @@ -115,7 +165,7 @@ bash.extra = "export LANG=C.utf8"; commands = mkCommands "tools" tools - ++ mkRunCommands "packages" { inherit (packages) default; } + ++ mkRunCommands "packages" { inherit (packages) default pipeline; } ; }; }; diff --git a/pipeline.sh b/pipeline.sh new file mode 100755 index 000000000..04ba4239d --- /dev/null +++ b/pipeline.sh @@ -0,0 +1,62 @@ +mkdir -p pipeline +cd pipeline + +shopt -s expand_aliases + +EO=0.34.2 +alias eo="eoc --parser=${EO}" + +cat > app.eo < app + QQ.io.stdout > @ + "Hello, world!\n" +EOT + +eo clean +eo link +eo --alone dataize app > before.txt + +eo phi + +# Now, you modify/normalize this file: +IO=".eoc/phi/app.phi" +I=".eoc/phi/app.bk.phi" +mv "$IO" "$I" +stack run normalize-phi < "$I" > "$IO" \ + || { + printf "\n\nNormalizer failed" + printf "\n\n* EO expression:\n\n" + cat app.eo + printf "\n\n* Phi expression:\n\n" + cat "$I" + printf "\n\n* Error:\n\n" + cat "$IO" + exit 1 + } + +printf "\n\nNormalizer succeeded!\n\n" +printf "\n\n* Phi expression:\n\n" +cat "$I" +printf "\n\n* Normalized Phi expression:\n\n" +cat "$IO" +printf "\n\n* Diff:\n\n" +diff "$I" "$IO" + +eo unphi + +cp .eoc/unphi/app.xmir .eoc/2-optimize/app.xmir + +eo print + +cp .eoc/print/app.eo app.eo + +eo clean +eo link +eo --alone dataize app > after.txt + +if [ "$(cat before.txt)" == "$(cat after.txt)" ]; then + echo 'SUCCESS' +else + echo 'FAILURE' + exit 1 +fi \ No newline at end of file