| CARVIEW |
rewrite-inspector: Inspection of rewriting steps
A terminal UI for inspecting steps taken by a rewriting process. Useful for the optimization phase of a compiler, or even evaluators of small languages.
[Skip to Readme]
Downloads
- rewrite-inspector-0.1.0.11.tar.gz [browse] (Cabal source package)
- Package description (as included in the package)
Maintainer's Corner
For package maintainers and hackage trustees
Candidates
- No Candidates
| Versions [RSS] | 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3, 0.1.0.4, 0.1.0.5, 0.1.0.6, 0.1.0.7, 0.1.0.8, 0.1.0.9, 0.1.0.10, 0.1.0.11 |
|---|---|
| Dependencies | base (>=4.10 && <5), binary (>=0.8.5 && <0.11), brick (==0.50), containers (>=0.5.0.0 && <0.7), data-default (>=0.7.1.1), hashable (>=1.2.1.0 && <1.4), microlens (>=0.3.0.0), microlens-th, prettyprinter (>=1.2.0.1 && <2.0), rewrite-inspector, text, vty (>=5.26) [details] |
| License | BSD-3-Clause |
| Author | Orestis Melkonian |
| Maintainer | Orestis Melkonian <melkon.or@gmail.com> |
| Uploaded | by omelkonian at 2019-10-28T13:32:10Z |
| Category | rewriting, inspection, terminal, user interface |
| Home page | https://github.com/omelkonian/rewrite-inspector/ |
| Bug tracker | https://github.com/omelkonian/rewrite-inspector/issues |
| Source repo | head: git clone git://github.com/omelkonian/rewrite-inspector.git |
| Distributions | |
| Executables | str-example, expr-example |
| Downloads | 5359 total (36 in the last 30 days) |
| Rating | (no votes yet) [estimated by Bayesian average] |
| Your Rating |
|
| Status | Docs uploaded by user Build status unknown [no reports yet] |
Readme for rewrite-inspector-0.1.0.11
[back to package description]Rewrite Inspector
A terminal user-interface (TUI) for inspecting steps taken by a rewriting process. Useful for the optimization phase of a compiler, or even evaluators of small languages.
Usage Instructions
To use the library, the user's type of language expressions
must be an instance of the Diff typeclass.
Let's see an example for a simple language for arithmetic expressions.
data Expr = N Int | Expr :+: Expr deriving (Eq, Show)
We first need to give the type of contexts, which navigate to a certain sub-term:
data ExprContext = L | R deriving (Eq, Show)
We can then give the instance for the Diff typeclass, by providing the following:
readHistory: A way to read the rewrite history from file (for this example, always return a constant history).ppr': A pretty-printing for (for this example, the type of annotations is just the type of contexts)patch: A way to patch a given expression at some context.
Below is the complete definition of our instance:
instance Diff Expr where
type Ann Expr = ExprContext
type Options Expr = ()
type Ctx Expr = ExprContext
readHistory _ = return [ HStep { _ctx = [L]
, _bndrS = "top"
, _name = "adhocI"
, _before = N 1
, _after = N 11 :+: N 12
}
, HStep { _ctx = [L, L]
, _bndrS = "top"
, _name = "adhocII"
, _before = N 11
, _after = N 111 :+: N 112
}
, HStep { _ctx = []
, _bndrS = "top"
, _name = "normalization"
, _before = N 1 :+: (N 2 :+: N 3)
, _after = ((N 111 :+: N 112) :+: N 12)
:+: (N 2 :+: N 3)
}
]
ppr' _ (N n) = pretty n
ppr' opts (e :+: e') = hsep [ annotate L (ppr' opts e)
, "+"
, annotate R (ppr' opts e')
]
patch _ [] e' = e'
patch curE (c:cs) e' = let go e = patch e cs e' in
case (curE, c) of
(l :+: r, L) -> go l :+: r
(l :+: r, R) -> l :+: go r
_ -> error "patch"
Finally, we are ready to run our TUI to inspect the rewriting steps with proper
highlighting (.ini files are used to provide styling directives):
main :: IO ()
main = runTerminal @Expr "examples/expr/theme.ini"
For more examples, check the folder.
Features
The features depicted below have been recorded on the optimizing phase of the
.
-
Use
Ctrl-pto show/hide keyboard controls:
-
Syntax highlighting:

-
Navigate through the rewriting steps with highlighted diffs:

-
Also navigate through all top-level binders:

-
Hide extraneous code output, suc as uniques/types/qualifiers:

-
Individual and grouped scrolling for code panes, both vertically and horizontally:

-
Move to next transformation with the given step number:

-
Move to next transformation with the given name:

-
Search for string occurrences within source code:

-
Inside code panes, the line width is dynamically adjusted depending on available space:

-
User-configurable colour theme:
