xp-lang / compiler
XP Compiler
Requires
- php: >=5.5.0
- xp-framework/collections: ^7.0 | ^6.5
- xp-framework/core: ^8.0 | ^7.0 | ^6.11
- xp-framework/io-collections: ^7.0 | ^6.5
- xp-framework/logging: ^7.0 | ^6.5
- xp-framework/parser: ^7.0 | ^6.0
- xp-framework/patterns: ^7.0 | ^6.6
- xp-framework/tokenize: ^7.0 | ^6.6
Requires (Dev)
- xp-framework/http: ^7.0 | ^6.0
- xp-framework/rdbms: ^7.0 | ^6.0
- xp-framework/unittest: ^7.0 | ^6.5
- xp-framework/xml: ^7.0 | ^6.0
README
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!
Getting started
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!
Differences
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,
~
).
Features
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
Further reading
To get an overview of XP Language's features, these are good reads:
Developing
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
Directory structure
[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
Using it
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!
Contributing
To contribute, use the GitHub way - fork, hack, and submit a pull request!