[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SMIE implementation for the C-like languages
From: |
Stefan Monnier |
Subject: |
Re: SMIE implementation for the C-like languages |
Date: |
Mon, 09 Nov 2015 23:12:58 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) |
>> 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
- SMIE implementation for the C-like languages, Arthur Evstifeev, 2015/11/09
- Re: SMIE implementation for the C-like languages, Stefan Monnier, 2015/11/09
- Re: SMIE implementation for the C-like languages, Arthur Evstifeev, 2015/11/09
- Re: SMIE implementation for the C-like languages,
Stefan Monnier <=
- Re: SMIE implementation for the C-like languages, Arthur Evstifeev, 2015/11/10
- Re: SMIE implementation for the C-like languages, Stefan Monnier, 2015/11/11
- Re: SMIE implementation for the C-like languages, Arthur Evstifeev, 2015/11/13
- Re: SMIE implementation for the C-like languages, Markus Triska, 2015/11/18
- Re: SMIE implementation for the C-like languages, Stefan Monnier, 2015/11/18
- Re: SMIE implementation for the C-like languages, Stefan Monnier, 2015/11/11