zsh-users
 help / color / mirror / code / Atom feed
* ZQL – a language for *declaring* scripts content. Any ideas for changes maybe?
@ 2019-07-22 16:27 Sebastian Gniazdowski
  2019-07-22 19:01 ` Ray Andrews
  2019-07-23 20:50 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2019-07-22 16:27 UTC (permalink / raw)
  To: Zsh Users

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-23 22:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 16:27 ZQL – a language for *declaring* scripts content. Any ideas for changes maybe? Sebastian Gniazdowski
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

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