From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21180 invoked by alias); 29 Dec 2017 08:38:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23017 Received: (qmail 19654 invoked by uid 1010); 29 Dec 2017 08:38:20 -0000 X-Qmail-Scanner-Diagnostics: from mail-qt0-f181.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.216.181):SA:0(-2.6/5.0):. Processed in 2.680828 secs); 29 Dec 2017 08:38:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=frh2QWnxl6099LsFsz/8qg7ZquFzjLj1VMUKOYrY6OI=; b=fDfTlY7ozPwq5Uh0Stus8XvsqNPDNAdsdaCFj1rtxkxv7iSZWo5DaKzQDuTA3+CCcK wgAHhTOIBosePQcMSIuFY1Xkp/mU16u2QfsouHivn/akf9uXCzEW5UqBy2eh/hEk6+a7 qzuSg7HiRl8gQjncDSAB75htD82qloBCqq99LJxLUVGSrr4EPVPSi+Ajd4y0b5qBZEzn jiuPTKm+/eMncRWE5ZiVKbwIrq+ea/hwgW3TS8qtOTOgHeyqHigaK4y53v3kIc6B0t8n A0rDWRIlqSMg7smKc3nU+KJKUxr+0i6NkSzt/jDPxDto2ZjHOi9axpkRiu3DTSQQff5z qgsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=frh2QWnxl6099LsFsz/8qg7ZquFzjLj1VMUKOYrY6OI=; b=SDrj1aRpn3t4t0fKj6Xv0oztPYbMAF3qZdE2wio3DuqvcvNmecnZ/W4Wp/JkigxR1z oGDChdsNdBwtjOs/XhQ87NlkVuPYaRs+DE0zup6lDUYdnP3qICSIOC4qVKJBspByBtqr HEJ2QW1dyEb/pc0/+VF8KjnVrgUtohUq9NIeEP/tjLqimc1GnKnv5mehg00+Ratq3vUy OEq2vXEZa0bA3tQP16nY0cqPmV9LMSt7BGyyZzQmfq2axGZO1wT0jrXBQM9b6hzIqs1Z HaD4Sk23MAsYIEkVii0/ruJnu20wtb8n/seeRJBj65pZ4QvuHus+4Ps+PLgH/TpBodCV E5Jw== X-Gm-Message-State: AKGB3mK5IIwfF9rLFNYr7YdYi6+5YBEaAFgndD25RNdFfuxFOx/r5F0Y 8bsOLZs8EdyszgLZDv/wsclgxQel/6eyqem4W5wcZ19o X-Google-Smtp-Source: ACJfBovavKVbRNLdrzFbdsQPHRjrG/ehy6CJvjoaI8tljsR+grpCEKfqSmFhH++FRThjbtI2BlMNDBXG/qdEU+eBK58= X-Received: by 10.200.52.137 with SMTP id w9mr46217890qtb.290.1514536694017; Fri, 29 Dec 2017 00:38:14 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Bart Schaefer Date: Fri, 29 Dec 2017 00:38:13 -0800 Message-ID: Subject: Re: Can zsh `else` reserved keyword command be aliased and the lexem itself be repurposed as `fi` keyword command? To: Zsh Users Content-Type: text/plain; charset="UTF-8" On Thu, Dec 28, 2017 at 7:07 AM, mathieu stumpf guntz wrote: > it might be expected that a command `keyword` equivalent of what `builtin` > and `command` are doing for their respective eponymous token category If you haven't already, go read https://askubuntu.com/a/590335 which was linked from https://stackoverflow.com/questions/47999451/can-zsh-buildtins-be-aliased Your hypothetical "keyword" would have to itself be a keyword (and thus not a command). > This problem was found in the following tricky scenario: being able to > replace `else` with `alie` and `fi` with `else`. [...] > alias alie="keyword else" > alias else='fi' What's the underlying reason for doing this? That is, aside from the overall desire to write in Esperanto (?), I get wanting "alie" to mean the same thing "else" means, but not why "else" should mean "fi". Even in your "alie echo 'mirinda mondo'" example it looks like "else" is meant to act as "fi;else" so that you can continue with more of the sentence. > This is not yet a working solution, but here is an idea: using the `-r` flag > of `enable` and `disable` builtin commands to change visibility of the > `else` keyword This is doomed to failure, because complex shell syntax is fully parsed before it is executed. Your "disable" or "enable" has to take place before the parsing step, because it won't be executed during the parse. Some extremely simple cases might appear to work at the command prompt, but as soon as you embed them in a larger structure like a function body they will fail. In fact the "fully parsed before executed" property is one of the important reasons for keywords being distinct from commands. Aliases "work" before the parse because they are merely text replacements and can be done before full token analysis is performed. What is needed is an alias that ends recursive replacement. Normally one does this by including quoting (e.g., a leading backslash) in the value of the alias, but that doesn't help in this case because it prevents the replacement from being considered a keyword as well. There may be a clever way to accomplish this -- recursion stops if replacement results in a previously replaced alias, for example, to avoid infinite loop -- but I haven't worked out an answer.