2017 © Pedro Peláez
 

library compiler

AST for the XP Framework

image

xp-framework/compiler

AST for the XP Framework

  • Sunday, June 24, 2018
  • by thekid
  • Repository
  • 1 Watchers
  • 1 Stars
  • 697 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 8 Open issues
  • 42 Versions
  • 30 % Grown

The README.md

XP Compiler

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.4+ Supports PHP 8.0+ Latest Stable Version, (*1)

Compiles future PHP to today's PHP., (*2)

Usage

After adding the compiler to your project via composer require xp-framework/compiler, it will hook into the class loading chain and compile .php-files on-demand. This keeps the efficient code-save-reload/rerun development process typical for PHP., (*3)

Example

The following code uses Hack language, PHP 8.4, PHP 8.3, PHP 8.2, 8.1 and 8.0 features but runs on anything >= PHP 7.4. Builtin features from newer PHP versions are translated to work with the currently executing runtime if necessary., (*4)

<?php // In a file "HelloWorld.php"

use lang\Reflection;
use util\Date;
use util\cmd\Console;

#[Author('Timm Friebe')]
#[Permissions(0o777)]
class HelloWorld {
  private const string GREETING= 'Hello';

  public static function main(array<string> $args): void {
    $greet= fn($to, $from) => self::GREETING.' '.$to.' from '.$from;
    $author= Reflection::type(self::class)->annotation(Author::class)->argument(0);

    Console::writeLine(new Date()->toString(), ': ', $greet($args[0] ?? 'World', from: $author));
  }
}

To run this code, use xp -m /path/to/xp/reflection HelloWorld in a terminal window., (*5)

Compilation

Compilation can also be performed explicitely by invoking the compiler:, (*6)

# Compile code and write result to a class file
$ xp compile HelloWorld.php HelloWorld.class.php

# Compile standard input and write to standard output.
$ echo "<?php ..." | xp compile -

# Compile src/main/php and src/test/php to the dist folder.
$ xp compile -o dist src/main/php/ src/test/php/

# Compile src/main/php to the dist.xar archive
$ xp compile -o dist.xar src/main/php/

# Compile src/main/php, do not write output
$ xp compile -n src/main/php/

# Target PHP 7.4 (default target is current PHP version)
$ xp compile -t php:7.4 HelloWorld.php HelloWorld.class.php

# Emit XP meta information (includes lang.ast.emit.php.XpMeta):
$ xp compile -t php:7.4 -a php:xp-meta -o dist src/main/php

The -o and -n options accept multiple input sources following them. The -q option suppresses all diagnostic output except for errors., (*7)

Features supported

XP Compiler supports features such as annotations, arrow functions, enums, property type-hints, the null-safe instance operator as well as all PHP 7 and PHP 8 syntax additions. A complete list including examples can be found in our Wiki., (*8)

More features

Additional syntax like an is operator, generics or record types can be added by installing compiler plugins from here:, (*9)

$ composer require xp-lang/php-is-operator
# ...

$ xp compile
Usage: xp compile <in> [<out>]

@FileSystemCL<./vendor/xp-framework/compiler/src/main/php>
lang.ast.emit.PHP74
lang.ast.emit.PHP80
lang.ast.emit.PHP81
lang.ast.emit.PHP82
lang.ast.emit.PHP83 [*]
lang.ast.emit.PHP84
lang.ast.emit.PHP85
lang.ast.syntax.php.Using [*]

@FileSystemCL<./vendor/xp-lang/php-is-operator/src/main/php>
lang.ast.syntax.php.IsOperator

Implementation status

Some features from newer PHP versions as well as Hack language are still missing. The goal, however, is to have all features implemented - with the exception of where Hack's direction conflicts with PHP! An overview can be seen on this Wiki page., (*10)

To contribute, open issues and/or pull requests., (*11)

See also

The Versions

24/06 2018

dev-refactor/errors

dev-refactor/errors http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

24/06 2018

dev-master

9999999-dev http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

24/06 2018

v2.10.1

2.10.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

21/06 2018

v2.10.0

2.10.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

19/06 2018

v2.9.0

2.9.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

17/06 2018

v2.8.0

2.8.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

16/06 2018

v2.7.0

2.7.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

16/06 2018

v2.6.2

2.6.2.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

10/06 2018

v2.6.1

2.6.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

10/06 2018

v2.6.0

2.6.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

10/06 2018

v2.5.1

2.5.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

09/06 2018

v2.5.0

2.5.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

08/06 2018

v2.4.0

2.4.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

02/04 2018

v2.3.0

2.3.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

02/04 2018

dev-feature/using

dev-feature/using http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

30/03 2018

v2.2.0

2.2.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

29/03 2018

v2.1.0

2.1.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

26/02 2018

dev-feature/compile-to-dir

dev-feature/compile-to-dir http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

25/02 2018

v2.0.5

2.0.5.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

19/11 2017

v2.0.4

2.0.4.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

16/11 2017

v2.0.3

2.0.3.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

14/11 2017

v2.0.2

2.0.2.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

06/11 2017

v2.0.1

2.0.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

06/11 2017

v2.0.0

2.0.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

04/11 2017

v1.4.0

1.4.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

04/11 2017

v1.3.0

1.3.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

31/10 2017

v1.2.1

1.2.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

31/10 2017

v1.2.0

1.2.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

31/10 2017

v1.1.2

1.1.2.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

31/10 2017

v1.1.1

1.1.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

31/10 2017

v1.1.0

1.1.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

25/10 2017

v1.0.0

1.0.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

22/10 2017

v0.9.1

0.9.1.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

22/10 2017

v0.9.0

0.9.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

18/10 2017

v0.8.0

0.8.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/10 2017

v0.7.0

0.7.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/10 2017

v0.6.0

0.6.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/10 2017

v0.5.0

0.5.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/10 2017

v0.4.0

0.4.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

15/10 2017

v0.3.0

0.3.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

14/10 2017

v0.2.0

0.2.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp

14/10 2017

v0.1.0

0.1.0.0 http://xp-framework.net/

AST for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

module xp