From 0cf164c11c3f4d1e221f97630cb98f345dbacd27 Mon Sep 17 00:00:00 2001 From: z7zmey Date: Tue, 10 Apr 2018 16:19:47 +0300 Subject: [PATCH] issue #8: update Parser constructor --- php5/parser.go | 21 +++------------------ php7/parser.go | 21 +++------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/php5/parser.go b/php5/parser.go index 84bc23d..5d40e13 100644 --- a/php5/parser.go +++ b/php5/parser.go @@ -1,12 +1,8 @@ package php5 import ( - "bufio" - goToken "go/token" "io" - "github.com/cznic/golex/lex" - "github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/errors" "github.com/z7zmey/php-parser/node" @@ -21,7 +17,7 @@ func (lval *yySymType) Token(t token.Token) { // Parser structure type Parser struct { - scanner.Lexer + *scanner.Lexer lastToken *token.Token positionBuilder *position.Builder errors []*errors.Error @@ -32,21 +28,10 @@ type Parser struct { // NewParser creates and returns new Parser func NewParser(src io.Reader, fName string) *Parser { - file := goToken.NewFileSet().AddFile(fName, -1, 1<<31-1) - lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(scanner.Rune2Class)) - if err != nil { - panic(err) - } - - scanner := scanner.Lexer{ - Lexer: lx, - StateStack: []int{0}, - PhpDocComment: "", - Comments: nil, - } + lexer := scanner.NewLexer(src, fName) return &Parser{ - scanner, + lexer, nil, nil, nil, diff --git a/php7/parser.go b/php7/parser.go index ac36532..c17c64b 100644 --- a/php7/parser.go +++ b/php7/parser.go @@ -1,12 +1,8 @@ package php7 import ( - "bufio" - goToken "go/token" "io" - "github.com/cznic/golex/lex" - "github.com/z7zmey/php-parser/comment" "github.com/z7zmey/php-parser/errors" "github.com/z7zmey/php-parser/node" @@ -21,7 +17,7 @@ func (lval *yySymType) Token(t token.Token) { // Parser structure type Parser struct { - scanner.Lexer + *scanner.Lexer lastToken *token.Token positionBuilder *position.Builder errors []*errors.Error @@ -32,21 +28,10 @@ type Parser struct { // NewParser creates and returns new Parser func NewParser(src io.Reader, fName string) *Parser { - file := goToken.NewFileSet().AddFile(fName, -1, 1<<31-1) - lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(scanner.Rune2Class)) - if err != nil { - panic(err) - } - - scanner := scanner.Lexer{ - Lexer: lx, - StateStack: []int{0}, - PhpDocComment: "", - Comments: nil, - } + lexer := scanner.NewLexer(src, fName) return &Parser{ - scanner, + lexer, nil, nil, nil,