Git Product home page Git Product logo

tequila's Introduction

Introduction

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.

Syntax

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 or false, case insensitive);
  • the null value (null, case insensitive);
  • a string;
  • a variable;
  • a nested command.

String formats

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

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

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)

Architecture

Run sequence

Bootstrapping

The tequila script is executed, it

  1. sets the include path;
  2. loads Gallic if necessary and configures it (used for class loading);
  3. instantiates a new Tequila object;
  4. uses the configuration file to… configure Tequila;
  5. calls Tequila::start().

Input loop

Tequila::start() runs a loop which reads and executes commands until it is asked to stop.

  1. It ensures it was not already running, otherwise throws an exception.
  2. While it is running it:
    1. asks for a command to execute with Tequila::prompt($prompt);
    2. if not empty it is pushed on the history;
    3. calls Tequila::executeCommand($command);
    4. if there was an error, prints it, otherwise prints the return value if not null.

Command execution

Tequila::executeCommand($command)

  1. parses the given command if necessary with Tequila::parseCommand($command);
  2. executes all nested commands (with itself);
  3. executes the command with Tequila::execute($class, $method, $args).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.