Skip to content

Commit

Permalink
Merge branch 'master' into docs-update
Browse files Browse the repository at this point in the history
  • Loading branch information
aabounegm authored Feb 12, 2024
2 parents ae33f33 + 6eafd04 commit 6649d2b
Show file tree
Hide file tree
Showing 15 changed files with 677 additions and 23 deletions.
27 changes: 20 additions & 7 deletions .github/workflows/ghc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,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 ⟧ ⟧ ⟧) ⟧
```
#### Output
By default, the normalization output will be printed to `stdout`.
Expand Down
36 changes: 21 additions & 15 deletions eo-phi-normalizer/app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

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)

data CLINamedParams = CLINamedParams
{ chain :: Bool
, rulesYaml :: Maybe String
, outPath :: Maybe String
, single :: Bool
}
deriving (Generic, Show, ParseRecord, Read, ParseField)

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions eo-phi-normalizer/src/Language/EO/Phi/Rules/Yaml.hs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ matchObject (MetaObject m) obj =
, bindingsMetas = []
, attributeMetas = []
}
matchObject Termination Termination = [emptySubst]
matchObject _ _ = [] -- ? emptySubst ?

evaluateMetaFuncs :: Object -> Object
Expand Down
17 changes: 17 additions & 0 deletions eo-phi-normalizer/test/eo/phi/rules/yegor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pre-commit==3.6.0
pre-commit==3.6.1
1 change: 1 addition & 0 deletions site/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# README
1 change: 1 addition & 0 deletions site/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/docs
13 changes: 13 additions & 0 deletions site/docs/book.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions site/docs/src/README.md
3 changes: 3 additions & 0 deletions site/docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Summary

- [README](./README.md)
Loading

0 comments on commit 6649d2b

Please sign in to comment.