Skip to content

Commit 7d47ac9

Browse files
committed
remove unused vars & update docs
1 parent 9660945 commit 7d47ac9

File tree

4 files changed

+89
-100
lines changed

4 files changed

+89
-100
lines changed

docs/README.md

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,36 @@
22

33
# engine
44

5+
Initialise a new parser instance with the specified options
6+
7+
Usage :
8+
9+
```js
10+
var parser = require('php-parser');
11+
var instance = new parser({
12+
parser: {
13+
extractDoc: true,
14+
suppressErrors: true
15+
},
16+
ast: {
17+
withPositions: true
18+
},
19+
lexer: {
20+
short_tags: true,
21+
asp_tags: true
22+
}
23+
});
24+
25+
var evalAST = instance.parseEval('some php code');
26+
var codeAST = instance.parseCode('<?php some php code', 'foo.php');
27+
var tokens = instance.tokenGetAll('<?php some php code');
28+
```
29+
530
Type: Engine
631

732
**Parameters**
833

9-
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
34+
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** List of options
1035

1136
**Properties**
1237

@@ -17,13 +42,13 @@ Type: Engine
1742

1843
## parseEval
1944

20-
parsing eval string as '$x = 1;'
45+
Parse an evaluating mode string (no need to open php tags)
2146

2247
**Parameters**
2348

24-
- `buffer`
49+
- `buffer` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
2550

26-
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)**
51+
Returns **Program**
2752

2853
## parseCode
2954

@@ -54,63 +79,12 @@ Returns **Program**
5479

5580
## tokenGetAll
5681

57-
split the buffer into tokens
58-
59-
**Parameters**
60-
61-
- `buffer`
62-
63-
## create
64-
65-
Creates a new instance
66-
67-
**Parameters**
68-
69-
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
70-
71-
Returns **Engine**
72-
73-
## parseEval
74-
75-
Evaluate the buffer
76-
77-
**Parameters**
78-
79-
- `buffer`
80-
- `options`
81-
82-
## parseCode
83-
84-
Static function that parse a php code with open/close tags
85-
86-
Sample code :
87-
88-
```php
89-
<?php $x = 1;
90-
```
91-
92-
Usage :
93-
94-
```js
95-
var parser = require('php-parser');
96-
var ast = parser.parseCode('...php code...', 'foo.php');
97-
```
98-
99-
**Parameters**
100-
101-
- `buffer` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The code to be parsed
102-
- `filename` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Filename
103-
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional options
104-
105-
Returns **Program**
106-
107-
## tokenGetAll
82+
Extract tokens from the specified buffer.
10883

109-
Split the buffer into tokens
84+
> Note that the output tokens are _STRICLY_ similar to PHP function `token_get_all`
11085
11186
**Parameters**
11287

113-
- `buffer`
114-
- `options`
88+
- `buffer` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)**
11589

116-
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>**
90+
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Each item can be a string or an array with following informations [token_name, text, line_number]

docs/parser.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
# parser
44

5-
The PHP Parser class
5+
The PHP Parser class that build the AST tree from the lexer
6+
7+
Type: Parser
68

79
**Parameters**
810

@@ -11,11 +13,12 @@ The PHP Parser class
1113

1214
**Properties**
1315

