From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 130FD3854146 for ; Mon, 15 May 2023 09:42:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 130FD3854146 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f450815d0bso60080335e9.0 for ; Mon, 15 May 2023 02:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1684143747; x=1686735747; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=asjnDMtZJSuzpfWzDFVBTBL45UDky0AnI1to/D9jAk0=; b=C6oa9jFSU3kkP+GCFVh0yzdLkNjxEBhjsDT4IiP9hp3FoffuEjcZtMnsOcOXQE10lX Ouqk4+aaRX+X3Gt54R8dZJOUgXvjdI5oUqR8RaVzt4DnLL/g502LbP5KwRPw+aan6AUE Fp4bcTp4C6kjkrjSOR9Lkqf+gcFgdCZ1yMm6+rcwFF486bUvFuCmB2waIcrtrcu9x7/i rfFaf2AL8LLPyoUY4jM9fntpJte9jRWfSa0XSdhfd8UAfmMoeYiLWq2hdeYR9C3P7igw fcK85Ms+jsGYYM7fFI0bZbJnQfZgNChHpwvuZm1vwReu5d94yiWmP3AFwEso5/lYy1O1 7ikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684143747; x=1686735747; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=asjnDMtZJSuzpfWzDFVBTBL45UDky0AnI1to/D9jAk0=; b=eUFgsJw2a50qIRqk3EXyVzRsPkJGYv4bWiKYsGhhfSj5v8GUygye1wzoUcvQ7T9OVj PE/RQ+uwVLe+p46irSUNxSYRnPnGoyKUCs0b41lhbFcH7rnUtvL0ULFd57a3smfmBsAh eazi6pA9YXGab/oyifJHHh0rFSqYIP9CyjEdQQPupFL4qaI79atFgs0kEIDkEkzikuB3 67HSQl+NgfRtM+t/wkNf637lsqel7ZFwdoKbpNmFJOMgbjQ7gwelDDm3107gQXqgmcv9 c9dFfab3F6j3QNYwjMMxNa2URV2Qb8YXiEiO7mgYzppM0XGeMdvTWP12ykZ4QOWn6heI yFpg== X-Gm-Message-State: AC+VfDwYkMFm9/qyrJyR8nhk4K9i+QkHfm83uzhOsQpWuSD7w3myT8o0 c4063cd0JafVCL1uMA3mXdZosfIGKzggs3w6M2i2KQ== X-Google-Smtp-Source: ACHHUZ7GJmKwjlHFgBHaoDaUcWSvB526gjbIWT1SRu+bzrxIjBiu6cFvNOKHqn/hzo3fPTesm1Th0g== X-Received: by 2002:a1c:f207:0:b0:3f5:f83:4d7e with SMTP id s7-20020a1cf207000000b003f50f834d7emr379812wmc.27.1684143746842; Mon, 15 May 2023 02:42:26 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id y21-20020a05600c365500b003f42cc3262asm18121546wmq.34.2023.05.15.02.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:42:26 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Javier Miranda Subject: [COMMITTED] ada: INOX: prototype RFC on String Interpolation Date: Mon, 15 May 2023 11:42:23 +0200 Message-Id: <20230515094223.1407571-1-poulhies@adacore.com> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Javier Miranda gcc/ada/ * doc/gnat_rm/implementation_defined_pragmas.rst (Extensions_Allowed): Document string interpolation. * gnat_rm.texi: Regenerate. * gnat_ugn.texi: Regenerate. Tested on x86_64-pc-linux-gnu, committed on master. --- .../implementation_defined_pragmas.rst | 63 +++++++ gcc/ada/gnat_rm.texi | 160 +++++++++++++++++- gcc/ada/gnat_ugn.texi | 2 +- 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 ed42d087a25..725d5241845 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 212ed3df9d8..81b36b87288 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 e8512cb0471..134a42e3df9 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 -- 2.40.0