Re: Emacs-devel Digest, Vol 148, Issue 12

From:

Stefan Monnier

Subject:

Re: Emacs-devel Digest, Vol 148, Issue 12

Date:

Tue, 07 Jun 2016 14:59:05 -0400

User-agent:

Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> (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
Hmm... this seems to be clearly an interaction with sml-mode.
I just tried it with my local copy of sml-mode (straight from elpa.git)
and don't see the above indentation behavior. I also tried it after
replacing `sml-mode' with `prog-mode' as the parent, and that doesn't
show the problematic behavior either.
> 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)?
The tree is never created, so the question doesn't really have an answer.
The grammar is only used for navigation (e.g. to jump over the "+ 2 * z"
in "x + 2 * z + y" when moving forward).
> 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"?
I think it would be "c".
Stefan