From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.help Subject: Re: Working around the limitations of SMIE Date: Sat, 12 Nov 2022 14:06:14 -0500 Message-ID: References: <874jv795xg.fsf@posteo.net> <87zgcx1mzw.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20837"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Stefan Monnier via Users list for the GNU Emacs text editor To: Philip Kaludercic Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 12 20:06:45 2022 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 1otvq0-0005FV-Ud for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 12 Nov 2022 20:06:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otvpe-0003gL-8H; Sat, 12 Nov 2022 14:06:22 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otvpd-0003es-6f for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 14:06:21 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otvpb-0001sp-CO for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 14:06:20 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 3620610012E; Sat, 12 Nov 2022 14:06:17 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 5F2BB100091; Sat, 12 Nov 2022 14:06:15 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1668279975; bh=N5kjXVjdgUo5FE4zLvc4vPpKjx9MEdvVfsyxOnkUUeg=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=QUbNH/SxKbcbXs22HBaV/i0peW5ZJGsLrkhfk068ZdmYlefdNYlZInqRFIAt7c9xc nEKFG9cwtIt7+wpoYNPJjcClBXEOzjSZnC0C0oxTdu4zA/HOGKTOG2Ya76ZgAMl6me f/rs/QFFZyzsVmIvwpjpfS4TyTw3DEu+mz9uljeajMyju4CU/LmVivPwtm/4+XunWw th4b5/VK+mSOrDEbX6nba4ShqWLm6x/OTP7mxqSfyrotJ7Gk+CQwXRHFsWTQZ1lSI3 q223vBp6eNZQbgcwz4RCAKxiq+xXLYtznIKR/MvO6+ETd8OZdB7pGrKIc8FX02ogpS Qbdyh9IS8nOsQ== Original-Received: from pastel (unknown [104.247.241.157]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 39CC91209D6; Sat, 12 Nov 2022 14:06:15 -0500 (EST) In-Reply-To: <87zgcx1mzw.fsf@posteo.net> (Philip Kaludercic's message of "Fri, 11 Nov 2022 16:20:35 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:140915 Archived-At: >>> I am writing a major mode for a little language I am using at >>> university, and wanted to try using SMIE for indentation and all the >>> other things. The issue I find myself confronted with is that functions >>> are defined as in the following example: >>> >>> func funktion(x : int): float >>> x := x * x; >>> return x; >>> end >>> >>> where there is no delimiter between the return type (float), and the >>> rest of the body (such as "begin" or something like that). >> >> How is the separation between the function's return type and the >> function's body defined? Is it based on the newline that follows the >> type, or is the language constrained to have types that are >> a single identifiers? > > The latter. This is the grammar production: > > functionDeclaration: ' func ' identifier '( ' ( parameterDeclaration ( ', ' > parameterDeclaration ) * ) ? ') ' > ( ': ' typeName ) ? block ' end ' ; Hmm... so the only "reliable" separator token is the close parenthesis, huh? I think I'd go with a hack in the lexer which checks if this is "the close paren of a function definition" and make it include the subsequent type annotation (if present). I.e. that new token would cover the whole of ')' ( ':' typeName ) ? Then again, that wouldn't work with the usual handling of parens in SMIE (IOW, you couldn't rely on syntax tables for them any more) :-( Maybe instead you can try and make the lexer recognize just ": typeName" (treating it as a special token) and then tweak the indentation rules so as to align the subsequent instruction with it. >>> Another issue I ran into with the above definition is that instructions >>> are not indented correctly, as the above grammar doesn't express that in >>> this language doesn't expect a semicolon after an end (just like C >>> doesn't expect one after a "}"). So the result is that >>> >>> instead of: >>> >>> while y >= y1 do >>> dummy := zeile(x1, x2, xstep, y); >>> y := y - ystep; >>> end >>> return 0; >>> >>> I get: >>> >>> while y >= y1 do >>> dummy := zeile(x1, x2, xstep, y); >>> y := y - ystep; >>> end >>> return 0; >> >> Based on my experience, I suspect that the simplest solution for this is >> to make "end" return 2 tokens (the "end" and then a ghost ";"). > > Funnily enough I had tried this out too, but I must have messed up > somewhere because the result wasn't what I had intended. IIRC it's easier to get it not to work than to get it to work, the "messed up" doesn't carry the right connotation. Stefan