Skip to content

Commit 766e459

Browse files
Add doc comment examples to key ExprXxxNode types in SyntaxOak.fs
Add short inline doc comments (/// Example: ...) to the most commonly encountered expression node types, making it easier for new contributors to understand which F# syntax constructs each node represents. Types documented: ExprLazyNode, ExprNewNode, ExprTupleNode, ExprArrayOrListNode, ExprRecordNode, ExprLambdaNode, ExprMatchLambdaNode, ExprMatchNode, ExprSameInfixAppsNode, ExprInfixAppNode, ExprChain, ExprAppLongIdentAndSingleParenArgNode, ExprAppSingleParenArgNode, ExprAppNode, ExprIfThenNode, ExprIfThenElseNode, ExprIfThenElifNode. Relates to #2991. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6a1d873 commit 766e459

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Fantomas.Core/SyntaxOak.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ type Pattern =
684684
| IsInst n -> n
685685
| QuoteExpr n -> n
686686

687+
/// Example: `lazy computeExpensiveValue`
687688
type ExprLazyNode(lazyWord: SingleTextNode, expr: Expr, range) =
688689
inherit NodeBase(range)
689690

@@ -728,6 +729,7 @@ type ExprTypedNode(expr: Expr, operator: string, t: Type, range) =
728729
member val Operator = operator
729730
member val Type = t
730731

732+
/// Example: `new StringBuilder(capacity)`
731733
type ExprNewNode(newKeyword: SingleTextNode, t: Type, arguments: Expr, range) =
732734
inherit NodeBase(range)
733735

@@ -737,6 +739,7 @@ type ExprNewNode(newKeyword: SingleTextNode, t: Type, arguments: Expr, range) =
737739
member val Type = t
738740
member val Arguments = arguments
739741

742+
/// Example: `(a, b, c)` — items are interleaved with comma `SingleTextNode` separators
740743
type ExprTupleNode(items: Choice<Expr, SingleTextNode> list, range) =
741744
inherit NodeBase(range)
742745

@@ -757,6 +760,7 @@ type ExprStructTupleNode(structNode: SingleTextNode, tuple: ExprTupleNode, closi
757760
member val Tuple = tuple
758761
member val ClosingParen = closingParen
759762

763+
/// Example: `[a; b; c]` for a list, `[|a; b; c|]` for an array — determined by the opening/closing tokens
760764
type ExprArrayOrListNode(openingToken: SingleTextNode, elements: Expr list, closingToken: SingleTextNode, range) =
761765
inherit NodeBase(range)
762766

@@ -848,6 +852,7 @@ type ExprRecordBaseNode(openingBrace: SingleTextNode, fields: RecordFieldNode li
848852
/// <summary>
849853
/// Represents a record instance, parsed from both `SynExpr.Record` and `SynExpr.AnonRecd`.
850854
/// </summary>
855+
/// Example: `{ Field1 = value1; Field2 = value2 }` or with copy-and-update syntax `{ existing with Field1 = newValue }`
851856
type ExprRecordNode
852857
(
853858
openingBrace: SingleTextNode,
@@ -1075,6 +1080,7 @@ type ExprParenLambdaNode(openingParen: SingleTextNode, lambda: ExprLambdaNode, c
10751080
member val Lambda = lambda
10761081
member val ClosingParen = closingParen
10771082

1083+
/// Example: `fun x y -> x + y`
10781084
type ExprLambdaNode(funNode: SingleTextNode, parameters: Pattern list, arrow: SingleTextNode, expr: Expr, range) =
10791085
inherit NodeBase(range)
10801086

@@ -1107,13 +1113,15 @@ type MatchClauseNode
11071113
member val Arrow = arrow
11081114
member val BodyExpr = bodyExpr
11091115

1116+
/// Example: `function | Some x -> x | None -> defaultValue`
11101117
type ExprMatchLambdaNode(functionNode: SingleTextNode, clauses: MatchClauseNode list, range) =
11111118
inherit NodeBase(range)
11121119

11131120
override val Children: Node array = [| yield functionNode; yield! nodes clauses |]
11141121
member val Function = functionNode
11151122
member val Clauses = clauses
11161123

1124+
/// Example: `match x with | Some v -> v | None -> 0`
11171125
type ExprMatchNode
11181126
(matchNode: SingleTextNode, matchExpr: Expr, withNode: SingleTextNode, clauses: MatchClauseNode list, range) =
11191127
inherit NodeBase(range)
@@ -1170,6 +1178,7 @@ type ExprPrefixAppNode(operator: SingleTextNode, expr: Expr, range) =
11701178

11711179
type InfixApp = interface end
11721180

1181+
/// Example: `a + b + c` — a sequence of the *same* operator applied repeatedly (avoids redundant nesting)
11731182
type ExprSameInfixAppsNode(leadingExpr: Expr, subsequentExpressions: (SingleTextNode * Expr) list, range) =
11741183
inherit NodeBase(range)
11751184
interface InfixApp
@@ -1183,6 +1192,7 @@ type ExprSameInfixAppsNode(leadingExpr: Expr, subsequentExpressions: (SingleText
11831192
member val LeadingExpr = leadingExpr
11841193
member val SubsequentExpressions = subsequentExpressions
11851194

1195+
/// Example: `a + b` — a single binary infix application with two different operands or operators
11861196
type ExprInfixAppNode(lhs: Expr, operator: SingleTextNode, rhs: Expr, range) =
11871197
inherit NodeBase(range)
11881198
interface InfixApp
@@ -1232,18 +1242,21 @@ type ChainLink =
12321242
| AppUnit n -> n
12331243
| IndexExpr e -> Expr.Node e
12341244

1245+
/// Example: `person.Address.City.ToUpper()` — a chain of dot-separated member accesses and calls
12351246
type ExprChain(links: ChainLink list, range) =
12361247
inherit NodeBase(range)
12371248
override val Children: Node array = List.map ChainLink.Node links |> List.toArray
12381249
member val Links = links
12391250

1251+
/// Example: `List.map(f)` — a qualified name (dotted identifier) applied to a single parenthesised argument
12401252
type ExprAppLongIdentAndSingleParenArgNode(functionName: IdentListNode, argExpr: Expr, range) =
12411253
inherit NodeBase(range)
12421254

12431255
override val Children: Node array = [| yield functionName; yield Expr.Node argExpr |]
12441256
member val FunctionName = functionName
12451257
member val ArgExpr = argExpr
12461258

1259+
/// Example: `f(a)` — a general expression (not a simple dotted name) applied to a single parenthesised argument
12471260
type ExprAppSingleParenArgNode(functionExpr: Expr, argExpr: Expr, range) =
12481261
inherit NodeBase(range)
12491262
override val Children: Node array = [| yield Expr.Node functionExpr; yield Expr.Node argExpr |]
@@ -1291,6 +1304,7 @@ type ExprNestedIndexWithoutDotNode(identifierExpr: Expr, indexExpr: Expr, argume
12911304
member val Index = indexExpr
12921305
member val Argument = argumentExpr
12931306

1307+
/// Example: `List.map f xs` — a function applied to two or more space-separated arguments
12941308
type ExprAppNode(functionExpr: Expr, arguments: Expr list, range) =
12951309
inherit NodeBase(range)
12961310

@@ -1441,6 +1455,7 @@ type IfKeywordNode =
14411455

14421456
member x.Range = x.Node.Range
14431457

1458+
/// Example: `if condition then result`
14441459
type ExprIfThenNode(ifNode: IfKeywordNode, ifExpr: Expr, thenNode: SingleTextNode, thenExpr: Expr, range) =
14451460
inherit NodeBase(range)
14461461

@@ -1455,6 +1470,7 @@ type ExprIfThenNode(ifNode: IfKeywordNode, ifExpr: Expr, thenNode: SingleTextNod
14551470
member val Then = thenNode
14561471
member val ThenExpr = thenExpr
14571472

1473+
/// Example: `if condition then trueResult else falseResult`
14581474
type ExprIfThenElseNode
14591475
(
14601476
ifNode: IfKeywordNode,
@@ -1482,6 +1498,7 @@ type ExprIfThenElseNode
14821498
member val Else = elseNode
14831499
member val ElseExpr = elseExpr
14841500

1501+
/// Example: `if a then x elif b then y else z` — contains one or more `if/elif` branches and an optional `else`
14851502
type ExprIfThenElifNode(branches: ExprIfThenNode list, elseBranch: (SingleTextNode * Expr) option, range) =
14861503
inherit NodeBase(range)
14871504

0 commit comments

Comments
 (0)