Skip to content

Commit

Permalink
Remove tokenKinds from TokenParser.fs. (#2048)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf authored Jan 29, 2022
1 parent e4b06f6 commit 4a65cb4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/Fantomas/AstTransformer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1182,14 +1182,12 @@ module private Ast =
visit elementType (fun nodes ->
mkNode SynType_Array range :: nodes
|> finalContinuation)
| SynType.Fun (argType, returnType, range) ->
| SynType.Fun (argType, returnType, _range) ->
let continuations: ((TriviaNodeAssigner list -> TriviaNodeAssigner list) -> TriviaNodeAssigner list) list =
[ visit argType; visit returnType ]

let finalContinuation (nodes: TriviaNodeAssigner list list) : TriviaNodeAssigner list =
mkNode SynType_Fun range
:: (List.collect id nodes)
|> finalContinuation
List.collect id nodes |> finalContinuation

Continuation.sequence continuations finalContinuation
| SynType.Var (_, range) ->
Expand Down
13 changes: 9 additions & 4 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4244,7 +4244,9 @@ and genType astContext outerBracket t =
| THashConstraint t ->
let wrapInParentheses f =
match t with
| TApp (_, ts, isPostfix) when (isPostfix && List.isNotEmpty ts) -> sepOpenT +> f +> sepCloseT
| TApp (_, ts, isPostfix, range) when (isPostfix && List.isNotEmpty ts) ->
sepOpenT +> f +> sepCloseT
|> genTriviaFor SynType_App range
| _ -> f

!- "#" +> wrapInParentheses (loop t)
Expand All @@ -4264,9 +4266,11 @@ and genType astContext outerBracket t =
// Do similar for tuples after an arrow
| TFun (t, TTuple ts) -> loop t +> sepArrow +> loopTTupleList ts
| TFuns ts -> col sepArrow ts loop
| TApp (TLongIdent "nativeptr", [ t ], true) when astContext.IsCStylePattern -> loop t -- "*"
| TApp (TLongIdent "byref", [ t ], true) when astContext.IsCStylePattern -> loop t -- "&"
| TApp (t, ts, isPostfix) ->
| TApp (TLongIdent "nativeptr", [ t ], true, range) when astContext.IsCStylePattern ->
loop t -- "*" |> genTriviaFor SynType_App range
| TApp (TLongIdent "byref", [ t ], true, range) when astContext.IsCStylePattern ->
loop t -- "&" |> genTriviaFor SynType_App range
| TApp (t, ts, isPostfix, range) ->
let postForm =
match ts with
| [] -> loop t
Expand All @@ -4282,6 +4286,7 @@ and genType astContext outerBracket t =
postForm
(loop t
+> genPrefixTypes astContext ts current.Range)
|> genTriviaFor SynType_App range

| TLongIdentApp (t, s, ts) ->
loop t -- sprintf ".%s" s
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas/SourceParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ let rec (|TFuns|_|) =

let (|TApp|_|) =
function
| SynType.App (t, _, ts, _, _, isPostfix, _) -> Some(t, ts, isPostfix)
| SynType.App (t, _, ts, _, _, isPostfix, range) -> Some(t, ts, isPostfix, range)
| _ -> None

let (|TLongIdentApp|_|) =
Expand Down
6 changes: 1 addition & 5 deletions src/Fantomas/TokenParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,6 @@ let private tokenNames =
"AND_BANG"
"IN" ]

let private tokenKinds = [ FSharpTokenCharKind.Operator ]

let internal getFsToken tokenName =
match tokenName with
| "AMP" -> AMP
Expand Down Expand Up @@ -1177,9 +1175,7 @@ let internal getFsToken tokenName =

let getTriviaNodesFromTokens (mkRange: MkRange) (tokens: Token list) =
tokens
|> List.filter (fun t ->
List.exists (fun tn -> tn = t.TokenInfo.TokenName) tokenNames
|| List.exists (fun tk -> tk = t.TokenInfo.CharClass) tokenKinds)
|> List.filter (fun t -> List.exists (fun tn -> tn = t.TokenInfo.TokenName) tokenNames)
|> List.map (fun t ->
let range = getRangeBetween mkRange t t
TriviaNodeAssigner(TriviaNodeType.Token(getFsToken t.TokenInfo.TokenName, t), range))
3 changes: 2 additions & 1 deletion src/Fantomas/TriviaTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ type FsAstType =
| SynType_LongIdentApp
| SynType_Tuple
| SynType_Array
| SynType_Fun
// Not an ideal trivia node candidate as the ident inside the SynType.Fun are better suited
// | SynType_Fun
| SynType_Var
| SynType_Anon
| SynType_WithGlobalConstraints
Expand Down

0 comments on commit 4a65cb4

Please sign in to comment.