From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nikolay Kudryavtsev Newsgroups: gmane.emacs.help Subject: SMIE grammar for C-style function expressions Date: Mon, 27 Sep 2021 17:39:47 +0300 Message-ID: <8c6fc2a9-1086-c026-459d-1e703563ae1d@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="13815"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 Cc: Stefan Monnier To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 27 16:43:24 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUrqk-0003Q0-UG for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 27 Sep 2021 16:43:22 +0200 Original-Received: from localhost ([::1]:39592 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUrqj-0000qO-VM for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 27 Sep 2021 10:43:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUrnM-0006So-R2 for help-gnu-emacs@gnu.org; Mon, 27 Sep 2021 10:39:52 -0400 Original-Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]:41862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUrnL-0002OL-4I for help-gnu-emacs@gnu.org; Mon, 27 Sep 2021 10:39:52 -0400 Original-Received: by mail-lf1-x12f.google.com with SMTP id t10so78457241lfd.8 for ; Mon, 27 Sep 2021 07:39:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-transfer-encoding:content-language; bh=JGyL4h9/p5CDSv83keFTyl89B8qFGSOasVZ1f5KEpGk=; b=UAXoWyknYzMBQ9gpt98jUYbItdtqKgvzVbMCljLjp4HEQFOOeFmSLta5dGZjpo7uCR R0ezcntjPcqLf4VzGdAMRM2SFJpUePgw0vROSWLQKAoVnmbtd5z8LHS+F6a/5IXqI4sr KmBCGmJm1pZFq7mHwrbSYWGGcYWLarzklK2u2S1VshC0aJtI4NPCM/ErBXMPlAi7tvCs jrwYrsjtpCX/81ys7EDUHKORnaz5K8yxSgle1KKsXqoeONV7mpRbREQWXGyB71GUASeX U8+ukM4fPpsFNn3JtOIGzSdfyiGZdkbSaWGS7qQOmLBWAW1IC1HSR9Qstl8au9Sj6hPY NVIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=JGyL4h9/p5CDSv83keFTyl89B8qFGSOasVZ1f5KEpGk=; b=FHejCcZ8KQQQ94eUykIxNfERVODZW0xL5blClEIMO9TndO4q7vRWZXpub9tNV8hChD JqCk2Z1QAOXehEqjYCX1TW2FgIIJVSCaUvn8tkOtUXrmnGEqnx2ostSnyNMiWaD6x+8w X2DD6dxUbwa4J28aBcH4qh4abvTPCN3NuL5YZzb8td7GhWnwAuIMvn0T5DX588KBQKb7 nwsUErUsGQ+RDpMl1maKZY6SJUf/kzpjMptobefhieHGGJxc0Uq+qlTzCPyem3LwhPox OXsb4Zfki5rQp1INy5NPQCaDrDeNlOktwJ84LmLm6dyrLrtR9swrzoET9BGAJ45YZtjn UdYA== X-Gm-Message-State: AOAM530uqJogqeJDSRrTjAjD4F3fSaA9sBqJI9o2Vw1ZJmq/TBOkeNV3 la/nt08S2GRuVjbX/k1LrGA= X-Google-Smtp-Source: ABdhPJxtnOW8ek2pNi9E1OYyG4l8BrSihZJy6HQH3ynbblNGoBY1tLdsUQtWasBto1TCdQnRCjDSuw== X-Received: by 2002:a2e:164e:: with SMTP id 14mr244078ljw.122.1632753588262; Mon, 27 Sep 2021 07:39:48 -0700 (PDT) Original-Received: from ?IPv6:2a02:2168:b115:9d00:d0d9:1e8c:3d1b:f7a1? ([2a02:2168:b115:9d00:d0d9:1e8c:3d1b:f7a1]) by smtp.gmail.com with ESMTPSA id t6sm1956703lji.109.2021.09.27.07.39.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Sep 2021 07:39:47 -0700 (PDT) X-Google-Original-From: Nikolay Kudryavtsev Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::12f; envelope-from=nikolay.kudryavtsev@gmail.com; helo=mail-lf1-x12f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:133294 Archived-At: Hello. Recently, I've been working on a major mode with an indentation implementation based on SMIE. I've been also collecting some notes with the plan of writing a post on reddit, describing the experience gained. Since the language I'm working on is kind of a nightmare to indent, some part of my post is going to be SMIE-related. 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 } 'f' here is a keyword, which in practice would be "function" or say "def" like in Python so lets mark it like this: "f" n ( a ) { s } Both '( a )' and '{ s }' are lists and SMIE grammars generally prefer to abstract those, to keep parens considered openers and closers. So now our grammar looks like this: args = ( a ) stmts = { s } "f" n args stmts Now the grammar we ended up with is invalid in SMIE because non terminals appear consequently in it. The simplest solution would probably be using virtual keywords, to separate our non terminals: "f" n " : " args " : " stmts This of course puts a bit of a strain on the lexer, since it has to recognize when to give out those tokens. So, is this the recommended solution for such cases, or maybe there's some other preferred way?