Tequila is a basic PHP shell.
It currently has only one feature: instantiating objects and calling methods on them.
It seems small but is in fact enough to have a very a functioning shell with various utility classes.
A basic command has the following format:
class method arg1 ... argN # Comment
Where each of this entries (except the comment) can be:
- a boolean value (
true
orfalse
, case insensitive); - the null value (
null
, case insensitive); - a string;
- a variable;
- a nested command.
There is 3 formats which aim to be enough for any use.
The first and simplest is plain: only alphanumerics, /, -, _, . and escaped sequences are allowed, but they are very light to type and therefore much used for classes and methods names.
this\ is\ a\ plain\ string
The second one is the quoted format which provides an easy way to type much strings. They start and end with a quote ("), every characters are allowed but quotes and backslashes must be escaped, you even may use escaped sequences.
"This is a quoted string"
The last one is raw and allows the user to type raw string very easily without needing to escape special characters. They start with a percent sign (%) followed by a start delimiter which can be anything but an alphanumeric, a space or a control character, and they end with the same character except for (, [, { and < where it is the opposite (respectively ), ], } and >). Thus you may use the character which suits the best your string. Please note that matching pairs inside the string are ignored.
%{A raw string}
%(Backslashes do not need to be escaped \, and nested pairs are allowed.)
Escaped sequences:
- \n: New line
- \r: Carriage return
- \t: Tabulation
- \: Backslash itself
- ": Quote (only for quoted strings)
- \ : Space (only for naked strings)
Variables associate a identifier to a value.
An identifier is a string which conforms to the following regular expression
/[a-z0-9_]+/i
.
A variable starts with a dollar sign ($) followed by its identifier.
class method $my_variable
Nested commands are mainly used to add dynamicity to scripts but can very handy in many other situations.
A nested command starts with a dollar sign followed by a left parenthesis ($() and ends with a right parenthesis ()).
class1 method $(class2 method)
The tequila
script is executed, it
- sets the include path;
- loads Gallic if necessary and configures it (used for class loading);
- instantiates a new
Tequila
object; - uses the configuration file to⦠configure Tequila;
- calls
Tequila::start()
.
Tequila::start()
runs a loop which reads and executes commands until it is
asked to stop.
- It ensures it was not already running, otherwise throws an exception.
- While it is running it:
- asks for a command to execute with
Tequila::prompt($prompt)
; - if not empty it is pushed on the history;
- calls
Tequila::executeCommand($command)
; - if there was an error, prints it, otherwise prints the return value if not
null
.
- asks for a command to execute with
Tequila::executeCommand($command)
- parses the given command if necessary with
Tequila::parseCommand($command)
; - executes all nested commands (with itself);
- executes the command with
Tequila::execute($class, $method, $args)
.