14-
- `EOF` **Integer**
15-
- `lexer` **Lexer**
16-
- `token` **(Integer | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))**
17-
- `extractDoc` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
18-
- `debug` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
16+
- `lexer` **Lexer** current lexer instance
17+
- `ast` **AST** the AST factory instance
18+
- `token` **(Integer | [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** current token
19+
- `extractDoc` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** should extract documentation as AST node
20+
- `suppressErrors` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** should ignore parsing errors and continue
21+
- `debug` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** should output debug informations
1922

2023
## getTokenName
2124

src/index.js

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,33 @@ function combine(src, to) {
3434
}
3535

3636
/**
37+
* Initialise a new parser instance with the specified options
38+
*
39+
* Usage :
40+
* ```js
41+
* var parser = require('php-parser');
42+
* var instance = new parser({
43+
* parser: {
44+
* extractDoc: true,
45+
* suppressErrors: true
46+
* },
47+
* ast: {
48+
* withPositions: true
49+
* },
50+
* lexer: {
51+
* short_tags: true,
52+
* asp_tags: true
53+
* }
54+
* });
55+
*
56+
* var evalAST = instance.parseEval('some php code');
57+
* var codeAST = instance.parseCode('<?php some php code', 'foo.php');
58+
* var tokens = instance.tokenGetAll('<?php some php code');
59+
* ```
60+
*
3761
* @constructor {Engine}
38-
* @param {Object} options
62+
* @param {Object} options - List of options
63+
*
3964
* @property {Lexer} lexer
4065
* @property {Parser} parser
4166
* @property {AST} ast
@@ -55,25 +80,28 @@ var engine = function(options) {
5580
};
5681

5782
/**
58-
* Creates a new instance
83+
* Creates a new instance (Helper)
5984
* @param {Object} options
6085
* @return {Engine}
61-
*/
86+
* @private
87+
*/
6288
engine.create = function(options) {
6389
return new engine(options);
6490
};
6591

6692
/**
6793
* Evaluate the buffer
94+
* @private
6895
*/
6996
engine.parseEval = function(buffer, options) {
7097
var self = new engine(options);
7198
return self.parseEval(buffer);
7299
};
73100

74101
/**
75-
* parsing eval string as '$x = 1;'
76-
* @return {Array}
102+
* Parse an evaluating mode string (no need to open php tags)
103+
* @param {String} buffer
104+
* @return {Program}
77105
*/
78106
engine.prototype.parseEval = function(buffer) {
79107
this.lexer.mode_eval = true;
@@ -83,21 +111,7 @@ engine.prototype.parseEval = function(buffer) {
83111

84112
/**
85113
* Static function that parse a php code with open/close tags
86-
*
87-
* Sample code :
88-
* ```php
89-
* <?php $x = 1;
90-
* ```
91-
*
92-
* Usage :
93-
* ```js
94-
* var parser = require('php-parser');
95-
* var ast = parser.parseCode('...php code...', 'foo.php');
96-
* ```
97-
* @param {String} buffer - The code to be parsed
98-
* @param {String} filename - Filename
99-
* @param {Object} options - Optional options
100-
* @return {Program}
114+
* @private
101115
*/
102116
engine.parseCode = function(buffer, filename, options) {
103117
if (typeof filename === 'object') {
@@ -137,15 +151,18 @@ engine.prototype.parseCode = function(buffer, filename) {
137151

138152
/**
139153
* Split the buffer into tokens
140-
* @return {String[]}
154+
* @private
141155
*/
142156
engine.tokenGetAll = function(buffer, options) {
143157
var self = new engine(options);
144158
return self.tokenGetAll(buffer);
145159
};
146160

147161
/**
148-
* split the buffer into tokens
162+
* Extract tokens from the specified buffer.
163+
* > Note that the output tokens are *STRICLY* similar to PHP function `token_get_all`
164+
* @param {String} buffer
165+
* @return {String[]} - Each item can be a string or an array with following informations [token_name, text, line_number]
149166
*/
150167
engine.prototype.tokenGetAll = function(buffer) {
151168
this.lexer.mode_eval = false;

src/parser.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,25 @@ function isNumber(n) {
1313

1414

1515
/**
16-
* The PHP Parser class
17-
*
18-
* @public @constructor {Parser}
19-
* @property {Integer} EOF
20-
* @property {Lexer} lexer
21-
* @property {Integer|String} token
22-
* @property {Boolean} extractDoc
23-
* @property {Boolean} debug
16+
* The PHP Parser class that build the AST tree from the lexer
17+
* @constructor {Parser}
18+
* @property {Lexer} lexer - current lexer instance
19+
* @property {AST} ast - the AST factory instance
20+
* @property {Integer|String} token - current token
21+
* @property {Boolean} extractDoc - should extract documentation as AST node
22+
* @property {Boolean} suppressErrors - should ignore parsing errors and continue
23+
* @property {Boolean} debug - should output debug informations
2424
*/
2525
var parser = function(lexer, ast) {
2626
this.lexer = lexer;
2727
this.ast = ast;
2828
this.tok = lexer.tok;
2929
this.EOF = lexer.EOF;
30-
// Private vars, do not use directly
31-
this._gracefulProxy = {};
32-
this._graceful = false;
3330
this.token = null;
3431
this.prev = null;
3532
this.debug = false;
3633
this.extractDoc = false;
3734
this.suppressErrors = false;
38-
this.lastError = false;
39-
this.startAt = [];
4035
this.entries = {
4136
'SCALAR': [
4237
this.tok.T_CONSTANT_ENCAPSED_STRING,

0 commit comments

Comments
 (0)