1.0.8 • Published 6 years ago
php7parser v1.0.8
php7parser
A fast and forgiving PHP7 recursive descent parser implemented in Typescript.
The parser outputs a parse tree of phrases (branches) and tokens (leaves). The complete source code is represented by the tree including whitespace.
Design Goals
- Modern browser and nodejs compatibility.
- Error tolerant and high performance.
- Output representative of full source code.
- Adherance to the PHP language specifications.
- Prefer error tolerance over enforcement of language constraints.
Usage
import { Parser } from 'php7parser';
let src = '<?php echo "Hello World!";';
let tree = Parser.parse(src);
Interface
export declare namespace Parser {
function parse(text: string): Phrase;
}
export interface Phrase {
/**
* Phrase type
*/
phraseType: PhraseType;
/**
* Phrase and token child nodes
*/
children: (Phrase | Token)[];
}
export interface ParseError extends Phrase {
/**
* The token that prompted the parse error
*/
unexpected: Token;
/**
* The expected token type
*/
expected?: TokenType;
}
export interface Token {
/**
* Token type
*/
tokenType: TokenType;
/**
* Offset within source where first char of token is found
*/
offset: number;
/**
* Length of token string
*/
length: number;
/**
* Lexer mode prior to this token being read.
*/
modeStack: LexerMode[];
}
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.9.9
7 years ago
0.9.8
7 years ago
0.9.7
7 years ago
0.9.6
7 years ago
0.9.5
7 years ago
0.9.4
7 years ago
0.9.3
7 years ago
0.9.2
7 years ago
0.9.1
7 years ago
0.9.0
7 years ago