@@ -46,7 +46,7 @@ type Context =
46
46
| CtxtElse of Position
47
47
| CtxtDo of Position
48
48
| CtxtInterfaceHead of Position
49
- | CtxtTypeDefns of Position // 'type <here> =', not removed when we find the "="
49
+ | CtxtTypeDefns of Position * equalsEndPos : Position option // 'type <here> =', not removed when we find the "="
50
50
51
51
| CtxtNamespaceHead of Position * token
52
52
| CtxtModuleHead of Position * token * LexingModuleAttributes * isNested : bool
@@ -69,7 +69,7 @@ type Context =
69
69
member c.StartPos =
70
70
match c with
71
71
| CtxtNamespaceHead ( p, _) | CtxtModuleHead ( p, _, _, _) | CtxtException p | CtxtModuleBody ( p, _) | CtxtNamespaceBody p
72
- | CtxtLetDecl (_, p) | CtxtDo p | CtxtInterfaceHead p | CtxtTypeDefns p | CtxtParen (_, p) | CtxtMemberHead p | CtxtMemberBody p
72
+ | CtxtLetDecl (_, p) | CtxtDo p | CtxtInterfaceHead p | CtxtTypeDefns( p , _) | CtxtParen (_, p) | CtxtMemberHead p | CtxtMemberBody p
73
73
| CtxtWithAsLet p
74
74
| CtxtWithAsAugment p
75
75
| CtxtMatchClauses (_, p) | CtxtIf p | CtxtMatch p | CtxtFor p | CtxtWhile p | CtxtWhen p | CtxtFunction p | CtxtFun p | CtxtTry p | CtxtThen p | CtxtElse p | CtxtVanilla ( p, _)
@@ -742,7 +742,7 @@ type LexFilterImpl (
742
742
743
743
//let indexerNotationWithoutDot = lexbuf.SupportsFeature LanguageFeature.IndexerNotationWithoutDot
744
744
745
- let tryPushCtxt strict tokenTup ( newCtxt : Context ) =
745
+ let tryPushCtxt strict ignoreIndent tokenTup ( newCtxt : Context ) =
746
746
let rec undentationLimit strict stack =
747
747
match newCtxt, stack with
748
748
| _, [] -> PositionWithColumn( newCtxt.StartPos, - 1 )
@@ -960,8 +960,10 @@ type LexFilterImpl (
960
960
// These contexts can have their contents exactly aligning
961
961
| _, ( CtxtParen _ | CtxtFor _ | CtxtWhen _ | CtxtWhile _ | CtxtTypeDefns _ | CtxtMatch _ | CtxtModuleBody (_, true ) | CtxtNamespaceBody _ | CtxtTry _ | CtxtMatchClauses _ | CtxtSeqBlock _ as limitCtxt :: _)
962
962
-> PositionWithColumn( limitCtxt.StartPos, limitCtxt.StartCol)
963
-
963
+
964
964
let isCorrectIndent =
965
+ if ignoreIndent then true else
966
+
965
967
match newCtxt with
966
968
// Don't bother to check pushes of Vanilla blocks since we've
967
969
// always already pushed a SeqBlock at this position.
@@ -992,7 +994,7 @@ type LexFilterImpl (
992
994
true
993
995
994
996
let pushCtxt tokenTup newCtxt =
995
- tryPushCtxt false tokenTup newCtxt |> ignore
997
+ tryPushCtxt false false tokenTup newCtxt |> ignore
996
998
997
999
let rec popCtxt () =
998
1000
match offsideStack with
@@ -1008,6 +1010,10 @@ type LexFilterImpl (
1008
1010
1009
1011
let replaceCtxt p ctxt = popCtxt(); pushCtxt p ctxt
1010
1012
1013
+ let replaceCtxtIgnoreIndent p ctxt =
1014
+ popCtxt()
1015
+ tryPushCtxt false true p ctxt |> ignore
1016
+
1011
1017
//----------------------------------------------------------------------------
1012
1018
// Peek ahead at a token, either from the old lexer or from our delayedStack
1013
1019
//--------------------------------------------------------------------------
@@ -1679,7 +1685,7 @@ type LexFilterImpl (
1679
1685
// | B
1680
1686
//
1681
1687
// <TOKEN> <-- close the type context sequence block here *)
1682
- | _, CtxtTypeDefns posType :: _ when offsidePos.Column = posType.Column && not ( isTypeSeqBlockElementContinuator token) -> - 1
1688
+ | _, CtxtTypeDefns( posType, _) :: _ when offsidePos.Column = posType.Column && not ( isTypeSeqBlockElementContinuator token) -> - 1
1683
1689
1684
1690
// This ensures we close a namespace body when we see the next namespace definition
1685
1691
//
@@ -1822,7 +1828,7 @@ type LexFilterImpl (
1822
1828
popCtxt()
1823
1829
reprocess()
1824
1830
1825
- | _, CtxtTypeDefns offsidePos :: _
1831
+ | _, CtxtTypeDefns( offsidePos, _) :: _
1826
1832
when isSemiSemi || ( if relaxWhitespace2OffsideRule || isTypeContinuator token then tokenStartCol + 1 else tokenStartCol) <= offsidePos.Column ->
1827
1833
if debug then dprintf " token at column %d is offside from TYPE(offsidePos=%a )! pop and reprocess\n " tokenStartCol outputPos offsidePos
1828
1834
popCtxt()
@@ -2076,8 +2082,9 @@ type LexFilterImpl (
2076
2082
pushCtxtSeqBlock tokenTup AddBlockEnd
2077
2083
returnToken tokenLexbufState token
2078
2084
2079
- | EQUALS, CtxtTypeDefns _ :: _ ->
2085
+ | EQUALS, CtxtTypeDefns( p , _) :: _ ->
2080
2086
if debug then dprintf " CtxType: EQUALS, pushing CtxtSeqBlock\n "
2087
+ replaceCtxtIgnoreIndent tokenTup ( CtxtTypeDefns( p, Some tokenTup.EndPos))
2081
2088
pushCtxtSeqBlock tokenTup AddBlockEnd
2082
2089
returnToken tokenLexbufState token
2083
2090
@@ -2202,7 +2209,7 @@ type LexFilterImpl (
2202
2209
let leadingBar = match ( peekNextToken()) with BAR -> true | _ -> false
2203
2210
2204
2211
if debug then dprintf " WITH, pushing CtxtMatchClauses, lookaheadTokenStartPos = %a , tokenStartPos = %a \n " outputPos lookaheadTokenStartPos outputPos tokenStartPos
2205
- tryPushCtxt strictIndentation lookaheadTokenTup ( CtxtMatchClauses( leadingBar, lookaheadTokenStartPos)) |> ignore
2212
+ tryPushCtxt strictIndentation false lookaheadTokenTup ( CtxtMatchClauses( leadingBar, lookaheadTokenStartPos)) |> ignore
2206
2213
2207
2214
returnToken tokenLexbufState OWITH
2208
2215
@@ -2385,22 +2392,42 @@ type LexFilterImpl (
2385
2392
pushCtxt tokenTup ( CtxtFun tokenStartPos)
2386
2393
returnToken tokenLexbufState OFUN
2387
2394
2395
+ // type I = interface .... end
2396
+ | INTERFACE, CtxtSeqBlock _ :: CtxtTypeDefns( typePos, Some equalsEndPos) :: _ when
2397
+ ( tokenTup.LastTokenPos = equalsEndPos &&
2398
+
2399
+ // Allow deindenting interface representation when started after `=`:
2400
+ //
2401
+ // type I = interface
2402
+ // abstract P: int
2403
+ // end
2404
+
2405
+ let allowDeindent = tokenTup.EndPos.Line = equalsEndPos.Line
2406
+
2407
+ let lookaheadTokenTup = peekNextTokenTup ()
2408
+ let lookaheadTokenStartPos = startPosOfTokenTup lookaheadTokenTup
2409
+ match lookaheadTokenTup.Token with
2410
+ | END ->
2411
+ lookaheadTokenStartPos.Column >= typePos.Column
2412
+
2413
+ | DEFAULT | OVERRIDE | INTERFACE | NEW | TYPE | STATIC | MEMBER | ABSTRACT | INHERIT | LBRACK_ LESS ->
2414
+ let limitPos = if allowDeindent then typePos else tokenTup.StartPos
2415
+ lookaheadTokenStartPos.Column >= limitPos.Column + 1
2416
+
2417
+ | _ ->
2418
+ false ) ->
2419
+
2420
+ if debug then dprintf " INTERFACE, pushing CtxtParen, tokenStartPos = %a \n " outputPos tokenStartPos
2421
+ pushCtxt tokenTup ( CtxtParen ( token, tokenStartPos))
2422
+ pushCtxtSeqBlock tokenTup AddBlockEnd
2423
+ returnToken tokenLexbufState token
2424
+
2425
+ // type C with interface .... with
2426
+ // type C = interface .... with
2388
2427
| INTERFACE, _ ->
2389
- let lookaheadTokenTup = peekNextTokenTup()
2390
- let lookaheadTokenStartPos = startPosOfTokenTup lookaheadTokenTup
2391
- match lookaheadTokenTup.Token with
2392
- // type I = interface .... end
2393
- | DEFAULT | OVERRIDE | INTERFACE | NEW | TYPE | STATIC | END | MEMBER | ABSTRACT | INHERIT | LBRACK_ LESS ->
2394
- if debug then dprintf " INTERFACE, pushing CtxtParen, tokenStartPos = %a , lookaheadTokenStartPos = %a \n " outputPos tokenStartPos outputPos lookaheadTokenStartPos
2395
- pushCtxt tokenTup ( CtxtParen ( token, tokenStartPos))
2396
- pushCtxtSeqBlock tokenTup AddBlockEnd
2397
- returnToken tokenLexbufState token
2398
- // type C with interface .... with
2399
- // type C = interface .... with
2400
- | _ ->
2401
- if debug then dprintf " INTERFACE, pushing CtxtInterfaceHead, tokenStartPos = %a , lookaheadTokenStartPos = %a \n " outputPos tokenStartPos outputPos lookaheadTokenStartPos
2402
- pushCtxt tokenTup ( CtxtInterfaceHead tokenStartPos)
2403
- returnToken tokenLexbufState OINTERFACE_ MEMBER
2428
+ if debug then dprintf " INTERFACE, pushing CtxtInterfaceHead, tokenStartPos = %a , lookaheadTokenStartPos \n " outputPos tokenStartPos
2429
+ pushCtxt tokenTup ( CtxtInterfaceHead tokenStartPos)
2430
+ returnToken tokenLexbufState OINTERFACE_ MEMBER
2404
2431
2405
2432
| CLASS, _ ->
2406
2433
if debug then dprintf " CLASS, pushing CtxtParen(%a )\n " outputPos tokenStartPos
@@ -2411,7 +2438,7 @@ type LexFilterImpl (
2411
2438
| TYPE, _ ->
2412
2439
insertComingSoonTokens( " TYPE" , TYPE_ COMING_ SOON, TYPE_ IS_ HERE)
2413
2440
if debug then dprintf " TYPE, pushing CtxtTypeDefns(%a )\n " outputPos tokenStartPos
2414
- pushCtxt tokenTup ( CtxtTypeDefns tokenStartPos)
2441
+ pushCtxt tokenTup ( CtxtTypeDefns( tokenStartPos, None ) )
2415
2442
pool.Return tokenTup
2416
2443
hwTokenFetch useBlockRule
2417
2444
@@ -2582,7 +2609,7 @@ type LexFilterImpl (
2582
2609
pushCtxtSeqBlockAt strictIndentation false fallbackToken ( peekNextTokenTup ()) addBlockEnd
2583
2610
2584
2611
and pushCtxtSeqBlockAt strict ( useFallback : bool ) ( fallbackToken : TokenTup ) ( tokenTup : TokenTup ) addBlockEnd =
2585
- let pushed = tryPushCtxt strict tokenTup ( CtxtSeqBlock( FirstInSeqBlock, startPosOfTokenTup tokenTup, addBlockEnd))
2612
+ let pushed = tryPushCtxt strict false tokenTup ( CtxtSeqBlock( FirstInSeqBlock, startPosOfTokenTup tokenTup, addBlockEnd))
2586
2613
if not pushed && useFallback then
2587
2614
// The upcoming token isn't sufficiently indented to start the new context.
2588
2615
// The parser expects proper contexts structure, so we push a new recovery context at the fallback token position.
0 commit comments