All Projects β†’ glayzzle β†’ Php Parser

glayzzle / Php Parser

Licence: bsd-3-clause
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Php Parser

Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (+6.25%)
Mutual labels:  ast, lexer, parser
Charly Vm
Fibers, Closures, C-Module System | NaN-boxing, bytecode-VM written in C++
Stars: ✭ 66 (-83.5%)
Mutual labels:  ast, lexer, parser
Works For Me
Collection of developer toolkits
Stars: ✭ 131 (-67.25%)
Mutual labels:  tokenizer, lexer, parser
pascal-interpreter
A simple interpreter for a large subset of Pascal language written for educational purposes
Stars: ✭ 21 (-94.75%)
Mutual labels:  tokenizer, ast, lexer
Participle
A parser library for Go
Stars: ✭ 2,302 (+475.5%)
Mutual labels:  ast, lexer, parser
bredon
A modern CSS value compiler in JavaScript
Stars: ✭ 39 (-90.25%)
Mutual labels:  tokenizer, ast, lexer
Csstree
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations
Stars: ✭ 1,121 (+180.25%)
Mutual labels:  ast, lexer, parser
Graphql Go Tools
Tools to write high performance GraphQL applications using Go/Golang.
Stars: ✭ 96 (-76%)
Mutual labels:  ast, lexer, parser
Query Translator
Query Translator is a search query translator with AST representation
Stars: ✭ 165 (-58.75%)
Mutual labels:  ast, tokenizer, parser
Lioness
The Lioness Programming Language
Stars: ✭ 155 (-61.25%)
Mutual labels:  ast, lexer, parser
Cub
The Cub Programming Language
Stars: ✭ 198 (-50.5%)
Mutual labels:  ast, lexer, parser
Snapdragon
snapdragon is an extremely pluggable, powerful and easy-to-use parser-renderer factory.
Stars: ✭ 180 (-55%)
Mutual labels:  ast, lexer, parser
Exprtk
C++ Mathematical Expression Parsing And Evaluation Library
Stars: ✭ 301 (-24.75%)
Mutual labels:  ast, lexer, parser
standard-packages
List of packages that use `standard`
Stars: ✭ 32 (-92%)
Mutual labels:  development, static-code-analysis
unimport
A linter, formatter for finding and removing unused import statements.
Stars: ✭ 119 (-70.25%)
Mutual labels:  static-code-analysis, ast
ocean
Programming language that compiles into a x86 ELF executable.
Stars: ✭ 164 (-59%)
Mutual labels:  ast, lexer
Swiftpascalinterpreter
Simple Swift interpreter for the Pascal language inspired by the Let’s Build A Simple Interpreter article series.
Stars: ✭ 270 (-32.5%)
Mutual labels:  ast, lexer
Verible
Verible is a suite of SystemVerilog developer tools, including a parser, style-linter, and formatter.
Stars: ✭ 384 (-4%)
Mutual labels:  lexer, parser
Bblfshd
A self-hosted server for source code parsing
Stars: ✭ 297 (-25.75%)
Mutual labels:  ast, parser
Awesome Standard
Documenting the explosion of packages in the standard ecosystem!
Stars: ✭ 300 (-25%)
Mutual labels:  development, static-code-analysis

php-parser

Coverage Status

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

Installation

This library is distributed with npm :

npm install php-parser --save

Usage

// 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

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

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 that change the behavior of the parser/lexer.

Documentation

Related projects

  • prettier/plugin-php : Prettier PHP Plugin
  • 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 : Generate pot file for WordPress plugins and themes
  • crane : PHP Intellisense/code-completion for VS Code
  • php-unparser : Produce code that uses the style format recommended by PSR-1 and PSR-2.
  • php-writer : Update PHP scripts from their AST
  • ts-php-inspections : Provide PHP code inspections written in typescript
  • php-reflection : Reflection API for PHP files
  • vscode-phpunit : vscode phpunit extension
  • lua2php : a Lua to PHP transpiler

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

License

This library is released under BSD-3 license clause.

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].