Skip to content

Commit dc097e2

Browse files
committed
Sketch shonky lexing and parsing for and!
1 parent 5753505 commit dc097e2

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/fsharp/ast.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ and
486486
/// AndBang(isUse, bindings, body, wholeRange)
487487
///
488488
/// F# syntax: and! pat = expr in expr (Must follow on directly from a let! / and!)
489-
| AndBang of isUse:bool * bindings:SynBinding list * body:SynAndBangExpr * range:range
490-
| EndOfAndBangChain of SynExpr
489+
| AndBang of bindSeqPoint:SequencePointInfoForBinding * isUse:bool * isFromSource:bool * SynPat * SynExpr * SynAndBangExpr * range:range
490+
| NotAndBang of SynExpr
491491
and
492492
[<NoEquality; NoComparison;RequireQualifiedAccess>]
493493
SynExpr =

src/fsharp/lex.fsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ rule token args skip = parse
243243
| ident '!'
244244
{ let tok = Keywords.KeywordOrIdentifierToken args lexbuf (lexemeTrimRight lexbuf 1)
245245
match tok with
246-
| LET _ -> BINDER (lexemeTrimRight lexbuf 1)
246+
| LET _ | AND -> BINDER (lexemeTrimRight lexbuf 1)
247247
| _ -> fail args lexbuf (FSComp.SR.lexIdentEndInMarkReserved("!")) (Keywords.KeywordOrIdentifierToken args lexbuf (lexeme lexbuf)) }
248248
| ident ('#')
249249
{ fail args lexbuf (FSComp.SR.lexIdentEndInMarkReserved("#")) (Keywords.KeywordOrIdentifierToken args lexbuf (lexeme lexbuf)) }

src/fsharp/pars.fsy

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3297,20 +3297,26 @@ declExpr:
32973297
| BINDER headBindingPattern EQUALS typedSeqExprBlock IN opt_OBLOCKSEP typedSeqExprBlock %prec expr_let
32983298
{ let spBind = SequencePointAtBinding(rhs2 parseState 1 5)
32993299
let m = unionRanges (rhs parseState 1) $7.Range
3300-
SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4,$7,m) }
3300+
match $1 with
3301+
| "and" -> SynAndBangExpr.AndBang (spBind,false,true,$2,$4,$7,m)
3302+
| _ -> SynAndBangExpr.NotAndBang (SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4,$7,m)) }
33013303

33023304
| OBINDER headBindingPattern EQUALS typedSeqExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP typedSeqExprBlock %prec expr_let
3303-
{ $5 (if $1 = "use" then "use!" else "let!") (rhs parseState 1) // report unterminated error
3305+
{ $5 (match $1 with | "use" -> "use!" | "let" -> "let!" | "and" -> "and!") (rhs parseState 1) // report unterminated error
33043306
let spBind = SequencePointAtBinding(unionRanges (rhs parseState 1) $4.Range)
33053307
let m = unionRanges (rhs parseState 1) $7.Range
3306-
SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4,$7,m) }
3308+
match $1 with
3309+
| "and" -> SynAndBangExpr.AndBang (spBind,false,true,$2,$4,$7,m)
3310+
| _ -> SynAndBangExpr.NotAndBang (SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4,$7,m)) }
33073311

33083312
| OBINDER headBindingPattern EQUALS typedSeqExprBlock hardwhiteDefnBindingsTerminator opt_OBLOCKSEP error %prec expr_let
33093313
{ // error recovery that allows intellisense when writing incomplete computation expressions
33103314
let spBind = SequencePointAtBinding(unionRanges (rhs parseState 1) $4.Range)
33113315
let mAll = unionRanges (rhs parseState 1) (rhs parseState 7)
33123316
let m = $4.Range.EndRange // zero-width range
3313-
SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4, SynExpr.ImplicitZero m, mAll) }
3317+
match $1 with
3318+
| "and" -> SynAndBangExpr.AndBang (spBind,false,true,$2,$4, SynExpr.ImplicitZero m, mAll)
3319+
| _ -> SynAndBangExpr.NotAndBang (SynExpr.LetOrUseBang(spBind,($1 = "use"),true,$2,$4, SynExpr.ImplicitZero m, mAll)) }
33143320

33153321
| DO_BANG typedSeqExpr IN opt_OBLOCKSEP typedSeqExprBlock %prec expr_let
33163322
{ let spBind = NoSequencePointAtDoBinding

0 commit comments

Comments
 (0)