From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Arthur Evstifeev Newsgroups: gmane.emacs.devel Subject: Re: SMIE implementation for the C-like languages Date: Wed, 11 Nov 2015 14:12:20 +1300 Message-ID: <87twot5ogb.fsf@ap4y.me> References: <87mvun7lnx.fsf@ap4y.me> <87611alen3.fsf@ap4y.me> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1447204767 20365 80.91.229.3 (11 Nov 2015 01:19:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 11 Nov 2015 01:19:27 +0000 (UTC) Cc: emacs-devel@gnu.org, Arthur Evstifeev To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 11 02:19:19 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZwK4D-00087C-H1 for ged-emacs-devel@m.gmane.org; Wed, 11 Nov 2015 02:19:17 +0100 Original-Received: from localhost ([::1]:36992 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwK4D-0004OE-0G for ged-emacs-devel@m.gmane.org; Tue, 10 Nov 2015 20:19:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwJxh-0005A9-NI for emacs-devel@gnu.org; Tue, 10 Nov 2015 20:12:34 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZwJxe-0007Jr-EH for emacs-devel@gnu.org; Tue, 10 Nov 2015 20:12:33 -0500 Original-Received: from ap4y.me ([45.79.156.233]:59253) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZwJxe-0007Jm-9j for emacs-devel@gnu.org; Tue, 10 Nov 2015 20:12:30 -0500 Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ap4y.me (Postfix) with ESMTPSA id 5016958F; Wed, 11 Nov 2015 01:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ap4y.me; s=default; t=1447204341; bh=e/p3pAM7RRV9z5RCESzimsiyYDNZoCyIJECrFTHvkN8=; h=References:From:To:Cc:Subject:In-reply-to:Date:From; b=QlrDdWVHQK+gKK/8ryu5dtDaCcEJbZD/pLXFhoo1HBLa0nlYF1cUTtLgUH4xl7L5F 3Al1NCRuwvvylDJTPtTMZGlGMma0LQ7jZoICedxbzH2w8ovvoyXh9Weu3G11ViEprj PNhjgtWgACql6UzZb9JtqccnW0WbeeWjY5tiC34k= In-reply-to: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 45.79.156.233 X-Mailman-Approved-At: Tue, 10 Nov 2015 20:19:13 -0500 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:194026 Archived-At: Stefan Monnier writes: >> 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? I'm a bit suspicious about :list-intro 'if', :elem 'args' and that :elem 'basic' was requested 2 times, especially if you compare against second example I sent yesterday (which has a proper indentation). What is specifically looking confusing to me is the whole situation with braces. I don't understand why smie produces different indentation results for cases when we tokenize braces and when we don't. I think both cases shouldn't be treated differently in grammars or indentation rules. From implementation perspective I understand why it happens at the moment. > >> 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). > Yes that's true, but braces are also a part of the syntax table. Since smie allow any sequence of sexp anywhere, I think this code block should be handled. I'm not sure what is the best way to do that but maybe something like a fallback logic to the syntax tables for such cases? >> 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. > I submitted a new bug report. >> 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. > I tried to reset forward-sexp-function and it works when I'm not tokenizing braces. When braces handled in lexer, I'm getting "Mismatched parenthesis" error similar to one of the previous examples. Thank you, Arthur