-
Notifications
You must be signed in to change notification settings - Fork 834
Parser: Update OBLOCKSEP token passing #18921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
9f9c0ec
8347ba2
3e1a3c7
02d2984
9139f3e
489cf4f
74db5c8
fcc7b41
ae13b59
c9be8b7
fb776ab
8828dad
aa7bd57
04d0c5b
ffdaa6e
7d89c7b
37b3cf1
d138a23
1ff5bed
53809e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,21 +308,13 @@ type SeqExprOnly = SeqExprOnly of bool | |
|
|
||
| [<NoEquality; NoComparison; RequireQualifiedAccess>] | ||
| type BlockSeparator = | ||
| | Semicolon of range: range * position: pos option | ||
| | Comma of range: range * position: pos option | ||
| | Offside of range: range * position: pos option | ||
| | Semicolon of range: range | ||
| | Comma of range: range | ||
|
|
||
| member this.Range = | ||
| match this with | ||
| | Semicolon(range = m) | ||
| | Comma(range = m) | ||
| | Offside(range = m) -> m | ||
|
|
||
| member this.Position = | ||
| match this with | ||
| | Semicolon(position = p) | ||
| | Comma(position = p) | ||
| | Offside(position = p) -> p | ||
| | Comma(range = m) -> m | ||
|
|
||
| type RecordFieldName = SynLongIdent * bool | ||
|
|
||
|
|
@@ -549,7 +541,7 @@ type SynExpr = | |
|
|
||
| | AnonRecd of | ||
| isStruct: bool * | ||
| copyInfo: (SynExpr * BlockSeparator) option * | ||
| copyInfo: (SynExpr * BlockSeparator option) option * | ||
| recordFields: (SynLongIdent * range option * SynExpr) list * | ||
| range: range * | ||
| trivia: SynExprAnonRecdTrivia | ||
|
|
@@ -558,7 +550,7 @@ type SynExpr = | |
|
|
||
| | Record of | ||
| baseInfo: (SynType * SynExpr * range * BlockSeparator option * range) option * | ||
| copyInfo: (SynExpr * BlockSeparator) option * | ||
| copyInfo: (SynExpr * BlockSeparator option) option * | ||
|
Comment on lines
-561
to
+553
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This place still looks very wrong. We've stored the |
||
| recordFields: SynExprRecordField list * | ||
| range: range | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3668,14 +3668,15 @@ namePatPairs: | |
| { let (id: Ident), mEq, (pat: SynPat) = $1 | ||
| let m = unionRanges id.idRange pat.Range | ||
| let lid = SynLongIdent([id], [], [None]) | ||
| NamePatPairField(lid, mEq, m, pat, Some $2) :: $3 } | ||
| NamePatPairField(lid, mEq, m, pat, $2) :: $3 } | ||
|
|
||
| | namePatPair seps_block seps_block namePatPairs | ||
| { reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsExpectingPattern ()) | ||
| { let mSep = match $3 with | Some sep -> sep.Range | None -> rhs parseState 3 | ||
| reportParseErrorAt mSep (FSComp.SR.parsExpectingPattern ()) | ||
| let (id: Ident), mEq, (pat: SynPat) = $1 | ||
| let m = unionRanges id.idRange pat.Range | ||
| let lid = SynLongIdent([id], [], [None]) | ||
| NamePatPairField(lid, mEq, m, pat, Some $2) :: $4 } | ||
| NamePatPairField(lid, mEq, m, pat, $2) :: $4 } | ||
|
|
||
| namePatPair: | ||
| | ident EQUALS parenPattern | ||
|
|
@@ -4016,13 +4017,13 @@ recordPatternElementsAux: | |
| | recordPatternElement seps_block recordPatternElementsAux | ||
| { let (lid: SynLongIdent), mEq, (pat: SynPat) = $1 | ||
| let m = unionRanges lid.Range pat.Range | ||
| NamePatPairField(lid, mEq, m, pat, Some $2) :: $3 } | ||
| NamePatPairField(lid, mEq, m, pat, $2) :: $3 } | ||
|
|
||
| | recordPatternElement seps_block seps_block recordPatternElementsAux | ||
| { reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsExpectingPattern ()) | ||
| let (lid: SynLongIdent), mEq, (pat: SynPat) = $1 | ||
| let m = unionRanges lid.Range pat.Range | ||
| NamePatPairField(lid, mEq, m, pat, Some $2) :: $4 } | ||
| NamePatPairField(lid, mEq, m, pat, $2) :: $4 } | ||
|
|
||
| recordPatternElement: | ||
| | path EQUALS parenPattern | ||
|
|
@@ -5709,7 +5710,7 @@ recdExprCore: | |
| | appExpr | ||
| { let mExpr = rhs parseState 1 | ||
| reportParseErrorAt mExpr (FSComp.SR.parsFieldBinding ()) | ||
| Some($1, BlockSeparator.Offside(mExpr.EndRange, None)), [] } | ||
| (Some($1, None), []) } | ||
|
|
||
| /* | ||
| handles cases when identifier can start from the underscore | ||
|
|
@@ -5743,36 +5744,40 @@ recdExprCore: | |
| | appExpr WITH recdBinding recdExprBindings opt_seps_block | ||
| { let l = List.rev $4 | ||
| let l = rebindRanges $3 l $5 | ||
| (Some($1, BlockSeparator.Offside(rhs parseState 2, None)), l) } | ||
| (Some($1, $5), l) } | ||
|
||
|
|
||
| | appExpr OWITH opt_seps_block OEND | ||
| { (Some($1, BlockSeparator.Offside(rhs parseState 2, None)), []) } | ||
| { (Some($1, $3), []) } | ||
|
|
||
| | appExpr OWITH recdBinding recdExprBindings opt_seps_block OEND | ||
| { let l = List.rev $4 | ||
| let l = rebindRanges $3 l $5 | ||
| (Some($1, BlockSeparator.Offside(rhs parseState 2, None)), l) } | ||
| (Some($1, $5), l) } | ||
|
|
||
| opt_seps_block: | ||
| | seps_block | ||
| { Some $1 } | ||
| { $1 } | ||
|
|
||
| | /* EMPTY */ | ||
| { None } | ||
|
|
||
| seps_block: | ||
| | OBLOCKSEP | ||
| { BlockSeparator.Offside((rhs parseState 1), None) } | ||
| { | ||
| // OBLOCKSEP is purely syntactic: do not produce a BlockSeparator value | ||
| // Treat it as absence of an explicit separator | ||
| None | ||
| } | ||
|
|
||
| | SEMICOLON | ||
| { let m = (rhs parseState 1) | ||
| BlockSeparator.Semicolon(m, Some m.End) } | ||
| Some (BlockSeparator.Semicolon(m)) } | ||
|
|
||
| | SEMICOLON OBLOCKSEP | ||
| { BlockSeparator.Semicolon((rhs2 parseState 1 2), Some (rhs parseState 1).End) } | ||
| { Some (BlockSeparator.Semicolon((rhs2 parseState 1 2))) } | ||
edgarfgp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| | OBLOCKSEP SEMICOLON | ||
| { BlockSeparator.Semicolon((rhs2 parseState 1 2), Some (rhs parseState 2).End) } | ||
| { Some (BlockSeparator.Semicolon((rhs2 parseState 1 2))) } | ||
edgarfgp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| /* identifier can start from the underscore */ | ||
|
|
@@ -5787,7 +5792,7 @@ pathOrUnderscore : | |
|
|
||
| recdExprBindings: | ||
| | recdExprBindings seps_block recdBinding | ||
| { ($3, Some $2) :: $1 } | ||
| { ($3, $2) :: $1 } | ||
|
|
||
| | /* EMPTY */ | ||
| { [] } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does
4magic constant come from? If we assume that a separator is;or,then it can't be 4 characters long.If this is a
withkeyword range, it should not be calculated from the id, it's job of the parser to preserve it correctly, like it was before.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was how it was originally. See https://github.com/dotnet/fsharp/pull/18899/files#diff-1e790bba80026c421a964cb1d8be0297aff37a0a3dbe7cbf954b54f6e3544e40L93-L100. But I think in this case we do not have a separator we can use
range0?