From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "andy22286@gmail.com" Newsgroups: gmane.emacs.devel Subject: Re: Emacs-devel Digest, Vol 148, Issue 12 Date: Tue, 7 Jun 2016 10:27:55 -0400 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1140f522d7dc050534b0ff67 X-Trace: ger.gmane.org 1465310409 18932 80.91.229.3 (7 Jun 2016 14:40:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Jun 2016 14:40:09 +0000 (UTC) To: emacs-devel@gnu.org, monnier@iro.umontreal.ca Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 07 16:40:09 2016 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 1bAIAq-0006VO-FY for ged-emacs-devel@m.gmane.org; Tue, 07 Jun 2016 16:40:08 +0200 Original-Received: from localhost ([::1]:50274 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAIAp-00064t-DI for ged-emacs-devel@m.gmane.org; Tue, 07 Jun 2016 10:40:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAHzN-0004TD-5s for emacs-devel@gnu.org; Tue, 07 Jun 2016 10:28:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bAHzL-0006z4-Mz for emacs-devel@gnu.org; Tue, 07 Jun 2016 10:28:17 -0400 Original-Received: from mail-oi0-x22b.google.com ([2607:f8b0:4003:c06::22b]:34215) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bAHzL-0006yz-G7 for emacs-devel@gnu.org; Tue, 07 Jun 2016 10:28:15 -0400 Original-Received: by mail-oi0-x22b.google.com with SMTP id e72so279102223oib.1 for ; Tue, 07 Jun 2016 07:28:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=aX09Vudk8ElDeRzRWlLxUSjV75rjxTQdrMJleBzNxW4=; b=ZzbkYiVvsgcDAJY3UwgGQH9QMZPdVxAO0tNZP2qKFPJne7ih93xdNrdDE7VlWa2nPe RkrGNNsaXINVMS/0dl9mlwkibgcALD00qwM/+pzFh21DNmn5Z82C9WIAYiwY2rMUpFFb 9jLsyee0BUyR1LYi8lVqU0/ZfEjBFf13rYqdiaffj7+I4aqFMR4JyrPqOmUevccCLRi5 +cTSNPx+QmvCbWiG+g7oF9/8QWcipIDiFrTBgTkUoueuGA4+ZS6r4BsYbtEIntB6fHiR 9yY4+ZmGcfPCLr43T8euGIAly8O8n0M/pwGRnsBYutu2jWpKM4adY8x3pPViJ79TWllX c3EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=aX09Vudk8ElDeRzRWlLxUSjV75rjxTQdrMJleBzNxW4=; b=UIi/uVFCbaZRJoHLgRiUUqA9UP8vWAerRC4mU1Un+iDadMQ3Z27y+C+4061fj3Wq+c fFVxsFcn/8KcrTadeEAud+1bg59OmVm7TQu6cChV+30AKbPOIgwCHcU/XxUeVvKdi2kS 8da3Mgh2cXuFvjS3CUWedh5D4Od46zkvFX3o5kO/zEthVuz4FSyPFBfYWBAapbhQ/IJ+ rFmyMw6ZQdPorrahQPn5LbJHgsEJm5kyz+VbUhHO1Xbub4rPqZ5b2yiVZ/MHWRBh98k2 GnOR5e+BKo4gMxWMHjHxPLPFnEVm5VNMB85hsNFQDmVCb4rCHCG4E4E3azenRYb8TVy3 37Yw== X-Gm-Message-State: ALyK8tK8nwN2v7Xty45aCmK/BVXwTqlnQFOa6Ivw6EMoFpUxwSNADNuHUGPpt51xFDmAgP+earzZKgx6Kt1cFQ== X-Received: by 10.157.27.212 with SMTP id v20mr11258450otv.82.1465309694776; Tue, 07 Jun 2016 07:28:14 -0700 (PDT) Original-Received: by 10.202.239.130 with HTTP; Tue, 7 Jun 2016 07:27:55 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::22b X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.devel:204223 Archived-At: --001a1140f522d7dc050534b0ff67 Content-Type: text/plain; charset=UTF-8 Somewhat related: here is an example I am having trouble with: sml-smie.el: (require 'smie) (defconst sml-smie-grammar (smie-prec2->grammar (smie-bnf->prec2 '((exp (var) ("local" exp "in" exp "end")) (var)) ))) (defun sml-smie-rules (kind token) (pcase (cons kind token) (`(:elem . basic) 4) (`(:elem . args) 2) )) (define-derived-mode my-sml-mode sml-mode "My SML" (smie-setup sml-smie-grammar #'sml-smie-rules)) indented test.sml: local local a in a end in a end I set the basic and args indentation to different values to show the problem I am running in to. I am not sure how this is being interpreted. The desired interpretation would be something like (local (local a in a end) in a end) though I am not sure if I am thinking about this properly. I am not sure when SMIE interprets entries as function arguments. In the indentation of test.sml, it appears that the second occurrence of "local" and the first occurrence of "a" are interpreted as arguments to the first occurrence of "local". Also, in general: Does the equivalent S-expression representing the parse tree have terminals in order, or are they moved to the front - i.e. does 1 + 2 for grammar (number "+" number) become (1 + 2) or (+ 1 2)? Is there any special behavior that occurs when generating the parse tree (either actually generating it or acting on an implicit parse tree)? What does smie-rule-parent-p use to determine the parent of a token? Is it the first token above the S-expression the current token is contained in, e.g. in ("a" "b" ("c" "d" "e") "f"), the parent of "d" is "b"? Thank you for all of the help! Andy On Mon, Jun 6, 2016 at 9:25 PM, wrote: > > Date: Mon, 06 Jun 2016 20:54:48 -0400 > From: Stefan Monnier > To: emacs-devel@gnu.org > Subject: Re: Debugging SMIE by printing an S-expression > Message-ID: > Content-Type: text/plain > > > I am having some trouble understanding the indentation I'm getting for a > > simple SMIE grammar and set of indentation rules. It seems like it would > > be useful to be able to print out an S-expression of what is being > parsed - > > the buffer, whatever has been reduced, really, anything at all just to > give > > me some insight as to what I want to match against in the indentation > rules > > - but really, to make sure what I think the grammar should produce is > being > > produced. Is there an easy way to do this? > > Not really, no. I don't think it would necessarily require changes to > the existing code, but it would require a second implementation of > parsing which additionally builds an s-exp of what it parsed. > > Instead, the usual way I use to find out how things are parsed is with > C-M-f and C-M-b, which is somewhat crude but works fairly well in my > experience once you learn to figure out how to interpret its behavior. > > > Stefan > > > > > > --001a1140f522d7dc050534b0ff67 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Somewhat related: here is an example I am having trouble w= ith:

sml-smie.el:

(require= 'smie)

(defconst sml-smie-grammar
= =C2=A0 (smie-prec2->grammar
=C2=A0 =C2=A0(smie-bnf->prec2
=C2=A0 =C2=A0 '((exp
=C2=A0 =C2=A0 =C2=A0 =C2=A0(var= )
=C2=A0 =C2=A0 =C2=A0 =C2=A0("local" exp "in"= ; exp "end"))
=C2=A0 =C2=A0 =C2=A0 (var))
=C2= =A0 =C2=A0)))

(defun sml-smie-rules (kind token)
=C2=A0 (pcase (cons kind token)
=C2=A0 =C2=A0 (`(:elem .= basic) 4)
=C2=A0 =C2=A0 (`(:elem . args) 2)
=C2=A0 =C2= =A0 ))

(define-derived-mode my-sml-mode sml-mode &= quot;My SML"
=C2=A0 (smie-setup
=C2=A0 =C2=A0sml-s= mie-grammar
=C2=A0 =C2=A0#'sml-smie-rules))

indented test.sml:

local=
=C2=A0 local
=C2=A0 a
in
=C2=A0 =C2=A0 a
end
in
=C2=A0 =C2=A0 a
end

I set the basic and args indentation to different values to show the pro= blem I am running in to.=C2=A0 I am not sure how this is being interpreted.= =C2=A0 The desired interpretation would be something like

(local
=C2=A0 (local
=C2=A0 =C2= =A0a
=C2=A0 =C2=A0in
=C2=A0 =C2=A0a
=C2=A0 =C2=A0end)<= /div>
=C2=A0in
= =C2=A0a
=C2=A0end)

though I am not sure if I am t= hinking about this properly.=C2=A0 I am not sure when SMIE interprets entri= es as function arguments.=C2=A0 In the indentation of test.sml, it appears = that the second occurrence of "local" and the first occurrence of= "a" are interpreted as arguments to the first occurrence of &quo= t;local".

Also, in general:

Does the equivalent S-expression representing the pars= e tree have terminals in order, or are they moved to the front - i.e. does = 1 + 2 for grammar (number "+" number) become (1 + 2) or (+ 1 2)?<= /div>

Is the= re any special behavior that occurs when generating the parse tree (either = actually generating it or acting on an implicit parse tree)?

What does smie-rule-= parent-p use to determine the parent of a token?=C2=A0 Is it the first toke= n above the S-expression the current token is contained in, e.g. in ("= a" "b" ("c" "d" "e") "f&q= uot;), the parent of "d" is "b"?

Thank you for all of the hel= p!

And= y

On Mon, Ju= n 6, 2016 at 9:25 PM, <emacs-devel-request@gnu.org> wrote:
Date: Mon, 06 Jun 2016 20:54:48 -0400
From: Stefan Monnier <monnie= r@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Debugging SMIE by printing an S-expression
Message-ID: <jwv37ophlhi.fsf-monnier+gmane.emacs.devel@gnu.org>
Content-Type: text/plain

> I am having some trouble understanding the indentation I'm getting= for a
> simple SMIE grammar and set of indentation rules.=C2=A0 It seems like = it would
> be useful to be able to print out an S-expression of what is being par= sed -
> the buffer, whatever has been reduced, really, anything at all just to= give
> me some insight as to what I want to match against in the indentation = rules
> - but really, to make sure what I think the grammar should produce is = being
> produced.=C2=A0 Is there an easy way to do this?

Not really, no.=C2=A0 I don't think it would necessarily require change= s to
the existing code, but it would require a second implementation of
parsing which additionally builds an s-exp of what it parsed.

Instead, the usual way I use to find out how things are parsed is with
C-M-f and C-M-b, which is somewhat crude but works fairly well in my
experience once you learn to figure out how to interpret its behavior.


=C2=A0 =C2=A0 =C2=A0 =C2=A0 Stefan






--001a1140f522d7dc050534b0ff67--