help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SMIE grammar for C-style function expressions


From: Stefan Monnier
Subject: Re: SMIE grammar for C-style function expressions
Date: Mon, 27 Sep 2021 22:34:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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 }

Could you clarify what you mean by "describe"?

SMIE does not concern itself with trying to detect syntax errors, so
nothing of the above seems hard at all: it should "just work" without
any special effort (just make sure SMIE knows that "(" matches ")" and
"{" matches "}" and that's it).

[ I'd expect more difficulty when you consider sequences of such
declarations, as in:

    f n1 ( a1 ) { s1 }
    f n2 ( a2 ) { s2 }

where there's no clear separator.  In such cases the better option
usually involves treating `f` as an infix separator (rather than
a prefix).  ]

Maybe the problem you're seeing has to do with having specific
indentation rules inside the `s` part, maybe?  If so, the problem is
better solved in the SMIE indentation rules than in the SMIE grammar.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]