unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: SMIE: defining a build.ninja grammar
Date: Sun, 9 Apr 2023 06:51:50 +0200	[thread overview]
Message-ID: <ZDJEZieEMzEXw5F+@tuxteam.de> (raw)
In-Reply-To: <efbaf4760b25133806e6401d919bac699e633aed.camel@baumlab.pro>

[-- Attachment #1: Type: text/plain, Size: 2147 bytes --]

On Fri, Apr 07, 2023 at 05:18:27PM +0300, Konstantin Kharlamov wrote:
> I initially posted this on Emacs stackexchange, but in absence of replies decided to re-post on the mailing list as that's where usually people knowing how SMIE works hang out.

I have no idea of SMIE, but I think I can answer one of
your questions -- perhaps in a surprising way:

[...]

> 3. How to define newline as a separator? E.g. a `build` ends with a newline, and then follows a region of assignments. I tried using a `"\n"`, but I'm not sure if SMIE interprets the backslash, nor that a `\n` will work with other newline types.

[...]

> My last attempt is the grammar below. I had some other variants that worked incorrectly, but they were incomplete as well. For this post I created a more complete version, but it does not compile for me because it doesn't like `text` definition, it throws `Adjacent non-terminals: id text`.
> 
>     (defvar test-mode-smie-grammar
>       (smie-prec2->grammar
>        (smie-bnf->prec2
>         '((id)
>           (path) ;; TODO: define how it's different from `id'
>           (statements (statement)
>                       (statement "\n" statements))
>           (statement (top_decls) (variable))
>           (text (id text)
>                 (text "\n"))
>           (variable (id "=" text))
>           (build_title (path build_title)
>                        (path ":"))
>           (top_decls
>            ("rule" id)
>            ("build" build_title ":" text)
>            )
>           ))))

Those "\n" you have there are translated by the Lisp reader
(i.e. "early") into code point 0x0A. So this is what SMIE is
going to see.

Now, no idea whether it special-cases this into "whatever counts
as a newline"; I'd venture a guess that it doesn't. I'd expect
that if "your" newlines are more complex than a simple "\n",
you'll have to extend the lexer, as detailed in "Defining
Tokens" [1] in the manual.

Cheers

[1] Info menu "SMIE Lexer" or this URL, if you prefer the intertubes:
   https://www.gnu.org/software/emacs/manual/html_node/elisp/SMIE-Lexer.html

-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

      reply	other threads:[~2023-04-09  4:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-07 14:18 SMIE: defining a build.ninja grammar Konstantin Kharlamov
2023-04-09  4:51 ` tomas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZDJEZieEMzEXw5F+@tuxteam.de \
    --to=tomas@tuxteam.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).