Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

ZQL – a language for *declaring* scripts content. Any ideas for changes maybe?



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



Messages sorted by: Reverse Date, Date, Thread, Author