Skip to content

Latest commit

 

History

History
1260 lines (758 loc) · 25.7 KB

File metadata and controls

1260 lines (758 loc) · 25.7 KB

AST

Class hierarchy


Parameters

  • withPositions
  • withSource

resolvePrecedence

Check and fix precence, by default using right

Parameters

  • result

prepare

Prepares an AST node

Parameters

  • kind (String | null) Defines the node type (if null, the kind must be passed at the function call)
  • parser Parser The parser instance (use for extracting locations)

Returns Function

AST

The AST builder class

Parameters

  • withPositions
  • withSource

Properties

  • withPositions Boolean Should locate any node (by default false)
  • withSource Boolean Should extract the node original code (by default false)

resolvePrecedence

Check and fix precence, by default using right

Parameters

  • result

prepare

Prepares an AST node

Parameters

  • kind (String | null) Defines the node type (if null, the kind must be passed at the function call)
  • parser Parser The parser instance (use for extracting locations)

Returns Function

Array

Extends Expression

Defines an array structure

Properties

  • items Array<Entry> List of array items
  • shortForm boolean Indicate if the short array syntax is used, ex [] instead array()

Examples

// PHP code :
[1, 'foo' => 'bar', 3]

// AST structure :
{
 "kind": "array",
 "shortForm": true
 "items": [{
   "kind": "entry",
   "key": null,
   "value": {"kind": "number", "value": "1"}
 }, {
   "kind": "entry",
   "key": {"kind": "string", "value": "foo", "isDoubleQuote": false},
   "value": {"kind": "string", "value": "bar", "isDoubleQuote": false}
 }, {
   "kind": "entry",
   "key": null,
   "value": {"kind": "number", "value": "3"}
 }]
}

Assign

Extends Statement

Assigns a value to the specified target

Properties

Bin

Extends Operation

Binary operations

Properties

Block

Extends Statement

A block statement, i.e., a sequence of statements surrounded by braces.

Properties

Boolean

Extends Literal

Defines a boolean value (true/false)

Break

Extends Node

A break statement

Properties

Call

Extends Statement

Executes a call statement

Properties

  • arguments Array<Arguments>

Case

Extends Node

A switch case statement

Properties

  • test (Expression | null) if null, means that the default case
  • body (Block | null)

Cast

Extends Operation

Binary operations

Properties

Catch

Extends Statement

Defines a catch statement

Properties

Class

Extends Declaration

A class definition

Properties

ClassConstant

Extends Constant

Defines a class/interface/trait constant

Properties

Clone

Extends Statement

Defines a clone call

Properties

Closure

Extends Statement

Defines a closure

Properties

Constant

Extends Declaration

Defines a namespace constant

Properties

  • value (Node | null)

ConstRef

Extends Expression

A constant reference

Properties

Continue

Extends Node

A continue statement

Properties

Declaration

Extends Statement

A declaration statement (function, class, interface...)

Properties

parseFlags

Generic flags parser

Parameters

Returns void

Declare

Extends Block

The declare construct is used to set execution directives for a block of code

Properties

MODE_SHORT

The node is declared as a short tag syntax :

<?php
declare(ticks=1):
// some statements
enddeclare;

Type: String

MODE_BLOCK

The node is declared bracket enclosed code :

<?php
declare(ticks=1) {
// some statements
}

Type: String

MODE_NONE

The node is declared as a simple statement. In order to make things simpler children of the node are automatically collected until the next declare statement.

<?php
declare(ticks=1);
// some statements
declare(ticks=2);
// some statements

Type: String

Do

Extends Statement

Defines a do/while statement

Properties

Documentation

Extends Node

A comment or documentation

Properties

Echo

Extends Sys

Defines system based call

Empty

Extends Sys

Defines an empty check call

Encapsed

Extends Literal

Defines an encapsed string (contains expressions)

Properties

  • type String Defines the type of encapsed string (shell, heredoc, string)
  • label (String | Null) The heredoc label, defined only when the type is heredoc

TYPE_STRING

The node is a double quote string :

<?php
echo "hello $world";

Type: String

TYPE_SHELL

The node is a shell execute string :

<?php
echo `ls -larth $path`;

Type: String

TYPE_HEREDOC

The node is a shell execute string :

<?php
echo <<<STR
 Hello $world
STR
;

Type: String

TYPE_OFFSET

The node contains a list of constref / variables / expr :

<?php
echo $foo->bar_$baz;

Type: String

Entry

Extends Node

An array entry - see Array

Properties

  • key (Node | null) The entry key/offset
  • value Node The entry value

Error

Extends Node

Defines an error node (used only on silentMode)

Properties

Eval

Extends Statement

Defines an eval statement

Properties

Exit

Extends Statement

Defines an exit / die call

Properties

  • status (Node | null)

Expression

Extends Node

Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.

For

Extends Statement

Defines a for iterator

Properties

Foreach

Extends Statement

Defines a foreach iterator

Properties

Function

Extends Declaration

Defines a classic function

Properties

Global

Extends Statement

Imports a variable from the global scope

Properties

Goto

Extends Statement

Defines goto statement

Properties

Halt

Extends Statement

Halts the compiler execution

Properties

  • after String String after the halt statement

Identifier

Extends Node

Defines an identifier node

Properties

UNQUALIFIED_NAME

This is an identifier without a namespace separator, such as Foo

Type: String

QUALIFIED_NAME

This is an identifier with a namespace separator, such as Foo\Bar

Type: String

FULL_QUALIFIED_NAME

This is an identifier with a namespace separator that begins with a namespace separator, such as \Foo\Bar. The namespace \Foo is also a fully qualified name.

Type: String

RELATIVE_NAME

This is an identifier starting with namespace, such as namespace\Foo\Bar.

Type: String

If

Extends Statement

Defines a if statement

Properties

Include

Extends Statement

Defines system include call

Properties

Inline

Extends Literal

Defines inline html output (treated as echo output)

Interface

Extends Declaration

An interface definition

Properties

Isset

Extends Sys

Defines an isset call

Label

Extends Node

A label statement (referenced by goto)

Properties

List

Extends Sys

Defines list assignment

Literal

Extends Expression

Defines an array structure

Properties

Location

Defines the location of the node (with it's source contents as string)

Parameters

  • source
  • start
  • end

Properties

Lookup

Extends Expression

Lookup on an offset in the specified object

Properties

Magic

Extends Literal

Defines magic constant

Method

Extends Function

Defines a class/interface/trait method

Properties

Namespace

Extends Block

The main program node

Properties

New

Extends Statement

Creates a new instance of the specified class

Properties

Node

A generic AST node

Parameters

  • kind
  • location

Properties

extends

Helper for extending the Node class

Parameters

Returns Function

String

Extends Literal

Defines a nowdoc string

Properties

String

Extends Literal

Defines a string (simple ou double quoted) - chars are already escaped

Properties

Number

Extends Literal

Defines a numeric value

OffsetLookup

Extends Lookup

Lookup on an offset in an array

Operation

Extends Expression

Defines binary operations

Parameter

Extends Declaration

Defines a function parameter

Properties

Parenthesis

Extends Operation

Parenthesis encapsulation (... expr ...)

Properties

Position

Each Position object consists of a line number (1-indexed) and a column number (0-indexed):

Parameters

  • line
  • column
  • offset

Properties

Post

Extends Operation

Defines a post operation $i++ or $i--

Properties

Pre

Extends Operation

Defines a pre operation ++$i or --$i

Properties

Print

Extends Sys

Outputs

Program

Extends Block

The main program node

Properties

Property

Extends Declaration

Defines a class property

Properties

PropertyLookup

Extends Lookup

Lookup to an object property

RetIf

Extends Statement

Defines a short if statement that returns a value

Properties

Return

Extends Node

A continue statement

Properties

Silent

Extends Statement

Avoids to show/log warnings & notices from the inner expression

Properties

Statement

Extends Node

Any statement.

Static

Extends Statement

Declares a static variable into the current scope

Properties

StaticLookup

Extends Lookup

Lookup to a static property

Switch

Extends Statement

Defines a switch statement

Properties

Sys

Extends Statement

Defines system based call

Properties

Throw

Extends Statement

Defines a throw statement

Properties

Trait

Extends Declaration

A trait definition

Properties

TraitAlias

Extends Node

Defines a trait alias

Properties

TraitPrecedence

Extends Node

Defines a trait alias

Properties

TraitUse

Extends Node

Defines a trait usage

Properties

Try

Extends Statement

Defines a try statement

Properties

Unary

Extends Operation

Unary operations

Properties

Unset

Extends Sys

Deletes references to a list of variables

UseGroup

Extends Statement

Defines a use statement (with a list of use items)

Properties

UseItem

Extends Statement

Defines a use statement (from namespace)

Properties

TYPE_CONST

Importing a constant

Type: String

TYPE_FUNC

Importing a function

Type: String

Variable

Extends Expression

Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.

Properties

  • name (String | Node) The variable name (can be a complex expression when the name is resolved dynamically)
  • byref boolean Indicate if the variable reference is used, ex &$foo
  • curly boolean Indicate if the name is defined between curlies, ex ${foo}

Examples

// PHP code :
&$foo
// AST output
{
 "kind": "variable",
 "name": "foo",
 "byref": true,
 "curly": false
}

Variadic

Extends Expression

Introduce a list of items into the arguments of the call

Properties

While

Extends Statement

Defines a while statement

Properties

Yield

Extends Expression

Defines a yield generator statement

Properties

YieldFrom

Extends Expression

Defines a yield from generator statement

Properties