all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* SMIE & transpose-sexps
@ 2014-02-27 11:54 krisajenkins
  2014-02-28  2:30 ` Stefan Monnier
       [not found] ` <mailman.16218.1393554659.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: krisajenkins @ 2014-02-27 11:54 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I'm trying to wrap my head around SMIE, and I think I'm stumbling on something I thought would be pretty basic. I'm hoping someone can help...

I've written some simple rules like this:

(defconst my-grammar
  (smie-prec2->grammar
   (smie-precs->prec2
	'((assoc "=")
	  (assoc "AND")))))

And I'm trying it out with a simple string like this:

a = b AND c = d

My (perhaps naive) assumption was that, with that enabled I could call:

a |= b AND c = d
M-x transpose-sexps =>
b |= a AND c = d

And:

a = b AND| c = d
M-x transpose-sexps =>
c = d AND| a = b

And that this would be both jolly useful in itself, and proof that I'd set up the parsing rules correctly. But it doesn't work, and I have no idea why. I do know that if I switch either token to a comma, it works for that token.

Does anyone know where I'm going wrong? Is what I'm trying to do even possible*? And if it's not possible, is there any other way to verify the parse tree, before I start trying to indent it?

Thanks,
Kris

* This line from the docs makes me believe it is: "For example, if the provided grammar is precise enough, transpose-sexps can correctly transpose the two arguments of a + operator, taking into account the precedence rules of the language."


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SMIE & transpose-sexps
  2014-02-27 11:54 SMIE & transpose-sexps krisajenkins
@ 2014-02-28  2:30 ` Stefan Monnier
       [not found] ` <mailman.16218.1393554659.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-02-28  2:30 UTC (permalink / raw)
  To: help-gnu-emacs

> And that this would be both jolly useful in itself, and proof that I'd
> set up the parsing rules correctly.  But it doesn't work, and I have
> no idea why.

It usually works for the "=" case but not for the AND case.

The reason is that transpose-sexps doesn't actually know about SMIE
tokens, so when it sees AND it has no idea it's an infix operator,
instead it uses the syntax-tables and thinks AND is an identifier.
For infix operators which are made of symbols (i.e. chars of
"punctuation" syntax), it happens to do the right thing, which is
neat indeed.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SMIE & transpose-sexps
       [not found] ` <mailman.16218.1393554659.10748.help-gnu-emacs@gnu.org>
@ 2014-02-28 12:11   ` Kris Jenkins
  2014-03-10 15:12     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Kris Jenkins @ 2014-02-28 12:11 UTC (permalink / raw)
  To: help-gnu-emacs

On Friday, 28 February 2014 02:30:27 UTC, Stefan Monnier  wrote:
> > And that this would be both jolly useful in itself, and proof that I'd
> 
> > set up the parsing rules correctly.  But it doesn't work, and I have
> 
> > no idea why.
> 
> 
> 
> It usually works for the "=" case but not for the AND case.
> 
> 
> 
> The reason is that transpose-sexps doesn't actually know about SMIE
> 
> tokens, so when it sees AND it has no idea it's an infix operator,
> 
> instead it uses the syntax-tables and thinks AND is an identifier.
> 
> For infix operators which are made of symbols (i.e. chars of
> 
> "punctuation" syntax), it happens to do the right thing, which is
> 
> neat indeed.
> 
> 
> 
> 
> 
>         Stefan

Aha, I see. Thanks for explaining. :-)

So...is there any other way to see SMIE's idea of the syntax tree for a given buffer, for debugging?

Cheers,
Kris


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: SMIE & transpose-sexps
  2014-02-28 12:11   ` Kris Jenkins
@ 2014-03-10 15:12     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2014-03-10 15:12 UTC (permalink / raw)
  To: help-gnu-emacs

> So...is there any other way to see SMIE's idea of the syntax tree for
> a given buffer, for debugging?

I use C-M-f (called before a prefix/infix token) and C-M-b (called after
a postfix/infix token) for debugging.


        Stefan




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-10 15:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-27 11:54 SMIE & transpose-sexps krisajenkins
2014-02-28  2:30 ` Stefan Monnier
     [not found] ` <mailman.16218.1393554659.10748.help-gnu-emacs@gnu.org>
2014-02-28 12:11   ` Kris Jenkins
2014-03-10 15:12     ` Stefan Monnier

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.