From c456fa90ceb687442061c6488c17afdc6230405a Mon Sep 17 00:00:00 2001 From: z7zmey Date: Mon, 25 Feb 2019 17:01:06 +0200 Subject: [PATCH] update README.md --- README.md | 96 ++++--------------------------------------------------- 1 file changed, 6 insertions(+), 90 deletions(-) diff --git a/README.md b/README.md index ec37a4b..c932164 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,3 @@ - - PHP Parser written in Go ======================== @@ -26,13 +19,13 @@ Features: - Fully support PHP 5 and PHP 7 syntax - Abstract syntax tree (AST) representation - Traversing AST -- Namespace resolver -- Able to parse syntax-invalid PHP files +- Resolving namespaced names +- Parsing syntax-invalid PHP files +- Saving and printing free-floating comments and whitespaces Roadmap ------- -- Pretty printer - Control Flow Graph (CFG) - PhpDocComment parser - Stabilize api @@ -53,11 +46,10 @@ php-parser [flags] ... | flag | type | description | |-------|------|----------------------------------------------| -| -d |string| dump format: [custom, go, json, pretty-json] | -| -p | bool | show positions | -| -r | bool | resolve names | +| -d |string| dump format: [custom, go, json, pretty-json] | +| -r | bool | resolve names | +| -ff | bool | parse and show free floating strings | | -prof |string| start profiler: [cpu, mem, trace] | -| -meta | bool | show meta info | | -php5 | bool | parse as PHP5 | Dump AST to stdout. @@ -106,79 +98,3 @@ Namespace resolver is a visitor that resolves nodes fully qualified name and sav - For `Class`, `Interface`, `Trait`, `Function`, `Constant` nodes it saves name with current namespace. - For `Name`, `Relative`, `FullyQualified` nodes it resolves `use` aliases and saves a fully qualified name. - -Parsing syntax-invalid PHP files --------------------------------- - -If we try to parse `$a$b;` then the parser triggers error 'syntax error: unexpected T_VARIABLE'. Token `$b` is unexpected, but parser recovers parsing process and returns `$b;` statement to AST, because it is syntactically correct. - -Pretty printer [work in progress] ---------------------------------- - -```Golang -nodes := &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Namespace{ - NamespaceName: &name.Name{ - Parts: []node.Node{ - &name.NamePart{Value: "Foo"}, - }, - }, - }, - &stmt.Class{ - Modifiers: []node.Node{ - &node.Identifier{Value: "abstract"}, - }, - ClassName: &name.Name{ - Parts: []node.Node{ - &name.NamePart{Value: "Bar"}, - }, - }, - Extends: &stmt.ClassExtends{ - ClassName: &name.Name{ - Parts: []node.Node{ - &name.NamePart{ - Value: "Baz" - }, - }, - }, - }, - Stmts: []node.Node{ - &stmt.ClassMethod{ - Modifiers: []node.Node{ - &node.Identifier{Value: "public"}, - }, - MethodName: &node.Identifier{Value: "greet"}, - Stmt: &stmt.StmtList{ - Stmts: []node.Node{ - &stmt.Echo{ - Exprs: []node.Node{ - &scalar.String{Value: "'Hello world'"}, - }, - }, - }, - }, - }, - }, - }, - }, -} - -file := os.Stdout -p := printer.NewPrinter(file, " ") -p.Print(nodes) -``` - -It prints to stdout: - -```PHP -