Module oursh::program [−][src]
Parsing and handling program syntax(es) of the shell.
Both, commands entered to the shell interactively through STDIN, and read
from a file, are programs. Our shell provides multiple discrete languages
to write programs in, each with a corresponding implementation of this
module's Program
trait.
POSIX Shell Language
The basic, portable POSIX shell language. For detailed information read the
posix
module docs.
a=0
b=1
for ((i=0; i<10; i++))
do
echo -n "$a "
fn=$((a + b))
a=$b
b=$fn
done
echo
Modern Shell Language
A more modern and ergonomic language. For more detailed information read
the modern
module docs.
# WIP
var a = 0
var b = 1
for i in 0..10 {
echo -n "$a "
let fn = $((a + b))
a = $b
b = $fn
}
echo
Default Syntax
Our shell has a PrimaryProgram
which is in charge of parsing programs
which are not passed in via a {#}
language block. This can be configured
to your preference. This does not effect the shell when launched in
POSIX compatibility mode, or when a specific default language is passed
as a flag.
{#}
Language Blocks
Both the posix
and modern
languages have support for a special expression which treats the body as a
program from another language. This forms the basis of oursh's modern
features, and backwards compatibility. While the primary goal of this
syntax is to be able to mix both POSIX and non-POSIX shell scripts, the
feature is much more powerful. Any interperator can be used, just like
with #!
.
date # Call `date` in the primary syntax.
{# date} # Specifies the alternate syntax.
# Use ruby, why not...
{#!ruby
require 'date'
puts Date.today
}
Strict POSIX compatibility can be enabled by removing this feature alone.
- TODO #5: Parse sequence of programs from stream.
- TODO #5: Partial parses for readline-ish / syntax highlighting.
Re-exports
pub use self::basic::Program as BasicProgram; |
pub use self::posix::Program as PosixProgram; |
Modules
ast |
Abstract Syntax Tree for programs between multiple languages. |
basic |
Single command programs with no features. |
posix |
The ubiquitous POSIX shell command language. |
Traits
Command |
A command is a task given by the user as part of a |
Program |
A program is as large as a file or as small as a line. |
Functions
parse |
Parse a program of the given type. |
parse_primary |
Parse a program of the primary type. |
Type Definitions
AlternateProgram |
TODO: alt explain |
PrimaryProgram |
The primary program type, used for unannotated blocks. |