Skip to content

Commit 4d01cda

Browse files
committed
- use a new rule for '"}" +' to catch the correct range start
- clean up work around structures introduced before and not needed anymore with this
1 parent 369bbfb commit 4d01cda

File tree

8 files changed

+72
-78
lines changed

8 files changed

+72
-78
lines changed

docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### Fixed
22

3-
* Fix wrong range start of INTERP_STRING_END. ([PR #16774](https://github.com/dotnet/fsharp/pull/16774))
3+
* Fix wrong range start of INTERP_STRING_END. ([PR #16774](https://github.com/dotnet/fsharp/pull/16774), [PR #16785](https://github.com/dotnet/fsharp/pull/16785))
44
* Fix missing warning for recursive calls in list comprehensions. ([PR #16652](https://github.com/dotnet/fsharp/pull/16652))
55
* Code generated files with > 64K methods and generated symbols crash when loaded. Use infered sequence points for debugging. ([Issue #16399](https://github.com/dotnet/fsharp/issues/16399), [#PR 16514](https://github.com/dotnet/fsharp/pull/16514))
66
* `nameof Module` expressions and patterns are processed to link files in `--test:GraphBasedChecking`. ([PR #16550](https://github.com/dotnet/fsharp/pull/16550), [PR #16743](https://github.com/dotnet/fsharp/pull/16743))

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2685,7 +2685,7 @@ module internal ParseAndCheckFile =
26852685
| INTERP_STRING_BEGIN_PART _ | INTERP_STRING_PART _ as tok, _ ->
26862686
let braceOffset =
26872687
match tok with
2688-
| INTERP_STRING_BEGIN_PART(_, SynStringKind.TripleQuote, (LexerContinuation.Token(_, (_, _, dl, _, _) :: _))) ->
2688+
| INTERP_STRING_BEGIN_PART(_, SynStringKind.TripleQuote, (LexerContinuation.Token(_, (_, _, dl, _) :: _))) ->
26892689
dl - 1
26902690
| _ -> 0
26912691

src/Compiler/Service/ServiceLexing.fs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ module FSharpTokenTag =
3535
let INTERP_STRING_BEGIN_PART =
3636
tagOfToken (INTERP_STRING_BEGIN_PART("a", SynStringKind.Regular, LexCont.Default))
3737

38-
let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", None, LexCont.Default))
39-
let INTERP_STRING_END = tagOfToken (INTERP_STRING_END("a", None, LexCont.Default))
38+
let INTERP_STRING_PART = tagOfToken (INTERP_STRING_PART("a", LexCont.Default))
39+
let INTERP_STRING_END = tagOfToken (INTERP_STRING_END("a", LexCont.Default))
4040
let LPAREN = tagOfToken LPAREN
4141
let RPAREN = tagOfToken RPAREN
4242
let LBRACK = tagOfToken LBRACK
@@ -491,9 +491,9 @@ module internal LexerStateEncoding =
491491
| STRING_TEXT cont
492492
| EOF cont
493493
| INTERP_STRING_BEGIN_PART(_, _, cont)
494-
| INTERP_STRING_PART(_, _, cont)
494+
| INTERP_STRING_PART(_, cont)
495495
| INTERP_STRING_BEGIN_END(_, _, cont)
496-
| INTERP_STRING_END(_, _, cont)
496+
| INTERP_STRING_END(_, cont)
497497
| LBRACE cont
498498
| RBRACE cont
499499
| BYTEARRAY(_, _, cont)
@@ -621,12 +621,12 @@ module internal LexerStateEncoding =
621621
let tag1, i1, kind1, rest =
622622
match stringNest with
623623
| [] -> false, 0, 0, []
624-
| (i1, kind1, _, _, _) :: rest -> true, i1, encodeStringStyle kind1, rest
624+
| (i1, kind1, _, _) :: rest -> true, i1, encodeStringStyle kind1, rest
625625

626626
let tag2, i2, kind2 =
627627
match rest with
628628
| [] -> false, 0, 0
629-
| (i2, kind2, _, _, _) :: _ -> true, i2, encodeStringStyle kind2
629+
| (i2, kind2, _, _) :: _ -> true, i2, encodeStringStyle kind2
630630

631631
(if tag1 then 0b100000000000 else 0)
632632
||| (if tag2 then 0b010000000000 else 0)
@@ -696,9 +696,9 @@ module internal LexerStateEncoding =
696696
let nest =
697697
[
698698
if tag1 then
699-
i1, decodeStringStyle kind1, 0, None, range0
699+
i1, decodeStringStyle kind1, 0, range0
700700
if tag2 then
701-
i2, decodeStringStyle kind2, 0, None, range0
701+
i2, decodeStringStyle kind2, 0, range0
702702
]
703703

704704
nest

src/Compiler/SyntaxTree/LexHelpers.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ type LexerStringFinisher =
188188
else
189189
INTERP_STRING_BEGIN_END(s, synStringKind, cont)
190190
else if isPart then
191-
INTERP_STRING_PART(s, None, cont)
191+
INTERP_STRING_PART(s, cont)
192192
else
193-
INTERP_STRING_END(s, None, cont)
193+
INTERP_STRING_END(s, cont)
194194
elif kind.IsByteString then
195195
let synByteStringKind =
196196
if isVerbatim then

src/Compiler/SyntaxTree/ParseHelpers.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ type LexerStringKind =
308308

309309
/// Represents the degree of nesting of '{..}' and the style of the string to continue afterwards, in an interpolation fill.
310310
/// Nesting counters and styles of outer interpolating strings are pushed on this stack.
311-
type LexerInterpolatedStringNesting = (int * LexerStringStyle * int * range option * range) list
311+
type LexerInterpolatedStringNesting = (int * LexerStringStyle * int * range) list
312312

313313
/// The parser defines a number of tokens for whitespace and
314314
/// comments eliminated by the lexer. These carry a specification of
@@ -973,7 +973,7 @@ let checkEndOfFileError t =
973973

974974
match nesting with
975975
| [] -> ()
976-
| (_, _, _, _, m) :: _ -> reportParseErrorAt m (FSComp.SR.parsEofInInterpolatedStringFill ())
976+
| (_, _, _, m) :: _ -> reportParseErrorAt m (FSComp.SR.parsEofInInterpolatedStringFill ())
977977

978978
type BindingSet = BindingSetPreAttrs of range * bool * bool * (SynAttributes -> SynAccess option -> SynAttributes * SynBinding list) * range
979979

src/Compiler/SyntaxTree/ParseHelpers.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type LexerStringKind =
118118

119119
static member String: LexerStringKind
120120

121-
type LexerInterpolatedStringNesting = (int * LexerStringStyle * int * range option * range) list
121+
type LexerInterpolatedStringNesting = (int * LexerStringStyle * int * range) list
122122

123123
[<RequireQualifiedAccess; NoComparison; NoEquality>]
124124
type LexerContinuation =

src/Compiler/lex.fsl

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ let checkExprGreaterColonOp (lexbuf:UnicodeLexing.Lexbuf) =
120120
let unexpectedChar lexbuf =
121121
LEX_FAILURE (FSComp.SR.lexUnexpectedChar(lexeme lexbuf))
122122

123-
let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringPartOrEnd =
123+
let startString args (lexbuf: UnicodeLexing.Lexbuf) =
124124
let buf = ByteBuffer.Create StringCapacity
125125
let m = lexbuf.LexemeRange
126126
let startp = lexbuf.StartPos
@@ -158,9 +158,9 @@ let startString args (lexbuf: UnicodeLexing.Lexbuf) altStartForStringPartOrEnd =
158158
INTERP_STRING_BEGIN_END (s, synStringKind, cont)
159159
else
160160
if isPart then
161-
INTERP_STRING_PART (s, altStartForStringPartOrEnd, cont)
161+
INTERP_STRING_PART (s, cont)
162162
else
163-
INTERP_STRING_END (s, altStartForStringPartOrEnd, cont)
163+
INTERP_STRING_END (s, cont)
164164
else
165165
let s = Lexhelp.stringBufferAsString buf
166166
let synStringKind =
@@ -587,20 +587,20 @@ rule token (args: LexArgs) (skip: bool) = parse
587587
else mlOnly m args skip lexbuf }
588588

589589
| '"'
590-
{ let buf, fin, m = startString args lexbuf None
590+
{ let buf, fin, m = startString args lexbuf
591591

592592
// Single quote in triple quote ok, others disallowed
593593
match args.stringNest with
594-
| (_, LexerStringStyle.ExtendedInterpolated, _, _, _) :: _
595-
| (_, LexerStringStyle.TripleQuote, _, _, _) :: _ -> ()
594+
| (_, LexerStringStyle.ExtendedInterpolated, _, _) :: _
595+
| (_, LexerStringStyle.TripleQuote, _, _) :: _ -> ()
596596
| _ :: _ -> errorR(Error(FSComp.SR.lexSingleQuoteInSingleQuote(), m))
597597
| [] -> ()
598598

599599
if not skip then STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, LexerStringStyle.SingleQuote, LexerStringKind.String, args.interpolationDelimiterLength, m))
600600
else singleQuoteString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }
601601

602602
| '$' '"' '"' '"'
603-
{ let buf, fin, m = startString args lexbuf None
603+
{ let buf, fin, m = startString args lexbuf
604604

605605
// Single quote in triple quote ok, others disallowed
606606
match args.stringNest with
@@ -612,7 +612,7 @@ rule token (args: LexArgs) (skip: bool) = parse
612612
else tripleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringFirst, args) skip lexbuf }
613613

614614
| ('$'+) '"' '"' '"'
615-
{ let buf, fin, m = startString args lexbuf None
615+
{ let buf, fin, m = startString args lexbuf
616616

617617
if lexbuf.SupportsFeature LanguageFeature.ExtendedStringInterpolation then
618618
// Single quote in triple quote ok, others disallowed
@@ -635,11 +635,11 @@ rule token (args: LexArgs) (skip: bool) = parse
635635
}
636636

637637
| '$' '"'
638-
{ let buf,fin,m = startString args lexbuf None
638+
{ let buf,fin,m = startString args lexbuf
639639

640640
// Single quote in triple quote ok, others disallowed
641641
match args.stringNest with
642-
| (_, style, _, _, _) :: _ when style = LexerStringStyle.ExtendedInterpolated || style = LexerStringStyle.TripleQuote -> ()
642+
| (_, style, _, _) :: _ when style = LexerStringStyle.ExtendedInterpolated || style = LexerStringStyle.TripleQuote -> ()
643643
| _ :: _ -> errorR(Error(FSComp.SR.lexSingleQuoteInSingleQuote(), m))
644644
| _ -> ()
645645

@@ -649,7 +649,7 @@ rule token (args: LexArgs) (skip: bool) = parse
649649
singleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringFirst, args) skip lexbuf }
650650

651651
| '"' '"' '"'
652-
{ let buf, fin, m = startString args lexbuf None
652+
{ let buf, fin, m = startString args lexbuf
653653

654654
args.interpolationDelimiterLength <- 0
655655

@@ -664,12 +664,12 @@ rule token (args: LexArgs) (skip: bool) = parse
664664
tripleQuoteString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }
665665

666666
| '@' '"'
667-
{ let buf, fin, m = startString args lexbuf None
667+
{ let buf, fin, m = startString args lexbuf
668668

669669
// Single quote in triple quote ok, others disallowed
670670
match args.stringNest with
671-
| (_, LexerStringStyle.ExtendedInterpolated, _, _, _) :: _
672-
| (_, LexerStringStyle.TripleQuote, _, _, _) :: _ -> ()
671+
| (_, LexerStringStyle.ExtendedInterpolated, _, _) :: _
672+
| (_, LexerStringStyle.TripleQuote, _, _) :: _ -> ()
673673
| _ :: _ -> errorR(Error(FSComp.SR.lexSingleQuoteInSingleQuote(), m))
674674
| _ -> ()
675675

@@ -679,11 +679,11 @@ rule token (args: LexArgs) (skip: bool) = parse
679679
verbatimString (buf, fin, m, LexerStringKind.String, args) skip lexbuf }
680680

681681
| ("$@" | "@$") '"'
682-
{ let buf, fin, m = startString args lexbuf None
682+
{ let buf, fin, m = startString args lexbuf
683683

684684
// Single quote in triple quote ok, others disallowed
685685
match args.stringNest with
686-
| (_, style, _, _, _) :: _ when style = LexerStringStyle.ExtendedInterpolated || style = LexerStringStyle.TripleQuote -> ()
686+
| (_, style, _, _) :: _ when style = LexerStringStyle.ExtendedInterpolated || style = LexerStringStyle.TripleQuote -> ()
687687
| _ :: _ -> errorR(Error(FSComp.SR.lexSingleQuoteInSingleQuote(), m))
688688
| _ -> ()
689689

@@ -888,33 +888,48 @@ rule token (args: LexArgs) (skip: bool) = parse
888888
{
889889
match args.stringNest with
890890
| [] -> ()
891-
| (counter, style, d, _, m) :: rest ->
891+
| (counter, style, d, m) :: rest ->
892892
// Note, we do not update the 'm', any incomplete-interpolation error
893893
// will be reported w.r.t. the first '{'
894-
args.stringNest <- (counter + 1, style, d, None, m) :: rest
894+
args.stringNest <- (counter + 1, style, d, m) :: rest
895895
// To continue token-by-token lexing may involve picking up the new args.stringNes
896896
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
897897
LBRACE cont
898898
}
899899

900900
| "|" { BAR }
901901

902+
| "}" +
903+
{
904+
match args.stringNest with
905+
| (1, style, _, _r) :: rest ->
906+
args.stringNest <- rest
907+
let buf, fin, m = startString args lexbuf
908+
if not skip then
909+
STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, style, LexerStringKind.InterpolatedStringPart, args.interpolationDelimiterLength, m))
910+
else
911+
match style with
912+
| LexerStringStyle.Verbatim -> verbatimString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
913+
| LexerStringStyle.SingleQuote -> singleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
914+
| LexerStringStyle.TripleQuote -> tripleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
915+
| LexerStringStyle.ExtendedInterpolated -> extendedInterpolatedString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
916+
| (counter, style, d, m) :: rest ->
917+
// Note, we do not update the 'm', any incomplete-interpolation error
918+
// will be reported w.r.t. the first '{'
919+
args.stringNest <- (counter - 1, style, d, m) :: rest
920+
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
921+
RBRACE cont
922+
| _ ->
923+
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
924+
RBRACE cont
925+
}
926+
902927
| "}"
903928
{
904-
// We encounter a '}' in the expression token stream. First check if we're in an interpolated string expression
905-
// and continue the string if necessary
906929
match args.stringNest with
907-
| (1, LexerStringStyle.ExtendedInterpolated, delimLength, altR, r) :: rest when delimLength > 1 ->
908-
// On the first "}" of multiple "}", keep the range of the starting "}" for later processing in startString
909-
let altStart =
910-
match altR with
911-
| None -> Some lexbuf.LexemeRange
912-
| _ -> altR
913-
args.stringNest <- (1, LexerStringStyle.ExtendedInterpolated, delimLength - 1, altStart, r) :: rest
914-
token args skip lexbuf
915-
| (1, style, _, altR, _r) :: rest ->
930+
| (1, style, _, _r) :: rest ->
916931
args.stringNest <- rest
917-
let buf, fin, m = startString args lexbuf altR
932+
let buf, fin, m = startString args lexbuf
918933
if not skip then
919934
STRING_TEXT (LexCont.String(args.ifdefStack, args.stringNest, style, LexerStringKind.InterpolatedStringPart, args.interpolationDelimiterLength, m))
920935
else
@@ -923,10 +938,10 @@ rule token (args: LexArgs) (skip: bool) = parse
923938
| LexerStringStyle.SingleQuote -> singleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
924939
| LexerStringStyle.TripleQuote -> tripleQuoteString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
925940
| LexerStringStyle.ExtendedInterpolated -> extendedInterpolatedString (buf, fin, m, LexerStringKind.InterpolatedStringPart, args) skip lexbuf
926-
| (counter, style, d, altR, m) :: rest ->
941+
| (counter, style, d, m) :: rest ->
927942
// Note, we do not update the 'm', any incomplete-interpolation error
928943
// will be reported w.r.t. the first '{'
929-
args.stringNest <- (counter - 1, style, d, altR, m) :: rest
944+
args.stringNest <- (counter - 1, style, d, m) :: rest
930945
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
931946
RBRACE cont
932947

@@ -1264,7 +1279,7 @@ and singleQuoteString (sargs: LexerStringArgs) (skip: bool) = parse
12641279
if kind.IsInterpolated then
12651280
// get a new range for where the fill starts
12661281
let m2 = lexbuf.LexemeRange
1267-
args.stringNest <- (1, LexerStringStyle.SingleQuote, args.interpolationDelimiterLength, None, m2) :: args.stringNest
1282+
args.stringNest <- (1, LexerStringStyle.SingleQuote, args.interpolationDelimiterLength, m2) :: args.stringNest
12681283
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
12691284
fin.Finish buf kind LexerStringFinisherContext.InterpolatedPart cont
12701285
else
@@ -1380,7 +1395,7 @@ and verbatimString (sargs: LexerStringArgs) (skip: bool) = parse
13801395
if kind.IsInterpolated then
13811396
// get a new range for where the fill starts
13821397
let m2 = lexbuf.LexemeRange
1383-
args.stringNest <- (1, LexerStringStyle.Verbatim, args.interpolationDelimiterLength, None, m2) :: args.stringNest
1398+
args.stringNest <- (1, LexerStringStyle.Verbatim, args.interpolationDelimiterLength, m2) :: args.stringNest
13841399
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
13851400
fin.Finish buf kind (LexerStringFinisherContext.InterpolatedPart ||| LexerStringFinisherContext.Verbatim) cont
13861401
else
@@ -1499,7 +1514,7 @@ and tripleQuoteString (sargs: LexerStringArgs) (skip: bool) = parse
14991514
if kind.IsInterpolated then
15001515
// get a new range for where the fill starts
15011516
let m2 = lexbuf.LexemeRange
1502-
args.stringNest <- (1, LexerStringStyle.TripleQuote, args.interpolationDelimiterLength, None, m2) :: args.stringNest
1517+
args.stringNest <- (1, LexerStringStyle.TripleQuote, args.interpolationDelimiterLength, m2) :: args.stringNest
15031518
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
15041519
fin.Finish buf kind (LexerStringFinisherContext.InterpolatedPart ||| LexerStringFinisherContext.TripleQuote) cont
15051520
else
@@ -1604,7 +1619,7 @@ and extendedInterpolatedString (sargs: LexerStringArgs) (skip: bool) = parse
16041619
let maxBraces = 2 * args.interpolationDelimiterLength - 1
16051620
if numBraces > maxBraces then
16061621
let m2 = lexbuf.LexemeRange
1607-
args.stringNest <- (1, LexerStringStyle.ExtendedInterpolated, args.interpolationDelimiterLength, None, m2) :: args.stringNest
1622+
args.stringNest <- (1, LexerStringStyle.ExtendedInterpolated, args.interpolationDelimiterLength, m2) :: args.stringNest
16081623
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
16091624
fail args lexbuf
16101625
(FSComp.SR.lexTooManyLBracesInTripleQuote())
@@ -1625,7 +1640,7 @@ and extendedInterpolatedString (sargs: LexerStringArgs) (skip: bool) = parse
16251640
String.replicate extraBraces "{" |> addUnicodeString buf
16261641
// get a new range for where the fill starts
16271642
let m2 = lexbuf.LexemeRange
1628-
args.stringNest <- (1, LexerStringStyle.ExtendedInterpolated, args.interpolationDelimiterLength, None, m2) :: args.stringNest
1643+
args.stringNest <- (1, LexerStringStyle.ExtendedInterpolated, args.interpolationDelimiterLength, m2) :: args.stringNest
16291644
let cont = LexCont.Token(args.ifdefStack, args.stringNest)
16301645
fin.Finish buf kind (LexerStringFinisherContext.InterpolatedPart ||| LexerStringFinisherContext.TripleQuote) cont
16311646
}

0 commit comments

Comments
 (0)