Skip to content

Commit

Permalink
Fixes and improvements based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
yav committed Sep 27, 2022
1 parent 42b56f6 commit 38ee399
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
13 changes: 7 additions & 6 deletions src/Cryptol/Parser/Unlit.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
--
-- Convert a literate source file into an ordinary source file.

{-# LANGUAGE OverloadedStrings, PatternGuards #-}
{-# LANGUAGE OverloadedStrings, Safe, PatternGuards #-}
module Cryptol.Parser.Unlit
( unLit, PreProc(..), guessPreProc, knownExts
) where
Expand Down Expand Up @@ -140,8 +140,9 @@ latex = comment []
rst :: [Text] -> [Block]
rst = comment []
where
isBeginCode l = case filter (not . Text.null) (Text.splitOn " " l) of
["..", "code::", "cryptol"] -> True
isBeginCode l = case filter (not . Text.null) (Text.split isSpace l) of
["..", dir, "cryptol"] -> dir == "code-block::" ||
dir == "sourcecode::"
_ -> False

isEmpty = Text.all isSpace
Expand All @@ -152,14 +153,14 @@ rst = comment []
comment acc ls =
case ls of
[] -> mk Comment acc
l : ls1 | isBeginCode l -> codeOptoins (l : acc) ls1
l : ls1 | isBeginCode l -> codeOptions (l : acc) ls1
| otherwise -> comment (l : acc) ls1

codeOptoins acc ls =
codeOptions acc ls =
case ls of
[] -> mk Comment acc
l : ls1 | isEmpty l -> mk Comment (l : acc) ++ code [] ls1
| otherwise -> codeOptoins (l : acc) ls1
| otherwise -> codeOptions (l : acc) ls1

code acc ls =
case ls of
Expand Down
8 changes: 4 additions & 4 deletions tests/issues/issue1441_a.rst
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
This is an RTS document. Here is some code:

.. code:: cryptol
.. code-block:: cryptol
f1 = 0x01
Now we are back to text. Here is some more code, this one with options:

.. code:: cryptol
.. code-block:: cryptol
:linenos:
f2 = 0x02
Back to text. Now two code blocks together:

.. code:: cryptol
.. code-block:: cryptol
f3 = 0x03
.. code:: cryptol
.. sourcecode:: cryptol
:linenos:

f4 = 0x4
Expand Down
10 changes: 5 additions & 5 deletions tests/issues/issue1441_b.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
This is an RTS document. Here is some code:

.. code:: cryptol
.. code-block:: cryptol
f1 = 0x01
Now we are back to text. Here is some more code, this one with options:

.. code:: cryptol
.. code-block:: cryptol
:linenos:
f2 = 0x02
Back to text. Now two code blocks together:

.. code:: cryptol
.. code-block:: cryptol
f3 = 0x03
.. code:: cryptol
.. code-block:: cryptol
:linenos:
f4 = 0x4
Now we are going to make an error and we want to get the correct location:

.. code:: cryptol
.. code-block:: cryptol
f5 = 0x1 + 0x02

0 comments on commit 38ee399

Please sign in to comment.