From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jan Stranik via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58847: Patch to properly parse c++11 multiline strings Date: Fri, 28 Oct 2022 16:13:42 -0400 Message-ID: Reply-To: Jan Stranik Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_C590E5F4-6E11-4CA5-A85C-58E06F51AFB1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29946"; mail-complaints-to="usenet@ciao.gmane.io" To: 58847@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 28 22:14:33 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooVkO-0007YH-Ji for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 28 Oct 2022 22:14:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooVk3-0005YJ-9j; Fri, 28 Oct 2022 16:14:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooVjx-0005Y7-Ad for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 16:14:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ooVju-0003Xp-Qj for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 16:14:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ooVju-0005Vv-Eq for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 16:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jan Stranik Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 28 Oct 2022 20:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58847 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166698803521174 (code B ref -1); Fri, 28 Oct 2022 20:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Oct 2022 20:13:55 +0000 Original-Received: from localhost ([127.0.0.1]:34376 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ooVjn-0005VR-KB for submit@debbugs.gnu.org; Fri, 28 Oct 2022 16:13:55 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:46042) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ooVjh-0005VD-KX for submit@debbugs.gnu.org; Fri, 28 Oct 2022 16:13:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooVjh-0005Xh-Ec for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 16:13:49 -0400 Original-Received: from stranik.org ([95.216.183.163]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooVjf-0003UW-Rm for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 16:13:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=stranik.org ; s=2020nix; h=To:Subject:From; bh=j4hGOLRviWV/4zNtM1w6f8Qo7hfKNzNgKuKKMB5BZI0=; b=N7B7wpNBg0jBkARtthslTNaXLM /diFLPSeoy275r7r4H9s6cUQ7OOkxzKDpsLLc+XIEOyFm5EQ1qsV5Nq7MWMbd3Uy9X2GsqprCv20t 7+bizKKgok9UVK0IDsq2mST7M8FQngZcMAE1ScnDpdApR0K7YZ5J36GhXRekRM4/CN1A=; Original-Received: from ool-2f14040e.dyn.optonline.net ([47.20.4.14] helo=smtpclient.apple) by stranik.org with esmtpsa (TLS1.2) tls TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1ooVjc-000nNv-6Q for bug-gnu-emacs@gnu.org; Fri, 28 Oct 2022 20:13:44 +0000 X-Mailer: Apple Mail (2.3696.120.41.1.1) Received-SPF: pass client-ip=95.216.183.163; envelope-from=jan@stranik.org; helo=stranik.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246458 Archived-At: --Apple-Mail=_C590E5F4-6E11-4CA5-A85C-58E06F51AFB1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hello -=20 I=E2=80=99m happy user of emacs and ebrowse feature. Recently I noticed = that ebrowse does not work for multi-line strings in c++.=20 The r-string parsing is on also for c files, but it does not matter = since c does not have r strings.=20 --Apple-Mail=_C590E5F4-6E11-4CA5-A85C-58E06F51AFB1 Content-Disposition: attachment; filename=ebrowse_rstring.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="ebrowse_rstring.patch" Content-Transfer-Encoding: 7bit EBROWSE: parse c++11 rstrings C++11 allows definition of multi-line stirngs. This patch makes ebrowse propely parse these strings. Example of test multi-line string: repro.cxx: ---------- struct Foo { using STR = const char*; STR rstrprefix = R"prefix(is is a C++11 multi line string )prefix"; STR rstr = R"( multiline string without a prefix )"; STR rstr_test = R"prefix( )prefix not at end )prefixtoolong" )pref" to short string still continues )prefix"; const char* str = "a regular string"; void func() { } }; ---------- ~/project/test/lit_repro $ c++ -std=c++10 -c repro.cxx # repro.cxx compiles ~/project/test/lit_repro $ ebrowse repro.cxx # current ebrowse chokes on file and produces wrong symbols repro.cxx:3: newline in string constant repro.cxx:4: newline in string constant repro.cxx:7: newline in string constant repro.cxx:8: newline in string constant repro.cxx:11: newline in string constant repro.cxx:12: newline in string constant repro.cxx:14: newline in string constant repro.cxx:15: newline in string constant repro.cxx:16: newline in string constant ~/project/test/lit_repro $ cat BROWSE [ebrowse-hs "ebrowse 5.0" " -x" () ()][ebrowse-ts [ebrowse-cs "Foo" () 0"repro.cxx" "struct Foo {" 12"repro.cxx" ] ()([ebrowse-ms "R" () 0 () "multiline string without a prefix )\";" 175 0 () () 0] [ebrowse-ms "pref" () 0 () ")prefix\";" 291 0 () () 0] [ebrowse-ms "str" () 0 () " const char* str = \"a regular string\";" 334 0 () () 0] ) ([ebrowse-ms "func" () 0 () " void func()" 351 0 () " void func()" 351] ) ~/project/test/lit_repro $ ~/Downloads/emacs-master/lib-src/ebrowse repro.cxx # patch properly parses source and generates symbols ~/project/test/lit_repro $ cat BROWSE [ebrowse-hs "ebrowse 5.0" " -x" () ()][ebrowse-ts [ebrowse-cs "Foo" () 0"repro.cxx" "struct Foo {" 12"repro.cxx" ] ()([ebrowse-ms "rstr" () 0 () "multiline string without a prefix )\";" 175 0 () () 0] [ebrowse-ms "rstr_test" () 0 () ")prefix\";" 291 0 () () 0] [ebrowse-ms "rstrprefix" () 0 () ")prefix\";" 117 0 () () 0] [ebrowse-ms "str" () 0 () " const char* str = \"a regular string\";" 334 0 () () 0] ) ([ebrowse-ms "func" () 0 () " void func()" 351 0 () " void func()" 351] ) Index: emacs-master/lib-src/ebrowse.c =================================================================== --- emacs-master.orig/lib-src/ebrowse.c +++ emacs-master/lib-src/ebrowse.c @@ -1574,6 +1574,51 @@ yylex (void) end_string: return end_char == '\'' ? CCHAR : CSTRING; + case 'R': + if (GET (c) == '"') { + /* c++11 rstrings */ + + #define RSTRING_EOF_CHECK do {if (c=='\0') { yyerror("unterminated c++11 rstring", NULL); UNGET(); return CSTRING;}}while(0) + char *rstring_prefix_start = in; + + while (GET (c) != '(') { + RSTRING_EOF_CHECK; + if (c == '"') + { + yyerror ("malformed c++11 rstring", NULL); + return CSTRING; + } + } + char *rstring_prefix_end = in - 1; + while (TRUE) { + switch(GET (c)) { + default: + RSTRING_EOF_CHECK; + break; + case '\n': + INCREMENT_LINENO; + break; + case ')': + { + char *in_saved = in; + char *prefix = rstring_prefix_start; + while (prefix != rstring_prefix_end && GET (c) == *prefix) { + RSTRING_EOF_CHECK; + prefix++; + } + if (prefix == rstring_prefix_end) { + if (GET(c) == '"') + return CSTRING; + RSTRING_EOF_CHECK; + } + in = in_saved; + } + } + } + } + + UNGET (); + /* fall through to ident */ case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': @@ -1581,7 +1626,7 @@ yylex (void) case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': - case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': + case 'O': case 'P': case 'Q': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case '_': { /* Identifier and keywords. */ --Apple-Mail=_C590E5F4-6E11-4CA5-A85C-58E06F51AFB1 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_C590E5F4-6E11-4CA5-A85C-58E06F51AFB1--