XP language is a feature-rich, typed and compiled programming language, based on the popular PHP language and designed to syntactically support features of the XP Framework. The source you write and compile with it can make use of the XP Framework's foundation classes. As the language itself is written in the XP Framework, no binary or proprietary extensions are needed!
Like in the XP framework, the entry point is always a class. In their most simple form, these classes have a static main() method. To try it out, create a file called HelloWorld.xp
with the following contents:
public class HelloWorld {
public static void main(string[] $args) {
util.cmd.Console::writeLine('Hello World!');
}
}
Then compile and run it!
$ xp HelloWorld
Hello World!
The things you will have noticed are:
- Classes may also have modifiers.
- The
extends Object
is optional and added by the compiler if omitted. - The keyword
function
is gone and replaced by the return type. Because the main() method does not return anything, we use void. - An array type is written as component[]
- Variables still have dollar signs. This makes it easy to spot them, that's why we've decided to keep this!
- Fully qualified classnames are written with dots.
- The object operator is also a dot (at the same time, the string concatenation operator is now the tilde,
~
).
The XP Language features - among others - support for the following:
- Namespaces (which are called packages)
- Imports, static imports and "on-demand" imports (
import util.*;
) - Varargs syntax
- Distinguishable types for arrays and maps
- Class literal
::class
, andfinally
- also for PHP < 5.5! - Properties with
get
andset
, and Indexers - Syntactic support for the following XP Framework features: Typesafe enumerations, Annotations, Generics, the
with
statement and a throws clause
To get an overview of XP Language's features, these are good reads:
In order to change XP Language and/or the Compiler itself, you need to clone this repository, e.g. using Git Read-Only:
$ cd [path]
$ git clone git://github.com/xp-lang/compiler.git
[path]/compiler
|- ChangeLog.md # Version log
|- README.md # This file
|- module.pth # Module classpath
`- src # Sourcecode, by Maven conventions
|- main
| `- php
`- test
|- php
`- config # Unittest configuration
Add that path to your use
setting before the global module path inside your xp.ini
, e.g.:
use=~/devel/xp-framework/core:~/devel/xp-lang/compiler
^^^^^^^^^^^^^^^^^^^^^^^^
On Windows systems, use ;
as separator
Enjoy!
To contribute, use the GitHub way - fork, hack, and submit a pull request!