From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andreas Matthias Newsgroups: gmane.emacs.help Subject: Re: SMIE: if-elseif-else constructs Date: Tue, 6 Oct 2020 15:29:55 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12331"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 06 15:30:57 2020 Return-path: Envelope-to: geh-help-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 1kPn3R-00033a-4Z for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 06 Oct 2020 15:30:57 +0200 Original-Received: from localhost ([::1]:39686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPn3Q-0006Yj-6g for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 06 Oct 2020 09:30:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPn2h-0006BP-N1 for help-gnu-emacs@gnu.org; Tue, 06 Oct 2020 09:30:11 -0400 Original-Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]:33237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPn2g-0006VV-4O for help-gnu-emacs@gnu.org; Tue, 06 Oct 2020 09:30:11 -0400 Original-Received: by mail-ej1-x62c.google.com with SMTP id c22so16301068ejx.0 for ; Tue, 06 Oct 2020 06:30:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=yQn47XOuOu7+VBfY+LuoakoPdq58rCMIvef82tlEil8=; b=bAo1wMUECBZ7TWHPTyHecmj0+dy0YHrquXH5RHFwMdIHWl04tA9CJGsk+uM3GSYdb4 8LzMmsJLVwGyB/l9RWxRBRuAsfSdCC+8VIsmEb55OS8CJKQu/KlTqc1e+Z3zKOO/nOqm nMM9ZU72di9QqvnDpk3yQtcFpfY1PPGytLiH2C5CmonJgHdxOCVV7OMi368MI3enXPe5 Ov8L3e3H6gUTnEK4GtoGzNG6UdmsmQd5dKU6eB4TLcIA0dZTopoeBogFXQWpHSZJCvNz 6cXavxJcX+bbpMaIKQ2vEeylxxEL5ctx5iciEXjlUG43Op6/p8AVnGeWSD2VRISJn1mn Ypqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=yQn47XOuOu7+VBfY+LuoakoPdq58rCMIvef82tlEil8=; b=O2XEpzdP/QbvSrY5xflNduCMS4+RCgJAypagcr6oftSg2J4czAFuCr2iq6wwA0WLw1 0/wkj+JYXmECRiJzxQvqqqsgMgu9c5brC5GgHqYIN7TI74KTwjTRTCpjW4M1TrIBtMSO nhtINro/xRglEQgIHL+GWi9wKjYxCJC1O5ZtpW9fg9yInNG/0d4Se2QSBJIsiIyaNQcp 8Po8rnKe7OFQzZa6IOfvJHUItkGYRk1fpHMRtbLuPQiWbXMrIWS7hqMN1X4vHOzOCrTm lIlqW65MxTLMfLCTgJlm6OJkqvLZeZZl38+KS0iRCZ45Uwr1UR/nBVph7fV0TX+wwuTH byYA== X-Gm-Message-State: AOAM533Fnpvw8P03OHM+Up5ygzDfV521AAfi+LNa9XHvioA068ztobLG YvpaNFzzwQcHtAKX+Wfr1NjZQ4J/gfDSLXiCoYfGb2Bx6RUBZQ== X-Google-Smtp-Source: ABdhPJxv3ekNCyhMbUZ37B9Nte7Z+wc1V+SFnPVvmpkdY6n32gNm/c7yeEailY7zDDP+eRjil0y/IRMLpcdcgyaQfog= X-Received: by 2002:a17:906:5046:: with SMTP id e6mr5470224ejk.449.1601991006904; Tue, 06 Oct 2020 06:30:06 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::62c; envelope-from=andreas.matthias@gmail.com; helo=mail-ej1-x62c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124332 Archived-At: Stefan Monnier wrote: > > > (assoc "then" "end") > > This says that > > a then b then c then d > > is acceptable and that `a`, `b`, and `c` should be considered as > siblings (i.e. at the same depth level). Same for `end`. I see. Using assoc seemed to be the easy way but was not reasonable. I think I've found a better way. I revised the grammar and adjusted the indentation rules. The following seems to work. (require 'smie) (setq foobar-grammar (smie-prec2->grammar (smie-bnf->prec2 `((insts (insts ";" insts) (inst)) (inst (if)) (exp) (if ("if" if-body1 "end")) (if-body1 (exp "then" if-body2)) (if-body2 (insts "elseif" if-body1) (insts "else" insts) (insts))) '((assoc ";") )))) (defun foobar-rules (kind token) (message "rule: (%s . %s) at point %d" kind token (point)) (pcase (cons kind token) (`(:elem . basic) foobar-indent-basic) (`(:before . "then") 0) (`(:after . "then") foobar-indent-basic) (`(:before . "else") 0) (`(:after . "else") foobar-indent-basic) (`(:before . "elseif") 0) (`(:after . "elseif") foobar-indent-basic) )) (setq foobar-indent-basic 4) (define-derived-mode foobar-mode prog-mode "foobar" :syntax-table nil (modify-syntax-entry ?/ ". 124") (modify-syntax-entry ?* ". 23b") (modify-syntax-entry ?\n ">") (setq comment-start "//") (smie-setup foobar-grammar #'foobar-rules) (font-lock-add-keywords nil `((,(regexp-opt '("if" "then" "elseif" "else" "end")) . font-lock-keyword-face))) (font-lock-mode) (font-lock-ensure (point-min) (point-max)))