all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Arthur Evstifeev <mail@ap4y.me>
Cc: emacs-devel@gnu.org
Subject: Re: SMIE implementation for the C-like languages
Date: Mon, 09 Nov 2015 23:12:58 -0500	[thread overview]
Message-ID: <jwv611ajyc7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87611alen3.fsf@ap4y.me> (Arthur Evstifeev's message of "Tue, 10 Nov 2015 16:25:20 +1300")

>> I have an "smc-mode" (i.e. SMIE-based c-mode) here which I wrote as an
>> exercise to try and see what it takes to get SMIE working acceptably for
>> the C language syntax.  It's not usable (it was really meant as an
>> experimental prototype/proof-of-concept), but if you're interested to
>> look at it, I could make it available somewhere.
> If it's not hard to do, I'll appreciate that.

I'll see how best to do that.  Don't hold your breath, tho: to me this
experiment just convinced me that SMIE is not up for it (yet?): the code
ends up doing a lot of parsing "by hand" instead of relying on SMIE.

> When in trying to indent such code:

> if true {
>     |bar
> }

> Token "bar" is positioned incorrectly and I see such requests from smie
> and lexer and indentation rules:

> forward: 15 -> 18 = bar
> backward: 15 -> 10 =
> forward: 9 -> 9 =
> backward: 9 -> 4 = true
> backward: 4 -> 1 = if
> forward: 9 -> 9 =
> :after '{'; sibling-p:nil parent:(nil 4 if) hanging:t == nil
> forward: 9 -> 9 =  [2 times]
> backward: 9 -> 4 = true
> backward: 4 -> 1 = if
> forward: 9 -> 9 =
> :before '{'; sibling-p:nil parent:(nil 4 if) hanging:t == nil
> forward: 9 -> 9 =
> backward: 9 -> 4 = true [2 times]
> backward: 4 -> 1 = if [3 times]
> :list-intro 'if'; sibling-p:nil parent:nil hanging:nil == nil
> forward: 4 -> 8 = true
> :elem 'args'; sibling-p:nil parent:nil hanging:nil == nil
> forward: 4 -> 8 = true
> :elem 'basic'; sibling-p:nil parent:nil hanging:nil == 4
> forward: 9 -> 9 =
> :elem 'basic'; sibling-p:nil parent:nil hanging:t == 4

> This logging output and indentation requests don't seem to be respecting
> defined grammar.

I don't see anything out of the ordinary here.  Which part seems odd to you?

> But blink-matching-open calls for the simple code block:

> {
> }|

> will return "Mismatched parenthesis" error.

That's because it tries to match "}" with an opening "if" (since your
grammar states ("if" exp "{" insts "}") which implies that "{" is an
infix terminal).

> smie output will still contain request for indentation of "}" even if
> lexer didn't return such token:

> forward: 19 -> 20 = end
> backward: 20 -> 19 = end
> backward: 19 -> 18 = ;
> backward: 18 -> 15 = bar
> backward: 15 -> 9 = begin
> backward: 9 -> 4 = true
> backward: 4 -> 1 = if
> :close-all '}'; sibling-p:t parent:(nil 1 if) hanging:nil == nil

Indeed.  Please send this via M-x report-emacs-bug so we get a number to
track this problem.

> But it doesn't change behavior of the blinking: for the same if
> construction blinking happens for the "if" token.  Is there a different
> way of altering this behavior?

My guess would be that the default blinking code uses forward-sexp which
goes through forward-sexp-function which SMIE sets up as well.  Try set
this var back to nil in swift-mode buffers, see if that helps.


        Stefan



  reply	other threads:[~2015-11-10  4:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-09  6:05 SMIE implementation for the C-like languages Arthur Evstifeev
2015-11-09 15:23 ` Stefan Monnier
2015-11-10  3:25   ` Arthur Evstifeev
2015-11-10  4:12     ` Stefan Monnier [this message]
2015-11-11  1:12       ` Arthur Evstifeev
2015-11-11 14:17         ` Stefan Monnier
2015-11-13  2:10           ` Arthur Evstifeev
2015-11-18 23:14             ` Markus Triska
2015-11-19  3:00               ` Stefan Monnier
2015-11-11 15:59     ` 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=jwv611ajyc7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=mail@ap4y.me \
    /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.