diff --git a/.github/workflows/compil.yml b/.github/workflows/compil.yml new file mode 100644 index 0000000..9c41b7a --- /dev/null +++ b/.github/workflows/compil.yml @@ -0,0 +1,92 @@ +name: Compil + +on: [push] + +jobs: + compil-check-job-run: + runs-on: ubuntu-latest + + outputs: + workflows: ${{ steps.filter.outputs.workflows }} + src: ${{ steps.filter.outputs.src }} + make: ${{ steps.filter.outputs.make }} + combined: ${{ steps.filter.outputs.workflows == 'true' || steps.filter.outputs.src == 'true' || steps.filter.outputs.make == 'true' }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check modified files need re run + id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + workflows: + - '.github/workflows/**' + src: + - '*.hs' + make: + - 'Makefile' + + compil-windows: + runs-on: windows-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: ./scripts/InstallDepsWindows.ps1 + + - name: Compil + run: make + + compil-linux: + runs-on: ubuntu-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: sudo ./scripts/InstallDepsLinux.bash + + - name: Compil + run: make + + compil-macos: + runs-on: macos-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: ./scripts/InstallDepsMacOS.zsh + + - name: Compil + run: make diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml new file mode 100644 index 0000000..267b8cb --- /dev/null +++ b/.github/workflows/documentation.yml @@ -0,0 +1,85 @@ +name: Documentation +on: [push] + +jobs: + documentation: + runs-on: ubuntu-latest + permissions: + contents: write # To push a branch + pages: write # To push to a GitHub Pages site + id-token: write # To update the deployment status + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Check modified files need re run + id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + docs: + - 'docs/**' + docs2: + - 'book.toml' + workflow: + - '.github/workflows/documentation.yml' + + - name: Install latest mdbook + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + run: | + tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name') + url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz" + mkdir mdbook + curl -sSL $url | tar -xz --directory=./mdbook + echo `pwd`/mdbook >> $GITHUB_PATH + + - name: Install emojify + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + run: | + wget --no-verbose https://github.com/shonfeder/emojitsu/releases/download/0.1.1/gh-actions-emojitsu + chmod +x gh-actions-emojitsu + # Emojify the markdown + find . -type f -name "*.md" -exec ./gh-actions-emojitsu emojify -i {} \; + + - name: Build Book + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + run: mdbook build + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Compil + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + run: | + if ! stack build; then + exit 0 + fi + + - name: Tests + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + run: | + if ! stack test --test-arguments "--html book/Tests.html"; then + exit 0 + fi + + - name: Setup Pages + if: github.ref == 'refs/heads/main' + uses: actions/configure-pages@v3 + + - name: Upload artifact + if: steps.filter.outputs.docs == 'true' || steps.filter.outputs.docs2 == 'true' || steps.filter.outputs.workflow == 'true' || github.ref == 'refs/heads/main' + uses: actions/upload-pages-artifact@v2 + with: + # Upload entire repository + path: 'book' + + - name: Deploy to GitHub Pages + if: github.ref == 'refs/heads/main' + id: deployment + uses: actions/deploy-pages@v2 diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 0000000..983b349 --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,24 @@ +name: Mirror + +on: [push] + +env: + MIRROR_URL: git@github.com:EpitechPromo2026/B-FUN-500-TLS-5-2-glados-xavier.mitault.git + +jobs: + mirror: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pixta-dev/repository-mirroring-action@v1 + if: github.repository != 'EpitechPromo2026/B-FUN-500-TLS-5-2-glados-xavier.mitault' + with: + target_repo_url: + ${{ env.MIRROR_URL }} + ssh_private_key: + ${{ secrets.SSH_KEY }} diff --git a/.github/workflows/norm.yml b/.github/workflows/norm.yml new file mode 100644 index 0000000..6739e83 --- /dev/null +++ b/.github/workflows/norm.yml @@ -0,0 +1,53 @@ +name: Norm + +on: [pull_request] + # lambdananas -o vera --exclude "Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" . >> lambdananas-reports.log +jobs: + + norm: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install Deps + run: | + sudo apt-get update && sudo apt-get install -y curl + curl -fsSL 'https://github.com/Saverio976/dotfiles/raw/main/.local/bin/lambdananas' > /tmp/lambdananas + chmod +x /tmp/lambdananas + + - name: Format + run: /tmp/lambdananas -o vera --exclude "Setup.hs:setup.hs:.git:.stack-work:test:tests:bonus" . >> lambdananas-reports.log + + - name: Is Empty + id: isEmpty + run: | + if [ "$(cat lambdananas-reports.log)" == "" ]; then + echo "isEmpty=true" >> $GITHUB_OUTPUT + else + echo "isEmpty=false" >> $GITHUB_OUTPUT + fi + + - name: Send coding style message Ok + uses: mshick/add-pr-comment@v2 + if: steps.isEmpty.outputs.isEmpty == 'true' + with: + message: "No coding style issue" + refresh-message-position: true + message-id: norm-cicd + + - name: Send coding style message KO + uses: mshick/add-pr-comment@v2 + if: steps.isEmpty.outputs.isEmpty == 'false' + with: + message-path: | + lambdananas-reports.log + refresh-message-position: true + message-id: norm-cicd + + - name: Exit Status + run: | + if [ ${{ steps.isEmpty.outputs.isEmpty }} == 'false' ]; then + exit 1 + fi diff --git a/.github/workflows/release.sh b/.github/workflows/release.sh new file mode 100755 index 0000000..dc25df6 --- /dev/null +++ b/.github/workflows/release.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# Release script run in Github CI + +BRANCH="$1" + +LAST_TAG=$(git tag | sort -t '.' --numeric-sort -k1,1 -k2,2 -k3,3 | tail -n 1) +LAST_TAG_MAJOR=$(echo "$LAST_TAG" | cut -d'.' -f1) +LAST_TAG_MINOR=$(echo "$LAST_TAG" | cut -d'.' -f2) +LAST_TAG_PATCH=$(echo "$LAST_TAG" | cut -d'.' -f3) + +git show --compact-summary "$LAST_TAG..HEAD" > CHANGELOG + +TAG_MAJOR="" +TAG_MINOR="" +TAG_PATCH="" + +WARNINGS="" + +if grep -q "^ MAJOR" CHANGELOG; then + TAG_MAJOR=$((LAST_TAG_MAJOR + 1)) + TAG_MINOR="0" + TAG_PATCH="0" +elif grep -q "^ MINOR" CHANGELOG; then + TAG_MAJOR=$((LAST_TAG_MAJOR + 0)) + TAG_MINOR=$((LAST_TAG_MINOR + 1)) + TAG_PATCH="0" +elif grep -q "^ PATCH" CHANGELOG; then + TAG_MAJOR=$((LAST_TAG_MAJOR + 0)) + TAG_MINOR=$((LAST_TAG_MINOR + 0)) + TAG_PATCH=$((LAST_TAG_PATCH + 1)) +else + WARNINGS="$WARNINGS ; This release is created with default bump version because no commits was ok" + TAG_MAJOR=$((LAST_TAG_MAJOR + 0)) + TAG_MINOR=$((LAST_TAG_MINOR + 0)) + TAG_PATCH=$((LAST_TAG_PATCH + 1)) +fi + +TAG="$TAG_MAJOR.$TAG_MINOR.$TAG_PATCH" + +gh release create "$TAG" \ + --title "v$TAG" \ + --generate-notes \ + --target "$BRANCH" + +echo "release_tag=$TAG" >> $GITHUB_OUTPUT +echo "$WARNINGS" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..df632a1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,143 @@ +name: Release + +on: + push: + branches: [main, dev] + +env: + BRANCH: "main" + +jobs: + release-create: + permissions: write-all + runs-on: ubuntu-latest + + outputs: + release: ${{ steps.release.outputs.release_tag }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - id: release + name: Create Release + if: github.repository != 'EpitechPromo2026/B-FUN-500-TLS-5-2-glados-xavier.mitault' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + if [[ "${{ github.ref }}" == 'refs/heads/main' ]]; then + export GITHUB_OUTPUT=$GITHUB_OUTPUT + bash ./.github/workflows/release.sh "${{ env.BRANCH }}" + else + echo "release_tag=0.0.0" >> $GITHUB_OUTPUT + fi + + release-windows: + runs-on: windows-latest + needs: [release-create] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: ./scripts/InstallDepsWindows.ps1 + + - name: Build + run: make + + - name: Upload To Release + if: github.ref == 'refs/heads/main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ needs.release-create.outputs.release }} "./koaky-exe.exe#koaky-windows.exe" + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: koaky.exe + path: ./koaky.exe + + release-linux: + runs-on: ubuntu-latest + needs: [release-create] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: sudo ./scripts/InstallDepsLinux.bash + + - name: Build + run: make + + - name: Rename + run: mv koaky-exe koaky-linux + + - name: Upload To Release + if: github.ref == 'refs/heads/main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ needs.release-create.outputs.release }} "./koaky-linux" + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: koaky-linux + path: ./koaky-linux + + release-macos: + runs-on: macos-latest + needs: [release-create] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: ./scripts/InstallDepsMacos.zsh + + - name: Build + run: make + + - name: Rename + run: mv koaky-exe koaky-macos + + - name: Upload To Release + if: github.ref == 'refs/heads/main' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh release upload ${{ needs.release-create.outputs.release }} "./koaky-macos" + + - name: Upload To Artifact + if: github.ref != 'refs/heads/main' + uses: actions/upload-artifact@v3 + with: + name: koaky-macos + path: ./koaky-macos diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..b89f8ee --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,88 @@ +name: Tests + +on: [pull_request] + +jobs: + compil-check-job-run: + runs-on: ubuntu-latest + + outputs: + workflows: ${{ steps.filter.outputs.workflows }} + src: ${{ steps.filter.outputs.src }} + make: ${{ steps.filter.outputs.make }} + package: ${{ steps.filter.outputs.package }} + stack: ${{ steps.filter.outputs.stack }} + combined: ${{ steps.filter.outputs.workflows == 'true' || steps.filter.outputs.src == 'true' || steps.filter.outputs.make == 'true' }} || steps.filter.outputs.package == 'true' || steps.filter.outputs.stack == 'true' + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check modified files need re run + id: filter + uses: dorny/paths-filter@v2 + with: + filters: | + workflows: + - '.github/workflows/**' + src: + - '*.hs' + make: + - 'Makefile' + package: + - 'package.yaml' + stack: + - 'stack.yaml' + + tests: + runs-on: ubuntu-latest + needs: [compil-check-job-run] + if: needs.compil-check-job-run.outputs.combined + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Haskell + uses: haskell-actions/setup@v2 + with: + enable-stack: true + stack-version: 'latest' + + - name: Install dependencies + run: sudo ./scripts/InstallDepsLinux.bash + + - name: Compil + run: make + + - name: Tests + id: failedTest + run: | + if ! stack test &> tests.log; then + echo "failedTest=true" >> $GITHUB_OUTPUT + else + echo "failedTest=false" >> $GITHUB_OUTPUT + fi + + - name: Upload stats + uses: actions/upload-artifact@v3 + with: + name: tests.log + path: tests.log + + - name: Send Test Ok + uses: mshick/add-pr-comment@v2 + if: steps.failedTest.outputs.failedTest == 'false' + with: + message: "Tests PASSED" + refresh-message-position: true + message-id: tests-cicd + + - name: Send Test KO + uses: mshick/add-pr-comment@v2 + if: steps.failedTest.outputs.failedTest == 'true' + with: + message-path: | + tests.log + refresh-message-position: true + message-id: tests-cicd diff --git a/.gitignore b/.gitignore index e38e5aa..c28ed56 100644 --- a/.gitignore +++ b/.gitignore @@ -171,3 +171,7 @@ tags *.log *.exe + +/make.exe +/libssp-0.dll +lambdananas-reports.log diff --git a/Makefile b/Makefile index 2ab2689..96bb1b1 100644 --- a/Makefile +++ b/Makefile @@ -8,20 +8,32 @@ TARGET = koaky MARVIN_TARGET = glados +CP = cp +RM = rm -rf + +ifeq ($(OS),Windows_NT) + BIN_STACK = $(TARGET)-exe.exe +else + BIN_STACK = $(TARGET)-exe +endif + all: $(TARGET) $(TARGET): - stack build - cp "$(shell stack path --local-install-root)/bin/$(TARGET)-exe" "$(TARGET)" - cp "$(TARGET)" "$(MARVIN_TARGET)" + stack build --copy-bins --local-bin-path . + $(CP) "$(BIN_STACK)" "$(MARVIN_TARGET)" clean: - stack purge + stack clean fclean: clean - $(RM) "$(TARGET)" + stack purge + $(RM) "$(BIN_STACK)" $(RM) "$(MARVIN_TARGET)" -re: fclean "$(TARGET)" +re: fclean $(TARGET) + +tests: + stack test .PHONY: $(TARGET) fclean re clean all diff --git a/app/Main.hs b/app/Main.hs index 39f89cc..58acc59 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,6 +1,10 @@ {- -- EPITECH PROJECT, 2023 +<<<<<<< HEAD -- Koaky +======= +-- Main +>>>>>>> main -- File description: -- Main -} diff --git a/book.toml b/book.toml new file mode 100644 index 0000000..c40f347 --- /dev/null +++ b/book.toml @@ -0,0 +1,23 @@ +[book] +title = "Koaky (Yet Another Programming Language)" +authors = ["@Saverio976", "@TTENSHII", "@guillaumeAbel"] +description = "Documentation of Koaky" +src = "docs" + +[build] +build-dir = "book" +create-missing = false +use-default-preprocessors = true + +[output.html] +git-repository-url = "https://github.com/X-R-G-B/koak" +edit-url-template = "https://github.com/X-R-G-B/koak/edit/main/{path}" + +[output.html.search] +enable = true +use-boolean-and = true +limit-results = 15 + +[output.html.print] +enable = true +page-break = true diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..fd86e18 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,4 @@ +# Koaky + +This is a new amazing programming language +made in Haskell. diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md new file mode 100644 index 0000000..6b4a296 --- /dev/null +++ b/docs/SUMMARY.md @@ -0,0 +1,7 @@ +# Summary + +This is a new amazing programming language +made in Haskell. + +[README](README.md) +[Tests](Tests.md) diff --git a/docs/Tests.md b/docs/Tests.md new file mode 100644 index 0000000..3bccffe --- /dev/null +++ b/docs/Tests.md @@ -0,0 +1 @@ +# this will be overwiten by the tests ... diff --git a/koaky.cabal b/koaky.cabal new file mode 100644 index 0000000..b9d8583 --- /dev/null +++ b/koaky.cabal @@ -0,0 +1,66 @@ +cabal-version: 1.12 + +-- This file has been generated from package.yaml by hpack version 0.36.0. +-- +-- see: https://github.com/sol/hpack + +name: koaky +version: 0.1.0.0 +description: Please see the README on GitHub at +homepage: https://github.com/X-R-G-B/koaky#readme +bug-reports: https://github.com/X-R-G-B/koaky/issues +author: @guillaumeAbel, @TTENSHII, @Saverio976 +maintainer: example@example.com +copyright: 2023 X-R-G-B +license: MIT +license-file: LICENSE +build-type: Simple +extra-source-files: + README.md + CHANGELOG.md + +source-repository head + type: git + location: https://github.com/X-R-G-B/koaky + +library + exposed-modules: + AST + ComputeAST + TextToAST + other-modules: + Paths_koaky + hs-source-dirs: + src + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wdefault -W -Woperator-whitespace + build-depends: + base >=4.7 && <5 + default-language: Haskell2010 + +executable koaky-exe + main-is: Main.hs + other-modules: + Paths_koaky + hs-source-dirs: + app + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wdefault -W -Woperator-whitespace -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , koaky + default-language: Haskell2010 + +test-suite koaky-test + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Paths_koaky + hs-source-dirs: + test + ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -Wdefault -W -Woperator-whitespace -threaded -rtsopts -with-rtsopts=-N + build-depends: + base >=4.7 && <5 + , koaky + , tasty + , tasty-html + , tasty-hunit + default-language: Haskell2010 diff --git a/package.yaml b/package.yaml index 334f2c4..b4a3ae8 100644 --- a/package.yaml +++ b/package.yaml @@ -1,10 +1,10 @@ name: koaky version: 0.1.0.0 -github: "githubuser/koaky" -license: BSD-3-Clause -author: "Author name here" +github: "X-R-G-B/koaky" +license: MIT +author: "@guillaumeAbel, @TTENSHII, @Saverio976" maintainer: "example@example.com" -copyright: "2023 Author name here" +copyright: "2023 X-R-G-B" extra-source-files: - README.md @@ -32,6 +32,9 @@ ghc-options: - -Wmissing-home-modules - -Wpartial-fields - -Wredundant-constraints +- -Wdefault +- -W +- -Woperator-whitespace library: source-dirs: src @@ -57,3 +60,6 @@ tests: - -with-rtsopts=-N dependencies: - koaky + - tasty + - tasty-hunit + - tasty-html diff --git a/scripts/InstallDepsLinux.bash b/scripts/InstallDepsLinux.bash new file mode 100755 index 0000000..eaccb47 --- /dev/null +++ b/scripts/InstallDepsLinux.bash @@ -0,0 +1,15 @@ +#!/bin/bash + +if command -v apt-get 2>/dev/null; then + apt-get update + apt-get install -y make +elif command -v pacman 2>/dev/null; then + pacman -Sy make +elif command -v dnf 2>/dev/null; then + dnf update + dnf install -y make +else + echo "Unsupported package manager" + echo "Please install 'make'" + exit 12 +fi diff --git a/scripts/InstallDepsMacos.zsh b/scripts/InstallDepsMacos.zsh new file mode 100755 index 0000000..d639cf0 --- /dev/null +++ b/scripts/InstallDepsMacos.zsh @@ -0,0 +1,3 @@ +#!/bin/zsh + +brew install make diff --git a/scripts/InstallDepsWindows.ps1 b/scripts/InstallDepsWindows.ps1 new file mode 100644 index 0000000..85207f0 --- /dev/null +++ b/scripts/InstallDepsWindows.ps1 @@ -0,0 +1,7 @@ +if (!(Test-Path "make.exe") -or !(Test-Path "libssp-0.dll")) { + Invoke-WebRequest -OutFile make.zip -Uri "https://github.com/maweil/MakeForWindows/releases/download/v4.4.1/make-bin-win64.zip" + Expand-Archive -Force make.zip . + Copy-Item "make-4.4.1\dist\make.exe" "make.exe" + Copy-Item "make-4.4.1\dist\libssp-0.dll" "libssp-0.dll" + Remove-Item -Recurse -Force "make-4.4.1" +} diff --git a/src/AST.hs b/src/AST.hs index 7d039cc..0204ae9 100644 --- a/src/AST.hs +++ b/src/AST.hs @@ -1,8 +1,8 @@ {- --- EPITECH PROJECT, 2023 --- Abstract Syntax Tree --- File description: --- Ast +-- EPITECH PROJECT, 2023 +-- Koaky +-- File description: +-- Abstract Syntax Tree -} module AST @@ -18,8 +18,22 @@ type Symbol = String data Atom = Number Int64 | Symbol Symbol -data Tree = Node Symbol (Maybe Tree) (Maybe Tree) | Leaf Atom +data Tree = Node Symbol [Tree] | Leaf Atom + +instance Eq Atom where + Number a == Number b = a == b + Symbol a == Symbol b = a == b + _ == _ = False instance Show Atom where - show (Number n) = show n - show (Symbol s) = s + show (Number a) = "Number:'" ++ show a ++ "'" + show (Symbol a) = "Symbol:'" ++ a ++ "'" + +instance Eq Tree where + Node a as == Node b bs = a == b && as == bs + Leaf a == Leaf b = a == b + _ == _ = False + +instance Show Tree where + show (Node a as) = "Node:'" ++ a ++ "'{" ++ show as ++ "}" + show (Leaf a) = "Leaf:'" ++ show a ++ "'" diff --git a/src/TextToAST.hs b/src/TextToAST.hs index 3921b15..4b06767 100644 --- a/src/TextToAST.hs +++ b/src/TextToAST.hs @@ -1,8 +1,8 @@ {- --- EPITECH PROJECT, 2023 --- Text To AST --- File description: --- TextToAST +-- EPITECH PROJECT, 2023 +-- Text To AST +-- File description: +-- TextToAST -} module TextToAST diff --git a/stack.yaml b/stack.yaml index 48acbf9..a34bc4c 100644 --- a/stack.yaml +++ b/stack.yaml @@ -17,8 +17,7 @@ # # resolver: ./custom-snapshot.yaml # resolver: https://example.com/snapshots/2023-01-01.yaml -resolver: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/22.yaml +resolver: lts-21.13 # User packages to be built. # Various formats can be used as shown in the example below. @@ -40,7 +39,10 @@ packages: # - git: https://github.com/commercialhaskell/stack.git # commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a # -# extra-deps: [] +extra-deps: +- tasty-1.4.2.2 +- tasty-hunit-0.10.1 +- tasty-html-0.4.2.1 # Override default flag values for local packages and extra-deps # flags: {} diff --git a/stack.yaml.lock b/stack.yaml.lock index b21f704..92ef11f 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -3,11 +3,31 @@ # For more information, please see the documentation at: # https://docs.haskellstack.org/en/stable/lock_files -packages: [] -snapshots: +packages: +- completed: + hackage: tasty-1.4.2.2@sha256:b987609178d70c0042b950302161a049be8a878aa8cee4a9c7ba81d22d29a3f5,2719 + pantry-tree: + sha256: a93f5e31aac66a82a885cb2ddc8eada9a8adefe8587da1c4085fae58b6bc4683 + size: 1944 + original: + hackage: tasty-1.4.2.2 - completed: - sha256: afd5ba64ab602cabc2d3942d3d7e7dd6311bc626dcb415b901eaf576cb62f0ea - size: 640060 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/22.yaml + hackage: tasty-hunit-0.10.1@sha256:ebc17b490750d4796b21d44001b852688cc39f9c34e387d5e7958e09b9b3f3b9,1602 + pantry-tree: + sha256: c00ed23d8281b6c6f4ec33dd1e9e3a7971b0a769b6140978cfaf2a6eff025c78 + size: 399 original: - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/22.yaml + hackage: tasty-hunit-0.10.1 +- completed: + hackage: tasty-html-0.4.2.1@sha256:92ded1b794bfd6a46d5705f418c531f51aba3907b92d68a28aed349fc03a8e0d,1599 + pantry-tree: + sha256: 88f745a7d4904c2f663baeadb3fe14ec0986c02341b2663d7e7051a680fdca3c + size: 547 + original: + hackage: tasty-html-0.4.2.1 +snapshots: +- completed: + sha256: 8017c7970c2a8a9510c60cc70ac245d59e0c34eb932b91d37af09fe59855d854 + size: 640038 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/13.yaml + original: lts-21.13 diff --git a/test/Spec.hs b/test/Spec.hs index cd4753f..d7ca972 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1,2 +1,21 @@ +import Test.Tasty +import Test.Tasty.HUnit +import Test.Tasty.Runners.Html + +import AST + main :: IO () -main = putStrLn "Test suite not yet implemented" +main = defaultMainWithIngredients (htmlRunner : defaultIngredients) tests + +tests :: TestTree +tests = testGroup "Tests" [unitTests] + +unitTests :: TestTree +unitTests = testGroup "Unit tests" + [ testCase "Basic AST creation 0" $ + assertEqual "define x 42" (Node "define" [Leaf (Symbol "x"), Leaf (Number 42)]) (Node "define" [Leaf (Symbol "x"), Leaf (Number 42)]) + , testCase "Basic AST creation 1" $ + assertEqual "foo" (Leaf (Symbol "foo")) (Leaf (Symbol "foo")) + , testCase "Basic AST creation 2" $ + assertEqual "42" (Leaf (Number 42)) (Leaf (Number 42)) + ]