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: SMIE implementation for the C-like languages Date: Mon, 09 Nov 2015 19:05:06 +1300 Message-ID: <87mvun7lnx.fsf@ap4y.me> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1447054754 24396 80.91.229.3 (9 Nov 2015 07:39:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Nov 2015 07:39:14 +0000 (UTC) Cc: monnier@iro.umontreal.ca To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 09 08:39:08 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 1Zvh2f-00077L-Fl for ged-emacs-devel@m.gmane.org; Mon, 09 Nov 2015 08:39:05 +0100 Original-Received: from localhost ([::1]:50644 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvh2f-000360-21 for ged-emacs-devel@m.gmane.org; Mon, 09 Nov 2015 02:39:05 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvfa7-000832-Bp for emacs-devel@gnu.org; Mon, 09 Nov 2015 01:05:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zvfa2-0004zk-Ru for emacs-devel@gnu.org; Mon, 09 Nov 2015 01:05:31 -0500 Original-Received: from ap4y.me ([45.79.156.233]:58209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvfa2-0004z9-Ng for emacs-devel@gnu.org; Mon, 09 Nov 2015 01:05:26 -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 765AB58F; Mon, 9 Nov 2015 06:05:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ap4y.me; s=default; t=1447049112; bh=wEXwpThcw1eyZgnvdfwtf6vmvzI1CsVLuEETw8UPezU=; h=From:To:Subject:CC:Date:From; b=jeVgj/X/mwXtqAOQYnm+KDPgghxn5PkYnzQFvKyqN7W4dMWQ6BZO7E+tH2YAgn1jk VoAOZ7rfp5SdgJCD9v0Tq2RxCz1qlGzOASS9tJfvmfKeAuELsj+4IfTwNDGEuY9VCv BbU/mUMl6FEnfmMpUXNConhm3ISdBY5ky33y/Mw0= 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: Mon, 09 Nov 2015 02:39:01 -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:193689 Archived-At: I'm currently maintaining smie implementation for the Swift language. Language itself is close to the family of C-like languages with some differences to the language constructions. I'm looking for some advice about applying smie to the languages that use braces as a terminators for the code blocks. 1. As stated in documentation tokens that are defined in syntax table don't have to be tokenised in lexer. I tried to go this way, but encountered situations where defined grammars are not respected. It seems that smie only tries to indent closer token with respect to the opener, rather than parent token defined by grammar. As far as I understand (after checking source code for smie-indent-forward/backward-token) this is expected behavior. So I decided to tokenise braces in lexer and it works for most of the cases, but I encountered issues with paren blinking: in some situations blinking fails with "Mismatched parenthesis". During some tests I decided to change lexer rules for braces to return begin/end tokens instead of braces. I noticed that smie still tries to indent "}" token in some situations, specifically `:close-all . "}"`. This seem to be related to blinking problem during blinking we have. So my question is what will be the semantically correct way of handling braces for the C-like languages? And secondary question is it expected that smie tries to indent tokens that are not returned by lexer? 2. As a sort of continuation of the previous problem, we are having problem understanding what will be semantically correct way of defining `sexp` for the smie based mode. At the moment we see a different behavior between non-smie c++ mode (which is close to the Swift) and something like ruby-mode. One of the contributers summarised differences in this post https://github.com/chrisbarrett/swift-mode/pull/117#issuecomment-154753070. I personally think grammar based sexp provided by smie are extremely useful, but they yield confusing results when it comes to blinking parens. For example grammar for "if" from here: https://github.com/chrisbarrett/swift-mode/blob/simplify_smie/swift-mode.el#L74-L129 works well for indentation and movements, but blinking on the close ("}") returns "if" token. So the question is it a right approach to use braces as a tokens for the grammars for C-like languages or there is a better way to support blinking and grammars at the same time? Thank you, Arthur