Skip to content

Commit

Permalink
Merge 895eccf into bb89fff
Browse files Browse the repository at this point in the history
  • Loading branch information
cseufert committed Jun 15, 2021
2 parents bb89fff + 895eccf commit 2372fe6
Show file tree
Hide file tree
Showing 50 changed files with 1,745 additions and 39 deletions.
2 changes: 2 additions & 0 deletions src/ast.js
Expand Up @@ -464,6 +464,8 @@ AST.prototype.checkNodes = function () {
require("./ast/arrowfunc"),
require("./ast/assign"),
require("./ast/assignref"),
require("./ast/attribute"),
require("./ast/attrgroup"),
require("./ast/bin"),
require("./ast/block"),
require("./ast/boolean"),
Expand Down
20 changes: 20 additions & 0 deletions src/ast/attrgroup.js
@@ -0,0 +1,20 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";

const Node = require("./node");
const KIND = "attrgroup";

/**
* Attribute group
* @constructor AttrGroup
* @extends {Node}
* @property {Attribute[]} attrs
*/
module.exports = Node.extends(KIND, function AttrGroup(attrs, docs, location) {
Node.apply(this, [KIND, docs, location]);
this.attrs = attrs || [];
});
27 changes: 27 additions & 0 deletions src/ast/attribute.js
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";

const Node = require("./node");
const KIND = "attribute";

/**
* Attribute Value
* @constructor Attribute
* @extends {Node}
* @property {String} name
* @property {Parameter[]} args
*/
module.exports = Node.extends(KIND, function Attribute(
name,
args,
docs,
location
) {
Node.apply(this, [KIND, docs, location]);
this.name = name;
this.args = args;
});
2 changes: 2 additions & 0 deletions src/ast/class.js
Expand Up @@ -15,6 +15,7 @@ const KIND = "class";
* @property {Identifier|null} extends
* @property {Identifier[]} implements
* @property {Declaration[]} body
* @property {AttrGroup[]} attrGroups
* @property {boolean} isAnonymous
* @property {boolean} isAbstract
* @property {boolean} isFinal
Expand All @@ -33,5 +34,6 @@ module.exports = Declaration.extends(KIND, function Class(
this.extends = ext;
this.implements = impl;
this.body = body;
this.attrGroups = [];
this.parseFlags(flags);
});
3 changes: 3 additions & 0 deletions src/ast/classconstant.js
Expand Up @@ -18,16 +18,19 @@ const IS_PRIVATE = "private";
* @constructor ClassConstant
* @extends {ConstantStatement}
* @property {string} visibility
* @property {AttrGroup[]} attrGroups
*/
const ClassConstant = ConstantStatement.extends(KIND, function ClassConstant(
kind,
constants,
flags,
attrGroups,
docs,
location
) {
ConstantStatement.apply(this, [kind || KIND, constants, docs, location]);
this.parseFlags(flags);
this.attrGroups = attrGroups;
});

/**
Expand Down
2 changes: 2 additions & 0 deletions src/ast/closure.js
Expand Up @@ -19,6 +19,7 @@ const KIND = "closure";
* @property {boolean} nullable
* @property {Block|null} body
* @property {boolean} isStatic
* @property {AttrGroup[]} attrGroups
*/
module.exports = Expression.extends(KIND, function Closure(
args,
Expand All @@ -38,4 +39,5 @@ module.exports = Expression.extends(KIND, function Closure(
this.nullable = nullable;
this.isStatic = isStatic || false;
this.body = null;
this.attrGroups = [];
});
2 changes: 2 additions & 0 deletions src/ast/function.js
Expand Up @@ -17,6 +17,7 @@ const KIND = "function";
* @property {boolean} byref
* @property {boolean} nullable
* @property {Block|null} body
* @property {AttrGroups[]} attrGroups
*/
module.exports = Declaration.extends(KIND, function _Function(
name,
Expand All @@ -33,4 +34,5 @@ module.exports = Declaration.extends(KIND, function _Function(
this.type = type;
this.nullable = nullable;
this.body = null;
this.attrGroups = [];
});
3 changes: 3 additions & 0 deletions src/ast/interface.js
Expand Up @@ -14,15 +14,18 @@ const KIND = "interface";
* @extends {Declaration}
* @property {Identifier[]} extends
* @property {Declaration[]} body
* @property {AttrGroup[]} attrGroups
*/
module.exports = Declaration.extends(KIND, function Interface(
name,
ext,
body,
attrGroups,
docs,
location
) {
Declaration.apply(this, [KIND, name, docs, location]);
this.extends = ext;
this.body = body;
this.attrGroups = attrGroups;
});
2 changes: 2 additions & 0 deletions src/ast/parameter.js
Expand Up @@ -24,6 +24,7 @@ const MODIFIER_PRIVATE = 4;
* @property {boolean} byref
* @property {boolean} variadic
* @property {boolean} nullable
* @property {AttrGroups[]} attrGroups
* @property {MODIFIER_PUBLIC|MODIFIER_PROTECTED|MODIFIER_PRIVATE} flags
*/
module.exports = Declaration.extends(KIND, function Parameter(
Expand All @@ -44,4 +45,5 @@ module.exports = Declaration.extends(KIND, function Parameter(
this.variadic = isVariadic;
this.nullable = nullable;
this.flags = flags || 0;
this.attrGroups = [];
});
3 changes: 3 additions & 0 deletions src/ast/property.js
Expand Up @@ -16,12 +16,14 @@ const KIND = "property";
* @property {Node|null} value
* @property {boolean} nullable
* @property {Identifier|Array<Identifier>|null} type
* @property {AttrGroup[]} attrGroups
*/
module.exports = Statement.extends(KIND, function Property(
name,
value,
nullable,
type,
attrGroups,
docs,
location
) {
Expand All @@ -30,4 +32,5 @@ module.exports = Statement.extends(KIND, function Property(
this.value = value;
this.nullable = nullable;
this.type = type;
this.attrGroups = attrGroups;
});
1 change: 1 addition & 0 deletions src/lexer.js
Expand Up @@ -474,6 +474,7 @@ lexer.prototype.next = function () {

// extends the lexer with states
[
require("./lexer/attribute.js"),
require("./lexer/comments.js"),
require("./lexer/initial.js"),
require("./lexer/numbers.js"),
Expand Down
60 changes: 60 additions & 0 deletions src/lexer/attribute.js
@@ -0,0 +1,60 @@
/**
* Copyright (C) 2018 Glayzzle (BSD3 License)
* @authors https://github.com/glayzzle/php-parser/graphs/contributors
* @url http://glayzzle.com
*/
"use strict";

module.exports = {
matchST_ATTRIBUTE: function () {
let listDepth = 0;
let ch = this.input();
if (this.is_WHITESPACE()) {
do {
ch = this.input();
} while (this.is_WHITESPACE());
this.unput(1);
return null;
}
switch (ch) {
case "]":
if (listDepth === 0) {
this.popState();
} else {
listDepth--;
}
return "]";
case "(":
case ")":
case ":":
case "=":
return this.consume_TOKEN();
case "[":
listDepth++;
return "[";
case ",":
return ",";
case '"':
return this.ST_DOUBLE_QUOTES();
case "'":
return this.T_CONSTANT_ENCAPSED_STRING();
case "/":
if (this._input[this.offset] === "/") {
return this.T_COMMENT();
} else if (this._input[this.offset] === "*") {
this.input();
return this.T_DOC_COMMENT();
}
}
if (this.is_LABEL_START()) {
this.consume_LABEL();
return this.tok.T_STRING;
} else if (this.is_NUM()) {
return this.consume_NUM();
}

throw new Error(
`Bad terminal sequence "${ch}" at line ${this.yylineno} (offset ${this.offset})`
);
},
};
5 changes: 5 additions & 0 deletions src/lexer/scripting.js
Expand Up @@ -16,6 +16,11 @@ module.exports = {
case "\r\n":
return this.T_WHITESPACE();
case "#":
if (this._input[this.offset] === "[") {
this.input();
this.begin("ST_ATTRIBUTE");
return this.tok.T_ATTRIBUTE;
}
return this.T_COMMENT();
case "/":
if (this._input[this.offset] === "/") {
Expand Down

0 comments on commit 2372fe6

Please sign in to comment.