|
2 | 2 | *
|
3 | 3 | * Package: php-parser
|
4 | 4 | * Parse PHP code and returns its AST
|
5 |
| - * Build: 638e56ff062f9db65357 - 2018-7-29 |
| 5 | + * Build: 65fd01ae827233e0f643 - 2018-8-15 |
6 | 6 | * License: BSD-3-Clause
|
7 | 7 | * Author: Ioan CHIRIAC
|
8 | 8 | *
|
@@ -4702,7 +4702,9 @@ module.exports = {
|
4702 | 4702 | }
|
4703 | 4703 |
|
4704 | 4704 | // ARRAYS
|
4705 |
| - case this.tok.T_ARRAY: // array parser |
| 4705 | + case this.tok.T_ARRAY: |
| 4706 | + // array parser |
| 4707 | + return this.read_array(); |
4706 | 4708 | case "[":
|
4707 | 4709 | // short array format
|
4708 | 4710 | return this.read_array();
|
@@ -5701,68 +5703,48 @@ module.exports = {
|
5701 | 5703 | return this.next().read_encapsed_string("`");
|
5702 | 5704 | }
|
5703 | 5705 |
|
5704 |
| - if (this.token === this.tok.T_LIST || this.token === "[") { |
| 5706 | + if (this.token === this.tok.T_LIST) { |
5705 | 5707 | var assign = null;
|
5706 |
| - var isShort = this.token === "["; |
5707 | 5708 | var isInner = this.innerList;
|
5708 | 5709 | result = this.node("list");
|
5709 | 5710 | if (!isInner) {
|
5710 |
| - this.innerListForm = isShort; |
5711 | 5711 | assign = this.node("assign");
|
5712 |
| - } else if (this.innerListForm !== isShort) { |
5713 |
| - // Both due to implementation issues, |
5714 |
| - // and for consistency's sake, list() |
5715 |
| - // cannot be nested inside [], nor vice-versa |
5716 |
| - this.expect(isShort ? "list" : "["); |
5717 | 5712 | }
|
5718 |
| - this.next(); |
5719 |
| - if (!isShort && this.expect("(")) { |
| 5713 | + if (this.next().expect("(")) { |
5720 | 5714 | this.next();
|
5721 | 5715 | }
|
5722 | 5716 |
|
5723 | 5717 | if (!this.innerList) this.innerList = true;
|
5724 | 5718 |
|
5725 | 5719 | // reads inner items
|
5726 |
| - var assignList = this.read_array_pair_list(isShort); |
5727 |
| - if (this.expect(isShort ? "]" : ")")) { |
| 5720 | + var assignList = this.read_array_pair_list(false); |
| 5721 | + if (this.expect(")")) { |
5728 | 5722 | this.next();
|
5729 | 5723 | }
|
5730 | 5724 |
|
5731 | 5725 | // check if contains at least one assignment statement
|
5732 |
| - if (!isShort) { |
5733 |
| - var hasItem = false; |
5734 |
| - for (var i = 0; i < assignList.length; i++) { |
5735 |
| - if (assignList[i] !== null) { |
5736 |
| - hasItem = true; |
5737 |
| - break; |
5738 |
| - } |
5739 |
| - } |
5740 |
| - if (!hasItem) { |
5741 |
| - this.raiseError("Fatal Error : Cannot use empty list on line " + this.lexer.yylloc.first_line); |
| 5726 | + var hasItem = false; |
| 5727 | + for (var i = 0; i < assignList.length; i++) { |
| 5728 | + if (assignList[i] !== null) { |
| 5729 | + hasItem = true; |
| 5730 | + break; |
5742 | 5731 | }
|
5743 | 5732 | }
|
| 5733 | + if (!hasItem) { |
| 5734 | + this.raiseError("Fatal Error : Cannot use empty list on line " + this.lexer.yylloc.first_line); |
| 5735 | + } |
5744 | 5736 |
|
5745 | 5737 | // handles the node resolution
|
5746 | 5738 | if (!isInner) {
|
5747 | 5739 | this.innerList = false;
|
5748 |
| - if (isShort) { |
5749 |
| - if (this.token === "=") { |
5750 |
| - return assign(result(assignList, isShort), this.next().read_expr(), "="); |
5751 |
| - } else { |
5752 |
| - // handles as an array declaration |
5753 |
| - result.setKind("array"); |
5754 |
| - return this.handleDereferencable(result(isShort, assignList)); |
5755 |
| - } |
| 5740 | + if (this.expect("=")) { |
| 5741 | + return assign(result(assignList, false), this.next().read_expr(), "="); |
5756 | 5742 | } else {
|
5757 |
| - if (this.expect("=")) { |
5758 |
| - return assign(result(assignList, isShort), this.next().read_expr(), "="); |
5759 |
| - } else { |
5760 |
| - // error fallback : list($a, $b); |
5761 |
| - return result(assignList, isShort); |
5762 |
| - } |
| 5743 | + // error fallback : list($a, $b); |
| 5744 | + return result(assignList, false); |
5763 | 5745 | }
|
5764 | 5746 | } else {
|
5765 |
| - return result(assignList, isShort); |
| 5747 | + return result(assignList, false); |
5766 | 5748 | }
|
5767 | 5749 | }
|
5768 | 5750 |
|
@@ -5994,7 +5976,16 @@ module.exports = {
|
5994 | 5976 | return result("post", "-", expr);
|
5995 | 5977 | }
|
5996 | 5978 | } else if (this.is("SCALAR")) {
|
| 5979 | + result = this.node(); |
5997 | 5980 | expr = this.read_scalar();
|
| 5981 | + if (expr.kind === "array" && expr.shortForm && this.token === "=") { |
| 5982 | + // list assign |
| 5983 | + var list = this.node("list")(expr.items, true); |
| 5984 | + if (expr.loc) list.loc = expr.loc; |
| 5985 | + var _right = this.next().read_expr(); |
| 5986 | + return result("assign", list, _right, "="); |
| 5987 | + } |
| 5988 | + // classic array |
5998 | 5989 | return this.handleDereferencable(expr);
|
5999 | 5990 | } else {
|
6000 | 5991 | this.error("EXPR");
|
@@ -6603,11 +6594,13 @@ module.exports = {
|
6603 | 6594 | items = this.read_array_pair_list(shortForm);
|
6604 | 6595 | }
|
6605 | 6596 | // check non empty entries
|
6606 |
| - items.forEach(function (item) { |
6607 |
| - if (item === null) { |
6608 |
| - this.raiseError("Cannot use empty array elements in arrays"); |
| 6597 | + /*for(let i = 0, size = items.length - 1; i < size; i++) { |
| 6598 | + if (items[i] === null) { |
| 6599 | + this.raiseError( |
| 6600 | + "Cannot use empty array elements in arrays" |
| 6601 | + ); |
6609 | 6602 | }
|
6610 |
| - }.bind(this)); |
| 6603 | + }*/ |
6611 | 6604 | this.expect(expect);
|
6612 | 6605 | this.next();
|
6613 | 6606 | return result(shortForm, items);
|
@@ -6918,7 +6911,11 @@ parser.prototype.text = function () {
|
6918 | 6911 | /** consume the next token **/
|
6919 | 6912 | parser.prototype.next = function () {
|
6920 | 6913 | // prepare the back command
|
6921 |
| - this.prev = [this.lexer.yylloc.last_line, this.lexer.yylloc.last_column, this.lexer.offset]; |
| 6914 | + if (this.token !== ";" || this.lexer.yytext === ";") { |
| 6915 | + // ignore '?>' from automated resolution |
| 6916 | + // https://github.com/glayzzle/php-parser/issues/168 |
| 6917 | + this.prev = [this.lexer.yylloc.last_line, this.lexer.yylloc.last_column, this.lexer.offset]; |
| 6918 | + } |
6922 | 6919 |
|
6923 | 6920 | // eating the token
|
6924 | 6921 | this.lex();
|
|
0 commit comments