diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index b14669b6e..000000000 --- a/index.d.ts +++ /dev/null @@ -1,365 +0,0 @@ -/*! - * Copyright (C) 2017 Glayzzle (BSD3 License) - * @authors https://github.com/glayzzle/php-parser/graphs/contributors - * @url http://glayzzle.com - */ - -declare module "php-parser" { - /** - * Token items - */ - const enum TokenEnum { - T_HALT_COMPILER = 101, - T_USE = 102, - T_ENCAPSED_AND_WHITESPACE = 103, - T_OBJECT_OPERATOR = 104, - T_STRING = 105, - T_DOLLAR_OPEN_CURLY_BRACES = 106, - T_STRING_VARNAME = 107, - T_CURLY_OPEN = 108, - T_NUM_STRING = 109, - T_ISSET = 110, - T_EMPTY = 111, - T_INCLUDE = 112, - T_INCLUDE_ONCE = 113, - T_EVAL = 114, - T_REQUIRE = 115, - T_REQUIRE_ONCE = 116, - T_NAMESPACE = 117, - T_NS_SEPARATOR = 118, - T_AS = 119, - T_IF = 120, - T_ENDIF = 121, - T_WHILE = 122, - T_DO = 123, - T_FOR = 124, - T_SWITCH = 125, - T_BREAK = 126, - T_CONTINUE = 127, - T_RETURN = 128, - T_GLOBAL = 129, - T_STATIC = 130, - T_ECHO = 131, - T_INLINE_HTML = 132, - T_UNSET = 133, - T_FOREACH = 134, - T_DECLARE = 135, - T_TRY = 136, - T_THROW = 137, - T_GOTO = 138, - T_FINALLY = 139, - T_CATCH = 140, - T_ENDDECLARE = 141, - T_LIST = 142, - T_CLONE = 143, - T_PLUS_EQUAL = 144, - T_MINUS_EQUAL = 145, - T_MUL_EQUAL = 146, - T_DIV_EQUAL = 147, - T_CONCAT_EQUAL = 148, - T_MOD_EQUAL = 149, - T_AND_EQUAL = 150, - T_OR_EQUAL = 151, - T_XOR_EQUAL = 152, - T_SL_EQUAL = 153, - T_SR_EQUAL = 154, - T_INC = 155, - T_DEC = 156, - T_BOOLEAN_OR = 157, - T_BOOLEAN_AND = 158, - T_LOGICAL_OR = 159, - T_LOGICAL_AND = 160, - T_LOGICAL_XOR = 161, - T_SL = 162, - T_SR = 163, - T_IS_IDENTICAL = 164, - T_IS_NOT_IDENTICAL = 165, - T_IS_EQUAL = 166, - T_IS_NOT_EQUAL = 167, - T_IS_SMALLER_OR_EQUAL = 168, - T_IS_GREATER_OR_EQUAL = 169, - T_INSTANCEOF = 170, - T_INT_CAST = 171, - T_DOUBLE_CAST = 172, - T_STRING_CAST = 173, - T_ARRAY_CAST = 174, - T_OBJECT_CAST = 175, - T_BOOL_CAST = 176, - T_UNSET_CAST = 177, - T_EXIT = 178, - T_PRINT = 179, - T_YIELD = 180, - T_YIELD_FROM = 181, - T_FUNCTION = 182, - T_DOUBLE_ARROW = 183, - T_DOUBLE_COLON = 184, - T_ARRAY = 185, - T_CALLABLE = 186, - T_CLASS = 187, - T_ABSTRACT = 188, - T_TRAIT = 189, - T_FINAL = 190, - T_EXTENDS = 191, - T_INTERFACE = 192, - T_IMPLEMENTS = 193, - T_VAR = 194, - T_PUBLIC = 195, - T_PROTECTED = 196, - T_PRIVATE = 197, - T_CONST = 198, - T_NEW = 199, - T_INSTEADOF = 200, - T_ELSEIF = 201, - T_ELSE = 202, - T_ENDSWITCH = 203, - T_CASE = 204, - T_DEFAULT = 205, - T_ENDFOR = 206, - T_ENDFOREACH = 207, - T_ENDWHILE = 208, - T_CONSTANT_ENCAPSED_STRING = 209, - T_LNUMBER = 210, - T_DNUMBER = 211, - T_LINE = 212, - T_FILE = 213, - T_DIR = 214, - T_TRAIT_C = 215, - T_METHOD_C = 216, - T_FUNC_C = 217, - T_NS_C = 218, - T_START_HEREDOC = 219, - T_END_HEREDOC = 220, - T_CLASS_C = 221, - T_VARIABLE = 222, - T_OPEN_TAG = 223, - T_OPEN_TAG_WITH_ECHO = 224, - T_CLOSE_TAG = 225, - T_WHITESPACE = 226, - T_COMMENT = 227, - T_DOC_COMMENT = 228, - T_ELLIPSIS = 229, - T_COALESCE = 230, - T_POW = 231, - T_POW_EQUAL = 232, - T_SPACESHIP = 233, - T_COALESCE_EQUAL = 234 - } - - /** - * The tokens dictionnary - */ - interface TokenDefinition { - /** List of token names as texts */ - values: String[], - /** Define tokens */ - names: TokenEnum[] - } - - /** - * The token structure - */ - interface Token extends Array { - // token name - 0: String; - // the token value - 1: TokenEnum; - // the current line - 2: Number - } - - /** - * Each Position object consists of a line number (1-indexed) and a column number (0-indexed): - */ - interface Position { - line: Number; - column: Number; - offset: Number; - } - - /** - * Defines the location of the node (with it's source contents as string) - */ - interface Location { - source: string; - start: Position; - end: Position; - } - - /** - * - */ - interface Node { - kind: String; - loc: Location; - } - - /** - * Error node - */ - interface ParserError extends Node { - message: String; - token: Token; - line: Number; - expected: any; - } - - /** - * A block statement, i.e., a sequence of statements surrounded by braces. - */ - interface Block extends Node { - children: Node[]; - } - - /** - * The main root node - */ - interface Program extends Block { - errors: ParserError[]; - } - - interface Parser { - lexer: Lexer; - ast: AST; - token: TokenEnum; - prev: TokenEnum; - debug: Boolean; - extractDoc: Boolean; - suppressErrors: Boolean; - getTokenName(token:TokenEnum): String; - parse(code: String, filename: String): Program; - raiseError(message: String, msgExpect: String, expect: any, token: TokenEnum): ParserError; - error(expect: String): ParserError; - node(kind:String): Node; - expectEndOfStatement(): Boolean; - showlog(): Parser; - expect(token:TokenEnum): Boolean; - expect(tokens:TokenEnum[]): Boolean; - text(): String; - next(): Parser; - ignoreComments(): Parser; - nextWithComments(): Parser; - is(type: String): Boolean; - // @todo other parsing functions ... - } - - interface KeywordsDictionnary { - [index: string]: TokenEnum - } - - interface yylloc { - first_offset: Number; - first_line: Number; - first_column: Number; - last_line: Number; - last_column: Number; - } - - interface LexerState { - yytext: String; - offset: Number; - yylineno: Number; - yyprevcol: Number; - yylloc: yylloc; - } - - interface Lexer { - debug: Boolean; - all_tokens: Boolean; - comment_tokens: Boolean; - mode_eval: Boolean; - asp_tags: Boolean; - short_tags: Boolean; - keywords: KeywordsDictionnary; - castKeywords: KeywordsDictionnary; - setInput(input:String): Lexer; - input(size:Number): String; - unput(size:Number): Lexer; - tryMatch(match:String): Boolean; - tryMatchCaseless(match:String): Boolean; - ahead(size:Number): String; - consume(size:Number): Lexer; - getState(): LexerState; - setState(state:LexerState): Lexer; - appendToken(value:TokenEnum, ahead:Number): Lexer; - lex(): TokenEnum; - begin(state:String): Lexer; - popState(): String; - next(): TokenEnum; - // @todo other lexer functions ... - } - - - interface AST { - /** - * - */ - withPositions: Boolean; - /** - * Option, if true extracts original source code attached to the node (by default false) - */ - withSource: Boolean; - /** - * Constructor - */ - constructor(withPositions:Boolean, withSource:Boolean): AST; - constructor(withPositions:Boolean): AST; - constructor(): AST; - /** - * Create a position node from specified parser - * including it's lexer current state - */ - position(parser:Parser): Position; - /** - * Prepares an AST node - */ - prepare(kind:String, parser:Parser): Function; - } - - /** - * List of options / extensions - */ - interface Options { - ast?: { - withPositions?: Boolean; - withSource?: Boolean; - }; - lexer?: { - debug?: Boolean; - all_tokens?: Boolean; - comment_tokens?: Boolean; - mode_eval?: Boolean; - asp_tags?: Boolean; - short_tags?: Boolean; - }; - parser?: { - debug?: Boolean; - extractDoc?: Boolean; - suppressErrors?: Boolean; - }; - } - - /** - * Initialise a new parser instance with the specified options - */ - export default class Engine { - // ----- STATIC HELPERS - static create(options?: Options) : Engine; - static parseEval(buffer: String, options: Options) : Program; - static parseEval(buffer: String) : Program; - static parseCode(buffer: String, filename: String, options: Options) : Program; - static parseCode(buffer: String, options: Options) : Program; - static parseCode(buffer: String) : Program; - static tokenGetAll(buffer: String, options: Options) : Token[]; - static tokenGetAll(buffer: String) : Token[]; - // ----- INSTANCE FUNCTIONS - ast: AST; - lexer: Lexer; - parser: Parser; - tokens: TokenDefinition; - constructor(options?: Options); - parseEval(buffer: String) : Program; - parseCode(buffer: String, filename: String) : Program; - parseCode(buffer: String) : Program; - tokenGetAll(buffer: String) : Token[]; - } -} diff --git a/package-lock.json b/package-lock.json index 9d18ce3a4..ea71d53fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10890,6 +10890,15 @@ "punycode": "^2.1.1" } }, + "tsd-jsdoc": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tsd-jsdoc/-/tsd-jsdoc-2.5.0.tgz", + "integrity": "sha512-80fcJLAiUeerg4xPftp+iEEKWUjJjHk9AvcHwJqA8Zw0R4oASdu3kT/plE/Zj19QUTz8KupyOX25zStlNJjS9g==", + "dev": true, + "requires": { + "typescript": "^3.2.1" + } + }, "tslib": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz", @@ -10950,6 +10959,12 @@ "is-typedarray": "^1.0.0" } }, + "typescript": { + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.7.tgz", + "integrity": "sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==", + "dev": true + }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", diff --git a/package.json b/package.json index 7aed6cb0e..bdddbd2bb 100644 --- a/package.json +++ b/package.json @@ -1,77 +1,80 @@ -{ - "name": "php-parser", - "version": "3.0.3", - "description": "Parse PHP code from JS and returns its AST", - "main": "src/index.js", - "browser": "dist/php-parser.js", - "files": [ - "src", - "dist", - "index.d.ts", - "LICENSE" - ], - "scripts": { - "fix": "eslint . --fix", - "test": "jest", - "husky": "npm run test", - "prebuild": "npm run test", - "build": "webpack --config webpack.config.js", - "-postbuild": "npm run build-docs", - "build-docs": "jsdoc -c .jsdoc.json", - "publish-docs": "git subtree push --prefix docs origin gh-pages" - }, - "husky": { - "hooks": { - "pre-commit": "npm run husky" - } - }, - "repository": { - "type": "git", - "url": "https://github.com/glayzzle/php-parser" - }, - "bugs": { - "url": "https://github.com/glayzzle/php-parser/issues" - }, - "homepage": "https://glayzzle.com/", - "keywords": [ - "php", - "php5", - "php7", - "php8", - "parser", - "lexer", - "tokenizer", - "ast" - ], - "author": "Ioan CHIRIAC", - "contributors": [ - { - "name": "Filippo Conti", - "email": "filippo@codekraft.it", - "url": "https://b4dnewz.github.io/" - }, - { - "name": "Christian Zosel", - "email": "christian@zosel.ch", - "url": "https://twitter.com/chrzosel" - } - ], - "license": "BSD-3-Clause", - "devDependencies": { - "@babel/core": "^7.3.4", - "@babel/preset-env": "^7.3.4", - "babel-loader": "^8.0.5", - "coveralls": "^3.0.3", - "eslint": "^5.15.0", - "eslint-plugin-jest": "^24.0.0", - "eslint-plugin-prettier": "^3.0.1", - "husky": "^6.0.0", - "jest": "^26.4.2", - "jest-runner-eslint": "^0.9.0", - "jsdoc": "^3.5.5", - "jsdoc-template": "^1.2.0", - "prettier": "^2.0.2", - "webpack": "^5.30.0", - "webpack-cli": "^4.6.0" - } -} +{ + "name": "php-parser", + "version": "3.0.3", + "description": "Parse PHP code from JS and returns its AST", + "main": "src/index.js", + "browser": "dist/php-parser.js", + "files": [ + "src", + "dist", + "types.d.ts", + "LICENSE" + ], + "types": "types.d.ts", + "scripts": { + "fix": "eslint . --fix", + "test": "jest", + "husky": "npm run test", + "prebuild": "npm run test", + "build": "webpack --config webpack.config.js", + "-postbuild": "npm run build-docs", + "build-docs": "jsdoc -c .jsdoc.json", + "build-types": "jsdoc -t node_modules/tsd-jsdoc/dist -r src -d .", + "publish-docs": "git subtree push --prefix docs origin gh-pages" + }, + "husky": { + "hooks": { + "pre-commit": "npm run husky" + } + }, + "repository": { + "type": "git", + "url": "https://github.com/glayzzle/php-parser" + }, + "bugs": { + "url": "https://github.com/glayzzle/php-parser/issues" + }, + "homepage": "https://glayzzle.com/", + "keywords": [ + "php", + "php5", + "php7", + "php8", + "parser", + "lexer", + "tokenizer", + "ast" + ], + "author": "Ioan CHIRIAC", + "contributors": [ + { + "name": "Filippo Conti", + "email": "filippo@codekraft.it", + "url": "https://b4dnewz.github.io/" + }, + { + "name": "Christian Zosel", + "email": "christian@zosel.ch", + "url": "https://twitter.com/chrzosel" + } + ], + "license": "BSD-3-Clause", + "devDependencies": { + "@babel/core": "^7.3.4", + "@babel/preset-env": "^7.3.4", + "babel-loader": "^8.0.5", + "coveralls": "^3.0.3", + "eslint": "^5.15.0", + "eslint-plugin-jest": "^24.0.0", + "eslint-plugin-prettier": "^3.0.1", + "husky": "^6.0.0", + "jest": "^26.4.2", + "jest-runner-eslint": "^0.9.0", + "jsdoc": "^3.5.5", + "jsdoc-template": "^1.2.0", + "prettier": "^2.0.2", + "tsd-jsdoc": "^2.5.0", + "webpack": "^5.30.0", + "webpack-cli": "^4.6.0" + } +} diff --git a/src/ast.js b/src/ast.js index bff1c2959..93e8b704b 100644 --- a/src/ast.js +++ b/src/ast.js @@ -119,6 +119,7 @@ const Position = require("./ast/position"); /** * The AST builder class * @constructor AST + * @memberOf module:php-parser * @tutorial AST * @property {Boolean} withPositions - Should locate any node (by default false) * @property {Boolean} withSource - Should extract the node original code (by default false) @@ -131,9 +132,11 @@ const AST = function (withPositions, withSource) { /** * Create a position node from specified parser * including it's lexer current state - * @param {Parser} - * @return {Position} * @private + * @function AST#position + * @memberOf module:php-parser + * @param {Parser} parser + * @return {Position} */ AST.prototype.position = function (parser) { return new Position( @@ -174,12 +177,22 @@ AST.precedence = {}; }); }); +/** + * @private + * @function AST#isRightAssociative + * @memberOf module:php-parser + * @param operator + * @return {boolean} + */ AST.prototype.isRightAssociative = function (operator) { return operator === "**" || operator === "??"; }; /** * Change parent node informations after swapping childs + * @private + * @function AST#swapLocations + * @memberOf module:php-parser */ AST.prototype.swapLocations = function (target, first, last, parser) { if (this.withPositions) { @@ -196,6 +209,9 @@ AST.prototype.swapLocations = function (target, first, last, parser) { /** * Includes locations from first & last into the target + * @private + * @function AST#resolveLocations + * @memberOf module:php-parser */ AST.prototype.resolveLocations = function (target, first, last, parser) { if (this.withPositions) { @@ -216,6 +232,9 @@ AST.prototype.resolveLocations = function (target, first, last, parser) { /** * Check and fix precence, by default using right + * @private + * @function AST#resolvePrecedence + * @memberOf module:php-parser */ AST.prototype.resolvePrecedence = function (result, parser) { let buffer, lLevel, rLevel; @@ -345,8 +364,11 @@ AST.prototype.resolvePrecedence = function (result, parser) { /** * Prepares an AST node + * @private + * @function AST#prepare + * @memberOf module:php-parser * @param {String|null} kind - Defines the node type - * (if null, the kind must be passed at the function call) + * @param {*} docs - (if null, the kind must be passed at the function call) * @param {Parser} parser - The parser instance (use for extracting locations) * @return {Function} */ @@ -413,6 +435,7 @@ AST.prototype.prepare = function (kind, docs, parser) { /** * Sets a list of trailing comments + * @private * @param {*} docs */ result.setTrailingComments = function (docs) { @@ -426,6 +449,8 @@ AST.prototype.prepare = function (kind, docs, parser) { /** * Release a node without using it on the AST + * @private + * @param {*} target */ result.destroy = function (target) { if (docs) { diff --git a/src/ast/array.js b/src/ast/array.js index 08c8355be..34aa13eb6 100644 --- a/src/ast/array.js +++ b/src/ast/array.js @@ -11,6 +11,7 @@ const KIND = "array"; /** * Defines an array structure * @constructor Array + * @memberOf module:php-parser * @example * // PHP code : * [1, 'foo' => 'bar', 3] @@ -30,7 +31,7 @@ const KIND = "array"; * ] * } * @extends {Expression} - * @property {Entry|Expr|Variable} items List of array items + * @property {Entry|Expression|Variable} items List of array items * @property {boolean} shortForm Indicate if the short array syntax is used, ex `[]` instead `array()` */ module.exports = Expr.extends( diff --git a/src/ast/arrowfunc.js b/src/ast/arrowfunc.js index 75bb7a379..9030f839f 100644 --- a/src/ast/arrowfunc.js +++ b/src/ast/arrowfunc.js @@ -11,6 +11,7 @@ const KIND = "arrowfunc"; /** * Defines an arrow function (it's like a closure) * @constructor ArrowFunc + * @memberOf module:php-parser * @extends {Expression} * @property {Parameter[]} arguments * @property {Identifier} type diff --git a/src/ast/assign.js b/src/ast/assign.js index 744a11b48..361423f27 100644 --- a/src/ast/assign.js +++ b/src/ast/assign.js @@ -11,6 +11,7 @@ const KIND = "assign"; /** * Assigns a value to the specified target * @constructor Assign + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} left * @property {Expression} right diff --git a/src/ast/assignref.js b/src/ast/assignref.js index 9b0acefcd..b2b7cc72b 100644 --- a/src/ast/assignref.js +++ b/src/ast/assignref.js @@ -10,7 +10,8 @@ const KIND = "assignref"; /** * Assigns a value to the specified target - * @constructor Assign + * @constructor AssignRef + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} left * @property {Expression} right diff --git a/src/ast/bin.js b/src/ast/bin.js index 9efe23abd..e25b35d38 100644 --- a/src/ast/bin.js +++ b/src/ast/bin.js @@ -10,6 +10,7 @@ const KIND = "bin"; /** * Binary operations * @constructor Bin + * @memberOf module:php-parser * @extends {Operation} * @property {String} type * @property {Expression} left diff --git a/src/ast/block.js b/src/ast/block.js index 041a0d5d9..2666837f9 100644 --- a/src/ast/block.js +++ b/src/ast/block.js @@ -11,6 +11,7 @@ const KIND = "block"; /** * A block statement, i.e., a sequence of statements surrounded by braces. * @constructor Block + * @memberOf module:php-parser * @extends {Statement} * @property {Node[]} children */ diff --git a/src/ast/boolean.js b/src/ast/boolean.js index e0d1b8b61..4890b2d9d 100644 --- a/src/ast/boolean.js +++ b/src/ast/boolean.js @@ -11,6 +11,7 @@ const KIND = "boolean"; /** * Defines a boolean value (true/false) * @constructor Boolean + * @memberOf module:php-parser * @extends {Literal} */ module.exports = Literal.extends( diff --git a/src/ast/break.js b/src/ast/break.js index 79e073153..2e98e2515 100644 --- a/src/ast/break.js +++ b/src/ast/break.js @@ -11,6 +11,7 @@ const KIND = "break"; /** * A break statement * @constructor Break + * @memberOf module:php-parser * @extends {Statement} * @property {Number|Null} level */ diff --git a/src/ast/byref.js b/src/ast/byref.js index 312997733..89cfb98c2 100644 --- a/src/ast/byref.js +++ b/src/ast/byref.js @@ -11,8 +11,9 @@ const KIND = "byref"; /** * Passing by Reference - so the function can modify the variable * @constructor ByRef + * @memberOf module:php-parser * @extends {Expression} - * @property {expr} what + * @property {ExpressionStatement} what */ module.exports = Expression.extends(KIND, function ByRef(what, docs, location) { Expression.apply(this, [KIND, docs, location]); diff --git a/src/ast/call.js b/src/ast/call.js index 69c025a75..b7d5093e6 100644 --- a/src/ast/call.js +++ b/src/ast/call.js @@ -11,9 +11,10 @@ const KIND = "call"; /** * Executes a call statement * @constructor Call + * @memberOf module:php-parser * @extends {Expression} - * @property {Identifier|Variable|??} what - * @property {Arguments[]} arguments + * @property {Identifier|Variable} what + * @property {Variable[]} arguments */ module.exports = Expression.extends( KIND, diff --git a/src/ast/case.js b/src/ast/case.js index d3726ca9f..4a13d6078 100644 --- a/src/ast/case.js +++ b/src/ast/case.js @@ -11,6 +11,7 @@ const KIND = "case"; /** * A switch case statement * @constructor Case + * @memberOf module:php-parser * @extends {Statement} * @property {Expression|null} test - if null, means that the default case * @property {Block|null} body diff --git a/src/ast/cast.js b/src/ast/cast.js index 21fdde28c..d28e4d65b 100644 --- a/src/ast/cast.js +++ b/src/ast/cast.js @@ -11,6 +11,7 @@ const KIND = "cast"; /** * Binary operations * @constructor Cast + * @memberOf module:php-parser * @extends {Operation} * @property {String} type * @property {String} raw diff --git a/src/ast/catch.js b/src/ast/catch.js index e94403a74..b7015161b 100644 --- a/src/ast/catch.js +++ b/src/ast/catch.js @@ -11,6 +11,7 @@ const KIND = "catch"; /** * Defines a catch statement * @constructor Catch + * @memberOf module:php-parser * @extends {Statement} * @property {Identifier[]} what * @property {Variable} variable diff --git a/src/ast/class.js b/src/ast/class.js index ea34adf58..aabab46cd 100644 --- a/src/ast/class.js +++ b/src/ast/class.js @@ -11,6 +11,7 @@ const KIND = "class"; /** * A class definition * @constructor Class + * @memberOf module:php-parser * @extends {Declaration} * @property {Identifier|null} extends * @property {Identifier[]} implements diff --git a/src/ast/classconstant.js b/src/ast/classconstant.js index 9023c0b66..204208f34 100644 --- a/src/ast/classconstant.js +++ b/src/ast/classconstant.js @@ -16,6 +16,7 @@ const IS_PRIVATE = "private"; /** * Defines a class/interface/trait constant * @constructor ClassConstant + * @memberOf module:php-parser * @extends {ConstantStatement} * @property {string} visibility */ @@ -29,7 +30,10 @@ const ClassConstant = ConstantStatement.extends( /** * Generic flags parser - * @param {Integer[]} flags + * @function + * @name ClassConstant#parseFlags + * @memberOf module:php-parser + * @param {Array} flags * @return {void} */ ClassConstant.prototype.parseFlags = function (flags) { diff --git a/src/ast/clone.js b/src/ast/clone.js index f2ee4f9b7..54ff3e37b 100644 --- a/src/ast/clone.js +++ b/src/ast/clone.js @@ -11,6 +11,7 @@ const KIND = "clone"; /** * Defines a clone call * @constructor Clone + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} what */ diff --git a/src/ast/closure.js b/src/ast/closure.js index 8dadb0170..8a607e627 100644 --- a/src/ast/closure.js +++ b/src/ast/closure.js @@ -11,11 +11,12 @@ const KIND = "closure"; /** * Defines a closure * @constructor Closure + * @memberOf module:php-parser * @extends {Expression} * @property {Parameter[]} arguments * @property {Variable[]} uses * @property {Identifier} type - * @property {boolean} byref + * @property {Boolean} byref * @property {boolean} nullable * @property {Block|null} body * @property {boolean} isStatic diff --git a/src/ast/comment.js b/src/ast/comment.js index 9bd11d6fa..cfde90c2e 100644 --- a/src/ast/comment.js +++ b/src/ast/comment.js @@ -10,6 +10,7 @@ const Node = require("./node"); /** * Abstract documentation node (ComentLine or CommentBlock) * @constructor Comment + * @memberOf module:php-parser * @extends {Node} * @property {String} value */ diff --git a/src/ast/commentblock.js b/src/ast/commentblock.js index 7687f3941..c6217c43e 100644 --- a/src/ast/commentblock.js +++ b/src/ast/commentblock.js @@ -11,6 +11,7 @@ const KIND = "commentblock"; /** * A comment block (multiline) * @constructor CommentBlock + * @memberOf module:php-parser * @extends {Comment} */ module.exports = Comment.extends( diff --git a/src/ast/commentline.js b/src/ast/commentline.js index 034c6bee7..8c5105b1e 100644 --- a/src/ast/commentline.js +++ b/src/ast/commentline.js @@ -11,6 +11,7 @@ const KIND = "commentline"; /** * A single line comment * @constructor CommentLine + * @memberOf module:php-parser * @extends {Comment} */ module.exports = Comment.extends( diff --git a/src/ast/constant.js b/src/ast/constant.js index e51153f53..a6a28658f 100644 --- a/src/ast/constant.js +++ b/src/ast/constant.js @@ -11,6 +11,7 @@ const KIND = "constant"; /** * Defines a constant * @constructor Constant + * @memberOf module:php-parser * @extends {Node} * @property {string} name * @property {Node|string|number|boolean|null} value diff --git a/src/ast/constantstatement.js b/src/ast/constantstatement.js index 60a6f2150..161876255 100644 --- a/src/ast/constantstatement.js +++ b/src/ast/constantstatement.js @@ -11,6 +11,7 @@ const KIND = "constantstatement"; /** * Declares a constants into the current scope * @constructor ConstantStatement + * @memberOf module:php-parser * @extends {Statement} * @property {Constant[]} constants */ diff --git a/src/ast/continue.js b/src/ast/continue.js index fdbf85faf..c968b9a88 100644 --- a/src/ast/continue.js +++ b/src/ast/continue.js @@ -11,8 +11,9 @@ const KIND = "continue"; /** * A continue statement * @constructor Continue + * @memberOf module:php-parser * @extends {Statement} - * @property {Number|Null} level + * @property {number|null} level */ module.exports = Statement.extends( KIND, diff --git a/src/ast/declaration.js b/src/ast/declaration.js index e0cc9ae2e..6a04a532f 100644 --- a/src/ast/declaration.js +++ b/src/ast/declaration.js @@ -16,6 +16,7 @@ const IS_PRIVATE = "private"; /** * A declaration statement (function, class, interface...) * @constructor Declaration + * @memberOf module:php-parser * @extends {Statement} * @property {Identifier|string} name */ @@ -29,7 +30,10 @@ const Declaration = Statement.extends( /** * Generic flags parser - * @param {Integer[]} flags + * @function + * @name Declaration#parseFlags + * @memberOf module:php-parser + * @param {Array} flags * @return {void} */ Declaration.prototype.parseFlags = function (flags) { diff --git a/src/ast/declare.js b/src/ast/declare.js index 4bdf32cb8..b1c5f54f3 100644 --- a/src/ast/declare.js +++ b/src/ast/declare.js @@ -11,6 +11,7 @@ const KIND = "declare"; /** * The declare construct is used to set execution directives for a block of code * @constructor Declare + * @memberOf module:php-parser * @extends {Block} * @property {Array[]} directives * @property {String} mode @@ -33,7 +34,8 @@ const Declare = Block.extends( * // some statements * enddeclare; * ``` - * @constant {String} MODE_SHORT + * @constant {String} Declare#MODE_SHORT + * @memberOf module:php-parser */ Declare.MODE_SHORT = "short"; @@ -45,7 +47,8 @@ Declare.MODE_SHORT = "short"; * // some statements * } * ``` - * @constant {String} MODE_BLOCK + * @constant {String} Declare#MODE_BLOCK + * @memberOf module:php-parser */ Declare.MODE_BLOCK = "block"; @@ -60,7 +63,8 @@ Declare.MODE_BLOCK = "block"; * declare(ticks=2); * // some statements * ``` - * @constant {String} MODE_NONE + * @constant {String} Declare#MODE_NONE + * @memberOf module:php-parser */ Declare.MODE_NONE = "none"; diff --git a/src/ast/declaredirective.js b/src/ast/declaredirective.js index f17f84bad..cc90b165e 100644 --- a/src/ast/declaredirective.js +++ b/src/ast/declaredirective.js @@ -11,6 +11,7 @@ const KIND = "declaredirective"; /** * Defines a constant * @constructor DeclareDirective + * @memberOf module:php-parser * @extends {Node} * @property {Identifier} name * @property {Node|string|number|boolean|null} value diff --git a/src/ast/do.js b/src/ast/do.js index a8415177e..6f306acb0 100644 --- a/src/ast/do.js +++ b/src/ast/do.js @@ -11,6 +11,7 @@ const KIND = "do"; /** * Defines a do/while statement * @constructor Do + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} test * @property {Statement} body diff --git a/src/ast/echo.js b/src/ast/echo.js index 3a98ea7ea..1ec637374 100644 --- a/src/ast/echo.js +++ b/src/ast/echo.js @@ -11,6 +11,7 @@ const KIND = "echo"; /** * Defines system based call * @constructor Echo + * @memberOf module:php-parser * @property {boolean} shortForm * @extends {Statement} */ diff --git a/src/ast/empty.js b/src/ast/empty.js index 435b692f4..cb86e2801 100644 --- a/src/ast/empty.js +++ b/src/ast/empty.js @@ -11,6 +11,7 @@ const KIND = "empty"; /** * Defines an empty check call * @constructor Empty + * @memberOf module:php-parser * @extends {Expression} */ module.exports = Expression.extends( diff --git a/src/ast/encapsed.js b/src/ast/encapsed.js index 4437f193f..d8311a33d 100644 --- a/src/ast/encapsed.js +++ b/src/ast/encapsed.js @@ -11,6 +11,7 @@ const KIND = "encapsed"; /** * Defines an encapsed string (contains expressions) * @constructor Encapsed + * @memberOf module:php-parser * @extends {Literal} * @property {String} type - Defines the type of encapsed string (shell, heredoc, string) * @property {String|Null} label - The heredoc label, defined only when the type is heredoc @@ -29,7 +30,8 @@ const Encapsed = Literal.extends( * bar_$baz; * ``` - * @constant {String} TYPE_OFFSET - `offset` + * @constant {String} Encapsed#TYPE_OFFSET - `offset` + * @memberOf module:php-parser */ Encapsed.TYPE_OFFSET = "offset"; diff --git a/src/ast/encapsedpart.js b/src/ast/encapsedpart.js index 0b8608615..90f852f9c 100644 --- a/src/ast/encapsedpart.js +++ b/src/ast/encapsedpart.js @@ -11,6 +11,7 @@ const KIND = "encapsedpart"; /** * Part of `Encapsed` node * @constructor EncapsedPart + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} expression * @property {String} syntax diff --git a/src/ast/entry.js b/src/ast/entry.js index 310e2258c..50f50b871 100644 --- a/src/ast/entry.js +++ b/src/ast/entry.js @@ -11,6 +11,7 @@ const KIND = "entry"; /** * An array entry - see [Array](#array) * @constructor Entry + * @memberOf module:php-parser * @extends {Expression} * @property {Node|null} key The entry key/offset * @property {Node} value The entry value diff --git a/src/ast/error.js b/src/ast/error.js index 0f7544807..918ed399f 100644 --- a/src/ast/error.js +++ b/src/ast/error.js @@ -11,6 +11,7 @@ const KIND = "error"; /** * Defines an error node (used only on silentMode) * @constructor Error + * @memberOf module:php-parser * @extends {Node} * @property {string} message * @property {number} line diff --git a/src/ast/eval.js b/src/ast/eval.js index 728dc0866..1c5f38b95 100644 --- a/src/ast/eval.js +++ b/src/ast/eval.js @@ -11,6 +11,7 @@ const KIND = "eval"; /** * Defines an eval statement * @constructor Eval + * @memberOf module:php-parser * @extends {Expression} * @property {Node} source */ diff --git a/src/ast/exit.js b/src/ast/exit.js index b92be5361..0a34b4edd 100644 --- a/src/ast/exit.js +++ b/src/ast/exit.js @@ -11,9 +11,10 @@ const KIND = "exit"; /** * Defines an exit / die call * @constructor Exit + * @memberOf module:php-parser * @extends {Expression} * @property {Node|null} expression - * @property {Boolean} useDie + * @property {boolean} useDie */ module.exports = Expression.extends( KIND, diff --git a/src/ast/expression.js b/src/ast/expression.js index 3b4d39d8e..c64f16a6c 100644 --- a/src/ast/expression.js +++ b/src/ast/expression.js @@ -12,6 +12,7 @@ const KIND = "expression"; * Any expression node. Since the left-hand side of an assignment may * be any expression in general, an expression can also be a pattern. * @constructor Expression + * @memberOf module:php-parser * @extends {Node} */ module.exports = Node.extends(KIND, function Expression(kind, docs, location) { diff --git a/src/ast/expressionstatement.js b/src/ast/expressionstatement.js index e7ea88503..05a4e697a 100644 --- a/src/ast/expressionstatement.js +++ b/src/ast/expressionstatement.js @@ -11,6 +11,7 @@ const KIND = "expressionstatement"; /** * Defines an expression based statement * @constructor ExpressionStatement + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} expression */ diff --git a/src/ast/for.js b/src/ast/for.js index 9fe2362c2..628becd8c 100644 --- a/src/ast/for.js +++ b/src/ast/for.js @@ -11,6 +11,7 @@ const KIND = "for"; /** * Defines a for iterator * @constructor For + * @memberOf module:php-parser * @extends {Statement} * @property {Expression[]} init * @property {Expression[]} test diff --git a/src/ast/foreach.js b/src/ast/foreach.js index 75a19f8ac..cf183778d 100644 --- a/src/ast/foreach.js +++ b/src/ast/foreach.js @@ -11,6 +11,7 @@ const KIND = "foreach"; /** * Defines a foreach iterator * @constructor Foreach + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} source * @property {Expression|null} key diff --git a/src/ast/function.js b/src/ast/function.js index 17a312d9c..70ecc472f 100644 --- a/src/ast/function.js +++ b/src/ast/function.js @@ -11,6 +11,7 @@ const KIND = "function"; /** * Defines a classic function * @constructor Function + * @memberOf module:php-parser * @extends {Declaration} * @property {Parameter[]} arguments * @property {Identifier} type diff --git a/src/ast/global.js b/src/ast/global.js index 97f1bed0b..a9dab2c71 100644 --- a/src/ast/global.js +++ b/src/ast/global.js @@ -11,6 +11,7 @@ const KIND = "global"; /** * Imports a variable from the global scope * @constructor Global + * @memberOf module:php-parser * @extends {Statement} * @property {Variable[]} items */ diff --git a/src/ast/goto.js b/src/ast/goto.js index e80f70174..4e00653eb 100644 --- a/src/ast/goto.js +++ b/src/ast/goto.js @@ -11,8 +11,9 @@ const KIND = "goto"; /** * Defines goto statement * @constructor Goto + * @memberOf module:php-parser * @extends {Statement} - * @property {String} label + * @property {string} label * @see {Label} */ module.exports = Statement.extends(KIND, function Goto(label, docs, location) { diff --git a/src/ast/halt.js b/src/ast/halt.js index eaa0dd2a9..acad687dc 100644 --- a/src/ast/halt.js +++ b/src/ast/halt.js @@ -11,6 +11,7 @@ const KIND = "halt"; /** * Halts the compiler execution * @constructor Halt + * @memberOf module:php-parser * @extends {Statement} * @property {String} after - String after the halt statement * @see http://php.net/manual/en/function.halt-compiler.php diff --git a/src/ast/identifier.js b/src/ast/identifier.js index 119467f45..b193f3488 100644 --- a/src/ast/identifier.js +++ b/src/ast/identifier.js @@ -11,6 +11,7 @@ const KIND = "identifier"; /** * Defines an identifier node * @constructor Identifier + * @memberOf module:php-parser * @extends {Node} * @property {string} name */ diff --git a/src/ast/if.js b/src/ast/if.js index 26bc88e9a..00cb0e988 100644 --- a/src/ast/if.js +++ b/src/ast/if.js @@ -11,6 +11,7 @@ const KIND = "if"; /** * Defines a if statement * @constructor If + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} test * @property {Block} body diff --git a/src/ast/include.js b/src/ast/include.js index 976cacbce..a4f019b25 100644 --- a/src/ast/include.js +++ b/src/ast/include.js @@ -11,6 +11,7 @@ const KIND = "include"; /** * Defines system include call * @constructor Include + * @memberOf module:php-parser * @extends {Expression} * @property {Node} target * @property {boolean} once diff --git a/src/ast/inline.js b/src/ast/inline.js index cc4398811..78dba08a1 100644 --- a/src/ast/inline.js +++ b/src/ast/inline.js @@ -11,6 +11,7 @@ const KIND = "inline"; /** * Defines inline html output (treated as echo output) * @constructor Inline + * @memberOf module:php-parser * @extends {Literal} */ module.exports = Literal.extends( diff --git a/src/ast/interface.js b/src/ast/interface.js index 0a0740e70..9437d86bd 100644 --- a/src/ast/interface.js +++ b/src/ast/interface.js @@ -11,6 +11,7 @@ const KIND = "interface"; /** * An interface definition * @constructor Interface + * @memberOf module:php-parser * @extends {Declaration} * @property {Identifier[]} extends * @property {Declaration[]} body diff --git a/src/ast/isset.js b/src/ast/isset.js index cf7afd804..9dc33e3a4 100644 --- a/src/ast/isset.js +++ b/src/ast/isset.js @@ -11,6 +11,7 @@ const KIND = "isset"; /** * Defines an isset call * @constructor Isset + * @memberOf module:php-parser * @extends {Expression} */ module.exports = Expression.extends( diff --git a/src/ast/label.js b/src/ast/label.js index 6acc239c0..c1e630413 100644 --- a/src/ast/label.js +++ b/src/ast/label.js @@ -11,6 +11,7 @@ const KIND = "label"; /** * A label statement (referenced by goto) * @constructor Label + * @memberOf module:php-parser * @extends {Statement} * @property {String} name */ diff --git a/src/ast/list.js b/src/ast/list.js index 5cc9b8e2d..93801adb7 100644 --- a/src/ast/list.js +++ b/src/ast/list.js @@ -11,6 +11,7 @@ const KIND = "list"; /** * Defines list assignment * @constructor List + * @memberOf module:php-parser * @extends {Expression} * @property {boolean} shortForm */ diff --git a/src/ast/literal.js b/src/ast/literal.js index 0a3678e19..fbbabc5a5 100644 --- a/src/ast/literal.js +++ b/src/ast/literal.js @@ -11,6 +11,7 @@ const KIND = "literal"; /** * Defines an array structure * @constructor Literal + * @memberOf module:php-parser * @extends {Expression} * @property {string} raw * @property {Node|string|number|boolean|null} value diff --git a/src/ast/location.js b/src/ast/location.js index 4015c23fe..65a975e89 100644 --- a/src/ast/location.js +++ b/src/ast/location.js @@ -8,7 +8,8 @@ /** * Defines the location of the node (with it's source contents as string) * @constructor Location - * @property {String|null} source + * @memberOf module:php-parser + * @property {string|null} source * @property {Position} start * @property {Position} end */ diff --git a/src/ast/lookup.js b/src/ast/lookup.js index cef2628e9..752fc52c3 100644 --- a/src/ast/lookup.js +++ b/src/ast/lookup.js @@ -11,6 +11,7 @@ const KIND = "lookup"; /** * Lookup on an offset in the specified object * @constructor Lookup + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} what * @property {Expression} offset diff --git a/src/ast/magic.js b/src/ast/magic.js index 9f68384a4..b7ed97c27 100644 --- a/src/ast/magic.js +++ b/src/ast/magic.js @@ -11,6 +11,7 @@ const KIND = "magic"; /** * Defines magic constant * @constructor Magic + * @memberOf module:php-parser * @extends {Literal} */ module.exports = Literal.extends( diff --git a/src/ast/method.js b/src/ast/method.js index e5127ce8a..727db188a 100644 --- a/src/ast/method.js +++ b/src/ast/method.js @@ -5,19 +5,20 @@ */ "use strict"; -const _Function = require("./function"); +const Function_ = require("./function"); const KIND = "method"; /** * Defines a class/interface/trait method * @constructor Method - * @extends {_Function} + * @memberOf module:php-parser + * @extends {Function} * @property {boolean} isAbstract * @property {boolean} isFinal * @property {boolean} isStatic * @property {string} visibility */ -module.exports = _Function.extends(KIND, function Method() { - _Function.apply(this, arguments); +module.exports = Function_.extends(KIND, function Method() { + Function_.apply(this, arguments); this.kind = KIND; }); diff --git a/src/ast/name.js b/src/ast/name.js index da9623598..be103ea74 100644 --- a/src/ast/name.js +++ b/src/ast/name.js @@ -11,6 +11,7 @@ const KIND = "name"; /** * Defines a class reference node * @constructor Name + * @memberOf module:php-parser * @extends {Reference} * @property {string} name * @property {string} resolution @@ -34,24 +35,28 @@ const Name = Reference.extends( /** * This is an identifier without a namespace separator, such as Foo - * @constant {String} UNQUALIFIED_NAME + * @constant {String} Name#UNQUALIFIED_NAME + * @memberOf module:php-parser */ Name.UNQUALIFIED_NAME = "uqn"; /** * This is an identifier with a namespace separator, such as Foo\Bar - * @constant {String} QUALIFIED_NAME + * @constant {String} Name#QUALIFIED_NAME + * @memberOf module:php-parser */ Name.QUALIFIED_NAME = "qn"; /** * This is an identifier with a namespace separator that begins with * a namespace separator, such as \Foo\Bar. The namespace \Foo is also * a fully qualified name. - * @constant {String} FULL_QUALIFIED_NAME + * @constant {String} Name#FULL_QUALIFIED_NAME + * @memberOf module:php-parser */ Name.FULL_QUALIFIED_NAME = "fqn"; /** * This is an identifier starting with namespace, such as namespace\Foo\Bar. - * @constant {String} RELATIVE_NAME + * @constant {String} Name#RELATIVE_NAME + * @memberOf module:php-parser */ Name.RELATIVE_NAME = "rn"; diff --git a/src/ast/namespace.js b/src/ast/namespace.js index ae5541bbd..3a7a78d7a 100644 --- a/src/ast/namespace.js +++ b/src/ast/namespace.js @@ -11,9 +11,10 @@ const KIND = "namespace"; /** * The main program node * @constructor Namespace + * @memberOf module:php-parser * @extends {Block} - * @property {String} name - * @property {Boolean} withBrackets + * @property {string} name + * @property {boolean} withBrackets */ module.exports = Block.extends( KIND, diff --git a/src/ast/new.js b/src/ast/new.js index c00f0c016..7f492b31f 100644 --- a/src/ast/new.js +++ b/src/ast/new.js @@ -11,9 +11,10 @@ const KIND = "new"; /** * Creates a new instance of the specified class * @constructor New + * @memberOf module:php-parser * @extends {Expression} * @property {Identifier|Variable|Class} what - * @property {Arguments[]} arguments + * @property {Variable[]} arguments */ module.exports = Expression.extends( KIND, diff --git a/src/ast/node.js b/src/ast/node.js index a77fe61e7..98a69ad22 100644 --- a/src/ast/node.js +++ b/src/ast/node.js @@ -8,10 +8,11 @@ /** * A generic AST node * @constructor Node + * @memberOf module:php-parser * @property {Location|null} loc - * @property {Comment[]} leadingComments - * @property {Comment[]?} trailingComments - * @property {String} kind + * @property {CommentBlock[]|Comment[]|null} leadingComments + * @property {CommentBlock[]|Comment[]|null} trailingComments + * @property {string} kind */ const Node = function Node(kind, docs, location) { this.kind = kind; @@ -25,6 +26,8 @@ const Node = function Node(kind, docs, location) { /** * Attach comments to current node + * @function Node#setTrailingComments + * @memberOf module:php-parser * @param {*} docs */ Node.prototype.setTrailingComments = function (docs) { @@ -33,6 +36,8 @@ Node.prototype.setTrailingComments = function (docs) { /** * Destroying an unused node + * @function Node#destroy + * @memberOf module:php-parser */ Node.prototype.destroy = function (node) { if (!node) { @@ -65,6 +70,8 @@ Node.prototype.destroy = function (node) { /** * Includes current token position of the parser + * @function Node#includeToken + * @memberOf module:php-parser * @param {*} parser */ Node.prototype.includeToken = function (parser) { @@ -86,7 +93,9 @@ Node.prototype.includeToken = function (parser) { /** * Helper for extending the Node class - * @param {String} type + * @function Node.extends + * @memberOf module:php-parser + * @param {string} type * @param {Function} constructor * @return {Function} */ diff --git a/src/ast/noop.js b/src/ast/noop.js index 0b512b936..f9d9e1ef0 100644 --- a/src/ast/noop.js +++ b/src/ast/noop.js @@ -12,6 +12,7 @@ const KIND = "noop"; * Ignore this node, it implies a no operation block, for example : * [$foo, $bar, /* here a noop node * /] * @constructor Noop + * @memberOf module:php-parser * @extends {Node} */ module.exports = Node.extends(KIND, function Noop(docs, location) { diff --git a/src/ast/nowdoc.js b/src/ast/nowdoc.js index 3402ef03a..dd156c7cc 100644 --- a/src/ast/nowdoc.js +++ b/src/ast/nowdoc.js @@ -11,9 +11,10 @@ const KIND = "nowdoc"; /** * Defines a nowdoc string * @constructor NowDoc + * @memberOf module:php-parser * @extends {Literal} - * @property {String} label - * @property {String} raw + * @property {string} label + * @property {string} raw */ module.exports = Literal.extends( KIND, diff --git a/src/ast/nullkeyword.js b/src/ast/nullkeyword.js index 5640a179d..cc6bf5f4d 100644 --- a/src/ast/nullkeyword.js +++ b/src/ast/nullkeyword.js @@ -11,6 +11,7 @@ const KIND = "nullkeyword"; /** * Represents the null keyword * @constructor NullKeyword + * @memberOf module:php-parser * @extends {Node} */ module.exports = Node.extends(KIND, function NullKeyword(raw, docs, location) { diff --git a/src/ast/number.js b/src/ast/number.js index bcdf8dac9..fc6e6bea5 100644 --- a/src/ast/number.js +++ b/src/ast/number.js @@ -11,6 +11,7 @@ const KIND = "number"; /** * Defines a numeric value * @constructor Number + * @memberOf module:php-parser * @extends {Literal} */ module.exports = Literal.extends( diff --git a/src/ast/offsetlookup.js b/src/ast/offsetlookup.js index 0323a5de2..6b1d080f2 100644 --- a/src/ast/offsetlookup.js +++ b/src/ast/offsetlookup.js @@ -11,6 +11,7 @@ const KIND = "offsetlookup"; /** * Lookup on an offset in an array * @constructor OffsetLookup + * @memberOf module:php-parser * @extends {Lookup} */ module.exports = Lookup.extends( diff --git a/src/ast/operation.js b/src/ast/operation.js index 852fbd848..6e3eda9ea 100644 --- a/src/ast/operation.js +++ b/src/ast/operation.js @@ -11,6 +11,7 @@ const KIND = "operation"; /** * Defines binary operations * @constructor Operation + * @memberOf module:php-parser * @extends {Expression} */ module.exports = Expr.extends(KIND, function Operation(kind, docs, location) { diff --git a/src/ast/parameter.js b/src/ast/parameter.js index 08db41503..0762ec8ea 100644 --- a/src/ast/parameter.js +++ b/src/ast/parameter.js @@ -11,6 +11,7 @@ const KIND = "parameter"; /** * Defines a function parameter * @constructor Parameter + * @memberOf module:php-parser * @extends {Declaration} * @property {Identifier|null} type * @property {Node|null} value diff --git a/src/ast/parentreference.js b/src/ast/parentreference.js index 9a8ba1258..5b41d01da 100644 --- a/src/ast/parentreference.js +++ b/src/ast/parentreference.js @@ -11,6 +11,7 @@ const KIND = "parentreference"; /** * Defines a class reference node * @constructor ParentReference + * @memberOf module:php-parser * @extends {Reference} */ const ParentReference = Reference.extends( diff --git a/src/ast/position.js b/src/ast/position.js index b802df37e..6e4f123c4 100644 --- a/src/ast/position.js +++ b/src/ast/position.js @@ -8,9 +8,10 @@ /** * Each Position object consists of a line number (1-indexed) and a column number (0-indexed): * @constructor Position - * @property {Number} line - * @property {Number} column - * @property {Number} offset + * @memberOf module:php-parser + * @property {number} line + * @property {number} column + * @property {number} offset */ const Position = function (line, column, offset) { this.line = line; diff --git a/src/ast/post.js b/src/ast/post.js index 4ae0f30ab..4ea93506f 100644 --- a/src/ast/post.js +++ b/src/ast/post.js @@ -11,6 +11,7 @@ const KIND = "post"; /** * Defines a post operation `$i++` or `$i--` * @constructor Post + * @memberOf module:php-parser * @extends {Operation} * @property {String} type * @property {Variable} what diff --git a/src/ast/pre.js b/src/ast/pre.js index c2c1a2580..974a91ec9 100644 --- a/src/ast/pre.js +++ b/src/ast/pre.js @@ -11,6 +11,7 @@ const KIND = "pre"; /** * Defines a pre operation `++$i` or `--$i` * @constructor Pre + * @memberOf module:php-parser * @extends {Operation} * @property {String} type * @property {Variable} what diff --git a/src/ast/print.js b/src/ast/print.js index c72bebe09..1d9317afb 100644 --- a/src/ast/print.js +++ b/src/ast/print.js @@ -11,6 +11,7 @@ const KIND = "print"; /** * Outputs * @constructor Print + * @memberOf module:php-parser * @extends {Expression} */ module.exports = Expression.extends( diff --git a/src/ast/program.js b/src/ast/program.js index 1cc06591b..9080332f0 100644 --- a/src/ast/program.js +++ b/src/ast/program.js @@ -11,10 +11,11 @@ const KIND = "program"; /** * The main program node * @constructor Program + * @memberOf module:php-parser * @extends {Block} * @property {Error[]} errors - * @property {Doc[]?} comments - * @property {String[]?} tokens + * @property {Comment[]|null} comments + * @property {String[]|null} tokens */ module.exports = Block.extends( KIND, diff --git a/src/ast/property.js b/src/ast/property.js index 4b8890406..c34a09559 100644 --- a/src/ast/property.js +++ b/src/ast/property.js @@ -11,6 +11,7 @@ const KIND = "property"; /** * Defines a class property * @constructor Property + * @memberOf module:php-parser * @extends {Statement} * @property {string} name * @property {Node|null} value diff --git a/src/ast/propertylookup.js b/src/ast/propertylookup.js index 8c622b908..06f504503 100644 --- a/src/ast/propertylookup.js +++ b/src/ast/propertylookup.js @@ -11,6 +11,7 @@ const KIND = "propertylookup"; /** * Lookup to an object property * @constructor PropertyLookup + * @memberOf module:php-parser * @extends {Lookup} */ module.exports = Lookup.extends( diff --git a/src/ast/propertystatement.js b/src/ast/propertystatement.js index 56d13831d..d4ab2dff2 100644 --- a/src/ast/propertystatement.js +++ b/src/ast/propertystatement.js @@ -16,6 +16,7 @@ const IS_PRIVATE = "private"; /** * Declares a properties into the current scope * @constructor PropertyStatement + * @memberOf module:php-parser * @extends {Statement} * @property {Property[]} properties */ @@ -30,7 +31,9 @@ const PropertyStatement = Statement.extends( /** * Generic flags parser - * @param {Integer[]} flags + * @function PropertyStatement#parseFlags + * @memberOf module:php-parser + * @param {Array} flags * @return {void} */ PropertyStatement.prototype.parseFlags = function (flags) { diff --git a/src/ast/reference.js b/src/ast/reference.js index bd86b3837..e000937ad 100644 --- a/src/ast/reference.js +++ b/src/ast/reference.js @@ -11,6 +11,7 @@ const KIND = "reference"; /** * Defines a reference node * @constructor Reference + * @memberOf module:php-parser * @extends {Node} */ const Reference = Node.extends(KIND, function Reference(kind, docs, location) { diff --git a/src/ast/retif.js b/src/ast/retif.js index 879de91f9..2b4e85d49 100644 --- a/src/ast/retif.js +++ b/src/ast/retif.js @@ -11,6 +11,7 @@ const KIND = "retif"; /** * Defines a short if statement that returns a value * @constructor RetIf + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} test * @property {Expression} trueExpr diff --git a/src/ast/return.js b/src/ast/return.js index b320eaf49..c7c049baa 100644 --- a/src/ast/return.js +++ b/src/ast/return.js @@ -11,6 +11,7 @@ const KIND = "return"; /** * A continue statement * @constructor Return + * @memberOf module:php-parser * @extends {Statement} * @property {Expression|null} expr */ diff --git a/src/ast/selfreference.js b/src/ast/selfreference.js index cf2b6837f..68f546fdc 100644 --- a/src/ast/selfreference.js +++ b/src/ast/selfreference.js @@ -11,6 +11,7 @@ const KIND = "selfreference"; /** * Defines a class reference node * @constructor SelfReference + * @memberOf module:php-parser * @extends {Reference} */ const SelfReference = Reference.extends( diff --git a/src/ast/silent.js b/src/ast/silent.js index e565aabf8..fb0fe4712 100644 --- a/src/ast/silent.js +++ b/src/ast/silent.js @@ -11,6 +11,7 @@ const KIND = "silent"; /** * Avoids to show/log warnings & notices from the inner expression * @constructor Silent + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} expr */ diff --git a/src/ast/statement.js b/src/ast/statement.js index c4c578fc7..6f25bd8ee 100644 --- a/src/ast/statement.js +++ b/src/ast/statement.js @@ -11,6 +11,7 @@ const KIND = "statement"; /** * Any statement. * @constructor Statement + * @memberOf module:php-parser * @extends {Node} */ module.exports = Node.extends(KIND, function Statement(kind, docs, location) { diff --git a/src/ast/static.js b/src/ast/static.js index 5262f8651..f340e2724 100644 --- a/src/ast/static.js +++ b/src/ast/static.js @@ -11,6 +11,7 @@ const KIND = "static"; /** * Declares a static variable into the current scope * @constructor Static + * @memberOf module:php-parser * @extends {Statement} * @property {StaticVariable[]} variables */ diff --git a/src/ast/staticlookup.js b/src/ast/staticlookup.js index d1c0c102b..83bac113f 100644 --- a/src/ast/staticlookup.js +++ b/src/ast/staticlookup.js @@ -11,6 +11,7 @@ const KIND = "staticlookup"; /** * Lookup to a static property * @constructor StaticLookup + * @memberOf module:php-parser * @extends {Lookup} */ module.exports = Lookup.extends( diff --git a/src/ast/staticreference.js b/src/ast/staticreference.js index 706959ff3..e6962a58f 100644 --- a/src/ast/staticreference.js +++ b/src/ast/staticreference.js @@ -11,6 +11,7 @@ const KIND = "staticreference"; /** * Defines a class reference node * @constructor StaticReference + * @memberOf module:php-parser * @extends {Reference} */ const StaticReference = Reference.extends( diff --git a/src/ast/staticvariable.js b/src/ast/staticvariable.js index 6483e3c28..1a8c0caee 100644 --- a/src/ast/staticvariable.js +++ b/src/ast/staticvariable.js @@ -11,6 +11,7 @@ const KIND = "staticvariable"; /** * Defines a constant * @constructor StaticVariable + * @memberOf module:php-parser * @extends {Node} * @property {Variable} variable * @property {Node|string|number|boolean|null} defaultValue diff --git a/src/ast/string.js b/src/ast/string.js index ca1f4df69..3f1435e18 100644 --- a/src/ast/string.js +++ b/src/ast/string.js @@ -9,8 +9,9 @@ const Literal = require("./literal"); const KIND = "string"; /** - * Defines a string (simple ou double quoted) - chars are already escaped + * Defines a string (simple or double quoted) - chars are already escaped * @constructor String + * @memberOf module:php-parser * @extends {Literal} * @property {boolean} unicode * @property {boolean} isDoubleQuote diff --git a/src/ast/switch.js b/src/ast/switch.js index 3cb72da65..2748b9d0d 100644 --- a/src/ast/switch.js +++ b/src/ast/switch.js @@ -11,6 +11,7 @@ const KIND = "switch"; /** * Defines a switch statement * @constructor Switch + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} test * @property {Block} body diff --git a/src/ast/throw.js b/src/ast/throw.js index cb617df0d..36c51f88e 100644 --- a/src/ast/throw.js +++ b/src/ast/throw.js @@ -11,6 +11,7 @@ const KIND = "throw"; /** * Defines a throw statement * @constructor Throw + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} what */ diff --git a/src/ast/trait.js b/src/ast/trait.js index b48654831..8cf40cf66 100644 --- a/src/ast/trait.js +++ b/src/ast/trait.js @@ -11,6 +11,7 @@ const KIND = "trait"; /** * A trait definition * @constructor Trait + * @memberOf module:php-parser * @extends {Declaration} * @property {Declaration[]} body */ diff --git a/src/ast/traitalias.js b/src/ast/traitalias.js index 50e960687..b113de981 100644 --- a/src/ast/traitalias.js +++ b/src/ast/traitalias.js @@ -16,6 +16,7 @@ const IS_PRIVATE = "private"; /** * Defines a trait alias * @constructor TraitAlias + * @memberOf module:php-parser * @extends {Node} * @property {Identifier|null} trait * @property {Identifier} method diff --git a/src/ast/traitprecedence.js b/src/ast/traitprecedence.js index 6cd461c0b..b61c2b678 100644 --- a/src/ast/traitprecedence.js +++ b/src/ast/traitprecedence.js @@ -11,6 +11,7 @@ const KIND = "traitprecedence"; /** * Defines a trait alias * @constructor TraitPrecedence + * @memberOf module:php-parser * @extends {Node} * @property {Identifier|null} trait * @property {Identifier} method diff --git a/src/ast/traituse.js b/src/ast/traituse.js index b268aa098..ce9276900 100644 --- a/src/ast/traituse.js +++ b/src/ast/traituse.js @@ -11,6 +11,7 @@ const KIND = "traituse"; /** * Defines a trait usage * @constructor TraitUse + * @memberOf module:php-parser * @extends {Node} * @property {Identifier[]} traits * @property {Node[]|null} adaptations diff --git a/src/ast/try.js b/src/ast/try.js index 25e2a9dfc..1fced8bf3 100644 --- a/src/ast/try.js +++ b/src/ast/try.js @@ -11,6 +11,7 @@ const KIND = "try"; /** * Defines a try statement * @constructor Try + * @memberOf module:php-parser * @extends {Statement} * @property {Block} body * @property {Catch[]} catches diff --git a/src/ast/typereference.js b/src/ast/typereference.js index 246fc5f0a..73cee2119 100644 --- a/src/ast/typereference.js +++ b/src/ast/typereference.js @@ -11,6 +11,7 @@ const KIND = "typereference"; /** * Defines a class reference node * @constructor TypeReference + * @memberOf module:php-parser * @extends {Reference} * @property {string} name */ diff --git a/src/ast/unary.js b/src/ast/unary.js index 1f79dcf9b..94aee3073 100644 --- a/src/ast/unary.js +++ b/src/ast/unary.js @@ -11,8 +11,9 @@ const KIND = "unary"; /** * Unary operations * @constructor Unary + * @memberOf module:php-parser * @extends {Operation} - * @property {String} type + * @property {string} type * @property {Expression} what */ module.exports = Operation.extends( diff --git a/src/ast/unset.js b/src/ast/unset.js index 3cbdbf3b1..b33ee595a 100644 --- a/src/ast/unset.js +++ b/src/ast/unset.js @@ -11,6 +11,7 @@ const KIND = "unset"; /** * Deletes references to a list of variables * @constructor Unset + * @memberOf module:php-parser * @extends {Statement} */ module.exports = Statement.extends( diff --git a/src/ast/usegroup.js b/src/ast/usegroup.js index 439b2f07d..f42d305ea 100644 --- a/src/ast/usegroup.js +++ b/src/ast/usegroup.js @@ -11,9 +11,10 @@ const KIND = "usegroup"; /** * Defines a use statement (with a list of use items) * @constructor UseGroup + * @memberOf module:php-parser * @extends {Statement} - * @property {String|null} name - * @property {String|null} type - Possible value : function, const + * @property {string|null} name + * @property {string|null} type - Possible value : function, const * @property {UseItem[]} item * @see {Namespace} * @see http://php.net/manual/en/language.namespaces.importing.php diff --git a/src/ast/useitem.js b/src/ast/useitem.js index 08ee830e6..b35870018 100644 --- a/src/ast/useitem.js +++ b/src/ast/useitem.js @@ -11,9 +11,10 @@ const KIND = "useitem"; /** * Defines a use statement (from namespace) * @constructor UseItem + * @memberOf module:php-parser * @extends {Statement} - * @property {String} name - * @property {String|null} type - Possible value : function, const + * @property {string} name + * @property {string|null} type - Possible value : function, const * @property {Identifier|null} alias * @see {Namespace} * @see http://php.net/manual/en/language.namespaces.importing.php @@ -30,12 +31,14 @@ const UseItem = Statement.extends( /** * Importing a constant - * @constant {String} TYPE_CONST + * @constant {string} UseItem#TYPE_CONST + * @memberOf module:php-parser */ UseItem.TYPE_CONST = "const"; /** * Importing a function - * @constant {String} TYPE_FUNC + * @constant {string} UseItem#TYPE_FUNC + * @memberOf module:php-parser */ UseItem.TYPE_FUNCTION = "function"; diff --git a/src/ast/variable.js b/src/ast/variable.js index 0a2ba9f4a..28838590a 100644 --- a/src/ast/variable.js +++ b/src/ast/variable.js @@ -12,6 +12,7 @@ const KIND = "variable"; * Any expression node. Since the left-hand side of an assignment may * be any expression in general, an expression can also be a pattern. * @constructor Variable + * @memberOf module:php-parser * @extends {Expression} * @example * // PHP code : @@ -22,7 +23,7 @@ const KIND = "variable"; * "name": "foo", * "curly": false * } - * @property {String|Node} name The variable name (can be a complex expression when the name is resolved dynamically) + * @property {string|Node} name The variable name (can be a complex expression when the name is resolved dynamically) * @property {boolean} curly Indicate if the name is defined between curlies, ex `${foo}` */ module.exports = Expression.extends( diff --git a/src/ast/variadic.js b/src/ast/variadic.js index 2561645bf..3be60ace9 100644 --- a/src/ast/variadic.js +++ b/src/ast/variadic.js @@ -10,7 +10,8 @@ const KIND = "variadic"; /** * Introduce a list of items into the arguments of the call - * @constructor variadic + * @constructor Variadic + * @memberOf module:php-parser * @extends {Expression} * @property {Array|Expression} what * @see https://wiki.php.net/rfc/argument_unpacking diff --git a/src/ast/while.js b/src/ast/while.js index 2766ff4c9..fcb7b3b25 100644 --- a/src/ast/while.js +++ b/src/ast/while.js @@ -11,6 +11,7 @@ const KIND = "while"; /** * Defines a while statement * @constructor While + * @memberOf module:php-parser * @extends {Statement} * @property {Expression} test * @property {Statement} body diff --git a/src/ast/yield.js b/src/ast/yield.js index 2000408e1..b38fee38d 100644 --- a/src/ast/yield.js +++ b/src/ast/yield.js @@ -11,9 +11,10 @@ const KIND = "yield"; /** * Defines a yield generator statement * @constructor Yield + * @memberOf module:php-parser * @extends {Expression} - * @property {Expression|Null} value - * @property {Expression|Null} key + * @property {Expression|null} value + * @property {Expression|null} key * @see http://php.net/manual/en/language.generators.syntax.php */ module.exports = Expression.extends( diff --git a/src/ast/yieldfrom.js b/src/ast/yieldfrom.js index 09a36c3a1..3e604592d 100644 --- a/src/ast/yieldfrom.js +++ b/src/ast/yieldfrom.js @@ -11,6 +11,7 @@ const KIND = "yieldfrom"; /** * Defines a yield from generator statement * @constructor YieldFrom + * @memberOf module:php-parser * @extends {Expression} * @property {Expression} value * @see http://php.net/manual/en/language.generators.syntax.php diff --git a/src/index.js b/src/index.js index 24bd5c874..d3aaec4fa 100644 --- a/src/index.js +++ b/src/index.js @@ -38,6 +38,7 @@ function combine(src, to) { * Initialise a new parser instance with the specified options * * @class + * @memberOf module:php-parser * @tutorial Engine * @example * var parser = require('php-parser'); @@ -66,7 +67,7 @@ function combine(src, to) { * @property {AST} ast * @property {Object} tokens */ -const engine = function (options) { +const Engine = function (options) { if (typeof this === "function") { return new this(options); } @@ -106,6 +107,7 @@ const engine = function (options) { /** * Check if the inpyt is a buffer or a string + * @private * @param {Buffer|String} buffer Input value that can be either a buffer or a string * @return {String} Returns the string from input */ @@ -119,16 +121,16 @@ const getStringBuffer = function (buffer) { * @return {Engine} * @private */ -engine.create = function (options) { - return new engine(options); +Engine.create = function (options) { + return new Engine(options); }; /** * Evaluate the buffer * @private */ -engine.parseEval = function (buffer, options) { - const self = new engine(options); +Engine.parseEval = function (buffer, options) { + const self = new Engine(options); return self.parseEval(buffer); }; @@ -137,7 +139,7 @@ engine.parseEval = function (buffer, options) { * @param {String} buffer * @return {Program} */ -engine.prototype.parseEval = function (buffer) { +Engine.prototype.parseEval = function (buffer) { this.lexer.mode_eval = true; this.lexer.all_tokens = false; buffer = getStringBuffer(buffer); @@ -148,13 +150,13 @@ engine.prototype.parseEval = function (buffer) { * Static function that parse a php code with open/close tags * @private */ -engine.parseCode = function (buffer, filename, options) { +Engine.parseCode = function (buffer, filename, options) { if (typeof filename === "object" && !options) { // retro-compatibility options = filename; filename = "unknown"; } - const self = new engine(options); + const self = new Engine(options); return self.parseCode(buffer, filename); }; @@ -178,7 +180,7 @@ engine.parseCode = function (buffer, filename, options) { * @param {String} filename - Filename * @return {Program} */ -engine.prototype.parseCode = function (buffer, filename) { +Engine.prototype.parseCode = function (buffer, filename) { this.lexer.mode_eval = false; this.lexer.all_tokens = false; buffer = getStringBuffer(buffer); @@ -189,8 +191,8 @@ engine.prototype.parseCode = function (buffer, filename) { * Split the buffer into tokens * @private */ -engine.tokenGetAll = function (buffer, options) { - const self = new engine(options); +Engine.tokenGetAll = function (buffer, options) { + const self = new Engine(options); return self.tokenGetAll(buffer); }; @@ -200,7 +202,7 @@ engine.tokenGetAll = function (buffer, options) { * @param {String} buffer * @return {String[]} - Each item can be a string or an array with following informations [token_name, text, line_number] */ -engine.prototype.tokenGetAll = function (buffer) { +Engine.prototype.tokenGetAll = function (buffer) { this.lexer.mode_eval = false; this.lexer.all_tokens = true; buffer = getStringBuffer(buffer); @@ -220,8 +222,10 @@ engine.prototype.tokenGetAll = function (buffer) { return result; }; +/** @module php-parser */ + // exports the function -module.exports = engine; +module.exports = Engine; // makes libraries public module.exports.tokens = tokens; @@ -229,6 +233,7 @@ module.exports.lexer = lexer; module.exports.AST = AST; module.exports.parser = parser; module.exports.combine = combine; +module.exports.Engine = Engine; // allow the default export in index.d.ts -module.exports.default = engine; +module.exports.default = Engine; diff --git a/src/lexer.js b/src/lexer.js index 008c0dc1e..f7449f601 100644 --- a/src/lexer.js +++ b/src/lexer.js @@ -9,17 +9,18 @@ * This is the php lexer. It will tokenize the string for helping the * parser to build the AST from its grammar. * - * @class - * @property {Integer} EOF - * @property {Boolean} all_tokens defines if all tokens must be retrieved (used by token_get_all only) - * @property {Boolean} comment_tokens extracts comments tokens - * @property {Boolean} mode_eval enables the evald mode (ignore opening tags) - * @property {Boolean} asp_tags disables by default asp tags mode - * @property {Boolean} short_tags enables by default short tags mode - * @property {Object} keywords List of php keyword - * @property {Object} castKeywords List of php keywords for type casting + * @constructor Lexer + * @memberOf module:php-parser + * @property {number} EOF + * @property {boolean} all_tokens defines if all tokens must be retrieved (used by token_get_all only) + * @property {boolean} comment_tokens extracts comments tokens + * @property {boolean} mode_eval enables the evald mode (ignore opening tags) + * @property {boolean} asp_tags disables by default asp tags mode + * @property {boolean} short_tags enables by default short tags mode + * @property {object} keywords List of php keyword + * @property {object} castKeywords List of php keywords for type casting */ -const lexer = function (engine) { +const Lexer = function (engine) { this.engine = engine; this.tok = this.engine.tokens.names; this.EOF = 1; @@ -125,8 +126,10 @@ const lexer = function (engine) { /** * Initialize the lexer with the specified input + * @function Lexer#setInput + * @memberOf module:php-parser */ -lexer.prototype.setInput = function (input) { +Lexer.prototype.setInput = function (input) { this._input = input; this.size = input.length; this.yylineno = 1; @@ -165,7 +168,7 @@ lexer.prototype.setInput = function (input) { indentation: 0, indentation_uses_spaces: false, finished: false, - /** + /* * this used for parser to detemine the if current node segment is first encaps node. * if ture, the indentation will remove from the begining. and if false, the prev node * might be a variable '}' ,and the leading spaces should not be removed util meet the @@ -182,8 +185,10 @@ lexer.prototype.setInput = function (input) { /** * consumes and returns one char from the input + * @function Lexer#input + * @memberOf module:php-parser */ -lexer.prototype.input = function () { +Lexer.prototype.input = function () { const ch = this._input[this.offset]; if (!ch) return ""; this.yytext += ch; @@ -204,8 +209,10 @@ lexer.prototype.input = function () { /** * revert eating specified size + * @function Lexer#unput + * @memberOf module:php-parser */ -lexer.prototype.unput = function (size) { +Lexer.prototype.unput = function (size) { if (size === 1) { // 1 char unput (most cases) this.offset--; @@ -268,18 +275,36 @@ lexer.prototype.unput = function (size) { return this; }; -// check if the text matches -lexer.prototype.tryMatch = function (text) { +/** + * check if the text matches + * @function Lexer#tryMatch + * @memberOf module:php-parser + * @param {string} text + * @returns {boolean} + */ +Lexer.prototype.tryMatch = function (text) { return text === this.ahead(text.length); }; -// check if the text matches -lexer.prototype.tryMatchCaseless = function (text) { +/** + * check if the text matches + * @function Lexer#tryMatchCaseless + * @memberOf module:php-parser + * @param {string} text + * @returns {boolean} + */ +Lexer.prototype.tryMatchCaseless = function (text) { return text === this.ahead(text.length).toLowerCase(); }; -// look ahead -lexer.prototype.ahead = function (size) { +/** + * look ahead + * @function Lexer#ahead + * @memberOf module:php-parser + * @param {number} size + * @returns {string} + */ +Lexer.prototype.ahead = function (size) { let text = this._input.substring(this.offset, this.offset + size); if ( text[text.length - 1] === "\r" && @@ -290,8 +315,14 @@ lexer.prototype.ahead = function (size) { return text; }; -// consume the specified size -lexer.prototype.consume = function (size) { +/** + * consume the specified size + * @function Lexer#consume + * @memberOf module:php-parser + * @param {number} size + * @returns {Lexer} + */ +Lexer.prototype.consume = function (size) { for (let i = 0; i < size; i++) { const ch = this._input[this.offset]; if (!ch) break; @@ -315,8 +346,10 @@ lexer.prototype.consume = function (size) { /** * Gets the current state + * @function Lexer#getState + * @memberOf module:php-parser */ -lexer.prototype.getState = function () { +Lexer.prototype.getState = function () { return { yytext: this.yytext, offset: this.offset, @@ -335,8 +368,10 @@ lexer.prototype.getState = function () { /** * Sets the current lexer state + * @function Lexer#setState + * @memberOf module:php-parser */ -lexer.prototype.setState = function (state) { +Lexer.prototype.setState = function (state) { this.yytext = state.yytext; this.offset = state.offset; this.yylineno = state.yylineno; @@ -348,14 +383,26 @@ lexer.prototype.setState = function (state) { return this; }; -// prepend next token -lexer.prototype.appendToken = function (value, ahead) { +/** + * prepend next token + * @function Lexer#appendToken + * @memberOf module:php-parser + * @param {*} value + * @param {*} ahead + * @returns {Lexer} + */ +Lexer.prototype.appendToken = function (value, ahead) { this.tokens.push([value, ahead]); return this; }; -// return next match that has a token -lexer.prototype.lex = function () { +/** + * return next match that has a token + * @function Lexer#lex + * @memberOf module:php-parser + * @returns {number|string} + */ +Lexer.prototype.lex = function () { this.yylloc.prev_offset = this.offset; this.yylloc.prev_line = this.yylloc.last_line; this.yylloc.prev_column = this.yylloc.last_column; @@ -391,8 +438,14 @@ lexer.prototype.lex = function () { return token; }; -// activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) -lexer.prototype.begin = function (condition) { +/** + * activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) + * @function Lexer#begin + * @memberOf module:php-parser + * @param {*} condition + * @returns {Lexer} + */ +Lexer.prototype.begin = function (condition) { this.conditionStack.push(condition); this.curCondition = condition; this.stateCb = this["match" + condition]; @@ -402,8 +455,13 @@ lexer.prototype.begin = function (condition) { return this; }; -// pop the previously active lexer condition state off the condition stack -lexer.prototype.popState = function () { +/** + * pop the previously active lexer condition state off the condition stack + * @function Lexer#popState + * @memberOf module:php-parser + * @returns {string|*} + */ +Lexer.prototype.popState = function () { const n = this.conditionStack.length - 1; const condition = n > 0 ? this.conditionStack.pop() : this.conditionStack[0]; this.curCondition = this.conditionStack[this.conditionStack.length - 1]; @@ -414,8 +472,13 @@ lexer.prototype.popState = function () { return condition; }; -// return next match in input -lexer.prototype.next = function () { +/** + * return next match in input + * @function Lexer#next + * @memberOf module:php-parser + * @returns {number|*} + */ +Lexer.prototype.next = function () { let token; if (!this._input) { this.done = true; @@ -483,8 +546,8 @@ lexer.prototype.next = function () { require("./lexer/utils.js"), ].forEach(function (ext) { for (const k in ext) { - lexer.prototype[k] = ext[k]; + Lexer.prototype[k] = ext[k]; } }); -module.exports = lexer; +module.exports = Lexer; diff --git a/src/lexer/comments.js b/src/lexer/comments.js index ed8ba5e21..43501d701 100644 --- a/src/lexer/comments.js +++ b/src/lexer/comments.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a single line comment */ T_COMMENT: function () { @@ -32,7 +32,7 @@ module.exports = { } return this.tok.T_COMMENT; }, - /** + /* * Behaviour : https://github.com/php/php-src/blob/master/Zend/zend_language_scanner.l#L1927 */ T_DOC_COMMENT: function () { diff --git a/src/lexer/strings.js b/src/lexer/strings.js index ef575b41c..d51310f2a 100644 --- a/src/lexer/strings.js +++ b/src/lexer/strings.js @@ -217,7 +217,7 @@ module.exports = { return false; }, - /** + /* * Prematch the end of HEREDOC/NOWDOC end tag to preset the * context of this.heredoc_label */ @@ -249,14 +249,14 @@ module.exports = { }, matchST_NOWDOC: function () { - /** edge case : empty now doc **/ + // edge case : empty now doc if (this.isDOC_MATCH(this.offset, true)) { // @fixme : never reached (may be caused by quotes) this.consume(this.heredoc_label.length); this.popState(); return this.tok.T_END_HEREDOC; } - /** SCANNING CONTENTS **/ + // SCANNING CONTENTS let ch = this._input[this.offset - 1]; while (this.offset < this.size) { if (newline.includes(ch)) { @@ -275,14 +275,14 @@ module.exports = { }, matchST_HEREDOC: function () { - /** edge case : empty here doc **/ + // edge case : empty here doc let ch = this.input(); if (this.isDOC_MATCH(this.offset, true)) { this.consume(this.heredoc_label.length - 1); this.popState(); return this.tok.T_END_HEREDOC; } - /** SCANNING CONTENTS **/ + // SCANNING CONTENTS while (this.offset < this.size) { if (ch === "\\") { ch = this.input(); // ignore next diff --git a/src/parser.js b/src/parser.js index 3d4cab0b4..946939d4e 100644 --- a/src/parser.js +++ b/src/parser.js @@ -15,17 +15,18 @@ function isNumber(n) { /** * The PHP Parser class that build the AST tree from the lexer * - * @class + * @constructor Parser + * @memberOf module:php-parser * @tutorial Parser * @property {Lexer} lexer - current lexer instance * @property {AST} ast - the AST factory instance - * @property {Integer|String} token - current token - * @property {Boolean} extractDoc - should extract documentation as AST node - * @property {Boolean} extractTokens - should extract each token - * @property {Boolean} suppressErrors - should ignore parsing errors and continue - * @property {Boolean} debug - should output debug informations + * @property {number|string} token - current token + * @property {boolean} extractDoc - should extract documentation as AST node + * @property {boolean} extractTokens - should extract each token + * @property {boolean} suppressErrors - should ignore parsing errors and continue + * @property {boolean} debug - should output debug informations */ -const parser = function (lexer, ast) { +const Parser = function (lexer, ast) { this.lexer = lexer; this.ast = ast; this.tok = lexer.tok; @@ -243,8 +244,10 @@ const parser = function (lexer, ast) { /** * helper : gets a token name + * @function Parser#getTokenName + * @memberOf module:php-parser */ -parser.prototype.getTokenName = function (token) { +Parser.prototype.getTokenName = function (token) { if (!isNumber(token)) { return "'" + token + "'"; } else { @@ -255,8 +258,10 @@ parser.prototype.getTokenName = function (token) { /** * main entry point : converts a source code to AST + * @function Parser#parse + * @memberOf module:php-parser */ -parser.prototype.parse = function (code, filename) { +Parser.prototype.parse = function (code, filename) { this._errors = []; this.filename = filename || "eval"; this.currentNamespace = [""]; @@ -323,8 +328,10 @@ parser.prototype.parse = function (code, filename) { /** * Raise an error + * @function Parser#raiseError + * @memberOf module:php-parser */ -parser.prototype.raiseError = function (message, msgExpect, expect, token) { +Parser.prototype.raiseError = function (message, msgExpect, expect, token) { message += " on line " + this.lexer.yylloc.first_line; if (!this.suppressErrors) { const err = new SyntaxError( @@ -350,8 +357,10 @@ parser.prototype.raiseError = function (message, msgExpect, expect, token) { /** * handling errors + * @function Parser#error + * @memberOf module:php-parser */ -parser.prototype.error = function (expect) { +Parser.prototype.error = function (expect) { let msg = "Parse Error : syntax error"; let token = this.getTokenName(this.token); let msgExpect = ""; @@ -377,8 +386,10 @@ parser.prototype.error = function (expect) { /** * Creates a new AST node + * @function Parser#node + * @memberOf module:php-parser */ -parser.prototype.node = function (name) { +Parser.prototype.node = function (name) { if (this.extractDoc) { let docs = null; if (this._docIndex < this._docs.length) { @@ -392,7 +403,7 @@ parser.prototype.node = function (name) { } } const node = this.ast.prepare(name, docs, this); - /** + /* * TOKENS : * node1 commentA token commmentB node2 commentC token commentD node3 commentE token * @@ -453,9 +464,11 @@ parser.prototype.node = function (name) { /** * expects an end of statement or end of file + * @function Parser#expectEndOfStatement + * @memberOf module:php-parser * @return {boolean} */ -parser.prototype.expectEndOfStatement = function (node) { +Parser.prototype.expectEndOfStatement = function (node) { if (this.token === ";") { // include only real ';' statements // https://github.com/glayzzle/php-parser/issues/164 @@ -470,9 +483,14 @@ parser.prototype.expectEndOfStatement = function (node) { return true; }; -/** outputs some debug information on current token **/ const ignoreStack = ["parser.next", "parser.node", "parser.showlog"]; -parser.prototype.showlog = function () { +/** + * outputs some debug information on current token + * @private + * @function Parser#showlog + * @memberOf module:php-parser + */ +Parser.prototype.showlog = function () { const stack = new Error().stack.split("\n"); let line; for (let offset = 2; offset < stack.length; offset++) { @@ -512,11 +530,13 @@ parser.prototype.showlog = function () { * If the suppressError mode is activated, then the error will * be added to the program error stack and this function will return `false`. * + * @function Parser#expect + * @memberOf module:php-parser * @param {String|Number} token * @return {boolean} * @throws Error */ -parser.prototype.expect = function (token) { +Parser.prototype.expect = function (token) { if (Array.isArray(token)) { if (token.indexOf(this.token) === -1) { this.error(token); @@ -531,14 +551,20 @@ parser.prototype.expect = function (token) { /** * Returns the current token contents + * @function Parser#text + * @memberOf module:php-parser * @return {String} */ -parser.prototype.text = function () { +Parser.prototype.text = function () { return this.lexer.yytext; }; -/** consume the next token **/ -parser.prototype.next = function () { +/** + * consume the next token + * @function Parser#next + * @memberOf module:php-parser + */ +Parser.prototype.next = function () { // prepare the back command if (this.token !== ";" || this.lexer.yytext === ";") { // ignore '?>' from automated resolution @@ -578,8 +604,10 @@ parser.prototype.next = function () { /** * Eating a token + * @function Parser#lex + * @memberOf module:php-parser */ -parser.prototype.lex = function () { +Parser.prototype.lex = function () { // append on token stack if (this.extractTokens) { do { @@ -629,8 +657,10 @@ parser.prototype.lex = function () { /** * Check if token is of specified type + * @function Parser#is + * @memberOf module:php-parser */ -parser.prototype.is = function (type) { +Parser.prototype.is = function (type) { if (Array.isArray(type)) { return type.indexOf(this.token) !== -1; } @@ -656,12 +686,12 @@ parser.prototype.is = function (type) { require("./parser/variable.js"), ].forEach(function (ext) { for (const k in ext) { - if (parser.prototype.hasOwnProperty(k)) { + if (Parser.prototype.hasOwnProperty(k)) { // @see https://github.com/glayzzle/php-parser/issues/234 throw new Error("Function " + k + " is already defined - collision"); } - parser.prototype[k] = ext[k]; + Parser.prototype[k] = ext[k]; } }); -module.exports = parser; +module.exports = Parser; diff --git a/src/parser/array.js b/src/parser/array.js index 51dcc5c9f..19b3b40cd 100644 --- a/src/parser/array.js +++ b/src/parser/array.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Parse an array * ```ebnf * array ::= T_ARRAY '(' array_pair_list ')' | @@ -33,7 +33,7 @@ module.exports = { this.next(); return result(shortForm, items); }, - /** + /* * Reads an array of items * ```ebnf * array_pair_list ::= array_pair (',' array_pair?)* @@ -49,7 +49,7 @@ module.exports = { true ); }, - /** + /* * Reads an entry * array_pair: * expr T_DOUBLE_ARROW expr diff --git a/src/parser/class.js b/src/parser/class.js index 6019433d1..d72306e68 100644 --- a/src/parser/class.js +++ b/src/parser/class.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * reading a class * ```ebnf * class ::= class_scope? T_CLASS T_STRING (T_EXTENDS NAMESPACE_NAME)? (T_IMPLEMENTS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' CLASS_BODY '}' @@ -51,7 +51,7 @@ module.exports = { return result; }, - /** + /* * Reads a class body * ```ebnf * class_body ::= (member_flags? (T_VAR | T_STRING | T_FUNCTION))* @@ -131,7 +131,7 @@ module.exports = { this.next(); return result; }, - /** + /* * Reads variable list * ```ebnf * variable_list ::= (variable_declaration ',')* variable_declaration @@ -141,7 +141,7 @@ module.exports = { const result = this.node("propertystatement"); const properties = this.read_list( - /** + /* * Reads a variable declaration * * ```ebnf @@ -171,7 +171,7 @@ module.exports = { return result(null, properties, flags); }, - /** + /* * Reads constant list * ```ebnf * constant_list ::= T_CONST (constant_declaration ',')* constant_declaration @@ -183,7 +183,7 @@ module.exports = { } const result = this.node("classconstant"); const items = this.read_list( - /** + /* * Reads a constant declaration * * ```ebnf @@ -216,7 +216,7 @@ module.exports = { return result(null, items, flags); }, - /** + /* * Read member flags * @return array * 1st index : 0 => public, 1 => protected, 2 => private @@ -280,7 +280,7 @@ module.exports = { return result; }, - /** + /* * optional_type: * /- empty -/ { $$ = NULL; } * | type_expr { $$ = $1; } @@ -333,7 +333,7 @@ module.exports = { return [nullable, type]; }, - /** + /* * reading an interface * ```ebnf * interface ::= T_INTERFACE T_STRING (T_EXTENDS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' INTERFACE_BODY '}' @@ -356,7 +356,7 @@ module.exports = { const body = this.next().read_interface_body(); return result(propName, propExtends, body); }, - /** + /* * Reads an interface body * ```ebnf * interface_body ::= (member_flags? (T_CONST | T_FUNCTION))* @@ -405,7 +405,7 @@ module.exports = { } return result; }, - /** + /* * reading a trait * ```ebnf * trait ::= T_TRAIT T_STRING (T_EXTENDS (NAMESPACE_NAME ',')* NAMESPACE_NAME)? '{' FUNCTION* '}' @@ -428,7 +428,7 @@ module.exports = { const body = this.next().read_class_body(); return result(propName, body); }, - /** + /* * reading a use statement * ```ebnf * trait_use_statement ::= namespace_name (',' namespace_name)* ('{' trait_use_alias '}')? @@ -461,7 +461,7 @@ module.exports = { } return node(traits, adaptations); }, - /** + /* * Reading trait alias * ```ebnf * trait_use_alias ::= namespace_name ( T_DOUBLE_COLON T_STRING )? (T_INSTEADOF namespace_name) | (T_AS member_flags? T_STRING) diff --git a/src/parser/comment.js b/src/parser/comment.js index a8dd9e5c8..e2e905dfe 100644 --- a/src/parser/comment.js +++ b/src/parser/comment.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Comments with // or # or / * ... * / */ read_comment: function () { @@ -30,7 +30,7 @@ module.exports = { this.prev = prev; return result; }, - /** + /* * Comments with / ** ... * / */ read_doc_comment: function () { diff --git a/src/parser/expr.js b/src/parser/expr.js index ec8e46c14..dfd1f8b31 100644 --- a/src/parser/expr.js +++ b/src/parser/expr.js @@ -109,21 +109,21 @@ module.exports = { return expr; }, - /** + /* * Reads a cast expression */ read_expr_cast: function (type) { return this.node("cast")(type, this.text(), this.next().read_expr()); }, - /** + /* * Read a isset variable */ read_isset_variable: function () { return this.read_expr(); }, - /** + /* * Reads isset variables */ read_isset_variables: function () { @@ -192,7 +192,7 @@ module.exports = { return result; }, - /** + /* * Reads optional expression */ read_optional_expr: function (stopToken) { @@ -203,7 +203,7 @@ module.exports = { return null; }, - /** + /* * Reads exit expression */ read_exit_expr: function () { @@ -218,7 +218,7 @@ module.exports = { return expression; }, - /** + /* * ```ebnf * Reads an expression * expr ::= @todo @@ -508,7 +508,7 @@ module.exports = { return expr; }, - /** + /* * Recursively convert nested array to nested list. */ convertToList: function (array) { @@ -529,7 +529,7 @@ module.exports = { return node; }, - /** + /* * Reads assignment * @param {*} left */ @@ -548,7 +548,7 @@ module.exports = { return result("assignref", left, right); }, - /** + /* * * inline_function: * function returns_ref backup_doc_comment '(' parameter_list ')' lexical_vars return_type @@ -602,7 +602,7 @@ module.exports = { ); }, - /** + /* * ```ebnf * new_expr ::= T_NEW (namespace_name function_argument_list) | (T_CLASS ... class declaration) * ``` @@ -636,7 +636,7 @@ module.exports = { } return result(name, args); }, - /** + /* * Reads a class name * ```ebnf * read_new_class_name ::= namespace_name | variable diff --git a/src/parser/function.js b/src/parser/function.js index a9f79b75e..396acf343 100644 --- a/src/parser/function.js +++ b/src/parser/function.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * checks if current token is a reference keyword */ is_reference: function () { @@ -16,7 +16,7 @@ module.exports = { } return false; }, - /** + /* * checks if current token is a variadic keyword */ is_variadic: function () { @@ -26,7 +26,7 @@ module.exports = { } return false; }, - /** + /* * reading a function * ```ebnf * function ::= function_declaration code_block @@ -56,7 +56,7 @@ module.exports = { } return result; }, - /** + /* * reads a function declaration (without his body) * ```ebnf * function_declaration ::= T_FUNCTION '&'? T_STRING '(' parameter_list ')' @@ -154,7 +154,7 @@ module.exports = { return this.read_list(this.read_lexical_var, ","); }, - /** + /* * ```ebnf * lexical_var ::= '&'? T_VARIABLE * ``` @@ -169,7 +169,7 @@ module.exports = { this.next(); return result(name, false); }, - /** + /* * reads a list of parameters * ```ebnf * parameter_list ::= (parameter ',')* parameter? @@ -192,7 +192,7 @@ module.exports = { } return result; }, - /** + /* * ```ebnf * parameter ::= type? '&'? T_ELLIPSIS? T_VARIABLE ('=' expr)? * ``` @@ -227,7 +227,7 @@ module.exports = { } return node(parameterName, type, value, isRef, isVariadic, nullable); }, - /** + /* * Reads a list of arguments * ```ebnf * function_argument_list ::= '(' (argument_list (',' argument_list)*)? ')' @@ -242,7 +242,7 @@ module.exports = { this.expect(")") && this.next(); return result; }, - /** + /* * Reads non empty argument list */ read_non_empty_argument_list: function () { @@ -264,7 +264,7 @@ module.exports = { "," ); }, - /** + /* * ```ebnf * argument_list ::= T_ELLIPSIS? expr * ``` @@ -275,7 +275,7 @@ module.exports = { } return this.read_expr(); }, - /** + /* * read type hinting * ```ebnf * type ::= T_ARRAY | T_CALLABLE | namespace_name diff --git a/src/parser/if.js b/src/parser/if.js index b2a46ae5d..fda94ee19 100644 --- a/src/parser/if.js +++ b/src/parser/if.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads an IF statement * * ```ebnf @@ -48,7 +48,7 @@ module.exports = { } return result(test, body, alternate, shortForm); }, - /** + /* * reads an if expression : '(' expr ')' */ read_if_expr: function () { @@ -57,7 +57,7 @@ module.exports = { this.expect(")") && this.next(); return result; }, - /** + /* * reads an elseif (expr): statements */ read_elseif_short: function () { @@ -79,7 +79,7 @@ module.exports = { } return result(test, body(null, items), alternate, true); }, - /** + /* * */ read_else_short: function () { diff --git a/src/parser/loops.js b/src/parser/loops.js index e84e63d51..62847a6b8 100644 --- a/src/parser/loops.js +++ b/src/parser/loops.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a while statement * ```ebnf * while ::= T_WHILE (statement | ':' inner_statement_list T_ENDWHILE ';') @@ -31,7 +31,7 @@ module.exports = { } return result(test, body, shortForm); }, - /** + /* * Reads a do / while loop * ```ebnf * do ::= T_DO statement T_WHILE '(' expr ')' ';' @@ -53,7 +53,7 @@ module.exports = { } return result(test, body); }, - /** + /* * Read a for incremental loop * ```ebnf * for ::= T_FOR '(' for_exprs ';' for_exprs ';' for_exprs ')' for_statement @@ -98,7 +98,7 @@ module.exports = { } return result(init, test, increment, body, shortForm); }, - /** + /* * Reads a foreach loop * ```ebnf * foreach ::= '(' expr T_AS foreach_variable (T_DOUBLE_ARROW foreach_variable)? ')' statement @@ -140,7 +140,7 @@ module.exports = { } return result(source, key, value, body, shortForm); }, - /** + /* * Reads a foreach variable statement * ```ebnf * foreach_variable = diff --git a/src/parser/main.js b/src/parser/main.js index ba5a5db1c..8b18dfff8 100644 --- a/src/parser/main.js +++ b/src/parser/main.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * ```ebnf * start ::= (namespace | top_statement)* * ``` diff --git a/src/parser/namespace.js b/src/parser/namespace.js index 2825fe337..57d1d3974 100644 --- a/src/parser/namespace.js +++ b/src/parser/namespace.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a namespace declaration block * ```ebnf * namespace ::= T_NAMESPACE namespace_name? '{' @@ -64,7 +64,7 @@ module.exports = { return result(name, body, false); } }, - /** + /* * Reads a namespace name * ```ebnf * namespace_name ::= T_NS_SEPARATOR? (T_STRING T_NS_SEPARATOR)* T_STRING @@ -97,7 +97,7 @@ module.exports = { } return result("name", names, relative); }, - /** + /* * Reads a use statement * ```ebnf * use_statement ::= T_USE @@ -127,7 +127,7 @@ module.exports = { this.expect(";") && this.next(); return result; }, - /** + /* * * @see https://github.com/php/php-src/blob/master/Zend/zend_language_parser.y#L1045 */ @@ -135,7 +135,7 @@ module.exports = { // resolved as the same return this.read_variable(true, false); }, - /** + /* * Reads a use declaration * ```ebnf * use_declaration ::= use_type? namespace_name use_alias @@ -151,7 +151,7 @@ module.exports = { const alias = this.read_use_alias(); return result(name.name, alias, type); }, - /** + /* * Reads a list of use declarations * ```ebnf * use_declarations ::= use_declaration (',' use_declaration)* @@ -181,7 +181,7 @@ module.exports = { } return result; }, - /** + /* * Reads a use statement * ```ebnf * use_alias ::= (T_AS T_STRING)? @@ -200,7 +200,7 @@ module.exports = { } return result; }, - /** + /* * Reads the namespace type declaration * ```ebnf * use_type ::= (T_FUNCTION | T_CONST)? diff --git a/src/parser/scalar.js b/src/parser/scalar.js index 88ceace12..4af5695c6 100644 --- a/src/parser/scalar.js +++ b/src/parser/scalar.js @@ -17,7 +17,7 @@ const specialChar = { }; module.exports = { - /** + /* * Unescape special chars */ resolve_special_chars: function (text, doubleQuote) { @@ -43,7 +43,7 @@ module.exports = { ); }, - /** + /* * Remove all leading spaces each line for heredoc text if there is a indentation * @param {string} text * @param {number} indentation @@ -86,7 +86,7 @@ module.exports = { return text.replace(removementRegExp, "\n"); }, - /** + /* * Check indentation level of heredoc in text, if mismatch, raiseError * @param {string} text * @param {number} indentation @@ -102,8 +102,9 @@ module.exports = { const textSize = text.length; let offset = 0; let leadingWhitespaceCharCount = 0; - /** + /* * @var inCoutingState {boolean} reset to true after a new line + * @private */ let inCoutingState = true; const chToCheck = indentation_uses_spaces ? " " : "\t"; @@ -149,7 +150,7 @@ module.exports = { } }, - /** + /* * Reads dereferencable scalar */ read_dereferencable_scalar: function () { @@ -196,7 +197,7 @@ module.exports = { return result; }, - /** + /* * ```ebnf * scalar ::= T_MAGIC_CONST * | T_LNUMBER | T_DNUMBER @@ -289,7 +290,7 @@ module.exports = { } } }, - /** + /* * Handles the dereferencing */ read_dereferencable: function (expr) { @@ -305,7 +306,7 @@ module.exports = { } return result; }, - /** + /* * Reads and extracts an encapsed item * ```ebnf * encapsed_string_item ::= T_ENCAPSED_AND_WHITESPACE @@ -421,7 +422,7 @@ module.exports = { this.lexer.heredoc_label.first_encaps_node = false; return encapsedPart(result, syntax, curly); }, - /** + /* * Reads an encapsed string */ read_encapsed_string: function (expect, isBinary = false) { @@ -477,7 +478,7 @@ module.exports = { } return node; }, - /** + /* * Constant token */ get_magic_constant: function () { diff --git a/src/parser/statement.js b/src/parser/statement.js index c3444a659..d75fd6504 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * reading a list of top statements (helper for top_statement*) * ```ebnf * top_statements ::= top_statement* @@ -26,7 +26,7 @@ module.exports = { } return result; }, - /** + /* * reading a top statement * ```ebnf * top_statement ::= @@ -71,7 +71,7 @@ module.exports = { return this.read_statement(); } }, - /** + /* * reads a list of simple inner statements (helper for inner_statement*) * ```ebnf * inner_statements ::= inner_statement* @@ -91,7 +91,7 @@ module.exports = { } return result; }, - /** + /* * Reads a list of constants declaration * ```ebnf * const_list ::= T_CONST T_STRING '=' expr (',' T_STRING '=' expr)* ';' @@ -117,7 +117,7 @@ module.exports = { false ); }, - /** + /* * Reads a list of constants declaration * ```ebnf * declare_list ::= IDENTIFIER '=' expr (',' IDENTIFIER '=' expr)* @@ -143,7 +143,7 @@ module.exports = { } return result; }, - /** + /* * reads a simple inner statement * ```ebnf * inner_statement ::= '{' inner_statements '}' | token @@ -178,7 +178,7 @@ module.exports = { return this.read_statement(); } }, - /** + /* * Reads statements */ read_statement: function () { @@ -404,7 +404,7 @@ module.exports = { } } }, - /** + /* * ```ebnf * code_block ::= '{' (inner_statements | top_statements) '}' * ``` diff --git a/src/parser/switch.js b/src/parser/switch.js index 1b927d602..07c1785e7 100644 --- a/src/parser/switch.js +++ b/src/parser/switch.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a switch statement * ```ebnf * switch ::= T_SWITCH '(' expr ')' switch_case_list @@ -24,7 +24,7 @@ module.exports = { const body = this.read_switch_case_list(); return result(test, body, shortForm); }, - /** + /* * ```ebnf * switch_case_list ::= '{' ';'? case_list* '}' | ':' ';'? case_list* T_ENDSWITCH ';' * ``` @@ -66,7 +66,7 @@ module.exports = { } return result(null, items); }, - /** + /* * ```ebnf * case_list ::= ((T_CASE expr) | T_DEFAULT) (':' | ';') inner_statement* * ``` diff --git a/src/parser/try.js b/src/parser/try.js index 404c2adde..bc2db96a5 100644 --- a/src/parser/try.js +++ b/src/parser/try.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * ```ebnf * try ::= T_TRY '{' inner_statement* '}' * ( diff --git a/src/parser/utils.js b/src/parser/utils.js index 6bbdd1a4f..e5f6e9193 100644 --- a/src/parser/utils.js +++ b/src/parser/utils.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a short form of tokens * @param {Number} token - The ending token * @return {Block} @@ -30,7 +30,7 @@ module.exports = { return body(null, items); }, - /** + /* * https://wiki.php.net/rfc/trailing-comma-function-calls * @param {*} item * @param {*} separator @@ -53,7 +53,7 @@ module.exports = { return result; }, - /** + /* * Helper : reads a list of tokens / sample : T_STRING ',' T_STRING ... * ```ebnf * list ::= separator? ( item separator )* item @@ -95,7 +95,7 @@ module.exports = { return result; }, - /** + /* * Reads a list of names separated by a comma * * ```ebnf @@ -114,7 +114,7 @@ module.exports = { return this.read_list(this.read_namespace_name, ",", false); }, - /** + /* * Reads the byref token and assign it to the specified node * @param {*} cb */ @@ -130,7 +130,7 @@ module.exports = { return result; }, - /** + /* * Reads a list of variables declarations * * ```ebnf diff --git a/src/parser/variable.js b/src/parser/variable.js index 1f3d17e23..f1ff5e540 100644 --- a/src/parser/variable.js +++ b/src/parser/variable.js @@ -6,7 +6,7 @@ "use strict"; module.exports = { - /** + /* * Reads a variable * * ```ebnf @@ -234,7 +234,7 @@ module.exports = { } return result; }, - /** + /* * https://github.com/php/php-src/blob/493524454d66adde84e00d249d607ecd540de99f/Zend/zend_language_parser.y#L1231 */ read_encaps_var_offset: function () { @@ -270,7 +270,7 @@ module.exports = { } return offset; }, - /** + /* * ```ebnf * reference_variable ::= simple_variable ('[' OFFSET ']')* | '{' EXPR '}' * ``` @@ -298,7 +298,7 @@ module.exports = { } return result; }, - /** + /* * ```ebnf * simple_variable ::= T_VARIABLE | '$' '{' expr '}' | '$' simple_variable * ``` diff --git a/src/tokens.js b/src/tokens.js index 1e1af82c4..e840eb675 100644 --- a/src/tokens.js +++ b/src/tokens.js @@ -5,11 +5,159 @@ */ "use strict"; +/** + * @memberOf module:php-parser + * @readonly + * @enum + */ +const TokenNames = { + T_HALT_COMPILER: 101, + T_USE: 102, + T_ENCAPSED_AND_WHITESPACE: 103, + T_OBJECT_OPERATOR: 104, + T_STRING: 105, + T_DOLLAR_OPEN_CURLY_BRACES: 106, + T_STRING_VARNAME: 107, + T_CURLY_OPEN: 108, + T_NUM_STRING: 109, + T_ISSET: 110, + T_EMPTY: 111, + T_INCLUDE: 112, + T_INCLUDE_ONCE: 113, + T_EVAL: 114, + T_REQUIRE: 115, + T_REQUIRE_ONCE: 116, + T_NAMESPACE: 117, + T_NS_SEPARATOR: 118, + T_AS: 119, + T_IF: 120, + T_ENDIF: 121, + T_WHILE: 122, + T_DO: 123, + T_FOR: 124, + T_SWITCH: 125, + T_BREAK: 126, + T_CONTINUE: 127, + T_RETURN: 128, + T_GLOBAL: 129, + T_STATIC: 130, + T_ECHO: 131, + T_INLINE_HTML: 132, + T_UNSET: 133, + T_FOREACH: 134, + T_DECLARE: 135, + T_TRY: 136, + T_THROW: 137, + T_GOTO: 138, + T_FINALLY: 139, + T_CATCH: 140, + T_ENDDECLARE: 141, + T_LIST: 142, + T_CLONE: 143, + T_PLUS_EQUAL: 144, + T_MINUS_EQUAL: 145, + T_MUL_EQUAL: 146, + T_DIV_EQUAL: 147, + T_CONCAT_EQUAL: 148, + T_MOD_EQUAL: 149, + T_AND_EQUAL: 150, + T_OR_EQUAL: 151, + T_XOR_EQUAL: 152, + T_SL_EQUAL: 153, + T_SR_EQUAL: 154, + T_INC: 155, + T_DEC: 156, + T_BOOLEAN_OR: 157, + T_BOOLEAN_AND: 158, + T_LOGICAL_OR: 159, + T_LOGICAL_AND: 160, + T_LOGICAL_XOR: 161, + T_SL: 162, + T_SR: 163, + T_IS_IDENTICAL: 164, + T_IS_NOT_IDENTICAL: 165, + T_IS_EQUAL: 166, + T_IS_NOT_EQUAL: 167, + T_IS_SMALLER_OR_EQUAL: 168, + T_IS_GREATER_OR_EQUAL: 169, + T_INSTANCEOF: 170, + T_INT_CAST: 171, + T_DOUBLE_CAST: 172, + T_STRING_CAST: 173, + T_ARRAY_CAST: 174, + T_OBJECT_CAST: 175, + T_BOOL_CAST: 176, + T_UNSET_CAST: 177, + T_EXIT: 178, + T_PRINT: 179, + T_YIELD: 180, + T_YIELD_FROM: 181, + T_FUNCTION: 182, + T_DOUBLE_ARROW: 183, + T_DOUBLE_COLON: 184, + T_ARRAY: 185, + T_CALLABLE: 186, + T_CLASS: 187, + T_ABSTRACT: 188, + T_TRAIT: 189, + T_FINAL: 190, + T_EXTENDS: 191, + T_INTERFACE: 192, + T_IMPLEMENTS: 193, + T_VAR: 194, + T_PUBLIC: 195, + T_PROTECTED: 196, + T_PRIVATE: 197, + T_CONST: 198, + T_NEW: 199, + T_INSTEADOF: 200, + T_ELSEIF: 201, + T_ELSE: 202, + T_ENDSWITCH: 203, + T_CASE: 204, + T_DEFAULT: 205, + T_ENDFOR: 206, + T_ENDFOREACH: 207, + T_ENDWHILE: 208, + T_CONSTANT_ENCAPSED_STRING: 209, + T_LNUMBER: 210, + T_DNUMBER: 211, + T_LINE: 212, + T_FILE: 213, + T_DIR: 214, + T_TRAIT_C: 215, + T_METHOD_C: 216, + T_FUNC_C: 217, + T_NS_C: 218, + T_START_HEREDOC: 219, + T_END_HEREDOC: 220, + T_CLASS_C: 221, + T_VARIABLE: 222, + T_OPEN_TAG: 223, + T_OPEN_TAG_WITH_ECHO: 224, + T_CLOSE_TAG: 225, + T_WHITESPACE: 226, + T_COMMENT: 227, + T_DOC_COMMENT: 228, + T_ELLIPSIS: 229, + T_COALESCE: 230, + T_POW: 231, + T_POW_EQUAL: 232, + T_SPACESHIP: 233, + T_COALESCE_EQUAL: 234, + T_FN: 235, +}; + /** * PHP AST Tokens - * @type {Object} + * @readonly + * @memberOf module:php-parser + * + * @type {object} + * @property {Object.} values + * @property {TokenNames} names */ -module.exports = { +const tokens = { values: { 101: "T_HALT_COMPILER", 102: "T_USE", @@ -147,141 +295,7 @@ module.exports = { 234: "T_COALESCE_EQUAL", 235: "T_FN", }, - names: { - T_HALT_COMPILER: 101, - T_USE: 102, - T_ENCAPSED_AND_WHITESPACE: 103, - T_OBJECT_OPERATOR: 104, - T_STRING: 105, - T_DOLLAR_OPEN_CURLY_BRACES: 106, - T_STRING_VARNAME: 107, - T_CURLY_OPEN: 108, - T_NUM_STRING: 109, - T_ISSET: 110, - T_EMPTY: 111, - T_INCLUDE: 112, - T_INCLUDE_ONCE: 113, - T_EVAL: 114, - T_REQUIRE: 115, - T_REQUIRE_ONCE: 116, - T_NAMESPACE: 117, - T_NS_SEPARATOR: 118, - T_AS: 119, - T_IF: 120, - T_ENDIF: 121, - T_WHILE: 122, - T_DO: 123, - T_FOR: 124, - T_SWITCH: 125, - T_BREAK: 126, - T_CONTINUE: 127, - T_RETURN: 128, - T_GLOBAL: 129, - T_STATIC: 130, - T_ECHO: 131, - T_INLINE_HTML: 132, - T_UNSET: 133, - T_FOREACH: 134, - T_DECLARE: 135, - T_TRY: 136, - T_THROW: 137, - T_GOTO: 138, - T_FINALLY: 139, - T_CATCH: 140, - T_ENDDECLARE: 141, - T_LIST: 142, - T_CLONE: 143, - T_PLUS_EQUAL: 144, - T_MINUS_EQUAL: 145, - T_MUL_EQUAL: 146, - T_DIV_EQUAL: 147, - T_CONCAT_EQUAL: 148, - T_MOD_EQUAL: 149, - T_AND_EQUAL: 150, - T_OR_EQUAL: 151, - T_XOR_EQUAL: 152, - T_SL_EQUAL: 153, - T_SR_EQUAL: 154, - T_INC: 155, - T_DEC: 156, - T_BOOLEAN_OR: 157, - T_BOOLEAN_AND: 158, - T_LOGICAL_OR: 159, - T_LOGICAL_AND: 160, - T_LOGICAL_XOR: 161, - T_SL: 162, - T_SR: 163, - T_IS_IDENTICAL: 164, - T_IS_NOT_IDENTICAL: 165, - T_IS_EQUAL: 166, - T_IS_NOT_EQUAL: 167, - T_IS_SMALLER_OR_EQUAL: 168, - T_IS_GREATER_OR_EQUAL: 169, - T_INSTANCEOF: 170, - T_INT_CAST: 171, - T_DOUBLE_CAST: 172, - T_STRING_CAST: 173, - T_ARRAY_CAST: 174, - T_OBJECT_CAST: 175, - T_BOOL_CAST: 176, - T_UNSET_CAST: 177, - T_EXIT: 178, - T_PRINT: 179, - T_YIELD: 180, - T_YIELD_FROM: 181, - T_FUNCTION: 182, - T_DOUBLE_ARROW: 183, - T_DOUBLE_COLON: 184, - T_ARRAY: 185, - T_CALLABLE: 186, - T_CLASS: 187, - T_ABSTRACT: 188, - T_TRAIT: 189, - T_FINAL: 190, - T_EXTENDS: 191, - T_INTERFACE: 192, - T_IMPLEMENTS: 193, - T_VAR: 194, - T_PUBLIC: 195, - T_PROTECTED: 196, - T_PRIVATE: 197, - T_CONST: 198, - T_NEW: 199, - T_INSTEADOF: 200, - T_ELSEIF: 201, - T_ELSE: 202, - T_ENDSWITCH: 203, - T_CASE: 204, - T_DEFAULT: 205, - T_ENDFOR: 206, - T_ENDFOREACH: 207, - T_ENDWHILE: 208, - T_CONSTANT_ENCAPSED_STRING: 209, - T_LNUMBER: 210, - T_DNUMBER: 211, - T_LINE: 212, - T_FILE: 213, - T_DIR: 214, - T_TRAIT_C: 215, - T_METHOD_C: 216, - T_FUNC_C: 217, - T_NS_C: 218, - T_START_HEREDOC: 219, - T_END_HEREDOC: 220, - T_CLASS_C: 221, - T_VARIABLE: 222, - T_OPEN_TAG: 223, - T_OPEN_TAG_WITH_ECHO: 224, - T_CLOSE_TAG: 225, - T_WHITESPACE: 226, - T_COMMENT: 227, - T_DOC_COMMENT: 228, - T_ELLIPSIS: 229, - T_COALESCE: 230, - T_POW: 231, - T_POW_EQUAL: 232, - T_SPACESHIP: 233, - T_COALESCE_EQUAL: 234, - T_FN: 235, - }, + names: TokenNames, }; + +module.exports = Object.freeze(tokens); diff --git a/types.d.ts b/types.d.ts new file mode 100644 index 000000000..d0b17f82a --- /dev/null +++ b/types.d.ts @@ -0,0 +1,1334 @@ +declare module "php-parser" { + /** + * Defines an array structure + * @example + * // PHP code : + * [1, 'foo' => 'bar', 3] + * + * // AST structure : + * { + * "kind": "array", + * "shortForm": true + * "items": [ + * {"kind": "number", "value": "1"}, + * { + * "kind": "entry", + * "key": {"kind": "string", "value": "foo", "isDoubleQuote": false}, + * "value": {"kind": "string", "value": "bar", "isDoubleQuote": false} + * }, + * {"kind": "number", "value": "3"} + * ] + * } + * @property items - List of array items + * @property shortForm - Indicate if the short array syntax is used, ex `[]` instead `array()` + */ + class Array extends Expression { + /** + * List of array items + */ + items: Entry | Expression | Variable; + /** + * Indicate if the short array syntax is used, ex `[]` instead `array()` + */ + shortForm: boolean; + } + /** + * Defines an arrow function (it's like a closure) + */ + class ArrowFunc extends Expression { + arguments: Parameter[]; + type: Identifier; + body: Expression; + byref: boolean; + nullable: boolean; + isStatic: boolean; + } + /** + * Assigns a value to the specified target + */ + class Assign extends Expression { + left: Expression; + right: Expression; + operator: string; + } + /** + * Assigns a value to the specified target + */ + class AssignRef extends Expression { + left: Expression; + right: Expression; + operator: string; + } + /** + * Binary operations + */ + class Bin extends Operation { + type: string; + left: Expression; + right: Expression; + } + /** + * A block statement, i.e., a sequence of statements surrounded by braces. + */ + class Block extends Statement { + children: Node[]; + } + /** + * Defines a boolean value (true/false) + */ + class Boolean extends Literal { + } + /** + * A break statement + */ + class Break extends Statement { + level: number | null; + } + /** + * Passing by Reference - so the function can modify the variable + */ + class ByRef extends Expression { + what: ExpressionStatement; + } + /** + * Executes a call statement + */ + class Call extends Expression { + what: Identifier | Variable; + arguments: Variable[]; + } + /** + * A switch case statement + * @property test - if null, means that the default case + */ + class Case extends Statement { + /** + * if null, means that the default case + */ + test: Expression | null; + body: Block | null; + } + /** + * Binary operations + */ + class Cast extends Operation { + type: string; + raw: string; + expr: Expression; + } + /** + * Defines a catch statement + */ + class Catch extends Statement { + what: Identifier[]; + variable: Variable; + body: Statement; + } + /** + * A class definition + */ + class Class extends Declaration { + extends: Identifier | null; + implements: Identifier[]; + body: Declaration[]; + isAnonymous: boolean; + isAbstract: boolean; + isFinal: boolean; + } + /** + * Defines a class/interface/trait constant + */ + class ClassConstant extends ConstantStatement { + /** + * Generic flags parser + */ + parseFlags(flags: (number | null)[]): void; + visibility: string; + } + /** + * Defines a clone call + */ + class Clone extends Expression { + what: Expression; + } + /** + * Defines a closure + */ + class Closure extends Expression { + arguments: Parameter[]; + uses: Variable[]; + type: Identifier; + byref: boolean; + nullable: boolean; + body: Block | null; + isStatic: boolean; + } + /** + * Abstract documentation node (ComentLine or CommentBlock) + */ + class Comment extends Node { + value: string; + } + /** + * A comment block (multiline) + */ + class CommentBlock extends Comment { + } + /** + * A single line comment + */ + class CommentLine extends Comment { + } + /** + * Defines a constant + */ + class Constant extends Node { + name: string; + value: Node | string | number | boolean | null; + } + /** + * Declares a constants into the current scope + */ + class ConstantStatement extends Statement { + constants: Constant[]; + } + /** + * A continue statement + */ + class Continue extends Statement { + level: number | null; + } + /** + * A declaration statement (function, class, interface...) + */ + class Declaration extends Statement { + /** + * Generic flags parser + */ + parseFlags(flags: (number | null)[]): void; + name: Identifier | string; + } + /** + * The declare construct is used to set execution directives for a block of code + */ + class Declare extends Block { + /** + * The node is declared as a short tag syntax : + * ```php + * bar_$baz; + * ``` + */ + readonly TYPE_OFFSET: string; + /** + * Defines the type of encapsed string (shell, heredoc, string) + */ + type: string; + /** + * The heredoc label, defined only when the type is heredoc + */ + label: string | null; + } + /** + * Part of `Encapsed` node + */ + class EncapsedPart extends Expression { + expression: Expression; + syntax: string; + curly: boolean; + } + /** + * An array entry - see [Array](#array) + * @property key - The entry key/offset + * @property value - The entry value + * @property byRef - By reference + * @property unpack - Argument unpacking + */ + class Entry extends Expression { + /** + * The entry key/offset + */ + key: Node | null; + /** + * The entry value + */ + value: Node; + /** + * By reference + */ + byRef: boolean; + /** + * Argument unpacking + */ + unpack: boolean; + } + /** + * Defines an error node (used only on silentMode) + */ + class Error extends Node { + message: string; + line: number; + token: number | string; + expected: string | any[]; + } + /** + * Defines an eval statement + */ + class Eval extends Expression { + source: Node; + } + /** + * Defines an exit / die call + */ + class Exit extends Expression { + expression: Node | null; + useDie: boolean; + } + /** + * Any expression node. Since the left-hand side of an assignment may + * be any expression in general, an expression can also be a pattern. + */ + class Expression extends Node { + } + /** + * Defines an expression based statement + */ + class ExpressionStatement extends Statement { + expression: Expression; + } + /** + * Defines a for iterator + */ + class For extends Statement { + init: Expression[]; + test: Expression[]; + increment: Expression[]; + body: Statement; + shortForm: boolean; + } + /** + * Defines a foreach iterator + */ + class Foreach extends Statement { + source: Expression; + key: Expression | null; + value: Expression; + body: Statement; + shortForm: boolean; + } + /** + * Defines a classic function + */ + class Function extends Declaration { + arguments: Parameter[]; + type: Identifier; + byref: boolean; + nullable: boolean; + body: Block | null; + } + /** + * Imports a variable from the global scope + */ + class Global extends Statement { + items: Variable[]; + } + /** + * Defines goto statement + */ + class Goto extends Statement { + label: string; + } + /** + * Halts the compiler execution + * @property after - String after the halt statement + */ + class Halt extends Statement { + /** + * String after the halt statement + */ + after: string; + } + /** + * Defines an identifier node + */ + class Identifier extends Node { + name: string; + } + /** + * Defines a if statement + */ + class If extends Statement { + test: Expression; + body: Block; + alternate: Block | If | null; + shortForm: boolean; + } + /** + * Defines system include call + */ + class Include extends Expression { + target: Node; + once: boolean; + require: boolean; + } + /** + * Defines inline html output (treated as echo output) + */ + class Inline extends Literal { + } + /** + * An interface definition + */ + class Interface extends Declaration { + extends: Identifier[]; + body: Declaration[]; + } + /** + * Defines an isset call + */ + class Isset extends Expression { + } + /** + * A label statement (referenced by goto) + */ + class Label extends Statement { + name: string; + } + /** + * Defines list assignment + */ + class List extends Expression { + shortForm: boolean; + } + /** + * Defines an array structure + */ + class Literal extends Expression { + raw: string; + value: Node | string | number | boolean | null; + } + /** + * Defines the location of the node (with it's source contents as string) + */ + class Location { + source: string | null; + start: Position; + end: Position; + } + /** + * Lookup on an offset in the specified object + */ + class Lookup extends Expression { + what: Expression; + offset: Expression; + } + /** + * Defines magic constant + */ + class Magic extends Literal { + } + /** + * Defines a class/interface/trait method + */ + class Method extends Function { + isAbstract: boolean; + isFinal: boolean; + isStatic: boolean; + visibility: string; + } + /** + * Defines a class reference node + */ + class Name extends Reference { + /** + * This is an identifier without a namespace separator, such as Foo + */ + readonly UNQUALIFIED_NAME: string; + /** + * This is an identifier with a namespace separator, such as Foo\Bar + */ + readonly QUALIFIED_NAME: string; + /** + * This is an identifier with a namespace separator that begins with + * a namespace separator, such as \Foo\Bar. The namespace \Foo is also + * a fully qualified name. + */ + readonly FULL_QUALIFIED_NAME: string; + /** + * This is an identifier starting with namespace, such as namespace\Foo\Bar. + */ + readonly RELATIVE_NAME: string; + name: string; + resolution: string; + } + /** + * The main program node + */ + class Namespace extends Block { + name: string; + withBrackets: boolean; + } + /** + * Creates a new instance of the specified class + */ + class New extends Expression { + what: Identifier | Variable | Class; + arguments: Variable[]; + } + /** + * A generic AST node + */ + class Node { + /** + * Attach comments to current node + */ + setTrailingComments(docs: any): void; + /** + * Destroying an unused node + */ + destroy(): void; + /** + * Includes current token position of the parser + */ + includeToken(parser: any): void; + /** + * Helper for extending the Node class + */ + static extends(type: string, constructor: (...params: any[]) => any): (...params: any[]) => any; + loc: Location | null; + leadingComments: CommentBlock[] | Comment[] | null; + trailingComments: CommentBlock[] | Comment[] | null; + kind: string; + } + /** + * Ignore this node, it implies a no operation block, for example : + * [$foo, $bar, /* here a noop node * /] + */ + class Noop extends Node { + } + /** + * Defines a nowdoc string + */ + class NowDoc extends Literal { + label: string; + raw: string; + } + /** + * Represents the null keyword + */ + class NullKeyword extends Node { + } + /** + * Defines a numeric value + */ + class Number extends Literal { + } + /** + * Lookup on an offset in an array + */ + class OffsetLookup extends Lookup { + } + /** + * Defines binary operations + */ + class Operation extends Expression { + } + /** + * Defines a function parameter + */ + class Parameter extends Declaration { + type: Identifier | null; + value: Node | null; + byref: boolean; + variadic: boolean; + nullable: boolean; + } + /** + * Defines a class reference node + */ + class ParentReference extends Reference { + } + /** + * Each Position object consists of a line number (1-indexed) and a column number (0-indexed): + */ + class Position { + line: number; + column: number; + offset: number; + } + /** + * Defines a post operation `$i++` or `$i--` + */ + class Post extends Operation { + type: string; + what: Variable; + } + /** + * Defines a pre operation `++$i` or `--$i` + */ + class Pre extends Operation { + type: string; + what: Variable; + } + /** + * Outputs + */ + class Print extends Expression { + } + /** + * The main program node + */ + class Program extends Block { + errors: Error[]; + comments: Comment[] | null; + tokens: String[] | null; + } + /** + * Defines a class property + */ + class Property extends Statement { + name: string; + value: Node | null; + nullable: boolean; + type: Identifier | Identifier[] | null; + } + /** + * Lookup to an object property + */ + class PropertyLookup extends Lookup { + } + /** + * Declares a properties into the current scope + */ + class PropertyStatement extends Statement { + /** + * Generic flags parser + */ + parseFlags(flags: (number | null)[]): void; + properties: Property[]; + } + /** + * Defines a reference node + */ + class Reference extends Node { + } + /** + * Defines a short if statement that returns a value + */ + class RetIf extends Expression { + test: Expression; + trueExpr: Expression; + falseExpr: Expression; + } + /** + * A continue statement + */ + class Return extends Statement { + expr: Expression | null; + } + /** + * Defines a class reference node + */ + class SelfReference extends Reference { + } + /** + * Avoids to show/log warnings & notices from the inner expression + */ + class Silent extends Expression { + expr: Expression; + } + /** + * Any statement. + */ + class Statement extends Node { + } + /** + * Declares a static variable into the current scope + */ + class Static extends Statement { + variables: StaticVariable[]; + } + /** + * Lookup to a static property + */ + class StaticLookup extends Lookup { + } + /** + * Defines a class reference node + */ + class StaticReference extends Reference { + } + /** + * Defines a constant + */ + class StaticVariable extends Node { + variable: Variable; + defaultValue: Node | string | number | boolean | null; + } + /** + * Defines a string (simple or double quoted) - chars are already escaped + */ + class String extends Literal { + unicode: boolean; + isDoubleQuote: boolean; + } + /** + * Defines a switch statement + */ + class Switch extends Statement { + test: Expression; + body: Block; + shortForm: boolean; + } + /** + * Defines a throw statement + */ + class Throw extends Statement { + what: Expression; + } + /** + * A trait definition + */ + class Trait extends Declaration { + body: Declaration[]; + } + /** + * Defines a trait alias + */ + class TraitAlias extends Node { + trait: Identifier | null; + method: Identifier; + as: Identifier | null; + visibility: string | null; + } + /** + * Defines a trait alias + */ + class TraitPrecedence extends Node { + trait: Identifier | null; + method: Identifier; + instead: Identifier[]; + } + /** + * Defines a trait usage + */ + class TraitUse extends Node { + traits: Identifier[]; + adaptations: Node[] | null; + } + /** + * Defines a try statement + */ + class Try extends Statement { + body: Block; + catches: Catch[]; + allways: Block; + } + /** + * Defines a class reference node + */ + class TypeReference extends Reference { + name: string; + } + /** + * Unary operations + */ + class Unary extends Operation { + type: string; + what: Expression; + } + /** + * Deletes references to a list of variables + */ + class Unset extends Statement { + } + /** + * Defines a use statement (with a list of use items) + * @property type - Possible value : function, const + */ + class UseGroup extends Statement { + name: string | null; + /** + * Possible value : function, const + */ + type: string | null; + item: UseItem[]; + } + /** + * Defines a use statement (from namespace) + * @property type - Possible value : function, const + */ + class UseItem extends Statement { + /** + * Importing a constant + */ + readonly TYPE_CONST: string; + /** + * Importing a function + */ + readonly TYPE_FUNC: string; + name: string; + /** + * Possible value : function, const + */ + type: string | null; + alias: Identifier | null; + } + /** + * Any expression node. Since the left-hand side of an assignment may + * be any expression in general, an expression can also be a pattern. + * @example + * // PHP code : + * $foo + * // AST output + * { + * "kind": "variable", + * "name": "foo", + * "curly": false + * } + * @property name - The variable name (can be a complex expression when the name is resolved dynamically) + * @property curly - Indicate if the name is defined between curlies, ex `${foo}` + */ + class Variable extends Expression { + /** + * The variable name (can be a complex expression when the name is resolved dynamically) + */ + name: string | Node; + /** + * Indicate if the name is defined between curlies, ex `${foo}` + */ + curly: boolean; + } + /** + * Introduce a list of items into the arguments of the call + */ + class Variadic extends Expression { + what: any[] | Expression; + } + /** + * Defines a while statement + */ + class While extends Statement { + test: Expression; + body: Statement; + shortForm: boolean; + } + /** + * Defines a yield generator statement + */ + class Yield extends Expression { + value: Expression | null; + key: Expression | null; + } + /** + * Defines a yield from generator statement + */ + class YieldFrom extends Expression { + value: Expression; + } + /** + * The AST builder class + * @property withPositions - Should locate any node (by default false) + * @property withSource - Should extract the node original code (by default false) + */ + class AST { + /** + * Should locate any node (by default false) + */ + withPositions: boolean; + /** + * Should extract the node original code (by default false) + */ + withSource: boolean; + } + /** + * Initialise a new parser instance with the specified options + * @example + * var parser = require('php-parser'); + * var instance = new parser({ + * parser: { + * extractDoc: true, + * suppressErrors: true, + * version: 704 // or '7.4' + * }, + * ast: { + * withPositions: true + * }, + * lexer: { + * short_tags: true, + * asp_tags: true + * } + * }); + * + * var evalAST = instance.parseEval('some php code'); + * var codeAST = instance.parseCode(' Note that the output tokens are *STRICLY* similar to PHP function `token_get_all` + * @returns - Each item can be a string or an array with following informations [token_name, text, line_number] + */ + tokenGetAll(buffer: string): String[]; + lexer: Lexer; + parser: Parser; + ast: AST; + tokens: any; + } + /** + * This is the php lexer. It will tokenize the string for helping the + * parser to build the AST from its grammar. + * @property all_tokens - defines if all tokens must be retrieved (used by token_get_all only) + * @property comment_tokens - extracts comments tokens + * @property mode_eval - enables the evald mode (ignore opening tags) + * @property asp_tags - disables by default asp tags mode + * @property short_tags - enables by default short tags mode + * @property keywords - List of php keyword + * @property castKeywords - List of php keywords for type casting + */ + class Lexer { + /** + * Initialize the lexer with the specified input + */ + setInput(): void; + /** + * consumes and returns one char from the input + */ + input(): void; + /** + * revert eating specified size + */ + unput(): void; + /** + * check if the text matches + */ + tryMatch(text: string): boolean; + /** + * check if the text matches + */ + tryMatchCaseless(text: string): boolean; + /** + * look ahead + */ + ahead(size: number): string; + /** + * consume the specified size + */ + consume(size: number): Lexer; + /** + * Gets the current state + */ + getState(): void; + /** + * Sets the current lexer state + */ + setState(): void; + /** + * prepend next token + */ + appendToken(value: any, ahead: any): Lexer; + /** + * return next match that has a token + */ + lex(): number | string; + /** + * activates a new lexer condition state (pushes the new lexer condition state onto the condition stack) + */ + begin(condition: any): Lexer; + /** + * pop the previously active lexer condition state off the condition stack + */ + popState(): string | any; + /** + * return next match in input + */ + next(): number | any; + EOF: number; + /** + * defines if all tokens must be retrieved (used by token_get_all only) + */ + all_tokens: boolean; + /** + * extracts comments tokens + */ + comment_tokens: boolean; + /** + * enables the evald mode (ignore opening tags) + */ + mode_eval: boolean; + /** + * disables by default asp tags mode + */ + asp_tags: boolean; + /** + * enables by default short tags mode + */ + short_tags: boolean; + /** + * List of php keyword + */ + keywords: any; + /** + * List of php keywords for type casting + */ + castKeywords: any; + } + /** + * The PHP Parser class that build the AST tree from the lexer + * @property lexer - current lexer instance + * @property ast - the AST factory instance + * @property token - current token + * @property extractDoc - should extract documentation as AST node + * @property extractTokens - should extract each token + * @property suppressErrors - should ignore parsing errors and continue + * @property debug - should output debug informations + */ + class Parser { + /** + * helper : gets a token name + */ + getTokenName(): void; + /** + * main entry point : converts a source code to AST + */ + parse(): void; + /** + * Raise an error + */ + raiseError(): void; + /** + * handling errors + */ + error(): void; + /** + * Creates a new AST node + */ + node(): void; + /** + * expects an end of statement or end of file + */ + expectEndOfStatement(): boolean; + /** + * Force the parser to check the current token. + * + * If the current token does not match to expected token, + * the an error will be raised. + * + * If the suppressError mode is activated, then the error will + * be added to the program error stack and this function will return `false`. + */ + expect(token: string | number): boolean; + /** + * Returns the current token contents + */ + text(): string; + /** + * consume the next token + */ + next(): void; + /** + * Eating a token + */ + lex(): void; + /** + * Check if token is of specified type + */ + is(): void; + /** + * current lexer instance + */ + lexer: Lexer; + /** + * the AST factory instance + */ + ast: AST; + /** + * current token + */ + token: number | string; + /** + * should extract documentation as AST node + */ + extractDoc: boolean; + /** + * should extract each token + */ + extractTokens: boolean; + /** + * should ignore parsing errors and continue + */ + suppressErrors: boolean; + /** + * should output debug informations + */ + debug: boolean; + } + const enum TokenNames { + T_HALT_COMPILER = 101, + T_USE = 102, + T_ENCAPSED_AND_WHITESPACE = 103, + T_OBJECT_OPERATOR = 104, + T_STRING = 105, + T_DOLLAR_OPEN_CURLY_BRACES = 106, + T_STRING_VARNAME = 107, + T_CURLY_OPEN = 108, + T_NUM_STRING = 109, + T_ISSET = 110, + T_EMPTY = 111, + T_INCLUDE = 112, + T_INCLUDE_ONCE = 113, + T_EVAL = 114, + T_REQUIRE = 115, + T_REQUIRE_ONCE = 116, + T_NAMESPACE = 117, + T_NS_SEPARATOR = 118, + T_AS = 119, + T_IF = 120, + T_ENDIF = 121, + T_WHILE = 122, + T_DO = 123, + T_FOR = 124, + T_SWITCH = 125, + T_BREAK = 126, + T_CONTINUE = 127, + T_RETURN = 128, + T_GLOBAL = 129, + T_STATIC = 130, + T_ECHO = 131, + T_INLINE_HTML = 132, + T_UNSET = 133, + T_FOREACH = 134, + T_DECLARE = 135, + T_TRY = 136, + T_THROW = 137, + T_GOTO = 138, + T_FINALLY = 139, + T_CATCH = 140, + T_ENDDECLARE = 141, + T_LIST = 142, + T_CLONE = 143, + T_PLUS_EQUAL = 144, + T_MINUS_EQUAL = 145, + T_MUL_EQUAL = 146, + T_DIV_EQUAL = 147, + T_CONCAT_EQUAL = 148, + T_MOD_EQUAL = 149, + T_AND_EQUAL = 150, + T_OR_EQUAL = 151, + T_XOR_EQUAL = 152, + T_SL_EQUAL = 153, + T_SR_EQUAL = 154, + T_INC = 155, + T_DEC = 156, + T_BOOLEAN_OR = 157, + T_BOOLEAN_AND = 158, + T_LOGICAL_OR = 159, + T_LOGICAL_AND = 160, + T_LOGICAL_XOR = 161, + T_SL = 162, + T_SR = 163, + T_IS_IDENTICAL = 164, + T_IS_NOT_IDENTICAL = 165, + T_IS_EQUAL = 166, + T_IS_NOT_EQUAL = 167, + T_IS_SMALLER_OR_EQUAL = 168, + T_IS_GREATER_OR_EQUAL = 169, + T_INSTANCEOF = 170, + T_INT_CAST = 171, + T_DOUBLE_CAST = 172, + T_STRING_CAST = 173, + T_ARRAY_CAST = 174, + T_OBJECT_CAST = 175, + T_BOOL_CAST = 176, + T_UNSET_CAST = 177, + T_EXIT = 178, + T_PRINT = 179, + T_YIELD = 180, + T_YIELD_FROM = 181, + T_FUNCTION = 182, + T_DOUBLE_ARROW = 183, + T_DOUBLE_COLON = 184, + T_ARRAY = 185, + T_CALLABLE = 186, + T_CLASS = 187, + T_ABSTRACT = 188, + T_TRAIT = 189, + T_FINAL = 190, + T_EXTENDS = 191, + T_INTERFACE = 192, + T_IMPLEMENTS = 193, + T_VAR = 194, + T_PUBLIC = 195, + T_PROTECTED = 196, + T_PRIVATE = 197, + T_CONST = 198, + T_NEW = 199, + T_INSTEADOF = 200, + T_ELSEIF = 201, + T_ELSE = 202, + T_ENDSWITCH = 203, + T_CASE = 204, + T_DEFAULT = 205, + T_ENDFOR = 206, + T_ENDFOREACH = 207, + T_ENDWHILE = 208, + T_CONSTANT_ENCAPSED_STRING = 209, + T_LNUMBER = 210, + T_DNUMBER = 211, + T_LINE = 212, + T_FILE = 213, + T_DIR = 214, + T_TRAIT_C = 215, + T_METHOD_C = 216, + T_FUNC_C = 217, + T_NS_C = 218, + T_START_HEREDOC = 219, + T_END_HEREDOC = 220, + T_CLASS_C = 221, + T_VARIABLE = 222, + T_OPEN_TAG = 223, + T_OPEN_TAG_WITH_ECHO = 224, + T_CLOSE_TAG = 225, + T_WHITESPACE = 226, + T_COMMENT = 227, + T_DOC_COMMENT = 228, + T_ELLIPSIS = 229, + T_COALESCE = 230, + T_POW = 231, + T_POW_EQUAL = 232, + T_SPACESHIP = 233, + T_COALESCE_EQUAL = 234, + T_FN = 235 + } + /** + * PHP AST Tokens + */ + const tokens: { + values: { + [key: number]: string; + }; + names: TokenNames; + }; +} +