Skip to content

Instantly share code, notes, and snippets.

@TorbenKoehn
Created July 17, 2013 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TorbenKoehn/6019179 to your computer and use it in GitHub Desktop.
Save TorbenKoehn/6019179 to your computer and use it in GitHub Desktop.
OwnScript Specification

OwnScript Specification

Introduction

What is OwnScript? ...you might ask. OwnScript is a programming language based on good parts of specific other languages, namely PHP, JavaScript, Java, Ruby and C#

OwnScript combines the advantages of those into one, single language that

OwnScript is mostly a web development language, but might also be used as a system programming language. Primarily it offers web development tools.

Not all parts of OwnScript have been planned yet, but most parts will be decided while developing the language compiler itself

OwnScript is a JIT-compiled language similar to PHP The compiling process requires an OwnScript.exe/OwnScript.so program Next to the OwnScript Program there can be a configuration file OwnScript.yml OwnScript.yml can include other, system specific configuration files and set up configured environments for specific folders of your server

What can OwnScript do?

  • Multitasking. OwnScript's callbacks work asynchron similar to JavaScript's. To keep your threads timed OwnScript utilizes inbuilt Promises support similar to jQuery's
  • Namespace/Package support OwnScript will support Namespaces similar to C#'s, but are handled like JavaScript's (pseudo) namespaces
  • Operator overloading In OwnScript you can overload any specific operator
  • Cast overloading OwnScript can specify how specific classes are casted to different classes
  • Dynamic or strictly typed In OwnScript you can either use types....or not. It's up to you and doesn't affect other libraries at all.
  • OwnScript supports many fancy Ruby syntaxes that tend to be useful
  • OwnScript can be fully compiled into PHP
  • OwnScript supports no interfaces, but abstract classes, properties and methods The abstract classes work similar to interfaces (As in PHP)
  • OwnScript can extend multiple classes. For that have to handle each constructor Properties will be overridden based on the position of the extension in the extension list
  • Getters and Setters. OwnScript supports Getters and Setters that work similar to C#'s Next to "value" it also supports a "var" element that represents an anonymous, non-accessible property in the class
  • OwnScript has constructs for easy retrievement of client options (GET, POST data) and easy validation/filtering of those
  • OwnScript brings a complete, web development based standard library
  • OwnScript doesn't need semicolons (But it's not forbidden to use them)

Syntax specification

Blocks

OwnScript supports two types of blocks. One that's rather used for templating and one that brings back your old coding habits.

The most used one will probably this one

%declaration%:

    //contents of the code block
end

Notice the : at the end of the declaration and the "end". Those two tokens represent { and } as we know them. The second style is the default bracket style

%declaration% {

    //contents of the code block
}

You can use both bracket styles everywhere, whenever there's a block needed

Namespaces

A namespace is generally defined for a whole file or a a block of code You can also define the namespace manually

Default bracket style:

namespace Vendor.Module.SubModule:

    //namespace contents
end

Known bracket style:

namespace Vendor.Module.SubModule {
    
    //namespace contents
}

For the whole file (or until another namespace is defined):

namespace Vendor.Module.SubModule;

//namespace contents

Create namespace through object instance

Vendor.Module.SubModule = new Namespace;

Namespaces can also be nested. The parent namespace will be put in front of the child namespace

namespace Vendor.Module:

    namespace SubModule:

        //child namespace code
    end
    
    //parent namespace code
end

A namespace is an object of type Namespace and can be handled like a variable.

Importing namespaces

Important a namespace works with the use statement The use-statement is a one-liner and searches for the namespace or class and imports it to the current scope. use supports conflict handling with the as statement If the imported class is not a class, but a namespace, all classes in it will be imported Conflicted classes won't be imported then, but can be manually imported after the namespace import. Conflicting namespaces will throw errors.

Some examples:

use OwnScript.Web.Request

use Vendor.MyStuff.DuplicatedClass as NewName

use Vendor.MyStuff.Request
use OwnScript.Web
use OwnScript.Web.Request as OwnScriptRequest

In essence the use statement does nothing more than

var Request = OwnScript.Web.Request

which can also be used to import namespaces

Defining variables

Variables can be defined anywhere and usually belong to the parent block, e.g. the namespace or the class. Variables can be initialized with a type or no type (var), which is an object of type Variable and can access easy comparison methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment