# Introduction


# Overview

php-parser

&#x20;[![](https://api.travis-ci.org/glayzzle/php-parser.svg?branch=2.2.0)](https://travis-ci.org/glayzzle/php-parser) [![Coverage Status](https://coveralls.io/repos/github/glayzzle/php-parser/badge.svg?branch=master\&v=20170115)](https://coveralls.io/github/glayzzle/php-parser?branch=master) [![](https://badge.fury.io/js/php-parser.svg)](https://www.npmjs.com/package/php-parser) [![](https://img.shields.io/npm/dm/php-parser.svg?style=flat)](https://www.npmjs.com/package/php-parser) [![](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/glayzzle/Lobby) [![](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fglayzzle%2Fphp-parser.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fglayzzle%2Fphp-parser?ref=badge_shield)

This javascript library parses PHP code and convert it to AST.

## Installation

This library is distributed with [npm](https://www.npmjs.com/package/php-parser) :

```bash
npm install php-parser --save
```

## Usage

```javascript
// initialize the php parser factory class
var fs = require('fs');
var path = require('path');
var engine = require('php-parser');

// initialize a new parser instance
var parser = new engine({
  // some options :
  parser: {
    extractDoc: true,
    php7: true
  },
  ast: {
    withPositions: true
  }
});

// Retrieve the AST from the specified source
var eval = parser.parseEval('echo "Hello World";');

// Retrieve an array of tokens (same as php function token_get_all)
var tokens = parser.tokenGetAll('<?php echo "Hello World";');

// Load a static file (Note: this file should exist on your computer)
var phpFile = fs.readFileSync( './example.php' );

// Log out results
console.log( 'Eval parse:', eval );
console.log( 'Tokens parse:', tokens );
console.log( 'File parse:', parser.parseCode(phpFile) );
```

## Sample AST output

```javascript
{
  'kind': 'program',
  'children': [
    {
      'kind': 'echo',
      'arguments': [
        {
          'kind': 'string',
          'isDoubleQuote': true,
          'value': 'Hello World'
        }
      ]
    }
  ]
}
```

* Try it online (demo) : <http://glayzzle.com/php-parser/>
* Or from AST Explorer : <https://astexplorer.net/>

## API Overview

The main API exposes a class with the following methods :

* **parseEval**(String|Buffer) : parse a PHP code in eval style mode (without php open tags)
* **parseCode**(String|Buffer, String filename) : parse a PHP code by using php open tags.
* **tokenGetAll**(String|Buffer) : retrieves a list of all tokens from the specified input.

You can also [pass options](https://github.com/glayzzle/php-parser/wiki/Options) that change the behavior of the parser/lexer.

## Documentation

* [AST nodes definition](https://github.com/glayzzle/php-parser/blob/master/docs/AST.md)
* [List of options](https://github.com/glayzzle/php-parser/wiki/Options)
* [Main API](https://github.com/glayzzle/php-parser/tree/master/docs)
* [Lexer API](https://github.com/glayzzle/php-parser/blob/master/docs/lexer.md)
* [Parser API](https://github.com/glayzzle/php-parser/blob/master/docs/parser.md)

## Related projects

* [prettier/plugin-php](https://github.com/prettier/plugin-php) : Prettier PHP Plugin
* [babel-preset-php](https://gitlab.com/kornelski/babel-preset-php) : Babel preset for converting PHP syntax to JavaScript. It can run subset of PHP in the browser or in Node.js
* [wp-pot](https://github.com/rasmusbe/wp-pot) : Generate pot file for WordPress plugins and themes
* [crane](https://github.com/HvyIndustries/crane) : PHP Intellisense/code-completion for VS Code
* [php-unparser](https://github.com/chris-l/php-unparser) : Produce code that uses the style format recommended by PSR-1 and PSR-2.
* [php-writer](https://github.com/glayzzle/php-writer) : Update PHP scripts from their AST
* [ts-php-inspections](https://github.com/DaGhostman/ts-php-inspections) : Provide PHP code inspections written in typescript
* [php-reflection](https://github.com/glayzzle/php-reflection) : Reflection API for PHP files
* [vscode-phpunit](https://github.com/recca0120/vscode-phpunit) : vscode phpunit extension

> You can add here your own project by opening an issue request.

## License

This library is released under BSD-3 license clause.

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fglayzzle%2Fphp-parser.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fglayzzle%2Fphp-parser?ref=badge_large)


# Demo

!INCLUDE "Demo.html"


# Changelog

### 3.0.0-prerelease.8 : (2019-01-07)

* **235 : invalid ast for `self` and `parent`**
* **234 : regression with parens in `3.0.0-prerelease.7`**
* **230 : `resolvePrecedence` break location for `bin` nodes**
* **202 : \[bug] comment position in lookup**
* **194 : \[feature] implement trailingComments on nodes**
* **185 : \[bug] parens and staticlookup**
* **172 : cast precedence**
* **182 : strange with parens, staticlookup and offsetlookup**
* **167 : staticlookup is broken with curly**
* **239 : \[bug] call should be in ExpressionStatement**
* **207 : \[feature] use `identifier` for `class/interface/trait` name**
* **243 : Regression in prerelease 7 with echo**
* **181 : strange with parens and unary**

### 3.0.0-prerelease.7 : (2018-11-10)

* **201 : \[bug] curly in staticlookup bug**
* **175 : impossible detect curly in `encapsed` AST enhancement**
* **210 : \[bug] invalid ast for `const` enhancement**
* **220 : regression in `rc-6`**
* **204 : \[bug] invalid start offset encapsed AST bug**
* **165 : declare doesn't support inline nodes investigating**

Many thanks to @evilebottnawi for his help

### 3.0.0-prerelease.6 : (2018-10-21)

* fix #113 : Unhandled native identifiers
* fix #183 : `static` parsed as constref
* fix #188 : `constref` vs `identifier`
* impl #196 : identifier for function/method name

### 3.0.0-alpha3 : (2018-08-15)

* fix #168 : End location of `if` without semicolon
* impl #147 : Node informations about Binary and unicode strings
* impl #83 : Adding full support for PHP 7.2
* fix #122 : Detect foreach bad syntax
* impl #152 : Improve tests with JEST
* fix #164 : Fixing some location issues (partial)

### 3.0.0-alpha2 : (2018-04-14)

* fix #137 : Bug with parsing `list`
* fix #149 : Binary cast: isDoubleQuote incorrect
* fix #150 : strange ast with list
* fix #151 : Declare inside if

### 3.0.0-alpha1 : (2018-04-11)

* <https://github.com/glayzzle/php-parser/milestone/10>
* many fixes
* changed the way comments are handled
* add a new `raw` property on some nodes

### 2.2.0 : (2017-12-27)

* Impl #108 : add an option to disable PHP7 support
* Fix #107 : fix T\_DOUBLE\_COLON handler
* Fix #106 : infinite loops from lexer (unput)
* Fix #105 : T\_DOLLAR\_OPEN\_CURLY\_BRACES handles now expressions
* PR #102 : Normalize the way type casts are defined
* Fix #103 : Fix critical cast to null confusion

### 2.1.0 : (2017-11-01)

* Impl #91 & #92 : Functions support reserved names (PHP7)
* Fix #89 : parsing methods can use Buffers or Strings

### 2.0.7 : (2017-09-03)

* Fix #86 : bug on Object properties usage in PHP like `__proto__`, or `constructor`
* Fix #84 : remove null statements from bodies

### 2.0.6 : (2017-07-16)

* Fix precedence between bin, retif, unary
* Fix precedence with assign

### 2.0.4 : (2017-07-09)

* Fix AST errors on suppressErrors
* Add curly boolean on variable node (for `${bar}` syntax)
* Implement the static closure flag, ex: `$c = static function() {};`

### 2.0.0 : (2017-03-04)

* Update AST for operators, unify bin/bool/coalesce nodes
* Fix nested block usage on function bodies
* Avoid initial $ on variables
* Shell nodes are now exposed by encapsed nodes only
* Typescript definition file
* Avoid identifier nodes on namespaces & use statements
* Fix precedence on bin, unary, retif nodes
* Fix ending position on functions/methods/closures
* Fix lexer unput at the end of the file (infinite loops)
* Add encapsed node (type=offset) on dynamic offsets
* Implement annonymous class arguments
* Fix missing first char on encapsed T\_STRING\_VARNAME

### 1.0.0 : (2017-01-03)

* All nodes are now converted to objects
* Bruteforce tests are in a separate project
* Improved tests with mocha
* Many syntax fixes
* Tests over a silent error mode
* Release of a complete AST documentation

### 0.1.5 : (2016-12-27)

> The 0.1.x version starts to be deprecated

* Fix closure use token
* Improve silent errors handler
* Pass PHP7 tests
* Update class, traits, interface declarations
* Many syntax fixes

### 0.1.4 : (2016-12-12)

* Move from static instances to instanciated objects in order to fully handle

  promises
* Fix the silentLexer
* Fix the debug output mode
* Add positions on `expr->set`

### Older releases

* 0.1.3  : add comments nodes, add a browser version and improved parser stability
* 0.1.0  : major release, rewriting of the lexer and many bug fixes
* 0.0.10 : bugfixes and php7 implementation
* 0.0.9  : const (value as expr) bugfix
* 0.0.8  : all tokens are passed on ZF2 (many fixes)
* 0.0.7  : isset, unset, try, catch, finally, fix T\_STATIC, fix T\_NEW with a dynamic var name, improve tests
* 0.0.6  : Improve tests, implements arrays & new statements
* 0.0.5  : Implement traits


# Todo


# Options

When you call the parser you can pass options as following :

```javascript
var reader = require('php-parser');
reader.parseCode('<?php echo true;', {
  parser: {
    debug: false, 
    locations: false,
    extractDoc: false,
    suppressErrors: false
  },
  ast: {
    withPositions: true,
    withSource: true
  },
  lexer: {
    all_tokens: false,
    comment_tokens: false,
    mode_eval: false,
    asp_tags: false,
    short_tags: false
  }
});
```

## Parser

* debug : enables debug output, useful for handling parsing errors when extending the library.
* locations : attach location nodes to AST - [see more details](https://github.com/glayzzle/php-parser/wiki/Nodes-positions)
* extractDoc : extracting comments blocks - [see more details](https://github.com/glayzzle/php-parser/wiki/Annotations)
* suppressErrors: graceful parsing mode, when an error is raised it's ignored [see more details](https://github.com/glayzzle/php-parser/wiki/Graceful-mode)

## Lexer

* all\_tokens : extract all tokens (same output as `token_get_all` function in PHP)
* comment\_tokens: extract also comments tokens (used when all\_tokens is false)
* mode\_eval: ignoring open or close tags, the input is directly a PHP script
* asp\_tags: handles ASP like tags `<%` and `%>`
* short\_tags : handle short opening tag `<?`


# Parser

## Constants

[ignoreStack](/api/parser.js#ignoreStack)

outputs some debug information on current token

## parser

**Kind**: global class\
**Properties**

| Name           | Type                  | Description                               |
| -------------- | --------------------- | ----------------------------------------- |
| lexer          | `Lexer`               | current lexer instance                    |
| ast            | `AST`                 | the AST factory instance                  |
| token          | `Integer` \| `String` | current token                             |
| extractDoc     | `Boolean`             | should extract documentation as AST node  |
| extractTokens  | `Boolean`             | should extract each token                 |
| suppressErrors | `Boolean`             | should ignore parsing errors and continue |
| debug          | `Boolean`             | should output debug informations          |

* [parser](/api/parser.js#parser)
  * [.getTokenName()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+getTokenName)
  * [.parse()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+parse)
  * [.raiseError()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+raiseError)
  * [.error()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+error)
  * [.node()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+node)
  * [.expectEndOfStatement()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+expectEndOfStatement) ⇒ `boolean`
  * [.expect(token)](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+expect) ⇒ `boolean`
  * [.text()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+text) ⇒ `String`
  * [.next()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+next)
  * [.lex()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+lex)
  * [.is()](https://php-parser.glayzzle.com/api/pages/-L_3rojE0q9u57zp52X5#parser+is)

### parser.getTokenName()

helper : gets a token name

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.parse()

main entry point : converts a source code to AST

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.raiseError()

Raise an error

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.error()

handling errors

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.node()

Creates a new AST node

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.expectEndOfStatement() ⇒ `boolean`

expects an end of statement or end of file

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.expect(token) ⇒ `boolean`

Force the parser to check the current token.

If the current token does not match to expected token, the an error will be raised.

If the suppressError mode is activated, then the error will be added to the program error stack and this function will return `false`.

**Kind**: instance method of [`parser`](/api/parser.js#parser)\
**Throws**:

* Error

| Param | Type                 |
| ----- | -------------------- |
| token | `String` \| `Number` |

### parser.text() ⇒ `String`

Returns the current token contents

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.next()

consume the next token

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.lex()

Eating a token

**Kind**: instance method of [`parser`](/api/parser.js#parser)<br>

### parser.is()

Check if token is of specified type

## Constants

stance method of [`parser`](/api/parser.js#parser)

oreStack">\</a>

[ignoreStack](/api/parser.js#ignoreStack)

outputs some debug information on current tokenck debug information on current token \</dl> **Kind**: global constant

## API

* [array.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/array.js.md)
* [class.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/class.js.md)
* [comment.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/comment.js.md)
* [expr.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/expr.js.md)
* [function.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/function.js.md)
* [if.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/if.js.md)
* [loops.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/loops.js.md)
* [main.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/main.js.md)
* [namespace.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/namespace.js.md)
* [scalar.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/scalar.js.md)
* [statement.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/statement.js.md)
* [switch.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/switch.js.md)
* [try.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/try.js.md)
* [utils.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/utils.js.md)
* [variable.js](https://github.com/glayzzle/php-parser.glayzzle.com/tree/392b36f46748fbb049e5901bfce9a78bf1d0e48f/api/docs/api/variable.js.md)


# AST

You can see the AST as a DOM document, the source code of the program beeing the graphical text output, and the DOM beeing a representation of it.

The main node is the program node, and it's structured like this :

```javascript
  {
    "kind": "program",
    "children": [
      // array of nodes
    ]
  }
```

## Nodes

Every node has a common structure enabling you to scan them and act accordingly.

NOTE : This structure depends also on what options you enable.

```javascript
  {
    "kind": "node name",
    "loc": {
      ""
    },
    // the location node
    "loc": {
      "source": "original source code of the node",
      "start": {
        "line": 1, // 1 based
        "column": 0, // 0 based
        "offset": 0 // offset from the source code
      },
      "end": {
        // same structure as start
      }
    },
    "leadingComments": [
      // array of comments nodes
    ]
  }
```

## Nodes hierarchy

* [Location](/api/ast.js#location)
* [Position](/api/ast.js#position)
* [Node](/api/ast.js#node)
  * [Identifier](/api/ast.js#identifier)
  * [TraitUse](/api/ast.js#traituse)
  * [TraitAlias](/api/ast.js#traitalias)
  * [TraitPrecedence](/api/ast.js#traitprecedence)
  * [Entry](/api/ast.js#entry)
  * [Case](/api/ast.js#case)
  * [Label](/api/ast.js#label)
  * [Comment](/api/ast.js#comment)
    * [CommentLine](/api/ast.js#commentline)
    * [CommentBlock](/api/ast.js#commentblock)
  * [Error](/api/ast.js#error)
  * [Expression](/api/ast.js#expression)
    * [Array](/api/ast.js#array)
    * [Variable](/api/ast.js#variable)
    * [Variadic](/api/ast.js#variadic)
    * [ConstRef](/api/ast.js#constref)
    * [Yield](/api/ast.js#yield)
    * [YieldFrom](/api/ast.js#yieldfrom)
    * [Lookup](/api/ast.js#lookup)
      * [PropertyLookup](/api/ast.js#propertylookup)
      * [StaticLookup](/api/ast.js#staticlookup)
      * [OffsetLookup](/api/ast.js#offsetlookup)
    * [Operation](/api/ast.js#operation)
      * [Pre](/api/ast.js#pre)
      * [Post](/api/ast.js#post)
      * [Bin](/api/ast.js#bin)
      * [Parenthesis](/api/ast.js#parenthesis)
      * [Unary](/api/ast.js#unary)
      * [Cast](/api/ast.js#cast)
    * [Literal](/api/ast.js#literal)
      * [Boolean](/api/ast.js#boolean)
      * [String](/api/ast.js#string)
      * [Number](/api/ast.js#number)
      * [Inline](/api/ast.js#inline)
      * [Magic](/api/ast.js#magic)
      * [Nowdoc](/api/ast.js#nowdoc)
      * [Encapsed](/api/ast.js#encapsed)
  * [Statement](/api/ast.js#statement)
    * [Eval](/api/ast.js#eval)
    * [Exit](/api/ast.js#exit)
    * [Halt](/api/ast.js#halt)
    * [Clone](/api/ast.js#clone)
    * [Declare](/api/ast.js#declare)
    * [Global](/api/ast.js#global)
    * [Static](/api/ast.js#static)
    * [Include](/api/ast.js#include)
    * [Assign](/api/ast.js#assign)
    * [RetIf](/api/ast.js#retif)
    * [If](/api/ast.js#if)
    * [Do](/api/ast.js#do)
    * [While](/api/ast.js#while)
    * [For](/api/ast.js#for)
    * [Foreach](/api/ast.js#foreach)
    * [Switch](/api/ast.js#switch)
    * [Goto](/api/ast.js#goto)
    * [Silent](/api/ast.js#silent)
    * [Try](/api/ast.js#try)
    * [Catch](/api/ast.js#catch)
    * [Throw](/api/ast.js#throw)
    * [Call](/api/ast.js#call)
    * [Closure](/api/ast.js#closure)
    * [New](/api/ast.js#new)
    * [UseGroup](/api/ast.js#usegroup)
    * [UseItem](/api/ast.js#useitem)
    * [Block](/api/ast.js#block)
      * [Program](/api/ast.js#program)
      * [Namespace](/api/ast.js#namespace)
    * [Sys](/api/ast.js#sys)
      * [Echo](/api/ast.js#echo)
      * [List](/api/ast.js#list)
      * [Print](/api/ast.js#print)
      * [Isset](/api/ast.js#isset)
      * [Unset](/api/ast.js#unset)
      * [Empty](/api/ast.js#empty)
    * [Declaration](/api/ast.js#declaration)
      * [Class](/api/ast.js#class)
      * [Interface](/api/ast.js#interface)
      * [Trait](/api/ast.js#trait)
      * [Constant](/api/ast.js#constant)
        * [ClassConstant](/api/ast.js#classconstant)
      * [Function](/api/ast.js#function)
        * [Method](/api/ast.js#method)
      * [Parameter](/api/ast.js#parameter)
      * [Property](/api/ast.js#property)

## AST

**Kind**: global class\
**Properties**

| Name          | Type      | Description                                              |
| ------------- | --------- | -------------------------------------------------------- |
| withPositions | `Boolean` | Should locate any node (by default false)                |
| withSource    | `Boolean` | Should extract the node original code (by default false) |

* [AST](/api/ast.js#AST)
  * [.swapLocations()](https://php-parser.glayzzle.com/api/pages/-L_3rojFGMhK2rRrTLxA#AST+swapLocations)
  * [.resolvePrecedence()](https://php-parser.glayzzle.com/api/pages/-L_3rojFGMhK2rRrTLxA#AST+resolvePrecedence)
  * [.prepare(kind, parser)](https://php-parser.glayzzle.com/api/pages/-L_3rojFGMhK2rRrTLxA#AST+prepare) ⇒ `function`

### asT.swapLocations()

Change parent node informations after swapping childs

**Kind**: instance method of [`AST`](/api/ast.js#AST)<br>

### asT.resolvePrecedence()

Check and fix precence, by default using right

**Kind**: instance method of [`AST`](/api/ast.js#AST)<br>

### asT.prepare(kind, parser) ⇒ `function`

Prepares an AST node

**Kind**: instance method of [`AST`](/api/ast.js#AST)

| Param  | Type               | Description                                                                   |
| ------ | ------------------ | ----------------------------------------------------------------------------- |
| 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)                            |


# Lexer

## lexer

**Kind**: global class\
**Properties**

| Name            | Type      | Description                                                            |
| --------------- | --------- | ---------------------------------------------------------------------- |
| EOF             | `Integer` |                                                                        |
| all\_tokens     | `Boolean` | defines if all tokens must be retrieved (used by token\_get\_all only) |
| comment\_tokens | `Boolean` | extracts comments tokens                                               |
| mode\_eval      | `Boolean` | enables the evald mode (ignore opening tags)                           |
| asp\_tags       | `Boolean` | disables by default asp tags mode                                      |
| short\_tags     | `Boolean` | enables by default short tags mode                                     |
| keywords        | `Object`  | List of php keyword                                                    |
| castKeywords    | `Object`  | List of php keywords for type casting                                  |

* [lexer](/api/lexer.js#lexer)
  * [.setInput()](https://php-parser.glayzzle.com/api/pages/-L_3rojGjS83lWsvW2zE#lexer+setInput)
  * [.input()](https://php-parser.glayzzle.com/api/pages/-L_3rojGjS83lWsvW2zE#lexer+input)
  * [.unput()](https://php-parser.glayzzle.com/api/pages/-L_3rojGjS83lWsvW2zE#lexer+unput)
  * [.getState()](https://php-parser.glayzzle.com/api/pages/-L_3rojGjS83lWsvW2zE#lexer+getState)
  * [.setState()](https://php-parser.glayzzle.com/api/pages/-L_3rojGjS83lWsvW2zE#lexer+setState)

### lexer.setInput()

Initialize the lexer with the specified input

**Kind**: instance method of [`lexer`](/api/lexer.js#lexer)<br>

### lexer.input()

consumes and returns one char from the input

**Kind**: instance method of [`lexer`](/api/lexer.js#lexer)<br>

### lexer.unput()

revert eating specified size

**Kind**: instance method of [`lexer`](/api/lexer.js#lexer)<br>

### lexer.getState()

Gets the current state

**Kind**: instance method of [`lexer`](/api/lexer.js#lexer)<br>

### lexer.setState()

Sets the current lexer state

**Kind**: instance method of [`lexer`](/api/lexer.js#lexer)


