zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: ZQL – a language for *declaring* scripts content. Any ideas for changes maybe?
Date: Mon, 22 Jul 2019 18:27:41 +0200	[thread overview]
Message-ID: <CAKc7PVAy+R+D7eyAxNWQWKSj_xSLNcOLH34rX4RxazJzdT2v1Q@mail.gmail.com> (raw)

Hello,
when I once tried NixOS, a system with declarative configuration at
its core, i was naively expecting that I'll be able to declare zshrc.
So, for example, that I'll be able to write some kind of rule "append
command {X} to the end of the zshrc if it's not somewhere in the
file". Turned out that those expectations were way out of the scale,
as what was actually possible was to fill 3 configuration fields with
the text of the zshenv, zprofile and zshrc.

ZQL is to implement the feature. Example code:

PRE { setopt #; print "**"; ls $ }
        ALTER { echo * "added" }
        POST { VALUE=* }

1. PRE and POST are the contextual surroundings of the inner code that
does the editing.
2. The `setopt #` says: match setopt command that takes string.
3. So # denotes string. It doesn't matter if it's given as "#" or '#'
or # – it will match all three kinds of strings (unquoted, " and '
plus also $'').
4. Now, if instead of single # there will be two ##, then this is
quotation-locked matching – it matches strings with only the kind of
quoting that's used for symbol. So, for example, '##' will match only
'string'.
5. # matches strings but not variables
6. To match also variables, there's the * symbol, with the same
quotation-locking features.
7. To match variables, there's $ symbol (with the $$ counterpart as well).

So, basically, the command matches a context of three preceding
commands setopt, print and ls and one trailing command – an assignment
VALUE={anything}. After this, it then applies the middle editing block
ALTER wchi;

1. Leaves 1st echo argument untouched (because it has * assigned)
2. Sets second argument to "added"

This is how I imagine ZQL and the true declaring of zshrc contents.
For more information you can take a look at the project's wiki:

https://github.com/zdharma/declare-zsh/wiki/ZQL-draft

Are there any easily detectable flaws in the idea? What else could be
added to the language?

The project has fairly sophisticated parsing already implemented.
Currently, it allows to disable / enable zplugin's commands (that's
how the project started; I'm thinking about exposing a plugin
interface for other commands that might benefit from such
highly-targeted approach) by providing a plugin name / pattern
matching it.

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

             reply	other threads:[~2019-07-22 16:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-22 16:27 Sebastian Gniazdowski [this message]
2019-07-22 19:01 ` Ray Andrews
2019-07-23  0:49   ` Sebastian Gniazdowski
2019-07-23 20:50 ` Bart Schaefer
2019-07-23 22:09   ` duvall

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=CAKc7PVAy+R+D7eyAxNWQWKSj_xSLNcOLH34rX4RxazJzdT2v1Q@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.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.vuxu.org/mirror/zsh/

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).