disallow multiline strings that do not start with newline

This commit is contained in:
Gaute Berge 2023-10-25 14:18:08 +02:00
parent 67c1d66698
commit 51daca3161
2 changed files with 27 additions and 1 deletions

View File

@ -179,7 +179,7 @@ multiString pos end row col initialPos sr sc =
then
let !pos1 = plusPtr pos 1
in countLeadingWhiteSpaceThenMultiString 0 pos1 end (row + 1) 1 pos1 sr sc
else countLeadingWhiteSpaceThenMultiString 0 pos end row col initialPos sr sc
else Err sr sc E.StringMultilineWithoutLeadingNewline
countLeadingWhiteSpaceThenMultiString :: Int -> Ptr Word8 -> Ptr Word8 -> Row -> Col -> Ptr Word8 -> Row -> Col -> StringResult
countLeadingWhiteSpaceThenMultiString count pos end row col initialPos sr sc =

View File

@ -440,6 +440,7 @@ data String
= StringEndless_Single
| StringEndless_Multi
| StringEscape Escape
| StringMultilineWithoutLeadingNewline
deriving (Show)
data Escape
@ -2991,6 +2992,31 @@ toStringReport source string row col =
)
StringEscape escape ->
toEscapeReport source escape row col
StringMultilineWithoutLeadingNewline ->
let region = toRegion row col
in Report.Report "MULTILINE STRING WITHOUT NEWLINE" region [] $
Code.toSnippet
source
region
Nothing
( D.reflow "The contents of a multiline sting must start on a new line",
D.stack
[ D.reflow "Add a \"\"\" a new line right after the opening quotes.",
D.toSimpleNote "Here is a valid multi-line string for reference:",
D.dullyellow $
D.indent 4 $
D.vcat
[ "\"\"\"",
"# Multi-line Strings",
"",
"- start with triple double quotes",
"- write whatever you want",
"- no need to escape newlines or double quotes",
"- end with triple double quotes",
"\"\"\""
]
]
)
-- ESCAPES