Skip to content

Commit a1a156d

Browse files
authored
Fix parsing errors using anonymous records and code quotations (#18603)
1 parent 2854dfb commit a1a156d

37 files changed

+612
-44
lines changed

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

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

33
* Fix parsing errors using anonymous records and units of measures ([PR #18543](https://github.com/dotnet/fsharp/pull/18543))
4+
* Fix parsing errors using anonymous records and code quotations ([PR #18603](https://github.com/dotnet/fsharp/pull/18603))
45
* Fixed: Allow `return`, `return!`, `yield`, `yield!` type annotations without parentheses ([PR #18533](https://github.com/dotnet/fsharp/pull/18533))
56
* Range of `SynExprRecordField` should include the expression ([PR #18617](https://github.com/dotnet/fsharp/pull/18617))
67
* Allow `let!` and `use!` type annotations without requiring parentheses ([PR #18508](https://github.com/dotnet/fsharp/pull/18508))

src/Compiler/Driver/CompilerDiagnostics.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ type Exception with
11681168
| Parser.TOKEN_GREATER_RBRACK -> SR.GetString("Parser.TOKEN.GREATER.RBRACK")
11691169
| Parser.TOKEN_RQUOTE_DOT
11701170
| Parser.TOKEN_RQUOTE -> SR.GetString("Parser.TOKEN.RQUOTE")
1171+
| Parser.TOKEN_RQUOTE_BAR_RBRACE -> SR.GetString("Parser.TOKEN.RQUOTE.BAR.RBRACE")
11711172
| Parser.TOKEN_RBRACK -> SR.GetString("Parser.TOKEN.RBRACK")
11721173
| Parser.TOKEN_RBRACE
11731174
| Parser.TOKEN_RBRACE_COMING_SOON

src/Compiler/FSStrings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@
360360
<data name="Parser.TOKEN.GREATER.BAR.RBRACE" xml:space="preserve">
361361
<value>symbol '&gt;|}'</value>
362362
</data>
363+
<data name="Parser.TOKEN.RQUOTE.BAR.RBRACE" xml:space="preserve">
364+
<value>symbol '@&gt;|}' or '@@&gt;|}'</value>
365+
</data>
363366
<data name="Parser.TOKEN.GREATER.BAR.RBRACK" xml:space="preserve">
364367
<value>symbol '&gt;|]'</value>
365368
</data>

src/Compiler/Service/ServiceLexing.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ module internal TokenClassifications =
287287
| GREATER_BAR_RBRACK -> (FSharpTokenColorKind.Punctuation, FSharpTokenCharKind.Delimiter, FSharpTokenTriggerClass.None)
288288

289289
| RQUOTE _
290+
| RQUOTE_BAR_RBRACE _
290291
| RBRACK
291292
| RBRACE _
292293
| RBRACE_COMING_SOON
@@ -1389,6 +1390,7 @@ type FSharpTokenKind =
13891390
| RightArrow
13901391
| GreaterBarRightBracket
13911392
| GreaterBarRightBrace
1393+
| RQuoteBarRightBrace
13921394
| LeftParenthesisStarRightParenthesis
13931395
| Open
13941396
| Or
@@ -1659,6 +1661,7 @@ type FSharpToken =
16591661
| LQUOTE _ -> FSharpTokenKind.LeftQuote
16601662
| RQUOTE _ -> FSharpTokenKind.RightQuote
16611663
| RQUOTE_DOT _ -> FSharpTokenKind.RightQuoteDot
1664+
| RQUOTE_BAR_RBRACE _ -> FSharpTokenKind.RQuoteBarRightBrace
16621665
| PERCENT_OP _ -> FSharpTokenKind.PercentOperator
16631666
| BINDER _ -> FSharpTokenKind.Binder
16641667
| LESS _ -> FSharpTokenKind.Less

src/Compiler/Service/ServiceLexing.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ type public FSharpTokenKind =
458458
| RightArrow
459459
| GreaterBarRightBracket
460460
| GreaterBarRightBrace
461+
| RQuoteBarRightBrace
461462
| LeftParenthesisStarRightParenthesis
462463
| Open
463464
| Or

src/Compiler/SyntaxTree/LexFilter.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ type LexFilterImpl (
12101210
delayToken (pool.UseShiftedLocation(tokenTup, BAR_RBRACK, 1, 0))
12111211
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -2))
12121212
pool.Return tokenTup
1213+
| RQUOTE_BAR_RBRACE x ->
1214+
lexbuf.CheckLanguageFeatureAndRecover LanguageFeature.BetterAnonymousRecordParsing lexbuf.LexemeRange
1215+
delayToken (pool.UseShiftedLocation(tokenTup, BAR_RBRACE, 1, 0))
1216+
delayToken (pool.UseShiftedLocation(tokenTup, RQUOTE(x), 0, -2))
1217+
pool.Return tokenTup
12131218
| GREATER_RBRACK ->
12141219
delayToken (pool.UseShiftedLocation(tokenTup, RBRACK, 1, 0))
12151220
delayToken (pool.UseShiftedLocation(tokenTup, GREATER res, 0, -1))
@@ -2631,6 +2636,13 @@ type LexFilterImpl (
26312636
noMerge()
26322637
true
26332638

2639+
| RQUOTE_BAR_RBRACE x ->
2640+
lexbuf.CheckLanguageFeatureAndRecover LanguageFeature.BetterAnonymousRecordParsing lexbuf.LexemeRange
2641+
delayToken (pool.UseShiftedLocation(tokenTup, BAR_RBRACE, 1, 0))
2642+
delayToken (pool.UseShiftedLocation(tokenTup, RQUOTE(x), 0, -2))
2643+
pool.Return tokenTup
2644+
true
2645+
26342646
| _ ->
26352647
false
26362648

src/Compiler/lex.fsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,10 @@ rule token (args: LexArgs) (skip: bool) = parse
839839

840840
| "@@>" { checkExprOp lexbuf; RQUOTE ("<@@ @@>", true) }
841841

842+
| "@>|}" { RQUOTE_BAR_RBRACE ("<@ @>", false) }
843+
844+
| "@@>|}" { RQUOTE_BAR_RBRACE ("<@@ @@>", true) }
845+
842846
| '#' { HASH }
843847

844848
| '&' { AMP }

src/Compiler/pars.fsy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
7878
%token <bool> LET YIELD YIELD_BANG AND_BANG
7979
%token <bool> LESS GREATER /* here the bool indicates if the tokens are part of a type application or type parameter declaration, e.g. C<int>, detected by the lex filter */
8080
%token <string> PERCENT_OP BINDER
81-
%token <string * bool> LQUOTE RQUOTE RQUOTE_DOT
81+
%token <string * bool> LQUOTE RQUOTE RQUOTE_DOT RQUOTE_BAR_RBRACE
8282
%token BAR_BAR UPCAST DOWNCAST NULL RESERVED MODULE NAMESPACE DELEGATE CONSTRAINT BASE
8383
%token AND AS ASSERT OASSERT ASR BEGIN DO DONE DOWNTO ELSE ELIF END DOT_DOT DOT_DOT_HAT
8484
%token EXCEPTION FALSE FOR FUN FUNCTION IF IN JOIN_IN FINALLY DO_BANG

src/Compiler/xlf/FSStrings.cs.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Compiler/xlf/FSStrings.de.xlf

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)