Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Terrabuild.Configuration.Tests/TestFiles/WORKSPACE2
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ configuration {
secret2: $list.2
secret3: !false + !true
secret4: format("1", 2, $toto, true, nothing)
secret5: tostring(42)
secret5: tostring(40 + 1 + 2)
secret6: true & false | true
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Terrabuild.Configuration.Tests/Workspace.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ let parseWorkspace2() =
Expr.Variable "toto"
Expr.Bool true
Expr.Nothing ])
"secret5", Expr.Function (Function.ToString, [Expr.Number 42])
"secret5", Expr.Function (Function.ToString, [Expr.Function (Function.Plus, [Expr.Function (Function.Plus, [Expr.Number 40; Expr.Number 1]); Expr.Number 2])])
"secret6", Expr.Function (Function.Or, [ Expr.Function (Function.And, [Expr.Bool true; Expr.Bool false])
Expr.Bool true ])
] }

let extDotnet =
Expand Down
636 changes: 325 additions & 311 deletions src/Terrabuild.Configuration/Gen/ProjectLexer.fs

Large diffs are not rendered by default.

590 changes: 314 additions & 276 deletions src/Terrabuild.Configuration/Gen/ProjectParser.fs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Terrabuild.Configuration/Gen/ProjectParser.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type token =
| QUESTION
| COLON
| BANG
| AND
| OR
| TRIM
| UPPER
| LOWER
Expand Down Expand Up @@ -78,6 +80,8 @@ type tokenId =
| TOKEN_QUESTION
| TOKEN_COLON
| TOKEN_BANG
| TOKEN_AND
| TOKEN_OR
| TOKEN_TRIM
| TOKEN_UPPER
| TOKEN_LOWER
Expand Down
584 changes: 299 additions & 285 deletions src/Terrabuild.Configuration/Gen/WorkspaceLexer.fs

Large diffs are not rendered by default.

546 changes: 292 additions & 254 deletions src/Terrabuild.Configuration/Gen/WorkspaceParser.fs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Terrabuild.Configuration/Gen/WorkspaceParser.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type token =
| QUESTION
| COLON
| BANG
| AND
| OR
| TRIM
| UPPER
| LOWER
Expand Down Expand Up @@ -72,6 +74,8 @@ type tokenId =
| TOKEN_QUESTION
| TOKEN_COLON
| TOKEN_BANG
| TOKEN_AND
| TOKEN_OR
| TOKEN_TRIM
| TOKEN_UPPER
| TOKEN_LOWER
Expand Down
2 changes: 2 additions & 0 deletions src/Terrabuild.Configuration/ProjectParser/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ rule token = parse
| "-" { MINUS }
| "+" { PLUS }
| "!" { BANG }
| "&" { AND }
| "|" { OR }

| "#" { singleLineComment lexbuf }
| "//" { singleLineComment lexbuf }
Expand Down
8 changes: 5 additions & 3 deletions src/Terrabuild.Configuration/ProjectParser/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let debugPrint s = ignore s
%token COMMA
%token MINUS PLUS
%token TRIM UPPER LOWER REPLACE COUNT VERSION FORMAT TOSTRING
%token DOUBLE_QUESTION QUESTION COLON BANG
%token DOUBLE_QUESTION QUESTION COLON BANG AND OR
%token EOF
%token PROJECT EXTENSION TARGET
%token DEPENDENCIES LINKS OUTPUTS IGNORES INCLUDES LABELS VARIABLES CONTAINER INIT SCRIPT DEPENDS_ON REBUILD DEFAULTS NAME
Expand All @@ -43,8 +43,8 @@ let debugPrint s = ignore s
%right QUESTION
%left DOUBLE_QUESTION
%left DOUBLE_EQUAL NOT_EQUAL
%left MINUS
%left PLUS
%left MINUS PLUS
%left OR AND
%left DOT DOT_QUESTION
%right BANG
%left COMMA
Expand Down Expand Up @@ -142,6 +142,8 @@ Expr:
| Expr NOT_EQUAL Expr { Expr.Function (Function.NotEqual, [$1; $3]) }
| Expr PLUS Expr { Expr.Function (Function.Plus, [$1; $3]) }
| Expr MINUS Expr { Expr.Function (Function.Minus, [$1; $3]) }
| Expr AND Expr { Expr.Function (Function.And, [$1; $3]) }
| Expr OR Expr { Expr.Function (Function.Or, [$1; $3]) }
| TRIM ExprTuple { Expr.Function (Function.Trim, $2) }
| UPPER ExprTuple { Expr.Function (Function.Upper, $2) }
| LOWER ExprTuple { Expr.Function (Function.Lower, $2) }
Expand Down
2 changes: 2 additions & 0 deletions src/Terrabuild.Configuration/WorkspaceParser/Lexer.fsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ rule token = parse
| "-" { MINUS }
| "+" { PLUS }
| "!" { BANG }
| "&" { AND }
| "|" { OR }

