public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Elliott Slaughter <elliottslaughter-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Towards (better) Python filters for Pandoc with fluent queries
Date: Fri, 2 Jan 2015 21:46:39 -0800	[thread overview]
Message-ID: <CAJ9X=kbsYb5XpXP7715VihFAqAD34FF4BtwTeiuUiSHnynNFOg@mail.gmail.com> (raw)
In-Reply-To: <CAE4-1rVjgCKdkXWOVkmyiwhDxxDawLHaLt0qkr7nUEp0QnPQyQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

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

On Fri, Jan 2, 2015 at 2:34 AM, Mark Szepieniec <mszepien-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Just from a first glance, wouldn't it be handy to be able to do
>
> m = Matcher()
>     ...
>
> and then
>
> if m.matches(block):
>     ...
>
> This way you could reuse Matchers easily?
>

Thanks; that's the sort of feedback I'm looking for. And yes, I think this
makes sense. To take this a step further, I could imagine supporting
different matching functions for different use cases:

m.match(block) # matches only if the match starts at the root element
m.search(block) # matches if any element at or below the root matches
m.replace(block, replacement_func, count) # replaces up to count
occurrences of the pattern with the result of calling replacement_func

Would that be useful? My immediate need is for the first only, but I could
see cases where I would want the other two.


More generally, I think it makes sense to start thinking of this as more of
a full query language rather than just a way to do pattern matching. Are
there any major features missing that people would want from such a tool?

For example, one might imagine a feature allowing arbitrary subelements to
match. (This is essentially the // operator from XPath.) One potential API
for doing this might look like:

Matcher().Div().contains(Matcher().Emph()) # matches Emphs nested
arbitrarily deep inside a Div

This use case is notable because it is not automatically
backwards-compatible with my current API (it requires the same sort of API
rearrangement as Mark's suggestion above). Are there any other cases like
this? I don't necessarily care if the API is not feature complete on day 1,
but I would still prefer to design things to be forwards-compatible, if
possible. So if you have features you'd like to see, please let me know.


Comments appreciated.


-- 
Elliott Slaughter

"Don't worry about what anybody else is going to do. The best way to
predict the future is to invent it." - Alan Kay

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAJ9X%3DkbsYb5XpXP7715VihFAqAD34FF4BtwTeiuUiSHnynNFOg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 4046 bytes --]

  parent reply	other threads:[~2015-01-03  5:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-02  6:58 Elliott Slaughter
     [not found] ` <CAJ9X=kb9W0_Jd4ufPcRiZSSZ+5Bpftg4hZ82zCuBLb-moadnSQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-02 10:34   ` Mark Szepieniec
     [not found]     ` <CAE4-1rVjgCKdkXWOVkmyiwhDxxDawLHaLt0qkr7nUEp0QnPQyQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-03  5:46       ` Elliott Slaughter [this message]
2015-01-02 15:09   ` Wagner Macedo
2015-01-02 16:50   ` John MacFarlane
     [not found]     ` <20150102165038.GA25833-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>
2015-01-03  5:50       ` Elliott Slaughter
     [not found]         ` <CAJ9X=ka-d7_rg4qSejF_ueWysg_oJ_LxYS9QHcJKgdU-Os0XHQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-03 10:17           ` Caleb McDaniel
     [not found]             ` <4b9fb48b-091c-44c6-9201-f5c5b559253f-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-01-04  8:23               ` Elliott Slaughter
     [not found]                 ` <CAJ9X=kZu94RTat+SKLknvUJJQWnENd9xkF9DJCJCHhiBY-qyDA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-01-04  8:25                   ` Elliott Slaughter
2015-01-22  5:25       ` Elliott Slaughter

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

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

  git send-email \
    --in-reply-to='CAJ9X=kbsYb5XpXP7715VihFAqAD34FF4BtwTeiuUiSHnynNFOg@mail.gmail.com' \
    --to=elliottslaughter-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.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 NNTP newsgroup(s).