Skip to content

fix(kotlin): fix termination of """ string literals#2295

Merged
joshgoebel merged 3 commits intohighlightjs:masterfrom
joshgoebel:kotlin_string_fixes
Nov 22, 2019
Merged

fix(kotlin): fix termination of """ string literals#2295
joshgoebel merged 3 commits intohighlightjs:masterfrom
joshgoebel:kotlin_string_fixes

Conversation

@joshgoebel
Copy link
Copy Markdown
Member

- Properly handles cases: like """ends in a "quoted string""""
- Closes highlightjs#2280.
@joshgoebel joshgoebel added language enhancement An enhancement or new feature bug labels Nov 21, 2019
@egor-rogov
Copy link
Copy Markdown
Collaborator

I have had a look into Kotlin grammar (https://kotlinlang.org/docs/reference/grammar.html). The relevant parts are:

multiLineStringLiteral
  : '"""' (multiLineStringContent | multiLineStringExpression | '"')*
    TRIPLE_QUOTE_CLOSE
  ;

TRIPLE_QUOTE_CLOSE
  : ('"'? '"""') 
  ;

It seems that end: '"""(?=[^"])' is basically the same as end: '"?"""', but the latter is a bit simpler and closer to the grammar. Thoughts?

@joshgoebel
Copy link
Copy Markdown
Member Author

joshgoebel commented Nov 22, 2019

Screen Shot 2019-11-22 at 6 15 27 AM

I don' think those are the same... Is this not a problem? (just look at the end matches) A negative look behind would also work but since we don't have those yet I went with look ahead.

@egor-rogov
Copy link
Copy Markdown
Collaborator

Yeah, I played around a bit and looks like you're right. We need the rightmost match.

@joshgoebel joshgoebel merged commit dec92ac into highlightjs:master Nov 22, 2019
@joshgoebel joshgoebel deleted the kotlin_string_fixes branch December 6, 2019 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug enhancement An enhancement or new feature language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(kotlin) Incorrect handling of strings with triple quotes

2 participants