source | all docs for version 0.7.pre8 | all versions | oilshell.org
Warning: Work in progress! Leave feedback on Zulip or Github if you'd like this doc to be updated.
This document describes the Oil language. See What is Oil? for the larger context.
It also discusses future work.
ls -l
ls -l | wc -l
Oil retains them all. A big difference is that keywords rather than builtins are used for assignment.
Like Python, JS. See Oil language definition.
[[ ]] and []
echo -e and $''
remaining dynamic parsing in shell
arithmetic is still somewhat dynamic -- replaced by Oil expressions
assignment builtins support dynamism, replaced by var
and setvar
set
, and maybe =Another concept is parsing modes.
shopt -s all:oil # most important thing, turns on many options
if ( ) {
}
echo @array
set x = 1
builtin set -o errexit
equals:
x = 1
equivalent to
const x = 1
This is for Oil as a configuration language.
echo hi
Expression mode in three places:
echo @array
myprog --flag=$f(x, y)
var z = f(x+1, y)
Control FLow:
if grep foo if (foo) {} # replaces if [ -n $foo ]; then
while
for
switch/case -- for translation to C++ like mycpp match/case
Sigils:
Sigil Pairs:
${x} for word evaluation
$(( )) for shell arithmetic is deprecated
$(bare words) for command sub
@(bare words) for shell arrays
@[1 2 3] for typed arrays
@{ } for table literals / embedded TSV
$// for regexes
c'' c"" r'' r"" for strings
:{} for blocks
:() for unevaluated expressions
Table example:
var people = @{
name age:Int
bob 10_000
'andy c' 15_000
}
var people = {name: @(bob 'andy c'), age: @[10_000 15_000]}
Sigil pairs often change the lexer mode.
echo ${myfloat %.3f}
Formatters (like template languages)
echo ${myfloat|json}
var
, set
, do
, func
, return
var x = 1
auto for autovivification:
auto dict['key'] += 1
maybe const. I want that to be compile-time though.
return
has to be a keyword and not a builtin because it can take arbitrary data types, e.g.
return {name: 'bob', age: 15}
Later: Data Frames.
backslashes
##
%%%
Mentioned in the last post. This is big!
The use
builtin will provide scope.
But take simplified keyword args like Julia.
@ARGV
and ARGV
Assignment builtins local, declare, export
TODO: Link HN thread
echo
echo simplified
tweaked: eval
, trap
read
will probably be overhauled, simplified
use
, push
, repr
use
is like source with namespaces. I've come up with a good syntax but
the semantics will be tricky, e.g. caching modules.
push appends to an array
repr for debugging TODO: Probably more for debugging.
NOTE: Haven't decided if blocks have parameters or now? Maybe just magic variables.
cd ~/src { echo $PWD } replaces pushd/popd pairs
Shell options have a stack (modernish also has this):
shopt -s errexit {
}
Env is now a builtin and takes a block
env FOO=bar {
}
fork builtin replaces the weird &
terminator:
{ echo 1; sleep 1; echo 2; } &
fork { echo 1; sleep 1; echo 2 }
wait builtin replaces ( ), because ( ) is going
cd
, env
, and shopt
Have Their Own StackLike Python's context manager.
wait
and fork
builtins Replace () and & Syntaxeach { }
Runs Processes in Parallel and Replaces xargs
each func
each { }
Evaluates to JSON (like YAML and TOML):
server foo {
port = 80
}
And can also be serialized as command line flags.
Replaces anti-patterns:
BEGIN {
end
}
when x {
}
rule foo.c : foo.bar {
cc -o out @srcs
}
Probably use a block format. Compare with Python's optparse.o
See issue.
Haven't decided on this yet.
check {
}
Python and shell both borrow from C. Oil borrows from Python and C.
text over binary
Coprocesses
Data Frames from R
Low Level Bindings for POSIX, Linux, Containers
Find Dialect
Regex Dialect
Bootstrapping: optional static typing
switch/case
match/case -- algebraic data types, replace case statement?
Hejlsberg quote?