From 9cb8705f33bc9364426d42b036b803ccc68680bf Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Thu, 8 Feb 2024 15:51:42 +0300 Subject: [PATCH 1/9] feat: add mdbook site files --- site/README.md | 1 + site/docs/.gitignore | 1 + site/docs/book.toml | 13 ++ site/docs/src/README.md | 1 + site/docs/src/SUMMARY.md | 3 + site/docs/theme/index.hbs | 351 ++++++++++++++++++++++++++++++++++++ site/docs/theme/pagetoc.css | 110 +++++++++++ site/docs/theme/pagetoc.js | 114 ++++++++++++ site/index.html | 11 ++ 9 files changed, 605 insertions(+) create mode 100644 site/README.md create mode 100644 site/docs/.gitignore create mode 100644 site/docs/book.toml create mode 120000 site/docs/src/README.md create mode 100644 site/docs/src/SUMMARY.md create mode 100644 site/docs/theme/index.hbs create mode 100644 site/docs/theme/pagetoc.css create mode 100644 site/docs/theme/pagetoc.js create mode 100644 site/index.html diff --git a/site/README.md b/site/README.md new file mode 100644 index 000000000..7e5960073 --- /dev/null +++ b/site/README.md @@ -0,0 +1 @@ +# README diff --git a/site/docs/.gitignore b/site/docs/.gitignore new file mode 100644 index 000000000..2f8826912 --- /dev/null +++ b/site/docs/.gitignore @@ -0,0 +1 @@ +/docs diff --git a/site/docs/book.toml b/site/docs/book.toml new file mode 100644 index 000000000..d5e781fcc --- /dev/null +++ b/site/docs/book.toml @@ -0,0 +1,13 @@ +[book] +authors = ["Danila Danko"] +language = "en" +multilingual = false +src = "src" +title = "phi-normalizer" + +[output.html] +additional-css = ["theme/pagetoc.css"] +additional-js = ["theme/pagetoc.js"] + +[build] +build-dir = "./docs" diff --git a/site/docs/src/README.md b/site/docs/src/README.md new file mode 120000 index 000000000..8a33348c7 --- /dev/null +++ b/site/docs/src/README.md @@ -0,0 +1 @@ +../../../README.md \ No newline at end of file diff --git a/site/docs/src/SUMMARY.md b/site/docs/src/SUMMARY.md new file mode 100644 index 000000000..32c966896 --- /dev/null +++ b/site/docs/src/SUMMARY.md @@ -0,0 +1,3 @@ +# Summary + +- [README](./README.md) diff --git a/site/docs/theme/index.hbs b/site/docs/theme/index.hbs new file mode 100644 index 000000000..34a1732ce --- /dev/null +++ b/site/docs/theme/index.hbs @@ -0,0 +1,351 @@ + + + + + + {{ title }} + {{#if is_print }} + + {{/if}} + {{#if base_url}} + + {{/if}} + + + + {{> head}} + + + + + + {{#if favicon_svg}} + + {{/if}} + {{#if favicon_png}} + + {{/if}} + + + + {{#if print_enable}} + + {{/if}} + + + + {{#if copy_fonts}} + + {{/if}} + + + + + + + + {{#each additional_css}} + + {{/each}} + + {{#if mathjax_support}} + + + {{/if}} + + +
+ + + + + + + + + + + + + + + + + + + +
+ +
+ {{> header}} + + + + {{#if search_enabled}} + + {{/if}} + + + + +
+
+
+ {{{ content }}} +
+
+ +
+
+ + +
+
+ + + +
+ + {{#if live_reload_endpoint}} + + + {{/if}} + + {{#if google_analytics}} + + + {{/if}} + + {{#if playground_line_numbers}} + + {{/if}} + + {{#if playground_copyable}} + + {{/if}} + + {{#if playground_js}} + + + + + + {{/if}} + + {{#if search_js}} + + + + {{/if}} + + + + + + + {{#each additional_js}} + + {{/each}} + + {{#if is_print}} + {{#if mathjax_support}} + + {{else}} + + {{/if}} + {{/if}} + +
+ + diff --git a/site/docs/theme/pagetoc.css b/site/docs/theme/pagetoc.css new file mode 100644 index 000000000..7db0296af --- /dev/null +++ b/site/docs/theme/pagetoc.css @@ -0,0 +1,110 @@ +/* +* Prefixed by https://autoprefixer.github.io +* PostCSS: v8.4.14, +* Autoprefixer: v10.4.7 +* Browsers: last 4 version +*/ + +:root { + --toc-width: 270px; + --center-content-toc-shift: calc(-1 * var(--toc-width) / 2); +} + +.nav-chapters { + /* adjust width of buttons that bring to the previous or the next page */ + min-width: 50px; +} + +.previous { + /* + adjust the space between the left sidebar or the left side of the screen + and the button that leads to the previous page + */ + margin-left: var(--page-padding); +} + +@media only screen { + main { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + } + + @media (max-width: 1179px) { + .sidebar-hidden .sidetoc { + display: none; + } + } + + @media (max-width: 1439px) { + .sidebar-visible .sidetoc { + display: none; + } + } + + @media (1180px <= width <= 1439px) { + .sidebar-hidden main { + position: relative; + left: var(--center-content-toc-shift); + } + } + + @media (1440px <= width <= 1700px) { + .sidebar-visible main { + position: relative; + left: var(--center-content-toc-shift); + } + } + + .content-wrap { + overflow-y: auto; + width: 100%; + } + + .sidetoc { + margin-top: 20px; + margin-left: 10px; + margin-right: auto; + } + .pagetoc { + position: fixed; + /* adjust TOC width */ + width: var(--toc-width); + height: calc(100vh - var(--menu-bar-height) - 0.67em * 4); + overflow: auto; + } + .pagetoc a { + border-left: 1px solid var(--sidebar-bg); + color: var(--fg) !important; + display: block; + padding-bottom: 5px; + padding-top: 5px; + padding-left: 10px; + text-align: left; + text-decoration: none; + } + .pagetoc a:hover, + .pagetoc a.active { + background: var(--sidebar-bg); + color: var(--sidebar-fg) !important; + } + .pagetoc .active { + background: var(--sidebar-bg); + color: var(--sidebar-fg); + } + .pagetoc .pagetoc-H2 { + padding-left: 20px; + } + .pagetoc .pagetoc-H3 { + padding-left: 40px; + } + .pagetoc .pagetoc-H4 { + padding-left: 60px; + } +} + +@media print { + .sidetoc { + display: none; + } +} diff --git a/site/docs/theme/pagetoc.js b/site/docs/theme/pagetoc.js new file mode 100644 index 000000000..510525529 --- /dev/null +++ b/site/docs/theme/pagetoc.js @@ -0,0 +1,114 @@ +function forEach(elems, fun) { + Array.prototype.forEach.call(elems, fun); + } + + function getPagetoc(){ + return document.getElementsByClassName("pagetoc")[0] + } + + function getPagetocElems() { + return getPagetoc().children; + } + + function getHeaders(){ + return document.getElementsByClassName("header") + } + + // Un-active everything when you click it + function forPagetocElem(fun) { + forEach(getPagetocElems(), fun); + } + + function getRect(element) { + return element.getBoundingClientRect(); + } + + function overflowTop(container, element) { + return getRect(container).top - getRect(element).top; + } + + function overflowBottom(container, element) { + return getRect(container).bottom - getRect(element).bottom; + } + + var activeHref = location.href; + + var updateFunction = function (elem = undefined) { + var id = elem; + + if (!id && location.href != activeHref) { + activeHref = location.href; + forPagetocElem(function (el) { + if (el.href === activeHref) { + id = el; + } + }); + } + + if (!id) { + var elements = getHeaders(); + let margin = window.innerHeight / 3; + + forEach(elements, function (el, i, arr) { + if (!id && getRect(el).top >= 0) { + if (getRect(el).top < margin) { + id = el; + } else { + id = arr[Math.max(0, i - 1)]; + } + } + // a very long last section + // its heading is over the screen + if (!id && i == arr.length - 1) { + id = el + } + }); + } + + forPagetocElem(function (el) { + el.classList.remove("active"); + }); + + if (!id) return; + + forPagetocElem(function (el) { + if (id.href.localeCompare(el.href) == 0) { + el.classList.add("active"); + let pagetoc = getPagetoc(); + if (overflowTop(pagetoc, el) > 0) { + pagetoc.scrollTop = el.offsetTop; + } + if (overflowBottom(pagetoc, el) < 0) { + pagetoc.scrollTop -= overflowBottom(pagetoc, el); + } + } + }); + }; + + let elements = getHeaders(); + + if (elements.length > 1) { + // Populate sidebar on load + window.addEventListener("load", function () { + var pagetoc = getPagetoc(); + var elements = getHeaders(); + forEach(elements, function (el) { + var link = document.createElement("a"); + link.appendChild(document.createTextNode(el.text)); + link.href = el.hash; + link.classList.add("pagetoc-" + el.parentElement.tagName); + pagetoc.appendChild(link); + link.onclick = function () { + updateFunction(link); + }; + }); + updateFunction(); + }); + + // Handle active elements on scroll + window.addEventListener("scroll", function () { + updateFunction(); + }); + } else { + document.getElementsByClassName("sidetoc")[0].remove(); + } diff --git a/site/index.html b/site/index.html new file mode 100644 index 000000000..47b4ecc6a --- /dev/null +++ b/site/index.html @@ -0,0 +1,11 @@ + + + + + Redirecting + + + + Redirecting to Blog/... + + From cd6e775e3c6699730ceaabc14028f9bff4387abe Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Thu, 8 Feb 2024 16:08:03 +0300 Subject: [PATCH 2/9] fix: flag in stack-action --- .github/workflows/ghc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ghc.yml b/.github/workflows/ghc.yml index 4ca298037..91eeb7adf 100644 --- a/.github/workflows/ghc.yml +++ b/.github/workflows/ghc.yml @@ -38,7 +38,7 @@ jobs: - name: 🧰 Setup Stack uses: freckle/stack-action@v5 with: - stack-build-arguments: --${{ github.ref_name != 'master' && 'fast' || '' }} --pedantic + stack-build-arguments: ${{ github.ref_name != 'master' && '--fast' || '' }} --pedantic pipeline: name: "Run pipeline" @@ -55,7 +55,7 @@ jobs: - name: 🧰 Setup Stack uses: freckle/stack-action@v5 with: - stack-build-arguments: --${{ github.ref_name != 'master' && 'fast' || '' }} --pedantic + stack-build-arguments: ${{ github.ref_name != 'master' && '--fast' || '' }} --pedantic - uses: actions/setup-node@v4 with: From 22c8c5989a78f59024541e58fc3abad01df5eff8 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Thu, 8 Feb 2024 17:30:33 +0300 Subject: [PATCH 3/9] feat: build site in CI --- .github/workflows/ghc.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ghc.yml b/.github/workflows/ghc.yml index 4ca298037..2f7f6477b 100644 --- a/.github/workflows/ghc.yml +++ b/.github/workflows/ghc.yml @@ -74,10 +74,10 @@ jobs: env: PROGRAM: ${{ matrix.program }} - haddock: + docs: needs: [build] if: ${{ github.ref_name == 'master' }} - name: "Build and upload Haddock documentation (master)" + name: "Build and upload site (master)" runs-on: ubuntu-latest steps: @@ -95,10 +95,23 @@ jobs: mkdir -p dist/haddock mv $(stack path --local-doc-root)/* dist/haddock - - name: πŸš€ Publish Haddock Documentation + - name: Setup mdBook + uses: peaceiris/actions-mdbook@v1 + with: + mdbook-version: 'latest' + + - name: Build site + run: | + cd site/docs + mdbook build + mv docs ../../dist + + cd .. + mv index.html ../dist + + - name: πŸš€ Publish Site uses: JamesIves/github-pages-deploy-action@v4 with: token: ${{ secrets.GITHUB_TOKEN }} - folder: dist/haddock - target-folder: haddock + folder: dist single-commit: true From f44b51a83906faf00f68d077f2ec85ad655d7a64 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Fri, 9 Feb 2024 12:24:37 +0300 Subject: [PATCH 4/9] feat: add `single` option that prints a single normalized program --- eo-phi-normalizer/app/Main.hs | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/eo-phi-normalizer/app/Main.hs b/eo-phi-normalizer/app/Main.hs index 8e179ce62..6f8090935 100644 --- a/eo-phi-normalizer/app/Main.hs +++ b/eo-phi-normalizer/app/Main.hs @@ -8,13 +8,13 @@ module Main where -import Control.Monad (when) +import Control.Monad (unless, when) import Data.Foldable (forM_) import Data.List (nub) import Language.EO.Phi (Object (Formation), Program (Program), defaultMain, parseProgram, printTree) import Language.EO.Phi.Rules.Common (Context (..), applyRules, applyRulesChain) -import Language.EO.Phi.Rules.Yaml +import Language.EO.Phi.Rules.Yaml (RuleSet (rules, title), convertRule, parseRuleSetFromFile) import Options.Generic import System.IO (IOMode (WriteMode), hClose, hPutStr, hPutStrLn, openFile, stdout) @@ -22,6 +22,7 @@ data CLINamedParams = CLINamedParams { chain :: Bool , rulesYaml :: Maybe String , outPath :: Maybe String + , single :: Bool } deriving (Generic, Show, ParseRecord, Read, ParseField) @@ -31,6 +32,7 @@ instance ParseFields CLINamedParams where <$> parseFields (Just "Print out steps of reduction") (Just "chain") (Just 'c') Nothing <*> parseFields (Just "Path to the Yaml file with custom rules") (Just "rules-yaml") Nothing Nothing <*> parseFields (Just "Output file path (defaults to stdout)") (Just "output") (Just 'o') Nothing + <*> parseFields (Just "Print a single normlized expression") (Just "single") (Just 's') Nothing data CLIOptions = CLIOptions CLINamedParams (Maybe FilePath) deriving (Generic, Show, ParseRecord) @@ -46,7 +48,7 @@ main = do let logStr = hPutStr handle let logStrLn = hPutStrLn handle ruleSet <- parseRuleSetFromFile path - logStrLn ruleSet.title + unless single $ logStrLn ruleSet.title src <- maybe getContents readFile inPath let progOrError = parseProgram src case progOrError of @@ -57,18 +59,22 @@ main = do | otherwise = pure <$> applyRules (Context (convertRule <$> ruleSet.rules) [Formation bindings]) (Formation bindings) uniqueResults = nub results totalResults = length uniqueResults - logStrLn "Input:" - logStrLn (printTree input) - logStrLn "====================================================" - forM_ (zip [1 ..] uniqueResults) $ \(i, steps) -> do - logStrLn $ - "Result " <> show i <> " out of " <> show totalResults <> ":" - let n = length steps - forM_ (zip [1 ..] steps) $ \(k, step) -> do - Control.Monad.when chain $ - logStr ("[ " <> show k <> " / " <> show n <> " ]") - logStrLn (printTree step) - logStrLn "----------------------------------------------------" + when (totalResults == 0) $ error "Could not normalize the program" + if single + then logStrLn (printTree (head uniqueResults)) + else do + logStrLn "Input:" + logStrLn (printTree input) + logStrLn "====================================================" + forM_ (zip [1 ..] uniqueResults) $ \(i, steps) -> do + logStrLn $ + "Result " <> show i <> " out of " <> show totalResults <> ":" + let n = length steps + forM_ (zip [1 ..] steps) $ \(k, step) -> do + when chain $ + logStr ("[ " <> show k <> " / " <> show n <> " ]") + logStrLn (printTree step) + logStrLn "----------------------------------------------------" hClose handle -- TODO #48:15m still need to consider `chain` (should rewrite/change defaultMain to mainWithOptions) Nothing -> defaultMain From 3ad0df331befa745d8c7e3f79228226b87e1298e Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Fri, 9 Feb 2024 12:30:17 +0300 Subject: [PATCH 5/9] feat: document the `single` option in readme --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 4c95cca6b..68ad4d6ab 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,18 @@ Result 1 out of 1: ---------------------------------------------------- ``` +#### `--single` + +Use `--single` to print a single normalized program. + +```sh +# Command +stack run -- --single --rules-yaml ./eo-phi-normalizer/test/eo/phi/rules/yegor.yaml test.phi + +# Output +⟦ a ↦ ΞΎ.b (c ↦ ⟦ ⟧).d (ρ ↦ ⟦ b ↦ ⟦ c ↦ βˆ…, d ↦ ⟦ Ο† ↦ ΞΎ.ρ.c ⟧ ⟧ ⟧) ⟧ +``` + ## Rulesets A ruleset describes a set of user-defined rewriting rules. From 90a6181db6505ec0d241432127a4bcd045a0317c Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Sat, 10 Feb 2024 18:05:47 +0300 Subject: [PATCH 6/9] Add rule 12 to Yegor's user-defined rules --- eo-phi-normalizer/test/eo/phi/rules/yegor.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/eo-phi-normalizer/test/eo/phi/rules/yegor.yaml b/eo-phi-normalizer/test/eo/phi/rules/yegor.yaml index c41b0c06a..47b8a6ed0 100644 --- a/eo-phi-normalizer/test/eo/phi/rules/yegor.yaml +++ b/eo-phi-normalizer/test/eo/phi/rules/yegor.yaml @@ -136,3 +136,20 @@ rules: input: '⟦ ρ ↦ ⟦ ⟧, Οƒ ↦ ⟦ ⟧ ⟧.x' output: 'βŠ₯' matches: true + + - name: Rule 12 + description: 'Accessing an attribute on bottom' + pattern: | + βŠ₯.!a + result: | + βŠ₯ + when: [] + tests: + - name: 'Dispatch on bottom is bottom' + input: 'βŠ₯.a' + output: 'βŠ₯' + matches: true + - name: 'Dispatch on anything else is not touched' + input: '⟦ ⟧.a' + output: '⟦ ⟧.a' + matches: false From c248d6091fa0cdbf403a7f57300ca44d2cc0bd7f Mon Sep 17 00:00:00 2001 From: Abdelrahman Abounegm Date: Sat, 10 Feb 2024 19:12:57 +0300 Subject: [PATCH 7/9] Add a case for matching Termination --- eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs b/eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs index 7437f8d60..4dab1a80c 100644 --- a/eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs +++ b/eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs @@ -240,6 +240,7 @@ matchObject (MetaObject m) obj = , bindingsMetas = [] , attributeMetas = [] } +matchObject Termination Termination = [emptySubst] matchObject _ _ = [] -- ? emptySubst ? matchBindings :: [Binding] -> [Binding] -> [Subst] From 2bf06b7cd43ce2ce06fedf5ee5d78b4281183061 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sat, 10 Feb 2024 21:29:34 +0000 Subject: [PATCH 8/9] chore(deps): update dependency pre-commit to v3.6.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2cc93d1cb..d6a7661c1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pre-commit==3.6.0 \ No newline at end of file +pre-commit==3.6.1 \ No newline at end of file From 94eb0baa9483f9995843397be664fdcfbc6a92b2 Mon Sep 17 00:00:00 2001 From: Danila Danko Date: Sun, 11 Feb 2024 20:39:28 +0300 Subject: [PATCH 9/9] fix: redirect --- site/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/site/index.html b/site/index.html index 47b4ecc6a..13f44da18 100644 --- a/site/index.html +++ b/site/index.html @@ -6,6 +6,6 @@ - Redirecting to Blog/... + Redirecting to /docs...