From e317dd23fb5a897468b6d136ec193cfc7d56a59d Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Wed, 6 Mar 2019 10:35:38 +0200 Subject: [PATCH 1/6] Update README.md --- README.md | 69 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index c932164..16dec24 100644 --- a/README.md +++ b/README.md @@ -23,38 +23,7 @@ Features: - Parsing syntax-invalid PHP files - Saving and printing free-floating comments and whitespaces -Roadmap -------- - -- Control Flow Graph (CFG) -- PhpDocComment parser -- Stabilize api - -Install -------- - -``` -go get github.com/z7zmey/php-parser -``` - -CLI ---- - -``` -php-parser [flags] ... -``` - -| flag | type | description | -|-------|------|----------------------------------------------| -| -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] | -| -php5 | bool | parse as PHP5 | - -Dump AST to stdout. - -Example +Usage example ------- ```Golang @@ -91,6 +60,42 @@ func main() { } ``` +Who Uses +-------- + +[VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP + +Roadmap +------- + +- Control Flow Graph (CFG) +- PhpDocComment parser +- Stabilize api + +Install +------- + +``` +go get github.com/z7zmey/php-parser +``` + +CLI +--- + +``` +php-parser [flags] ... +``` + +| flag | type | description | +|-------|------|----------------------------------------------| +| -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] | +| -php5 | bool | parse as PHP5 | + +Dump AST to stdout. + Namespace resolver ------------------ From 984dba6a800d205293cb54751b174a90be38a8bc Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Wed, 6 Mar 2019 10:36:48 +0200 Subject: [PATCH 2/6] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 16dec24..6ca8879 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,11 @@ Features: - Parsing syntax-invalid PHP files - Saving and printing free-floating comments and whitespaces +Who Uses +-------- + +[VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP + Usage example ------- @@ -60,11 +65,6 @@ func main() { } ``` -Who Uses --------- - -[VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP - Roadmap ------- From 394f8821001f38fe5b4c4aaffd4fa20e50927a3f Mon Sep 17 00:00:00 2001 From: z7zmey Date: Wed, 1 May 2019 09:34:05 +0300 Subject: [PATCH 3/6] #88 Update README.md --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6ca8879..148985a 100644 --- a/README.md +++ b/README.md @@ -35,8 +35,8 @@ Usage example package main import ( - "fmt" "bytes" + "fmt" "os" "github.com/z7zmey/php-parser/php7" @@ -54,14 +54,12 @@ func main() { } visitor := visitor.Dumper{ - Writer: os.Stdout, - Indent: "", - Comments: parser.GetComments(), - Positions: parser.GetPositions(), + Writer: os.Stdout, + Indent: "", } rootNode := parser.GetRootNode() - rootNode.Walk(visitor) + rootNode.Walk(&visitor) } ``` From 32c9a7394c0d8b6126e244bca947af7b9061f3f1 Mon Sep 17 00:00:00 2001 From: "Iskander (Alex) Sharipov" Date: Tue, 13 Aug 2019 04:00:36 +0300 Subject: [PATCH 4/6] readme: mention phpgrep in "who uses" --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 148985a..329f3e1 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Who Uses -------- [VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP +[quasilyte/phpgrep](https://github.com/quasilyte/phpgrep) - phpgrep is a tool for syntax-aware PHP code search Usage example ------- From 5110c36dcacf760efbd661d063ab1b069882c65c Mon Sep 17 00:00:00 2001 From: Vadym Slizov Date: Mon, 19 Aug 2019 15:44:38 +0300 Subject: [PATCH 5/6] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 329f3e1..ca063af 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Who Uses -------- [VKCOM/noverify](https://github.com/VKCOM/noverify) - NoVerify is a pretty fast linter for PHP + [quasilyte/phpgrep](https://github.com/quasilyte/phpgrep) - phpgrep is a tool for syntax-aware PHP code search Usage example From c97ca17c6aceae830f4981388877cd2535ee3607 Mon Sep 17 00:00:00 2001 From: z7zmey Date: Tue, 20 Aug 2019 21:51:45 +0300 Subject: [PATCH 6/6] [#96] handle lexer errors --- scanner/lexer.go | 31 ++++++++++++++++++++----------- scanner/scanner_test.go | 12 ++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/scanner/lexer.go b/scanner/lexer.go index 52d47c7..182257d 100644 --- a/scanner/lexer.go +++ b/scanner/lexer.go @@ -4,6 +4,7 @@ package scanner import ( "bufio" "bytes" + "go/token" t "go/token" "io" "unicode" @@ -62,23 +63,31 @@ func Rune2Class(r rune) int { return classOther } +func (l *Lexer) lexErrorFunc(p token.Pos, msg string) { + pos := position.NewPosition( + l.File.Line(p), + l.File.Line(p), + int(p), + int(p), + ) + l.Errors = append(l.Errors, errors.NewError(msg, pos)) +} + // NewLexer the Lexer constructor func NewLexer(src io.Reader, fName string) *Lexer { - file := t.NewFileSet().AddFile(fName, -1, 1<<31-3) - lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class)) - if err != nil { - panic(err) - } - - return &Lexer{ - Lexer: lx, + lexer := &Lexer{ StateStack: []int{0}, - PhpDocComment: "", - FreeFloating: nil, - heredocLabel: "", tokenBytesBuf: &bytes.Buffer{}, TokenPool: &TokenPool{}, } + + file := t.NewFileSet().AddFile(fName, -1, 1<<31-3) + lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(Rune2Class), lex.ErrorFunc(lexer.lexErrorFunc)) + if err != nil { + panic(err) + } + lexer.Lexer = lx + return lexer } func (l *Lexer) Error(msg string) { diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index 68127d1..1a5a206 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -1420,3 +1420,15 @@ func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) { actual = lv.Tkn.Value assert.DeepEqual(t, expected, actual) } + +func TestBomInMiddleOfFile(t *testing.T) { + src := " 0) + assert.Assert(t, lexer.Errors[0].String() == "unicode (UTF-8) BOM in middle of file at line 1") +}