aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorJavier Miranda <miranda@adacore.com>2022-12-21 18:55:50 +0000
committerMarc Poulhiès <poulhies@adacore.com>2023-05-15 11:36:40 +0200
commitb7d26cb1fe3e8f8b44ae82894750d18d2094234e (patch)
tree228748a7b116275449e8c5705882d0f542e70841 /gcc/ada
parenta92397f05dea514bc7ccc355c70dfb97d2474cb0 (diff)
downloadgcc-b7d26cb1fe3e8f8b44ae82894750d18d2094234e.zip
gcc-b7d26cb1fe3e8f8b44ae82894750d18d2094234e.tar.gz
gcc-b7d26cb1fe3e8f8b44ae82894750d18d2094234e.tar.bz2
ada: INOX: prototype RFC on String Interpolation
gcc/ada/ * doc/gnat_rm/implementation_defined_pragmas.rst (Extensions_Allowed): Document string interpolation. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate.
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst63
-rw-r--r--gcc/ada/gnat_rm.texi160
-rw-r--r--gcc/ada/gnat_ugn.texi2
3 files changed, 223 insertions, 2 deletions
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index ed42d08..725d524 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -2425,6 +2425,69 @@ are identified below.
-- ...
end Stacks;
+* String Interpolation
+
+ The syntax for string literals is extended to support string interpolation.
+
+ Within an interpolated string literal, an arbitrary expression, when
+ enclosed in { ... }, is expanded at run time into the result of calling
+ 'Image on the result of evaluating the expression enclosed by the brace
+ characters, unless it is already a string or a single character.
+
+ Here is an example of this feature where the expressions "Name" and
+ "X + Y" will be evaluated and included in the string.
+
+ .. code-block:: ada
+
+ Put_Line (f"The name is {Name} and the sum is {X + Y}.");
+
+ In addition, an escape character (\'\\\') is provided for inserting certain
+ standard control characters (such as \'\\t\' for tabulation or \'\\n\' for
+ newline) or to escape characters with special significance to the
+ interpolated string syntax, namely \'"\', \'{\', \'}\',and \'\\\' itself.
+
+================= =================
+escaped_character meaning
+----------------- -----------------
+'\\a' ALERT
+'\\b' BACKSPACE
+'\\f' FORM FEED
+'\\n' LINE FEED
+'\\r' CARRIAGE RETURN
+'\\t' CHARACTER TABULATION
+'\\v' LINE TABULATION
+'\\0' NUL
+----------------- -----------------
+'\\\\' '\\'
+'\\"' '"'
+'\\{' '{'
+'\\}' '}'
+================= =================
+
+ Note that, unlike normal string literals, doubled characters have no
+ special significance. So to include a double-quote or a brace character
+ in an interpolated string, they must be preceded by a \'\\\'.
+ For example:
+
+ .. code-block:: ada
+
+ Put_Line
+ (f"X = {X} and Y = {Y} and X+Y = {X+Y};\n" &
+ f" a double quote is \" and" &
+ f" an open brace is \{");
+
+ Finally, a syntax is provided for creating multi-line string literals,
+ without having to explicitly use an escape sequence such as \'\\n\'. For
+ example:
+
+ .. code-block:: ada
+
+ Put_Line
+ (f"This is a multi-line"
+ "string literal"
+ "There is no ambiguity about how many"
+ "spaces are included in each line");
+
.. _Pragma-Extensions_Visible:
Pragma Extensions_Visible
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 212ed3d..81b36b8 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -19,7 +19,7 @@
@copying
@quotation
-GNAT Reference Manual , Dec 01, 2022
+GNAT Reference Manual , May 09, 2023
AdaCore
@@ -3880,8 +3880,166 @@ private
-- ...
end Stacks;
@end example
+
+@item
+String Interpolation
+
+The syntax for string literals is extended to support string interpolation.
+
+Within an interpolated string literal, an arbitrary expression, when
+enclosed in @{ … @}, is expanded at run time into the result of calling
+‘Image on the result of evaluating the expression enclosed by the brace
+characters, unless it is already a string or a single character.
+
+Here is an example of this feature where the expressions “Name” and
+“X + Y” will be evaluated and included in the string.
+
+@example
+Put_Line (f"The name is @{Name@} and the sum is @{X + Y@}.");
+@end example
+
+In addition, an escape character ('\') is provided for inserting certain
+standard control characters (such as '\t' for tabulation or '\n' for
+newline) or to escape characters with special significance to the
+interpolated string syntax, namely '”', '@{', '@}',and '\' itself.
@end itemize
+
+@multitable {xxxxxxxxxxxxxxxxxxx} {xxxxxxxxxxxxxxxxxxxxxxx}
+@item
+
+escaped_character
+
+@tab
+
+meaning
+
+@item
+
+‘\a’
+
+@tab
+
+ALERT
+
+@item
+
+‘\b’
+
+@tab
+
+BACKSPACE
+
+@item
+
+‘\f’
+
+@tab
+
+FORM FEED
+
+@item
+
+‘\n’
+
+@tab
+
+LINE FEED
+
+@item
+
+‘\r’
+
+@tab
+
+CARRIAGE RETURN
+
+@item
+
+‘\t’
+
+@tab
+
+CHARACTER TABULATION
+
+@item
+
+‘\v’
+
+@tab
+
+LINE TABULATION
+
+@item
+
+‘\0’
+
+@tab
+
+NUL
+
+@item
+
+‘\\’
+
+@tab
+
+‘\’
+
+@item
+
+‘\”’
+
+@tab
+
+‘”’
+
+@item
+
+‘\@{’
+
+@tab
+
+‘@{’
+
+@item
+
+‘\@}’
+
+@tab
+
+‘@}’
+
+@end multitable
+
+
+@quotation
+
+Note that, unlike normal string literals, doubled characters have no
+special significance. So to include a double-quote or a brace character
+in an interpolated string, they must be preceded by a '\'.
+For example:
+
+@example
+Put_Line
+ (f"X = @{X@} and Y = @{Y@} and X+Y = @{X+Y@};\n" &
+ f" a double quote is \" and" &
+ f" an open brace is \@{");
+@end example
+
+Finally, a syntax is provided for creating multi-line string literals,
+without having to explicitly use an escape sequence such as '\n'. For
+example:
+
+@example
+Put_Line
+ (f"This is a multi-line"
+ "string literal"
+ "There is no ambiguity about how many"
+ "spaces are included in each line");
+@end example
+@end quotation
+
@node Pragma Extensions_Visible,Pragma External,Pragma Extensions_Allowed,Implementation Defined Pragmas
@anchor{gnat_rm/implementation_defined_pragmas id12}@anchor{65}@anchor{gnat_rm/implementation_defined_pragmas pragma-extensions-visible}@anchor{66}
@section Pragma Extensions_Visible
diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi
index e8512cb..134a42e 100644
--- a/gcc/ada/gnat_ugn.texi
+++ b/gcc/ada/gnat_ugn.texi
@@ -29433,8 +29433,8 @@ to permit their use in free software.
@printindex ge
-@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{ }
@anchor{cf}@w{ }
+@anchor{gnat_ugn/gnat_utility_programs switches-related-to-project-files}@w{ }
@c %**end of body
@bye