From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: fabrice nicol Newsgroups: gmane.emacs.bugs Subject: bug#47408: [PATCH] Etags support for Mercury -- fix explicit tags for existentially-quantified procedures Date: Mon, 14 Jun 2021 17:10:26 +0200 Message-ID: <46bb9128-8bf5-e24c-2172-1cbb4202ee1d@gmail.com> References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D5E446D22BE77C2D422CDB37" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38086"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 To: 47408@debbugs.gnu.org, Eli Zaretskii , Francesco =?UTF-8?Q?Potort=C3=AC?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 14 17:10:23 2021 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 1lsoEF-0009hI-BD for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 14 Jun 2021 17:10:19 +0200 Original-Received: from localhost ([::1]:34076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lsoEE-0008G9-Bn for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 14 Jun 2021 11:10:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46826) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lsoDy-0008Df-F5 for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 11:10:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:35894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lsoDy-0008SZ-5l for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 11:10:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lsoDx-0003SC-RP for bug-gnu-emacs@gnu.org; Mon, 14 Jun 2021 11:10:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: fabrice nicol Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 14 Jun 2021 15:10:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47408 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 47408-submit@debbugs.gnu.org id=B47408.162368336313220 (code B ref 47408); Mon, 14 Jun 2021 15:10:01 +0000 Original-Received: (at 47408) by debbugs.gnu.org; 14 Jun 2021 15:09:23 +0000 Original-Received: from localhost ([127.0.0.1]:47440 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lsoDK-0003R9-ND for submit@debbugs.gnu.org; Mon, 14 Jun 2021 11:09:23 -0400 Original-Received: from mail-wr1-f41.google.com ([209.85.221.41]:38737) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lsoDJ-0003Qw-2F for 47408@debbugs.gnu.org; Mon, 14 Jun 2021 11:09:21 -0400 Original-Received: by mail-wr1-f41.google.com with SMTP id c9so14924198wrt.5 for <47408@debbugs.gnu.org>; Mon, 14 Jun 2021 08:09:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=tNmMbT9ZcjLSZSPK9Cx/5EEA5GgACTn+GdcQlzTbumA=; b=iSlavpXZI5FuNuex+KRr0P9aEMZJ8+OuWNVbxPWf8xGDhGKYraH6w+ixOcRNnNZnhq 6aB27nAVOAoFRSF/wQN6YCN59nC3dgueYTGuAcrQtaOZfwAhLbIr+s2F9KIIsE9VSc4h zsipAyUguivsOAYgAKu8tZBTQf3vl5u4VKhSRtE0sByeqUlWXxamIA2FkVpXNjrvSdEq D5w3vlQ8rCi/Lvay0QFn3AV/nukM3fuX5W7wLB9AKGEBCn7yAZAFSRxZeKDfZFYDJ04N GHUY8y27OE09krTz93TvFqpfi1mZlcXjnf2djvxm8w9tttvAt0tzLpKfIpnjlNVJiKin QAyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=tNmMbT9ZcjLSZSPK9Cx/5EEA5GgACTn+GdcQlzTbumA=; b=I2jlsU7TYLlACpaQVhzqWDbsb8cRguqOZdudiAdBiCZhf82X+DDKqJvy7h9gq7069W J9VL7DjOYHIaL60CRfNTHBsPnrJOgiywnjMZL7yRi1Q8nhoXILCG39qAa7lwE5nmc2oZ ix8U5xBfrJ9rpUOIn/DNRg8Do7ZsSqZeIjlHZYKwm21KgQh8G4NoBHkh9zPeH/AyT6vl QPaWa8QLtgIHRseLNjOywQKiMkdPgJVDQM2f5KREaIqxR/Z7PuxM623FrjxCl2fc95gU ku8UcxQWfNK3oS5pAiRGXVSC/AANe3I85nR+7rYp+WVstlqhi/3GPmPb+o8a6OzDZHyf gc4A== X-Gm-Message-State: AOAM531Y5Y7wODqk5tHRfwNZDzn1FajOGsQQciwVTvto26loAIbTUMXN NPxor3KGQR3/EuKqsLtd6ok= X-Google-Smtp-Source: ABdhPJy1ql8FZU2TlkIQ3k1U8kw4D36JQvzwoiym2VEa/2cqAs6fPrl9Uy1IeDNlN4Z3eL+2PRS7Jg== X-Received: by 2002:a05:6000:1847:: with SMTP id c7mr19274798wri.368.1623683354804; Mon, 14 Jun 2021 08:09:14 -0700 (PDT) Original-Received: from ?IPv6:2a01:cb1d:88b9:5c00:7b73:7901:965e:8523? ([2a01:cb1d:88b9:5c00:7b73:7901:965e:8523]) by smtp.gmail.com with ESMTPSA id l9sm13310093wme.21.2021.06.14.08.09.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Jun 2021 08:09:13 -0700 (PDT) In-Reply-To: Content-Language: en-US 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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:208508 Archived-At: This is a multi-part message in MIME format. --------------D5E446D22BE77C2D422CDB37 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, I'm sending the announced patch, which enables existentially-quantified procedures for both etags and ctags in Mercury etags/ctags support. Taking advantage of this to revise my prior contribution, I fixed an incidental issue (single-word declarations, which are very rare, were not tagged). I hope this works, Fabrice --------------D5E446D22BE77C2D422CDB37 Content-Type: text/x-patch; charset=UTF-8; name="0001-Fix-explicit-tag-issue-with-Mercury-etags-ctags-supp.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-Fix-explicit-tag-issue-with-Mercury-etags-ctags-supp.pa"; filename*1="tch" >From 58e85042f31716a4ae607ae4f93ce75f8065b006 Mon Sep 17 00:00:00 2001 From: Fabrice Nicol Date: Mon, 14 Jun 2021 14:30:54 +0200 Subject: [PATCH] Fix explicit tag issue with Mercury etags/ctags support Redesign of prior fix, which did not handle type quantifiers. Fix omission of single-word declarations like ':- interface.' * lib-src/etags.c (mercury_pr): Pass the newly corrected NAME and NAMELEN arguments to 'make_tag'. --- lib-src/etags.c | 114 +++++++++++++++++++++++++++++++----------------- 1 file changed, 73 insertions(+), 41 deletions(-) diff --git a/lib-src/etags.c b/lib-src/etags.c index 9f20e44caf..b96a44ec7a 100644 --- a/lib-src/etags.c +++ b/lib-src/etags.c @@ -6081,10 +6081,10 @@ prolog_atom (char *s, size_t pos) pos++; if (s[pos] != '\'') break; - pos++; /* A double quote */ + pos++; /* A double quote */ } else if (s[pos] == '\0') - /* Multiline quoted atoms are ignored. */ + /* Multiline quoted atoms are ignored. */ return 0; else if (s[pos] == '\\') { @@ -6119,6 +6119,13 @@ prolog_atom (char *s, size_t pos) static bool is_mercury_type = false; static bool is_mercury_quantifier = false; static bool is_mercury_declaration = false; +typedef struct +{ + size_t pos; /* Position reached in parsing tag name. */ + size_t namelength; /* Length of tag name */ + size_t totlength; /* Total length of parsed tag: this field is currently + reserved for control and debugging. */ +} mercury_pos_t; /* * Objective-C and Mercury have identical file extension .m. @@ -6374,10 +6381,12 @@ mercury_skip_comment (linebuffer *plb, FILE *inf) "initialise", "finalise", "mutable", "module", "interface", "implementation", "import_module", "use_module", "include_module", "end_module", "some", "all"}; -static size_t +static mercury_pos_t mercury_decl (char *s, size_t pos) { - if (s == NULL) return 0; + mercury_pos_t null_pos = {0, 0, 0}; + + if (s == NULL) return null_pos; size_t origpos; origpos = pos; @@ -6398,7 +6407,8 @@ mercury_decl (char *s, size_t pos) if (is_mercury_quantifier) { if (strcmp (buf, "pred") != 0 && strcmp (buf, "func") != 0) /* Bad syntax. */ - return 0; + return null_pos; + is_mercury_quantifier = false; /* Reset to base value. */ found_decl_tag = true; } @@ -6418,7 +6428,7 @@ mercury_decl (char *s, size_t pos) is_mercury_quantifier = true; } - break; /* Found declaration tag of rank j. */ + break; /* Found declaration tag of rank j. */ } else /* 'solver type' has a blank in the middle, @@ -6461,11 +6471,13 @@ mercury_decl (char *s, size_t pos) if (found_decl_tag) pos = skip_spaces (s + pos) - s; /* Skip len blanks again. */ else - return 0; + return null_pos; } /* From now on it is the same as for Prolog except for module dots. */ + size_t start_of_name = pos; + if (c_islower (s[pos]) || s[pos] == '_' ) { /* The name is unquoted. @@ -6478,7 +6490,8 @@ mercury_decl (char *s, size_t pos) && (c_isalnum (s[pos + 1]) || s[pos + 1] == '_'))) ++pos; - return pos - origpos; + mercury_pos_t position = {pos, pos - start_of_name + 1, pos - origpos}; + return position; } else if (s[pos] == '\'') { @@ -6493,28 +6506,37 @@ mercury_decl (char *s, size_t pos) ++pos; /* A double quote. */ } else if (s[pos] == '\0') /* Multiline quoted atoms are ignored. */ - return 0; + return null_pos; else if (s[pos] == '\\') { if (s[pos+1] == '\0') - return 0; + return null_pos; pos += 2; } else ++pos; } - return pos - origpos; + + mercury_pos_t position = {pos, pos - start_of_name + 1, pos - origpos}; + return position; } else if (is_mercury_quantifier && s[pos] == '[') /* :- some [T] pred/func. */ { for (++pos; s + pos != NULL && s[pos] != ']'; ++pos) {} - if (s + pos == NULL) return 0; + if (s + pos == NULL) return null_pos; ++pos; pos = skip_spaces (s + pos) - s; - return mercury_decl (s, pos) + pos - origpos; + mercury_pos_t position = mercury_decl (s, pos); + position.totlength += pos - origpos; + return position; + } + else if (s[pos] == '.') /* as in ':- interface.' */ + { + mercury_pos_t position = {pos, pos - origpos + 1, pos - origpos}; + return position; } else - return 0; + return null_pos; } static ptrdiff_t @@ -6523,6 +6545,7 @@ mercury_pr (char *s, char *last, ptrdiff_t lastlen) size_t len0 = 0; is_mercury_type = false; is_mercury_quantifier = false; + bool stop_at_rule = false; if (is_mercury_declaration) { @@ -6530,38 +6553,47 @@ mercury_pr (char *s, char *last, ptrdiff_t lastlen) len0 = skip_spaces (s + 2) - s; } - size_t len = mercury_decl (s, len0); - if (len == 0) return 0; - len += len0; + mercury_pos_t position = mercury_decl (s, len0); + size_t pos = position.pos; + int offset = 0; /* may be < 0 */ + if (pos == 0) return 0; + + /* Skip white space for rules in definitions before :- + and possibly multiline type definitions */ - if (( (s[len] == '.' /* This is a statement dot, not a module dot. */ - || (s[len] == '(' && (len += 1)) - || (s[len] == ':' /* Stopping in case of a rule. */ - && s[len + 1] == '-' - && (len += 2))) - && (lastlen != len || memcmp (s, last, len) != 0) + while (c_isspace (s[pos])) { ++pos; ++offset; } + + if (( ((s[pos] == '.' && (pos += 1)) /* case 1 + This is a statement dot, + not a module dot. */ + || (s[pos] == '(' && (pos += 1)) /* case 2 */ + || ((s[pos] == ':') /* case 3 */ + && s[pos + 1] == '-' && (stop_at_rule = true))) + && (lastlen != pos || memcmp (s, last, pos) != 0) ) /* Types are often declared on several lines so keeping just the first line. */ - || is_mercury_type) + + || is_mercury_type) /* When types are implemented. */ { - char *name = skip_non_spaces (s + len0); - size_t namelen; - if (name >= s + len) - { - name = s; - namelen = len; - } - else - { - name = skip_spaces (name); - namelen = len - (name - s); - } - /* Remove trailing non-name characters. */ - while (namelen > 0 && notinname (name[namelen - 1])) - namelen--; - make_tag (name, namelen, true, s, len, lineno, linecharno); - return len; + char *name = xnew (pos + 1, char); + size_t namelength = position.namelength; + if (stop_at_rule && offset) --offset; + + /* Left-trim type definitions. */ + + while (pos > namelength + offset + && c_isspace (s[pos - namelength - offset])) + --offset; + + memcpy (name, s + pos - namelength - offset, namelength); + + /* There is no need to correct namelength or call notinname. */ + name[namelength - 1] = '\0'; + + make_tag (name, namelength, true, s, pos, lineno, linecharno); + free (name); + return pos; } return 0; -- 2.31.1 --------------D5E446D22BE77C2D422CDB37--