| "#" { singleLineComment lexbuf }
| "//" { singleLineComment lexbuf }
Expand Down
8 changes: 5 additions & 3 deletions src/Terrabuild.Configuration/WorkspaceParser/Parser.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let debugPrint s = ignore s
%token COMMA
%token MINUS PLUS
%token TRIM UPPER LOWER REPLACE COUNT VERSION FORMAT TOSTRING
%token DOUBLE_QUESTION QUESTION COLON BANG
%token DOUBLE_QUESTION QUESTION COLON BANG AND OR
%token EOF
%token WORKSPACE TARGET CONFIGURATION EXTENSION
%token PROJECT SPACE DEPENDS_ON REBUILD VARIABLES CONTAINER INIT SCRIPT DEFAULTS NAME
Expand All @@ -43,8 +43,8 @@ let debugPrint s = ignore s
%right QUESTION
%left DOUBLE_QUESTION
%left DOUBLE_EQUAL NOT_EQUAL
%left MINUS
%left PLUS
%left MINUS PLUS
%left OR AND
%left DOT DOT_QUESTION
%right BANG
%left COMMA
Expand Down Expand Up @@ -127,6 +127,8 @@ Expr:
| Expr NOT_EQUAL Expr { Expr.Function (Function.NotEqual, [$1; $3]) }
| Expr PLUS Expr { Expr.Function (Function.Plus, [$1; $3]) }
| Expr MINUS Expr { Expr.Function (Function.Minus, [$1; $3]) }
| Expr AND Expr { Expr.Function (Function.And, [$1; $3]) }
| Expr OR Expr { Expr.Function (Function.Or, [$1; $3]) }
| TRIM ExprTuple { Expr.Function (Function.Trim, $2) }
| UPPER ExprTuple { Expr.Function (Function.Upper, $2) }
| LOWER ExprTuple { Expr.Function (Function.Lower, $2) }
Expand Down
62 changes: 44 additions & 18 deletions src/Terrabuild.Expressions.Tests/Eval.fs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,6 @@ let addMap() =
varUsed |> should be Empty
result |> should equal expected

[<Test>]
let addMapNothing() =
let expected = Value.Map (Map [ "toto", Value.Number 42
"titi", Value.String "pouet" ])
let result, varUsed = eval evaluationContext (Expr.Function (Function.Plus, [ Expr.Map (Map [ "toto", Expr.Number 42
"titi", Expr.String "pouet" ])
Expr.Nothing ]))
varUsed |> should be Empty
result |> should equal expected

[<Test>]
let addList() =
let expected = Value.List ([ Value.String "toto"; Value.Number 42 ])
Expand All @@ -105,14 +95,6 @@ let addList() =
varUsed |> should be Empty
result |> should equal expected

[<Test>]
let addListNothing() =
let expected = Value.List ([ Value.String "toto" ])
let result, varUsed = eval evaluationContext (Expr.Function (Function.Plus, [ Expr.List [Expr.String "toto"]
Expr.Nothing ]))
varUsed |> should be Empty
result |> should equal expected

