mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 16:56:29 +03:00
disallow multiline strings that do not start with newline
This commit is contained in:
parent
67c1d66698
commit
51daca3161
@ -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 =
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user