From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: SMIE examples and questions Date: Thu, 25 Jun 2020 12:54:21 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="112899"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: Emacs development discussions To: =?windows-1252?Q?Aur=E9lien?= Aptel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Jun 25 18:55:20 2020 Return-path: Envelope-to: ged-emacs-devel@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 1joV9j-000TFw-Od for ged-emacs-devel@m.gmane-mx.org; Thu, 25 Jun 2020 18:55:19 +0200 Original-Received: from localhost ([::1]:54862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1joV9i-0006do-PW for ged-emacs-devel@m.gmane-mx.org; Thu, 25 Jun 2020 12:55:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joV96-0005po-HK for emacs-devel@gnu.org; Thu, 25 Jun 2020 12:54:40 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:18975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1joV94-0004P6-4a for emacs-devel@gnu.org; Thu, 25 Jun 2020 12:54:39 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A9A581002D8; Thu, 25 Jun 2020 12:54:36 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 603D4100283; Thu, 25 Jun 2020 12:54:27 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1593104067; bh=34LMoQ0rjlT9wtKrTIN5wB4rDcIA2oQJyPl8WPHLybw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=bTDZC+G9AafW/Ex5/RI87+OL51pgkMXQUYepTZxJ12YIv8lzJwcK6lKYJHsUqG3JE /LmlFD6jDk9GVxv3pblOhmS7Cnb6sY89F22Biif3QZ2xu39roVP9r4E9tpqWf36RCA 9QIZl0fgyxDZJA7aIx+s/EUDc1r1uXcBVGgXc0HkSZCiECGbCktBDSdvjcZDuLn/Sw TnKUpeTRdEHy0rP7apQGXeVBJGaVyBxRTxzbayUnYT4PN+d4maDY7J/kM+8yD9wK1F imKRBlh5D1rWIrsFJ/ipxAgQ5bncWmFgL998Be7iWolGiilZidorgXKVjrT34AXx2l gHAITZ8fkib7w== Original-Received: from alfajor (65-110-220-255.cpe.pppoe.ca [65.110.220.255]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0A18C120225; Thu, 25 Jun 2020 12:54:26 -0400 (EDT) In-Reply-To: (=?windows-1252?Q?=22Aur=E9lien?= Aptel"'s message of "Thu, 25 Jun 2020 11:21:18 +0200") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/25 12:54:36 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] 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, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:252535 Archived-At: > Are there *simple* complete examples of SMIE out there? I find the > manual not that helpful to get started and existing modes look pretty > complex :( The only simple and complete ones are for language that are probably too simple. Maybe the rnc-mode and dts-mode GNU ELPA packages? You might also want to look at my SMIE paper (https://programming-journal.org/2021/5/1/) which walks through a small part of the rnc-mode SMIE code. > Is the forward lexer required or is the backward one enough? Both are needed. > What are the assumptions of SMIE regarding the lexer? > - What should it return when there is nothing to read (eg backward and > begining of buffer)? nil, usually. > - I assume if point is in the middle of a token, it should return > the complete current token (including text after point) and place the > point at token start? The caller of the lexer should normally make sure it's never in the middle of a token. This doesn't work if you have tokens that can span multiple lines (e.g. when LF itself is significant, such as the implicit ; in Javascript). > - Does point position matter regarding spaces (assuming they have no > meaning)? Is it ok if the lexer places the point sometime after and > sometime before them? It should place point right "after" (in the direction of movement) the token it has read. > - Can I safely call it manually without involving SMIE? Yes. > - I assume backward and forward lexer should always have the same > behaviour, even for spaces? Yes and no, since one should stop to the left of the spaces and the other to the right. > I understand there is no way to dump the AST after parsing, and that > grammar errors not being reported is a feature. There's no AST, indeed, and there are no possible errors (IOW errors can't be detected). > How am I supposed to debug parsing/indenting? I mostly use M-C-f and M-C-b for parsing. For the indentation rules you can use `M-x smie-edebug`. > If you have any tips or workflow, like the more practical order to > implement things, or how to debug that would be greatly appreciated. Start with the simple cases and then work your way up. If you want more concrete help, don't hesitate to send me your current code along with some sample source showing how it should be indented and the problems you're facing. Stefan