haskell / haskell/happy

Code blocks should strip alignment of opening brace

Open
#305 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Haskell
Stars
322
Forks
86
PR merge metrics
No merged PRs in 30d

Description

Motivated by https://github.com/haskell/happy/issues/303, I think we should offer a command-line flag such that a code block

```
| 'pattern' pattern_synonym_lhs '<-' pat_syn_pat where_decls
{% do { let (name, args, as) = $2
; mg <- mkPatSynMatchGroup name $51 }
```

is turned into

```
do { let (name, args, as) = $2
; mg <- mkPatSynMatchGroup name $51 }
```

instead of

```
do { let (name, args, as) = $2
; mg <- mkPatSynMatchGroup name $51 }
```

That is, try and trim a whitespace prefix from subsequent lines that corresponds to the alignment of `{%`.

I think we can make code blocks entirely insensitive to indentation by wrapping them in `do{...}`. Example:

```
x :: Int
x = do{ 42 } -- works on pure expressions as well

-- code block: {%do putStrLn "this is the"
-- putStrLn "code block"}

main = do
putStrLn "hi"
do{
do putStrLn "this is the"
putStrLn "code block"}
putStrLn "end"
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.