Skip to content

Commit

Permalink
futhark literate: do not choke on malformed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Nov 9, 2023
1 parent 6aa4e64 commit af43cd4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

* `futhark literate` no longer fails if the final line is a directive
without a trailing newline.

## [0.25.7]

### Added
Expand Down
8 changes: 4 additions & 4 deletions src/Futhark/CLI/Literate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ atStartOfLine = do
when (col /= pos1) empty

afterExp :: Parser ()
afterExp = choice [atStartOfLine, void eol]
afterExp = choice [atStartOfLine, choice [void eol, eof]]

withParsedSource :: Parser a -> (a -> T.Text -> b) -> Parser b
withParsedSource p f = do
Expand Down Expand Up @@ -369,12 +369,12 @@ parseBlock =
$> DirectiveImg
<*> parseExp postlexeme
<*> parseImgParams
<* eol,
<* choice [void eol, eof],
directiveName "plot2d"
$> DirectivePlot
<*> parseExp postlexeme
<*> parsePlotParams
<* eol,
<* choice [void eol, eof],
directiveName "gnuplot"
$> DirectiveGnuplot
<*> parseExp postlexeme
Expand All @@ -388,7 +388,7 @@ parseBlock =
$> DirectiveAudio
<*> parseExp postlexeme
<*> parseAudioParams
<* eol
<* choice [void eol, eof]
]
directiveName s = try $ token (":" <> s)

Expand Down
14 changes: 14 additions & 0 deletions tests_literate/expected/nonl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Note: it is intentional that this file does not include a final
newline character. Do not add it!

```futhark
def main x = x + 1
```

```
> main 1
```

```
2i32
```
6 changes: 6 additions & 0 deletions tests_literate/nonl.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Note: it is intentional that this file does not include a final
-- newline character. Do not add it!

def main x = x + 1

-- > main 1

0 comments on commit af43cd4

Please sign in to comment.