summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurin-Luis Lehning <65224843+e820@users.noreply.github.com>2021-03-07 23:25:39 +0100
committerXavier Claessens <xclaesse@gmail.com>2021-03-10 08:55:22 -0500
commitf7dd11133349cb459bf6a829b33443ab8e3694d4 (patch)
tree5cf60f6bab067f0f98b1315c577bfc1b1fe240cc
parent71e9909ffd9dac31504d115251ee5ab8f84420c3 (diff)
downloadmeson-f7dd11133349cb459bf6a829b33443ab8e3694d4.tar.gz
Some documentation language adjustments & improved error messages
-rw-r--r--docs/markdown/Syntax.md10
-rw-r--r--docs/markdown/snippets/fstrings.md2
-rw-r--r--mesonbuild/interpreterbase.py3
-rw-r--r--test cases/failing/113 invalid fstring/test.json2
4 files changed, 13 insertions, 4 deletions
diff --git a/docs/markdown/Syntax.md b/docs/markdown/Syntax.md
index 50287b2df..9ed32275e 100644
--- a/docs/markdown/Syntax.md
+++ b/docs/markdown/Syntax.md
@@ -198,7 +198,15 @@ s = f'int: @n@, string: @m@'
```
Currently only identity-expressions are supported inside of format
-strings.
+strings, meaning you cannot use arbitrary Meson expressions inside of them.
+
+```meson
+n = 10
+m = 5
+
+# The following is not a valid format string
+s = f'result: @n + m@'
+```
### String methods
diff --git a/docs/markdown/snippets/fstrings.md b/docs/markdown/snippets/fstrings.md
index df7dc2c09..45a238cb8 100644
--- a/docs/markdown/snippets/fstrings.md
+++ b/docs/markdown/snippets/fstrings.md
@@ -1,7 +1,7 @@
## Introducing format strings to the Meson language
In addition to the conventional `'A string @0@ to be formatted @1@'.format(n, m)`
-method of formatting strings in the Meson DSL, there's now the additional
+method of formatting strings in the Meson language, there's now the additional
`f'A string @n@ to be formatted @m@'` notation that provides a non-positional
and clearer alternative. Meson's format strings are currently restricted to
identity-expressions, meaning `f'format @'m' + 'e'@'` will not parse.
diff --git a/mesonbuild/interpreterbase.py b/mesonbuild/interpreterbase.py
index 01bfdaa4b..ec6ddc8ab 100644
--- a/mesonbuild/interpreterbase.py
+++ b/mesonbuild/interpreterbase.py
@@ -937,7 +937,8 @@ The result of this is undefined and will become a hard error in a future Meson r
try:
val = self.variables[var]
if not isinstance(val, (str, int, float, bool)):
- raise InvalidCode(f'Identifier "{var}" does not name a formattable variable.')
+ raise InvalidCode(f'Identifier "{var}" does not name a formattable variable ' +
+ '(has to be an integer, a string, a floating point number or a boolean).')
return str(val)
except KeyError:
diff --git a/test cases/failing/113 invalid fstring/test.json b/test cases/failing/113 invalid fstring/test.json
index 6834d80e0..17442fdca 100644
--- a/test cases/failing/113 invalid fstring/test.json
+++ b/test cases/failing/113 invalid fstring/test.json
@@ -1,7 +1,7 @@
{
"stdout": [
{
- "line": "test cases/failing/113 invalid fstring/meson.build:4:0: ERROR: Identifier \"dict\" does not name a formattable variable."
+ "line": "test cases/failing/113 invalid fstring/meson.build:4:0: ERROR: Identifier \"dict\" does not name a formattable variable (has to be an integer, a string, a floating point number or a boolean)."
}
]
}