Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DedSec256 committed Apr 13, 2023
1 parent 9b05a64 commit 1d60383
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ class FSharpDummyParser : PsiParser {

private fun PsiBuilder.parseConcatenation() =
parse {
val currentIndent = getCurrentLineOffset()
//val currentIndent = getCurrentLineOffset()

if (!parseStringExpression()) null
else if (!scanOrRollback { tryParseConcatenationPartAhead(currentIndent) }) null
else if (!scanOrRollback { tryParseConcatenationPartAhead() }) null
else {
whileMakingProgress {
scanOrRollback { tryParseConcatenationPartAhead(currentIndent) }
scanOrRollback { tryParseConcatenationPartAhead() }
}
FSharpElementTypes.DUMMY_EXPRESSION
}
}

private fun PsiBuilder.tryParseConcatenationPartAhead(requiredStringIndent: Int): Boolean {
private fun PsiBuilder.tryParseConcatenationPartAhead(): Boolean {
val hasSpaceBeforePlus = rawLookup(-1)?.let { isWhitespaceOrComment(it) } ?: false

if (tokenType != FSharpTokenType.PLUS) return false
Expand All @@ -55,21 +55,21 @@ class FSharpDummyParser : PsiParser {
// since "123" +"123" is not allowed
if (hasSpaceBeforePlus && currentOffset - afterPlusTokenIndent == 0) return false

val secondStringOperandIndent = getCurrentLineOffset()
//val secondStringOperandIndent = getCurrentLineOffset()
// since
// "123"
// + "123"
// is not allowed
if (secondStringOperandIndent < requiredStringIndent) return false
//if (secondStringOperandIndent < requiredStringIndent) return false

// since
// "123"
// more than one space after plus
// + "123"
// is not allowed
if (secondStringOperandIndent == requiredStringIndent &&
secondStringOperandIndent - afterPlusTokenIndent > 1
) return false
//if (secondStringOperandIndent == requiredStringIndent &&
// secondStringOperandIndent - afterPlusTokenIndent > 1
//) return false

return parseStringExpression()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.jetbrains.rider.ideaInterop.fileTypes.fsharp.lexer;

import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -100,7 +99,7 @@ public interface FSharpTokenType {
IElementType VERBATIM_INTERPOLATED_STRING_MIDDLE = createToken("VERBATIM_INTERPOLATED_STRING_MIDDLE");
IElementType VERBATIM_INTERPOLATED_STRING_END = createToken("VERBATIM_INTERPOLATED_STRING_END");
IElementType NEW_LINE = createToken("NEW_LINE");
IElementType WHITESPACE = TokenType.WHITE_SPACE;
IElementType WHITESPACE = createToken("WHITESPACE");
IElementType KEYWORD_STRING_SOURCE_DIRECTORY = createToken("KEYWORD_STRING_SOURCE_DIRECTORY");
IElementType KEYWORD_STRING_SOURCE_FILE = createToken("KEYWORD_STRING_SOURCE_FILE");
IElementType KEYWORD_STRING_LINE = createToken("KEYWORD_STRING_LINE");
Expand Down Expand Up @@ -276,12 +275,11 @@ public interface FSharpTokenType {
);

TokenSet BLOCK_COMMENTS = TokenSet.create(
SHEBANG,
SHEBANG, //TODO: remove?
BLOCK_COMMENT
);

TokenSet COMMENTS = TokenSet.create(
SHEBANG,
BLOCK_COMMENT,
LINE_COMMENT
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class FSharpDummyParserTests : RiderFrontendParserTest("", "fs", FSharpParserDef
fun `test concatenation 03 - multiline`() = doTest()
//TODO: compromise to avoid fair parsing
fun `test concatenation 04 - multiline with wrong offset 01`() = doTest()
//TODO: compromise to avoid fair parsing
fun `test concatenation 04 - multiline with wrong offset 02`() = doTest()
fun `test concatenation 05 - with ident`() = doTest()
fun `test concatenation 06 - unfinished`() = doTest()
fun `test concatenation 07 - multiline string`() = doTest()
//TODO: compromise to avoid fair parsing
fun `test concatenation 08 - multiline string with wrong offset`() = doTest()
fun `test concatenation 09 - with interpolated`() = doTest()

Expand All @@ -25,4 +27,5 @@ class FSharpDummyParserTests : RiderFrontendParserTest("", "fs", FSharpParserDef
fun `test unfinished 01 - regular`() = doTest()
fun `test unfinished 02 - interpolated 01`() = doTest()
fun `test unfinished 02 - interpolated 02`() = doTest()
fun `test unfinished 03 - interpolated in interpolated`() = doTest()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ FSharpFile
PsiWhiteSpace(' ')
PsiElement(IDENT)('id')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
PsiWhiteSpace('\n')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
FSharpExpression
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
PsiWhiteSpace('\n')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ FSharpFile
PsiElement(EQUALS)('=')
PsiWhiteSpace('\n')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
PsiWhiteSpace('\n')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
FSharpExpression
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
PsiWhiteSpace('\n')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ FSharpFile
PsiWhiteSpace(' ')
PsiElement(EQUALS)('=')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"\n\n123"')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
FSharpExpression
FSharpStringLiteralExpression
PsiElement(STRING)('"\n\n123"')
PsiWhiteSpace(' ')
PsiElement(PLUS)('+')
PsiWhiteSpace(' ')
FSharpStringLiteralExpression
PsiElement(STRING)('"123"')
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
$" {
1
"

1
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ FSharpFile
PsiElement(INT32)('1')
PsiWhiteSpace('\n')
FSharpStringLiteralExpression
PsiElement(UNFINISHED_STRING)('"')
PsiElement(UNFINISHED_STRING)('"\n\n1')
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$"""{ $"{ }"""

1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FSharpFile
FSharpInterpolatedStringLiteralExpression
FSharpInterpolatedStringLiteralExpressionPart
PsiElement(TRIPLE_QUOTE_INTERPOLATED_STRING_START)('$"""{')
PsiWhiteSpace(' ')
FSharpInterpolatedStringLiteralExpressionPart
PsiElement(REGULAR_INTERPOLATED_STRING_START)('$"{')
PsiWhiteSpace(' ')
FSharpInterpolatedStringLiteralExpressionPart
PsiElement(REGULAR_INTERPOLATED_STRING_END)('}"')
FSharpStringLiteralExpression
PsiElement(STRING)('""')
PsiWhiteSpace('\n')
PsiWhiteSpace('\n')
PsiElement(INT32)('1')

0 comments on commit 1d60383

Please sign in to comment.