From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.help Subject: Re: Working around the limitations of SMIE Date: Sun, 13 Nov 2022 00:12:24 +0000 Message-ID: <87a64vyaon.fsf@posteo.net> 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="39691"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Stefan Monnier via Users list for the GNU Emacs text editor To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Nov 13 01:13:10 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 1ou0cY-000AAE-Ib for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 13 Nov 2022 01:13:10 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ou0bv-0008OX-AC; Sat, 12 Nov 2022 19:12:31 -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 1ou0bu-0008OP-GM for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 19:12:30 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ou0bs-0001Z6-KK for help-gnu-emacs@gnu.org; Sat, 12 Nov 2022 19:12:30 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 0AF9D240103 for ; Sun, 13 Nov 2022 01:12:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1668298346; bh=zdNP7NYsf2UpOy6xYtE7HsdlyBWYcPOX0psv26tK6rM=; h=From:To:Cc:Subject:Date:From; b=G9Zn7FK2bYiRcSe/NAJico0WNUCBY3PHS7404H8Tzz7EVxtuLS4VSH7EIfBcI2cgG iRDfcv/5Q5+TljL42om+nYAcGVwuHnOSg+gz850fTGiTfYG8DSJJ2gGr25nhBjxRMj 2DQSaR64Fcfn4nm498k4YsocTCWsVZjgHVcADkfJu4j6ADxMrGlefE24JRc7mDtVy+ xX2fGsv7KX4gUIElqcbUIL5LnIl2HbM+HE0bHZNoYGSw/bzIBqynqODIK3r5GRQg0r eHiBRne3YQ4l/LSLNUDANl/DsIC780Aahxbl812NCAtun3MaLdoLnGalN6O/G5ME7c l12uEX69QJvnw== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4N8tDS6VXBz9rxF; Sun, 13 Nov 2022 01:12:24 +0100 (CET) In-Reply-To: (Stefan Monnier's message of "Sat, 12 Nov 2022 14:06:14 -0500") Received-SPF: pass client-ip=185.67.36.66; envelope-from=philipk@posteo.net; helo=mout02.posteo.de 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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:140916 Archived-At: Stefan Monnier writes: >>>> 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. I have managed to solve by making the tokenizer distinguish if it is looking at the function type with or without any whitespace inbetween. If there is, a ghost token is generated, if not the type token is returned. This appears to work well. Thanks for the hint, once again!