Commit 6174d0de authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Adjust unlit's behaviour on continuing comments

This behaviour is not set in stone, there is not full agreement yet.
The previous code was deciding wether to continue a comment based on wether
the intervenienting lines were completely blank or had at least one space in.
The other suggestion was to use a '.' to continue a comment line.
Instead, this change uses a single blank line between comments to continue
a comment and anything else terminates it with a blank line.
parent 08cc3c88
......@@ -53,6 +53,7 @@ unclassify (Blank s) = s
unclassify (Ordinary s) = s
unclassify (Line n file) = "# " ++ show n ++ " " ++ show file
unclassify (CPP s) = '#':s
unclassify (Comment "") = "--"
unclassify (Comment s) = "-- " ++ s
-- | 'unlit' takes a filename (for error reports), and transforms the
......@@ -112,14 +113,11 @@ reclassify = blank -- begin in blank state
comment (BeginCode :ls) = Blank "" : latex ls
comment (CPP l :ls) = CPP l : comment ls
comment (BirdTrack _:_ ) = [Error "comment line before program line"]
-- special case here: a truly empty line will terminate
-- a comment section (and send us into the "blank" state)
comment (Blank "" :ls) = Blank "" : blank ls
-- but a line containing whitespace will be treated as a
-- comment (prefixed with "-- "), unless it is followed by
-- a program line, in which case it is really blank.
comment (Blank l:ls@(BirdTrack _:_)) = Blank l : blank ls
comment (Blank l:ls) = Comment l : comment ls
-- a blank line and another ordinary line following a comment
-- will be treated as continuing the comment. Otherwise it's
-- then end of the comment, with a blank line.
comment (Blank l:ls@(Ordinary _:_)) = Comment l : comment ls
comment (Blank l:ls) = Blank l : blank ls
comment (Line n f :ls) = Line n f : comment ls
comment (Ordinary l:ls) = Comment l : comment ls
......
......@@ -38,8 +38,8 @@ cases =
( "abc\n", "-- abc\n" ) :
( "a\nb\n", "-- a\n-- b\n") :
( "a\n\n", "-- a\n\n") : -- comment -> blank
( "a\n\nb\n", "-- a\n\n-- b\n" ) : -- comment -> blank
( "a\n \n\n", "-- a\n-- \n\n" ) : -- comment -> comment
( "a\n\nb\n", "-- a\n--\n-- b\n" ) : -- comment -> blank
( "a\n \n\n", "-- a\n \n\n" ) : -- comment -> comment
( "a\n \n> x=x\n", "-- a\n \n x=x\n" ) : -- comment -> blank (> )
( "a\n \n>x=x\n", "-- a\n \n x=x\n" ) : -- comment -> blank (>)
( "a\n \nb\n", "-- a\n-- \n-- b\n" ) : -- comment -> comment
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment