Skip to content

Commit

Permalink
[Haskell] Fix multi-line strings
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Jul 28, 2021
1 parent a5e05e9 commit d0c5d31
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Haskell/Haskell.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,18 @@ contexts:
3: constant.character.escape.octal.haskell
4: constant.character.escape.hexadecimal.haskell
5: constant.character.escape.control.haskell
- match: (\\)\s*$
captures:
1: punctuation.separator.continuation.haskell
push: linteral-string-continuation

linteral-string-continuation:
- meta_include_prototype: false
- match: \\
scope: punctuation.separator.continuation.haskell
pop: 1
- match: (?=")
pop: 1

###[ KEYWORDS AND OPERATORS ]##################################################

Expand Down
8 changes: 8 additions & 0 deletions Haskell/tests/syntax_test_haskell.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3859,6 +3859,14 @@ main = do
-- ^ punctuation.definition.string.end.haskell
-- ^ keyword.operator.haskell

"This is a\
-- ^^^^^^^^^^^^ meta.string.haskell string.quoted.double.haskell
-- ^ punctuation.separator.continuation.haskell
\multi-line string literal\
\example"
-- ^^^^^^^^^ meta.string.haskell string.quoted.double.haskell
-- ^ punctuation.separator.continuation.haskell
-- ^ punctuation.definition.string.end.haskell

-- [ INFIX OPERATORS ] --------------------------------------------------------

Expand Down

2 comments on commit d0c5d31

@absop
Copy link

@absop absop commented on d0c5d31 Jul 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually,

"This is not\
\a syntactically correct\
\Haskell String Literal\
"

Because \ characters must come in pairs to indicate unnecessary white space characters. That is, for a \ at the end of a line of a string literal, there must be a corresponding \ in the next line before any other visible characters (including the end-of-string ") can occur, otherwise it will cause a lexical error.

Please refer to the definition below.

        - match: \\\s
          scope: punctuation.definition.string.escape.begin.haskell
          push:
            - match: \\
              scope: punctuation.definition.string.escape.end.haskell
              pop: 1
            - match: '"'
              scope: invalid.illegal.expect-closing-\.haskell
              pop: 2
            - match: \S
              scope: invalid.illegal.expect-closing-\.haskell
              pop: 1

@deathaxe
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hint.
Also thought about clearing string scope between those backslashes. Not sure about possible implications though.

Please sign in to comment.