Skip to content

Commit fcf9e7d

Browse files
committed
rebuild
1 parent 1df5350 commit fcf9e7d

File tree

3 files changed

+85
-119
lines changed

3 files changed

+85
-119
lines changed

dist/php-parser.js

Lines changed: 36 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! php-parser - BSD3 License - 2017-01-02 */
1+
/*! php-parser - BSD3 License - 2017-01-03 */
22

33
require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
44
// shim for using process in browser
@@ -3626,13 +3626,17 @@ module.exports = {
36263626
if (ch === '-') {
36273627
ch = this.input();
36283628
if (ch === '>') {
3629+
// https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1296
36293630
return this.tok.T_OBJECT_OPERATOR;
36303631
}
36313632
this.unput(1);
36323633
} else if (this.is_LABEL_START()) {
3634+
// https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1300
36333635
this.consume_LABEL();
3636+
this.popState();
36343637
return this.tok.T_STRING;
36353638
}
3639+
// https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1306
36363640
this.popState();
36373641
this.unput(1);
36383642
return false;
@@ -4532,11 +4536,6 @@ module.exports = {
45324536
var ch = this._input[this.offset - 1];
45334537
return tokens.indexOf(ch) !== -1;
45344538
},
4535-
// check if current char is a newline
4536-
is_NEWLINE: function() {
4537-
var ch = this._input[this.offset - 1];
4538-
return ch === '\n' || ch === '\r';
4539-
},
45404539
// check if current char is a whitespace
45414540
is_WHITESPACE: function() {
45424541
var ch = this._input[this.offset - 1];
@@ -4601,12 +4600,19 @@ var parser = function(lexer, ast) {
46014600
this.extractDoc = false;
46024601
this.suppressErrors = false;
46034602
this.entries = {
4603+
'VARIABLE': [
4604+
this.tok.T_VARIABLE,
4605+
'$', '&',
4606+
this.tok.T_NS_SEPARATOR,
4607+
this.tok.T_STRING,
4608+
this.tok.T_NAMESPACE,
4609+
this.tok.T_STATIC
4610+
],
46044611
'SCALAR': [
46054612
this.tok.T_CONSTANT_ENCAPSED_STRING,
46064613
this.tok.T_START_HEREDOC,
46074614
this.tok.T_LNUMBER,
46084615
this.tok.T_DNUMBER,
4609-
this.tok.T_STRING,
46104616
this.tok.T_ARRAY,'[',
46114617
this.tok.T_CLASS_C,
46124618
this.tok.T_TRAIT_C,
@@ -4616,7 +4622,6 @@ var parser = function(lexer, ast) {
46164622
this.tok.T_FILE,
46174623
this.tok.T_DIR,
46184624
this.tok.T_NS_C,
4619-
this.tok.T_NAMESPACE,
46204625
'"',
46214626
'b"',
46224627
'B"',
@@ -4641,13 +4646,6 @@ var parser = function(lexer, ast) {
46414646
this.tok.T_ABSTRACT,
46424647
this.tok.T_FINAL
46434648
],
4644-
'VARIABLE': [
4645-
this.tok.T_VARIABLE,
4646-
'$', '&',
4647-
this.tok.T_NS_SEPARATOR,
4648-
this.tok.T_STRING,
4649-
this.tok.T_STATIC
4650-
],
46514649
'EOS': [
46524650
';',
46534651
this.tok.T_CLOSE_TAG,
@@ -4934,16 +4932,6 @@ parser.prototype.is = function(type) {
49344932
}
49354933
};
49364934

4937-
/** convert an token to ast **/
4938-
parser.prototype.read_token = function() {
4939-
var result = this.token;
4940-
if (isNumber(result)) {
4941-
result = [result, this.text(), this.lexer.yylloc.first_line];
4942-
}
4943-
this.next();
4944-
return result;
4945-
};
4946-
49474935
// extends the parser with syntax files
49484936
[
49494937
require('./parser/array.js'),
@@ -6029,7 +6017,11 @@ module.exports = {
60296017
* ```
60306018
*/
60316019
,read_class_name_reference: function() {
6032-
if (this.token === '\\' || this.token === this.tok.T_STRING) {
6020+
if (
6021+
this.token === this.tok.T_NS_SEPARATOR ||
6022+
this.token === this.tok.T_STRING ||
6023+
this.token === this.tok.T_NAMESPACE
6024+
) {
60336025
var result = this.read_namespace_name();
60346026
if (this.token === this.tok.T_DOUBLE_COLON) {
60356027
result = this.read_static_getter(result);
@@ -6860,41 +6852,14 @@ module.exports = {
68606852
return node('binary', what);
68616853

68626854
// NUMERIC
6863-
case '-': // long
68646855
case this.tok.T_LNUMBER: // long
68656856
case this.tok.T_DNUMBER: // double
68666857
var result = this.node('number');
68676858
var value = this.text();
6868-
if (this.token === '-') {
6869-
this.next().expect([this.tok.T_LNUMBER, this.tok.T_DNUMBER]);
6870-
value += this.text();
6871-
}
68726859
this.next();
68736860
result = result(value);
68746861
return result;
68756862

6876-
// CONSTANTS
6877-
case this.tok.T_NAMESPACE:
6878-
case this.tok.T_NS_SEPARATOR:
6879-
case this.tok.T_STRING:
6880-
var value = this.read_namespace_name();
6881-
var result = ['constant', value];
6882-
if ( this.token == this.tok.T_DOUBLE_COLON) {
6883-
// class constant MyClass::CONSTANT
6884-
if (this.next().expect([this.tok.T_STRING, this.tok.T_CLASS])) {
6885-
result[1] = [value, this.text()];
6886-
this.next();
6887-
}
6888-
}
6889-
// CONSTANT ARRAYS OFFSET : MYCONST[1][0]...
6890-
while(this.token === '[') {
6891-
var node = this.node('offsetlookup');
6892-
var offset = this.next().read_expr();
6893-
if (this.expect(']')) this.next();
6894-
result = node(result, offset);
6895-
}
6896-
return result;
6897-
68986863
// ARRAYS
68996864
case this.tok.T_ARRAY: // array parser
69006865
case '[': // short array format
@@ -6979,18 +6944,18 @@ module.exports = {
69796944
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1246
69806945
else if (this.token === this.tok.T_CURLY_OPEN) {
69816946
result = this.next().read_variable(false, false, false);
6982-
if (this.expect('}')) this.next();
6947+
this.expect('}') && this.next();
69836948
}
69846949

69856950
// plain variable
69866951
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1231
69876952
else if (this.token === this.tok.T_VARIABLE) {
6988-
result = this.read_variable(false, true, false);
6953+
result = this.read_simple_variable(false);
69896954

69906955
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1233
69916956
if (this.token === '[') {
69926957
var node = this.node('offsetlookup');
6993-
var offset = this.next().read_expr();
6958+
var offset = this.next().read_encaps_var_offset();
69946959
this.expect(']') && this.next();
69956960
result = node(result, offset);
69966961
}
@@ -7272,16 +7237,15 @@ module.exports = {
72727237
this.expectEndOfStatement();
72737238
return result(expr);
72747239

7240+
// https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L429
72757241
case this.tok.T_BREAK:
72767242
case this.tok.T_CONTINUE:
72777243
var result = this.node(
72787244
this.token === this.tok.T_CONTINUE ? 'continue' : 'break'
72797245
), level = null;
7280-
if(this.next().token === this.tok.T_LNUMBER) {
7281-
level = this.node('number');
7282-
var value = this.text();
7283-
this.next();
7284-
level = level(value);
7246+
this.next(); // look ahead
7247+
if (this.token !== ';' && this.token !== this.tok.T_CLOSE_TAG) {
7248+
level = this.read_expr();
72857249
}
72867250
this.expectEndOfStatement();
72877251
return result(level);
@@ -7336,27 +7300,29 @@ module.exports = {
73367300
if (this.token === ':') {
73377301
this.nextWithComments();
73387302
while(this.token != this.EOF && this.token !== this.tok.T_ENDDECLARE) {
7339-
body.push(this.read_statement());
7303+
// @todo : check declare_statement from php / not valid
7304+
body.push(this.read_top_statement());
73407305
}
73417306
this.expect(this.tok.T_ENDDECLARE) && this.next();
73427307
this.expectEndOfStatement();
73437308
mode = this.ast.declare.MODE_SHORT;
73447309
} else if (this.token === '{') {
73457310
this.nextWithComments();
73467311
while(this.token != this.EOF && this.token !== '}') {
7347-
body.push(this.read_statement());
7312+
// @todo : check declare_statement from php / not valid
7313+
body.push(this.read_top_statement());
73487314
}
73497315
this.expect('}') && this.next();
73507316
mode = this.ast.declare.MODE_BLOCK;
73517317
} else {
73527318
this.expect(';') && this.next();
73537319
while(this.token != this.EOF && this.token !== this.tok.T_DECLARE) {
7354-
body.push(this.read_statement());
7320+
// @todo : check declare_statement from php / not valid
7321+
body.push(this.read_top_statement());
73557322
}
73567323
mode = this.ast.declare.MODE_NONE;
73577324
}
73587325
return result(what, body, mode);
7359-
break;
73607326

73617327
case this.tok.T_TRY:
73627328
return this.read_try();
@@ -7718,7 +7684,7 @@ module.exports = {
77187684
// reads the entry point
77197685
if (this.is([this.tok.T_VARIABLE, '$'])) {
77207686
result = this.read_reference_variable(encapsed, byref);
7721-
} else if (this.is([this.tok.T_NS_SEPARATOR, this.tok.T_STRING])) {
7687+
} else if (this.is([this.tok.T_NS_SEPARATOR, this.tok.T_STRING, this.tok.T_NAMESPACE])) {
77227688
result = this.node();
77237689
var name = this.read_namespace_name();
77247690
if (
@@ -7920,13 +7886,14 @@ module.exports = {
79207886
while(this.token != this.EOF) {
79217887
var node = this.node();
79227888
if (this.token == '[') {
7889+
var offset = null;
79237890
if (encapsed) {
7924-
result = this.next().read_encaps_var_offset();
7891+
offset = this.next().read_encaps_var_offset();
79257892
} else {
7926-
var offset = this.next().token === ']' ? null : this.read_dim_offset();
7927-
result = node('offsetlookup', result, offset);
7893+
offset = this.next().token === ']' ? null : this.read_dim_offset();
79287894
}
79297895
this.expect(']') && this.next();
7896+
result = node('offsetlookup', result, offset);
79307897
} else if (this.token == '{' && !encapsed) {
79317898
var offset = this.next().read_expr();
79327899
this.expect('}') && this.next();

0 commit comments

Comments
 (0)