Skip to content

Commit

Permalink
improved $1 (et al) error message plus updated rosetta stone
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorg committed Oct 8, 2023
1 parent 249ecb3 commit 3eb4856
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
12 changes: 5 additions & 7 deletions docs/parser/null-coalescing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ The following extract was taken from [Wikipedia](https://en.wikipedia.org/wiki/N

> The null coalescing operator (called the Logical Defined-Or operator in Perl)
> is a binary operator that is part of the syntax for a basic conditional
> expression in several programming languages, including C#, PowerShell as of
> version 7.0.0, Perl as of version 5.10, Swift, and PHP 7.0.0. While its
> behavior differs between implementations, the null coalescing operator
> generally returns the result of its left-most operand if it exists and is not
> null, and otherwise returns the right-most operand. This behavior allows a
> default value to be defined for cases where a more specific value is not
> available.
> expression in several programming languages. While its behavior differs
> between implementations, the null coalescing operator generally returns the
> result of its left-most operand if it exists and is not null, and otherwise
> returns the right-most operand. This behavior allows a default value to be
> defined for cases where a more specific value is not available.
>
> In contrast to the ternary conditional if operator used as `x ? x : y`, but
> like the binary Elvis operator used as `x ?: y`, the null coalescing operator
Expand Down
2 changes: 1 addition & 1 deletion docs/user-guide/rosetta-stone.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ if you want to learn more about shell scripting in Murex.
| [Assign a local variable](../commands/set.md) | `local foo="bar"` | `$foo = "bar"` [[2]](#footnotes) [[6]](#footnotes)<br/><br/>`out "bar" \| set $foo` |
| [Assign a global variable](../commands/global.md) | `foo="bar"` | `$GLOBAL.foo = "bar"` [[6]](#footnotes)<br/><br/>`out "bar" \| global $foo` |
| [Assign an environmental variable](../commands/export.md) | `export foo="bar"` | `export foo = "bar"` [[1]](#footnotes) [[2]](#footnotes) [[3]](#footnotes)<br/><br/>`$ENV.foo = "bar"` [[6]](#footnotes)<br/><br/>`out "bar" \| export $foo` [[3]](#footnotes) |
| [Assign with a default value](../parser/null-coalescing.md) | `FOOBAR="${VARIABLE:-default}"` | `$foobar = $variable ?: "default"` <br/><br/> (the elvis operator can be used in any part of expressions and just for assignments)
| [Assign with a default value](../parser/null-coalescing.md) | `FOOBAR="${VARIABLE:-default}"` | `$foobar = $variable ?? "default"` |

### Arrays
(eg arrays, lists)
Expand Down
12 changes: 5 additions & 7 deletions gen/parser/null_coalescing_op_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,11 @@
> The null coalescing operator (called the Logical Defined-Or operator in Perl)
> is a binary operator that is part of the syntax for a basic conditional
> expression in several programming languages, including C#, PowerShell as of
> version 7.0.0, Perl as of version 5.10, Swift, and PHP 7.0.0. While its
> behavior differs between implementations, the null coalescing operator
> generally returns the result of its left-most operand if it exists and is not
> null, and otherwise returns the right-most operand. This behavior allows a
> default value to be defined for cases where a more specific value is not
> available.
> expression in several programming languages. While its behavior differs
> between implementations, the null coalescing operator generally returns the
> result of its left-most operand if it exists and is not null, and otherwise
> returns the right-most operand. This behavior allows a default value to be
> defined for cases where a more specific value is not available.
>
> In contrast to the ternary conditional if operator used as `x ? x : y`, but
> like the binary Elvis operator used as `x ?: y`, the null coalescing operator
Expand Down
2 changes: 1 addition & 1 deletion gen/user-guide/rosetta-stone.inc.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if you want to learn more about shell scripting in Murex.
| [Assign a local variable](../commands/set.md) | `local foo="bar"` | `$foo = "bar"` [[2]](#footnotes) [[6]](#footnotes)<br/><br/>`out "bar" \| set $foo` |
| [Assign a global variable](../commands/global.md) | `foo="bar"` | `$GLOBAL.foo = "bar"` [[6]](#footnotes)<br/><br/>`out "bar" \| global $foo` |
| [Assign an environmental variable](../commands/export.md) | `export foo="bar"` | `export foo = "bar"` [[1]](#footnotes) [[2]](#footnotes) [[3]](#footnotes)<br/><br/>`$ENV.foo = "bar"` [[6]](#footnotes)<br/><br/>`out "bar" \| export $foo` [[3]](#footnotes) |
| [Assign with a default value](../parser/null-coalescing.md) | `FOOBAR="${VARIABLE:-default}"` | `$foobar = $variable ?: "default"` <br/><br/> (the elvis operator can be used in any part of expressions and just for assignments)
| [Assign with a default value](../parser/null-coalescing.md) | `FOOBAR="${VARIABLE:-default}"` | `$foobar = $variable ?? "default"` |

### Arrays
(eg arrays, lists)
Expand Down
2 changes: 1 addition & 1 deletion lang/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func errVarCannotUpdateIndexOrElement(name string) error {
}

func errVarNoParam(i int, err error) error {
return fmt.Errorf("variable '%d' cannot be defined: %s", i, err.Error())
return fmt.Errorf("variable '%d' is not set because the scope returned the following error when querying parameter %d: %s", i, i, err.Error())
}

func errVarZeroLengthPath(name string) error {
Expand Down

0 comments on commit 3eb4856

Please sign in to comment.