Skip to content

Commit 64f0c6d

Browse files
committed
Merge commit '95c0de64ae17c01d71956d26ae295540e8d3c359' of https://github.com/genintho/php-parser into cs-parser-intersect
2 parents a57b639 + 95c0de6 commit 64f0c6d

File tree

6 files changed

+383
-5
lines changed

6 files changed

+383
-5
lines changed

src/ast.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ AST.prototype.checkNodes = function () {
522522
require("./ast/include"),
523523
require("./ast/inline"),
524524
require("./ast/interface"),
525+
require("./ast/intersectiontype"),
525526
require("./ast/isset"),
526527
require("./ast/label"),
527528
require("./ast/list"),

src/ast/intersectiontype.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (C) 2018 Glayzzle (BSD3 License)
3+
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
4+
* @url http://glayzzle.com
5+
*/
6+
"use strict";
7+
8+
const Declaration = require("./declaration");
9+
const KIND = "intersectiontype";
10+
11+
/**
12+
* A union of types
13+
* @constructor IntersectionType
14+
* @extends {Declaration}
15+
* @property {TypeReference[]} types
16+
*/
17+
module.exports = Declaration.extends(
18+
KIND,
19+
function IntersectionType(types, docs, location) {
20+
Declaration.apply(this, [KIND, null, docs, location]);
21+
this.types = types;
22+
}
23+
);

src/parser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const Parser = function (lexer, ast) {
3535
this.EOF = lexer.EOF;
3636
this.token = null;
3737
this.prev = null;
38+
this.previous_token = null;
3839
this.debug = false;
3940
this.version = 801;
4041
this.extractDoc = false;
@@ -589,6 +590,8 @@ Parser.prototype.text = function () {
589590
* @memberOf module:php-parser
590591
*/
591592
Parser.prototype.next = function () {
593+
this.previous_token = this.token;
594+
592595
// prepare the back command
593596
if (this.token !== ";" || this.lexer.yytext === ";") {
594597
// ignore '?>' from automated resolution

src/parser/function.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ module.exports = {
1010
* checks if current token is a reference keyword
1111
*/
1212
is_reference: function () {
13-
if (this.token == "&") {
13+
if (this.previous_token === "&") {
14+
return true;
15+
}
16+
if (this.token === "&") {
1417
this.next();
1518
return true;
1619
}
@@ -288,19 +291,24 @@ module.exports = {
288291
},
289292
read_types() {
290293
const types = [];
291-
const unionType = this.node("uniontype");
294+
let isIntersection = false;
292295
let type = this.read_type();
293296
if (!type) return null;
294297
types.push(type);
295-
while (this.token === "|") {
298+
while (this.token === "|" || (this.version >= 801 && this.token === "&")) {
299+
isIntersection = this.token === "&";
296300
this.next();
297301
type = this.read_type();
298-
types.push(type);
302+
if (type) {
303+
types.push(type);
304+
}
299305
}
300306
if (types.length === 1) {
301307
return types[0];
302308
} else {
303-
return unionType(types);
309+
return isIntersection
310+
? this.node("intersectiontype")(types)
311+
: this.node("uniontype")(types);
304312
}
305313
},
306314
read_promoted() {

0 commit comments

Comments
 (0)