unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Reza Nikoopour <rnikoopour@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Help Understanding syntax-propertize-function
Date: Mon, 15 Mar 2021 19:30:08 -0400	[thread overview]
Message-ID: <jwvblbkrofw.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <CAKesZq3e0WZ50yFWtDfgfHNT1dtO0hwsYtewXQ+o-0Wh76xoMA@mail.gmail.com> (Reza Nikoopour's message of "Mon, 15 Mar 2021 15:48:13 -0700")

> Could someone help explain the following code:

I'm not sure which part you don't understand, so I'll stick to
generic ideas:

> (defun hcl--syntax-propertize-function (start end)
>   (goto-char start)
>   (hcl--syntax-propertize-heredoc end)
>   (funcall
>    (syntax-propertize-rules
>     (hcl--here-doc-beg-re
>      (2 (hcl--font-lock-open-heredoc
>          (match-beginning 0) (match-string 1) (match-beginning 2))))
>     ("\\s|" (0 (prog1 nil (hcl--syntax-propertize-heredoc end)))))
>    (point) end))

Since we don't know where `start` will be, it can be within a heredoc.
So we first call `hcl--syntax-propertize-heredoc` which should detect
when we're inside a heredoc and if so process it until its end and if not
do nothing.

Once that's done, we know we're not in a heredoc, hence we're in
"normal code" and we then use `syntax-propertize-rules` to try and
detect a few interesting conditions.  One of them is when we find
a match for `hcl--here-doc-beg-re`, in that case we call
`hcl--font-lock-open-heredoc` to place some syntactic marker at the
beginning of the heredoc.  The other is when we see a char of
syntactic category `|`, which doesn't occur in the wild but should
presumably be the result of `hcl--font-lock-open-heredoc` having placed
it there, so it announces the beginning of a heredoc, in which case we
can call `hcl--syntax-propertize-heredoc` to process it.


        Stefan




  reply	other threads:[~2021-03-15 23:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 22:48 Help Understanding syntax-propertize-function Reza Nikoopour
2021-03-15 23:30 ` Stefan Monnier [this message]
2021-03-15 23:58   ` Reza Nikoopour
2021-03-16  1:42     ` Stefan Monnier
2021-03-16 15:37       ` Reza Nikoopour
2021-03-16 17:29         ` Stefan Monnier
2021-03-16 17:50           ` Reza Nikoopour
2021-03-24 20:29   ` Filipp Gunbin
2021-03-24 22:10     ` Stefan Monnier
2021-03-24 22:54       ` Filipp Gunbin

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=jwvblbkrofw.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=rnikoopour@gmail.com \
    /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).