From patchwork Mon May 15 09:42:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 94018 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6790519vqo; Mon, 15 May 2023 02:44:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4BIbZtfSMGY5ULFs9WV9JtSFYlnc4VH+mkE3wupdd3e0ZE56EDdyyYh2QMZoMvAzQ4dfdb X-Received: by 2002:a05:6402:18a:b0:50d:9e7c:264d with SMTP id r10-20020a056402018a00b0050d9e7c264dmr22851237edv.8.1684143847850; Mon, 15 May 2023 02:44:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684143847; cv=none; d=google.com; s=arc-20160816; b=ZwyAeacm9ECz1he4VUaOfRXebtNsyCCNwjoJEfwT4bpeT7SDl3r6n+FQmJoRtbAwAk Zyd9VUGhEK+c9qBUmTj4cayxiYJ2ZNaPUlmE3P6bohfVJWT45APPFye4MwUJsJh1LR2f +gTLRzRsT46+wL4NFExW0FJJCDotOCAYXVDrAPOLz4C1r+wtJg84gDeAyYOK2OUlJj/C yEe8slW0YBW64QFPZaRajEO9K26TGfJNTCuzSNfFIyQHA+84hOFzyMb4bssg1ZfRD80f En8WkLji+WnPrqPq5PYnOto7WpY3bdPZFVnFqbycTamsYwkURNy9yXz/PcOjtjQddtZw Qjbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=asjnDMtZJSuzpfWzDFVBTBL45UDky0AnI1to/D9jAk0=; b=a3nUuHY2kX0nXh6UKXrgmbpGmFs42RKzqQSlkac7VH/Gi7JhhwWC9oa6PC5z+nCL+e YAsIB+pDELevZO3z8paeGJa9wdj2Hp72XqOhYziROVCRg4TlgjCzJaWc+1T5z47+j21S W0r+3Z+1VoL+lhTd6UKUZcQtFHvs7M6A7MoALaVwJAAcr+4jDMydH4A6SADA4kYZatvk YSP3jtENGyA8mumeNG0igZw50xS3hlU7Dz11Pdrth6tcNAUzm3McSYmEs40AEWhpjZiE jOn7dDu8FTMqDaDWrobwjpXO+xSzx5JqvJo54Nz2MLCv/rnCoFbVizbo7t5s1BAe16si +dig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JXcG+QBk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c6-20020aa7c746000000b0050bc725883fsi10668945eds.572.2023.05.15.02.44.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 May 2023 02:44:07 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=JXcG+QBk; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B15893853821 for ; Mon, 15 May 2023 09:43:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B15893853821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684143795; bh=asjnDMtZJSuzpfWzDFVBTBL45UDky0AnI1to/D9jAk0=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=JXcG+QBkiJNZ95+7tQPoZOg1XQqNzFqmCdY3+WCSOMLVpTsaNc8eIikOjJatx9z8+ f5j8hoPqH0em/NK/PdWbxh8HQtOVTCHrH7kFj+ph0twhvL2vN/tGlFEFqUyW+0MJVs 5WgR/LQT3G0xSUsbRbXLxASl/6cprSEG8bJ2KUa0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f450815d0bso60080335e9.0 for ; Mon, 15 May 2023 02:42:28 -0700 (PDT) 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-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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765952819218825150?= X-GMAIL-MSGID: =?utf-8?q?1765952819218825150?= 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