all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* SMIE grammar for C-style function expressions
@ 2021-09-27 14:39 Nikolay Kudryavtsev
  2021-09-27 18:41 ` Filipp Gunbin
  2021-09-28  2:34 ` Stefan Monnier
  0 siblings, 2 replies; 8+ messages in thread
From: Nikolay Kudryavtsev @ 2021-09-27 14:39 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: Stefan Monnier

Hello.

Recently, I've been working on a major mode with an indentation 
implementation based on SMIE. I've been also collecting some notes with 
the plan of writing a post on reddit, describing the experience gained. 
Since the language I'm working on is kind of a nightmare to indent, some 
part of my post is going to be SMIE-related.

With this in mind, I still have a very basic case that I don't think I 
100% grok, so I've decided to ask here. The case is this: what's the 
proper way to describe SMIE grammar for C-style functions? I remember 
Stefan talking that he has a prototype SMIE C implementation, but I 
don't think he ever published it.

To explain, a C-style function definition grammar looks something like this:

f n ( a ) { s }

'f' here is a keyword, which in practice would be "function" or say 
"def" like in Python so lets mark it like this:

"f" n ( a ) { s }

Both '( a )' and '{ s }' are lists and SMIE grammars generally prefer to 
abstract those, to keep parens considered openers and closers. So now 
our grammar looks like this:

args = ( a )

stmts = { s }

"f" n args stmts

Now the grammar we ended up with is invalid in SMIE because non 
terminals appear consequently in it. The simplest solution would 
probably be using virtual keywords, to separate our non terminals:

"f" n " : " args " : " stmts

This of course puts a bit of a strain on the lexer, since it has to 
recognize when to give out those tokens.

So, is this the recommended solution for such cases, or maybe there's 
some other preferred way?




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

end of thread, other threads:[~2021-09-28 18:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-27 14:39 SMIE grammar for C-style function expressions Nikolay Kudryavtsev
2021-09-27 18:41 ` Filipp Gunbin
2021-09-27 19:36   ` Nikolay Kudryavtsev
2021-09-28  2:34 ` Stefan Monnier
2021-09-28 11:47   ` Nikolay Kudryavtsev
2021-09-28 13:07     ` Stefan Monnier
2021-09-28 18:12       ` Nikolay Kudryavtsev
2021-09-28 18:45         ` 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.