From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Andrus Newsgroups: gmane.emacs.devel Subject: Re: SMIE help Date: Fri, 29 Nov 2013 22:05:41 -0700 Message-ID: <1E6750A3-2736-4A06-BAA1-8D9ABD021AB3@gmail.com> References: <4EF77C65-4918-4FBA-A952-C8A4B7F538D8@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1385787960 25253 80.91.229.3 (30 Nov 2013 05:06:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 30 Nov 2013 05:06:00 +0000 (UTC) Cc: "emacs-devel@gnu.org List" To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 30 06:06:05 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vmckk-0003YK-Ss for ged-emacs-devel@m.gmane.org; Sat, 30 Nov 2013 06:06:03 +0100 Original-Received: from localhost ([::1]:50886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vmckk-0001Fg-BR for ged-emacs-devel@m.gmane.org; Sat, 30 Nov 2013 00:06:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vmckc-0001FQ-HN for emacs-devel@gnu.org; Sat, 30 Nov 2013 00:05:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VmckX-0001FH-Ga for emacs-devel@gnu.org; Sat, 30 Nov 2013 00:05:54 -0500 Original-Received: from mail-ie0-x235.google.com ([2607:f8b0:4001:c03::235]:44048) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VmckX-0001F9-AV for emacs-devel@gnu.org; Sat, 30 Nov 2013 00:05:49 -0500 Original-Received: by mail-ie0-f181.google.com with SMTP id e14so17738311iej.12 for ; Fri, 29 Nov 2013 21:05:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=AmXhjZqsBLsHw6EL1Cx7S2Wt5XC9OvnaZBFDIysZ1Js=; b=xgeWAIwNHAlHZI3BcXqgHfhIy1CSQ/Uwi27XoQ1iXETjowEmmS8K9bOb/SwaOrH/X+ mG6+skYnOMk8p4uVSVDmifYBLBcroHTDpGH8t6RRBlTz3CjRNi/k6YyfiBGbynVLddc5 pSIlXw9GIrr+mT4eHln/5JwSyDY4TrGh3ZXe9cxpniiC47XRNuapkJpQdpCxn1zKYrev lWMykU35Sxb5BYXjMtiy8rwVFy9lIfEiVUPCH3HGArKt+jztoEUXPxaA5uRIFxiL3Yyt 0A1pVqfWk8afDfF4/TRwqpjPEGCuHwxg8dRQy2fA5AovlaQyunEkrf5sR8VrZPY35Vh8 cQEg== X-Received: by 10.43.145.197 with SMTP id jv5mr33771287icc.2.1385787948183; Fri, 29 Nov 2013 21:05:48 -0800 (PST) Original-Received: from [192.168.0.5] (174-29-174-200.hlrn.qwest.net. [174.29.174.200]) by mx.google.com with ESMTPSA id ri5sm54032561igc.1.2013.11.29.21.05.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 29 Nov 2013 21:05:47 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.1510) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c03::235 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:165920 Archived-At: On Nov 29, 2013, at 2:28 PM, Stefan Monnier = wrote: >> What I have works in many ways (though it could no doubt be >> simplified). My indentation is wildly off however in at least one >> case, and I have no idea how to fix it. The case of interest is the >> first line inside of a function (in the example the line starting = with >> local). Interestingly other lines in a function are fine. >=20 >> # example of well indented GAP code >> FittingHeight :=3D function (G) >> local fittingLength, F; >>=20 >> fittingLength :=3D 0; >=20 > Here's the problem: with the grammar you have, the above is parsed as > something like the following structure: >=20 > (:=3D FittingHeight > (function > ((G) (local (, fittingLength F))) > (:=3D fittingLength 0))) >=20 > So the "local ..." is aligned with "(G)". >=20 > You can see that it's a parsing problem by hitting C-M-b from right > after the first semi-colon of your example: it should jump to just > before "local" but instead it jumps to just before "(G)", as if "(G)" > was part of the first instruction. I see. That makes sense. > SMIE is not very good with "positional rules", as is the case here = where > there is no clear keyword between "(G)" and the function's body. > By "positional" I mean that "the *first* sexp-like thingy after > `function' is special". >=20 > You can solve this problem at 2 levels: > - the grammar level: you can't really fix it in gap-smie-grammar = itself > because SMIE's class of grammars is too limited to understand this, > but you can change the lexer such that it treats the close-paren = after > "(G" specially and returns another token. > - the indent-rules level: you give up parsing the code correctly and > instead patch things up in gap-smie-rules by adding a rule for > (:after . ")") which checks if this is the closing parent of > a "function (...)". >=20 > Doing it in indent-rules will lead to more efficient code, usually, = but > may also force you to add more and more special cases (tho in this > particular case, it might work OK). I presume solving it in the lexer will also cause the C-M-b to work as = expected in your example above. I use sexp-based motion all the time, = so I should probably take that route (at least eventually). For the = moment I think I'll try the indent-rules route since it does seem = easier. > In this particular case, you might like to try and patch things up in > gap-smie-rules, along the lines of: >=20 > (`(:after . ")") > (save-excursion > (up-list -1) > (when (equal "function" (car (smie-indent-backward-token))) > `(column . ,(+ gap-indent-step (smie-indent-virtual)))))) That works great! > After that, you'll also want to change the smie-rules for (:before > . "function"), probably, so as to treat "function (..)\n" as = "hanging": >=20 > (`(:before . "function") > (when (save-excursion > (forward-word 1) > (forward-sexp 1) > (smie-rule-hanging-p)) > (smie-rule-parent))) >=20 > so that the body of "function" is not indented relative to "function" > but relative to "FittingHeight :=3D". Thank you very much for SMIE and for answering my questions. -Ivan=