[<Test>]
let subNumber() =
let expected = Value.Number 3
Expand Down Expand Up @@ -321,3 +303,47 @@ let notAnything() =
let result, varUsed = eval evaluationContext (Expr.Function (Function.Not, [Expr.Number 42]))
varUsed |> should be Empty
result |> should equal (Value.Bool false)

[<Test>]
let andBool() =
let expected = Value.Bool false
let result, varUsed = eval evaluationContext (Expr.Function (Function.And, [Expr.Bool false; Expr.Bool false]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool false
let result, varUsed = eval evaluationContext (Expr.Function (Function.And, [Expr.Bool false; Expr.Bool true]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool false
let result, varUsed = eval evaluationContext (Expr.Function (Function.And, [Expr.Bool true; Expr.Bool false]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool true
let result, varUsed = eval evaluationContext (Expr.Function (Function.And, [Expr.Bool true; Expr.Bool true]))
varUsed |> should be Empty
result |> should equal expected

[<Test>]
let orBool() =
let expected = Value.Bool false
let result, varUsed = eval evaluationContext (Expr.Function (Function.Or, [Expr.Bool false; Expr.Bool false]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool true
let result, varUsed = eval evaluationContext (Expr.Function (Function.Or, [Expr.Bool false; Expr.Bool true]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool true
let result, varUsed = eval evaluationContext (Expr.Function (Function.Or, [Expr.Bool true; Expr.Bool false]))
varUsed |> should be Empty
result |> should equal expected

let expected = Value.Bool true
let result, varUsed = eval evaluationContext (Expr.Function (Function.Or, [Expr.Bool true; Expr.Bool true]))
varUsed |> should be Empty
result |> should equal expected
10 changes: 3 additions & 7 deletions src/Terrabuild.Expressions/Eval.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,26 @@ let rec eval (context: EvaluationContext) (expr: Expr) =
match f, values with
| Function.Plus, [Value.String left; Value.String right] -> Value.String (left + right)
| Function.Upper, [Value.String str] -> Value.String (str.ToUpperInvariant())
| Function.Upper, [Value.Nothing] -> Value.Nothing
| Function.Trim, [Value.String str] -> Value.String (str.Trim())
| Function.Lower, [Value.String str] -> Value.String (str.ToLowerInvariant())
| Function.Lower, [Value.Nothing] -> Value.Nothing
| Function.Replace, [Value.String str; Value.String value; Value.String newValue] -> Value.String (str.Replace(value, newValue))
| Function.Replace, [Value.Nothing; _; _] -> Value.Nothing

| Function.Plus, [Value.Number left; Value.Number right] -> Value.Number (left + right)
| Function.Minus, [Value.Number left; Value.Number right] -> Value.Number (left - right)

| Function.Plus, [Value.Map left; Value.Map right] -> Value.Map (left |> Map.addMap right)
| Function.Plus, [Value.Nothing; Value.Map right] -> Value.Map right
| Function.Plus, [Value.Map left; Value.Nothing] -> Value.Map left
| Function.Count, [Value.Map map] -> Value.Number map.Count

| Function.Plus, [Value.List left; Value.List right] -> Value.List (left @ right)
| Function.Plus, [Value.Nothing; Value.List right] -> Value.List right
| Function.Plus, [Value.List left; Value.Nothing] -> Value.List left
| Function.Count, [Value.List list] -> Value.Number list.Length

| Function.Not, [Value.Nothing] -> Value.Bool true
| Function.Not, [Value.Bool bool] -> Value.Bool (not bool)
| Function.Not, [_] -> Value.Bool false

| Function.And, [Value.Bool left; Value.Bool right] -> Value.Bool (left && right)
| Function.Or, [Value.Bool left; Value.Bool right] -> Value.Bool (left || right)

| Function.Version, [Value.String str] ->
let projectDir =
match context.ProjectDir with
Expand Down
2 changes: 2 additions & 0 deletions src/Terrabuild.Expressions/Expr.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Function =
| Equal
| NotEqual
| Not
| And
| Or

[<RequireQualifiedAccessAttribute>]
type Expr =
Expand Down
Loading