Skip to content

Commit

Permalink
null-coalesce operator
Browse files Browse the repository at this point in the history
  • Loading branch information
pchalamet committed Jun 1, 2024
1 parent 9d5a393 commit 051c7c8
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 494 deletions.
3 changes: 2 additions & 1 deletion src/Terrabuild.Configuration.Tests/TestFiles/WORKSPACE2
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ configuration release {
}
list: [ 1
2+3
"tutu" ]
"tutu"
nothing ?? 42 ]
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Terrabuild.Configuration.Tests/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ let parseWorkspace2() =
"titi", Expr.String "tagada" ])
"list", Expr.List [ Expr.Number 1
Expr.Function (Function.Plus, [ Expr.Number 2; Expr.Number 3 ])
Expr.String "tutu" ] ] }
Expr.String "tutu"
Expr.Function (Function.Coalesce, [ Expr.Nothing; Expr.Number 42 ]) ] ] }
let envDummy =
{ Variables = Map.empty }
let envSecret =
Expand Down
448 changes: 220 additions & 228 deletions src/Terrabuild.Configuration/Gen/ProjectLexer.fs

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions src/Terrabuild.Configuration/Gen/ProjectParser.fs

Large diffs are not rendered by default.

430 changes: 211 additions & 219 deletions src/Terrabuild.Configuration/Gen/WorkspaceLexer.fs

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions src/Terrabuild.Configuration/Gen/WorkspaceParser.fs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Terrabuild.Configuration/ProjectParser/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rule token = parse
| "upper" { UPPER }
| "lower" { LOWER }
| "version" { VERSION }
| "coalesce" { COALESCE }
| "??" { COALESCE }

| "project" { PROJECT }
| "target" { TARGET }
Expand Down
2 changes: 1 addition & 1 deletion src/Terrabuild.Configuration/ProjectParser/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Expr:
| LOWER LPAREN Expr RPAREN { Expr.Function (Function.Lower, [$3]) }
| VERSION LPAREN Expr RPAREN { Expr.Function (Function.Version, [$3]) }
| Expr DOT_LSQBRACKET ExprIndex RSQBRACKET { Expr.Function (Function.Item, [$1; $3]) }
| COALESCE LPAREN ExprListContent RPAREN { Expr.Function (Function.Coalesce, $3) }
| Expr COALESCE Expr { Expr.Function (Function.Coalesce, [$1; $3]) }

ExprIndex:
| Expr { $1 }
Expand Down
2 changes: 1 addition & 1 deletion src/Terrabuild.Configuration/WorkspaceParser/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rule token = parse
| "upper" { UPPER }
| "lower" { LOWER }
| "version" { VERSION }
| "coalesce" { COALESCE }
| "??" { COALESCE }

| "workspace" { WORKSPACE }
| "target" { TARGET }
Expand Down
2 changes: 1 addition & 1 deletion src/Terrabuild.Configuration/WorkspaceParser/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Expr:
| LOWER LPAREN Expr RPAREN { Expr.Function (Function.Lower, [$3]) }
| VERSION LPAREN Expr RPAREN { Expr.Function (Function.Version, [$3]) }
| Expr DOT_LSQBRACKET ExprIndex RSQBRACKET { Expr.Function (Function.Item, [$1; $3]) }
| COALESCE LPAREN ExprListContent RPAREN { Expr.Function (Function.Coalesce, $3) }
| Expr COALESCE Expr { Expr.Function (Function.Coalesce, [$1; $3]) }

ExprIndex:
| Expr { $1 }
Expand Down
2 changes: 1 addition & 1 deletion src/Terrabuild.Expressions.Tests/Eval.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let subNumber() =
[<Test>]
let coalesce() =
let expected = Value.Number 42
let varUsed, result = eval evaluationContext (Expr.Function (Function.Coalesce, [Expr.Nothing; Expr.Number 42; Expr.String "toto"]))
let varUsed, result = eval evaluationContext (Expr.Function (Function.Coalesce, [Expr.Nothing; Expr.Number 42]))
varUsed |> should be Empty
result |> should equal expected

Expand Down

0 comments on commit 051c7c8

Please sign in to comment.