From: "Björn Lindqvist" <bjourne@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: SMIE examples or guides
Date: Fri, 1 Jul 2016 21:28:01 +0200 [thread overview]
Message-ID: <CALG+76c3EqZgDAwsvJdTX--jHhn7844o-phZ__AfiTk1R0euvg@mail.gmail.com> (raw)
In-Reply-To: <jwvh9c9g7hi.fsf-monnier+emacs@gnu.org>
I managed to write the forward and backward tokenization functions:
(defun factor-smie-token (dir)
(pcase dir
('forward (forward-comment (point-max)))
('backward (forward-comment (- (point)))))
(let ((tok (buffer-substring-no-properties
(point)
(let ((syntax "w_\\\""))
(pcase dir
('forward (skip-syntax-forward syntax))
('backward (skip-syntax-backward syntax)))
(point)))))
;; Normalizes different indent starters.
(cond ((string-match factor-smie-indents-regex tok) ":")
(t tok))))
(defun factor-smie-forward-token ()
(factor-smie-token 'forward))
(defun factor-smie-backward-token ()
(factor-smie-token 'backward))
It works in 99% of the cases. But since almost any character can be
part of a token, it doesn't work perfectly. E.g te]st(ab3 would be a
perfectly valid variable name. I tried changing the syntax to
"w_()\\\"" and that fixes the tokenization but then I lose the useful
automatic indentation smie adds to opening- and closing bracket
characters. E.g I'm happy that smie indents:
[
neat
{
nice
}
(
good
)
]
It's very nice. But the following two lines are not right:
hi[there
two
They should be:
hi[there
two
2016-07-01 9:13 GMT+02:00 Stefan Monnier <monnier@iro.umontreal.ca>:
>> Many thanks! That appears to work. But there is one problem. In a
>> buffer with just this content:
>
>> [
>> \
>> ]
>
>> I get the error: (error "Bumped into unknown token")
>
> You should either give a different syntax to the \ char in the
> syntax-table, or change the :forward-token and :backward-token functions
> so they do something with \
>
>> (smie-bnf->prec2
>> '((exp (("HELLO" "HALLO" "CIAO" "SALUT") exp "BYE"))))))
>
> One way to do that is:
>
> (smie-bnf->prec2
> '((exp ("HELLO" exp "BYE")
> ("HALLO" exp "BYE")
> ("CIAO" exp "BYE")
> ("SALUT" exp "BYE"))))))
>
> Another is to change the :forward-token and :backward-token functions so
> they return the same string (e.g. "HELLO") when tokenizing any one of those.
>
>
> Stefan
--
mvh/best regards Björn Lindqvist
next prev parent reply other threads:[~2016-07-01 19:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-19 2:57 SMIE examples or guides Björn Lindqvist
2016-06-20 3:21 ` Stefan Monnier
2016-06-26 12:23 ` Björn Lindqvist
2016-06-27 8:31 ` Stefan Monnier
2016-06-27 12:32 ` Björn Lindqvist
2016-06-27 22:02 ` Stefan Monnier
2016-06-28 11:34 ` Björn Lindqvist
2016-06-28 21:42 ` Stefan Monnier
2016-06-28 22:30 ` Björn Lindqvist
2016-06-29 7:37 ` Stefan Monnier
2016-06-29 16:48 ` Björn Lindqvist
2016-06-30 7:23 ` Stefan Monnier
2016-06-30 11:27 ` Björn Lindqvist
2016-06-30 18:49 ` Stefan Monnier
2016-07-01 0:49 ` Björn Lindqvist
2016-07-01 7:13 ` Stefan Monnier
2016-07-01 19:28 ` Björn Lindqvist [this message]
2016-07-01 23:09 ` Stefan Monnier
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=CALG+76c3EqZgDAwsvJdTX--jHhn7844o-phZ__AfiTk1R0euvg@mail.gmail.com \
--to=bjourne@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=monnier@iro.umontreal.ca \
/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).