From: "Mattias Engdegård" <mattiase@acm.org>
To: Damien Cassou <damien@cassou.me>
Cc: emacs-devel@gnu.org
Subject: Re: Parsing beyond sexps
Date: Sun, 19 Jan 2020 10:46:18 +0100 [thread overview]
Message-ID: <6E24B253-0F38-468D-80D4-A4D78D96B89B@acm.org> (raw)
In-Reply-To: <87wo9nn9vd.fsf@cassou.me>
19 jan. 2020 kl. 09.11 skrev Damien Cassou <damien@cassou.me>:
> This is not enough though as I want comments and line/column positions
> in the yielded values. Is there anything I could use from Emacs core
> that would make my life easier?
Nothing in Emacs core that I know of, but you could have a look at how the 'relint' package does it: keep track of the position before each top-level form, and then maintain a path of list indices taken as it descends into each form. Example:
(defun select-weapon (opponent)
"A Matter of Life and Death."
(if (fencing-master-p opponent)
'duelling-pistols
'rapier))
The path to duelling-pistols would be (1 2 4), since it is built up backwards as a stack during descent: first take element 4 of the top-level form to the 'if'-expression, then element 2 of that form to the (quote duelling-pistols), and finally element 1 to get past the quote. Maintaining the path during traversal turns out to be fairly cheap.
The tuple <top-level-position, path> can then be transformed into <line, column> (or just a buffer position) when required for diagnostics; see 'relint--pos-line-col-from-toplevel-pos-path'. It's somewhat slow but not time-critical.
prev parent reply other threads:[~2020-01-19 9:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-19 8:11 Parsing beyond sexps Damien Cassou
2020-01-19 9:46 ` Mattias Engdegård [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=6E24B253-0F38-468D-80D4-A4D78D96B89B@acm.org \
--to=mattiase@acm.org \
--cc=damien@cassou.me \
--cc=emacs-devel@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.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
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).