From 22ef0de7ef6b8c1c696043a25c06488a26d24403 Mon Sep 17 00:00:00 2001 From: nikic Date: Fri, 12 Sep 2014 14:40:17 +0200 Subject: [PATCH] Add migration guide for 0.9 -> 1.0 --- CHANGELOG.md | 6 ++- README.md | 13 ++---- UPGRADE-1.0.md | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 UPGRADE-1.0.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a08fb0e..bd50728 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ Version 1.0.0-dev ----------------- -Nothing yet. +* [BC] Removed deprecated `Template` and `TemplateLoader` classes. + +* Fixed XML unserializer to properly work with new namespaced node names. Version 1.0.0-beta2 (31.08.2014) -------------------------------- @@ -22,7 +24,7 @@ Version 1.0.0-beta2 (31.08.2014) * The autoloader now only requires a file if it exists. This allows usages like `class_exists('PhpParser\NotExistingClass')`. -* Added experimental ``bin/php-parse.php`` script, which is intended to help exploring and debugging the node tree. +* Added experimental `bin/php-parse.php` script, which is intended to help exploring and debugging the node tree. * Separated the parser implemention (in `lib/PhpParser/ParserAbstract.php`) and the generated data (in `lib/PhpParser/Parser.php`). Furthermore the parser now uses meaningful variable names and contains comments diff --git a/README.md b/README.md index 2d5a899..cf0b95a 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,18 @@ PHP Parser ========== -This is a PHP 5.6 (and older) parser written in PHP. It's purpose is to simplify static code analysis and +This is a PHP 5.2 to PHP 5.6 parser written in PHP. It's purpose is to simplify static code analysis and manipulation. -[Documentation for version 0.9.x][doc_0_9] (stable; for running on PHP 5.2). - [**Documentation for version 1.0.x**][doc_master] (beta; for running on PHP >= 5.3). +[Documentation for version 0.9.x][doc_0_9] (unsupported; for running on PHP 5.2). + In a Nutshell ------------- -Basically, the parser does nothing more than turn some PHP code into an abstract syntax tree. ("nothing -more" is kind of sarcastic here as PHP has a ... uhm, let's just say "not nice" ... grammar, which makes -parsing PHP very hard.) - -For example, if you stick this code in the parser: +The parser turns PHP source code into an abstract syntax tree. For example, if you pass the following code into the +parser: ```php Expr_AssignOp_BitwiseAnd +Expr_AssignBitwiseOr => Expr_AssignOp_BitwiseOr +Expr_AssignBitwiseXor => Expr_AssignOp_BitwiseXor +Expr_AssignConcat => Expr_AssignOp_Concat +Expr_AssignDiv => Expr_AssignOp_Div +Expr_AssignMinus => Expr_AssignOp_Minus +Expr_AssignMod => Expr_AssignOp_Mod +Expr_AssignMul => Expr_AssignOp_Mul +Expr_AssignPlus => Expr_AssignOp_Plus +Expr_AssignShiftLeft => Expr_AssignOp_ShiftLeft +Expr_AssignShiftRight => Expr_AssignOp_ShiftRight + +Expr_BitwiseAnd => Expr_BinaryOp_BitwiseAnd +Expr_BitwiseOr => Expr_BinaryOp_BitwiseOr +Expr_BitwiseXor => Expr_BinaryOp_BitwiseXor +Expr_BooleanAnd => Expr_BinaryOp_BooleanAnd +Expr_BooleanOr => Expr_BinaryOp_BooleanOr +Expr_Concat => Expr_BinaryOp_Concat +Expr_Div => Expr_BinaryOp_Div +Expr_Equal => Expr_BinaryOp_Equal +Expr_Greater => Expr_BinaryOp_Greater +Expr_GreaterOrEqual => Expr_BinaryOp_GreaterOrEqual +Expr_Identical => Expr_BinaryOp_Identical +Expr_LogicalAnd => Expr_BinaryOp_LogicalAnd +Expr_LogicalOr => Expr_BinaryOp_LogicalOr +Expr_LogicalXor => Expr_BinaryOp_LogicalXor +Expr_Minus => Expr_BinaryOp_Minus +Expr_Mod => Expr_BinaryOp_Mod +Expr_Mul => Expr_BinaryOp_Mul +Expr_NotEqual => Expr_BinaryOp_NotEqual +Expr_NotIdentical => Expr_BinaryOp_NotIdentical +Expr_Plus => Expr_BinaryOp_Plus +Expr_ShiftLeft => Expr_BinaryOp_ShiftLeft +Expr_ShiftRight => Expr_BinaryOp_ShiftRight +Expr_Smaller => Expr_BinaryOp_Smaller +Expr_SmallerOrEqual => Expr_BinaryOp_SmallerOrEqual + +Scalar_ClassConst => Scalar_MagicConst_Class +Scalar_DirConst => Scalar_MagicConst_Dir +Scalar_FileConst => Scalar_MagicConst_File +Scalar_FuncConst => Scalar_MagicConst_Function +Scalar_LineConst => Scalar_MagicConst_Line +Scalar_MethodConst => Scalar_MagicConst_Method +Scalar_NSConst => Scalar_MagicConst_Namespace +Scalar_TraitConst => Scalar_MagicConst_Trait +``` + +These changes may affect custom pretty printers and code comparing the return value of ''Node::getType()'' to specific +strings. + +### Miscellaneous + + * The classes `Template` and `TemplateLoader` have been removed. You should use some other [code generation][code_gen] + project built on top of PHP-Parser instead. + + * The `PrettyPrinterAbstract::pStmts()` method now emits a leading newline if the statement list is not empty. + Custom pretty printers should remove the explicit newline before `pStmts()` calls. + + Old: + + ```php + public function pStmt_Trait(PHPParser_Node_Stmt_Trait $node) { + return 'trait ' . $node->name + . "\n" . '{' . "\n" . $this->pStmts($node->stmts) . "\n" . '}'; + } + ``` + + New: + + ```php + public function pStmt_Trait(Stmt\Trait_ $node) { + return 'trait ' . $node->name + . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; + } + ``` + + [code_gen]: https://github.com/nikic/PHP-Parser/wiki/Projects-using-the-PHP-Parser#code-generation \ No newline at end of file