all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "andy22286@gmail.com" <andy22286@gmail.com>
To: emacs-devel@gnu.org, monnier@iro.umontreal.ca
Subject: Re: Emacs-devel Digest, Vol 148, Issue 12
Date: Tue, 7 Jun 2016 10:27:55 -0400	[thread overview]
Message-ID: <CAHtDYY8SB+_nVSEeo_6VWjzihUrQWiMGSOCT9+-fL5psw2C63g@mail.gmail.com> (raw)
In-Reply-To: <mailman.5130.1465262749.1213.emacs-devel@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 3034 bytes --]

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, <emacs-devel-request@gnu.org> wrote:
>
> Date: Mon, 06 Jun 2016 20:54:48 -0400
> From: Stefan Monnier <monnier@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.  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
>
>
>
>
>
>

[-- Attachment #2: Type: text/html, Size: 5369 bytes --]

       reply	other threads:[~2016-06-07 14:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.5130.1465262749.1213.emacs-devel@gnu.org>
2016-06-07 14:27 ` andy22286 [this message]
2016-06-07 18:59   ` Emacs-devel Digest, Vol 148, Issue 12 Stefan Monnier
2016-06-07 19:01     ` andy22286
2016-06-07 19:07       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHtDYY8SB+_nVSEeo_6VWjzihUrQWiMGSOCT9+-fL5psw2C63g@mail.gmail.com \
    --to=andy22286@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.