php7: save all comments

This commit is contained in:
z7zmey 2018-05-27 18:02:58 +03:00
parent a9f54cba27
commit e396f81eea
7 changed files with 7795 additions and 4967 deletions

File diff suppressed because it is too large Load Diff

View File

@ -143,6 +143,29 @@ import (
%token <token> T_COALESCE %token <token> T_COALESCE
%token <token> T_SPACESHIP %token <token> T_SPACESHIP
%token <token> T_NOELSE %token <token> T_NOELSE
%token <token> T_PLUS_EQUAL
%token <token> T_MINUS_EQUAL
%token <token> T_MUL_EQUAL
%token <token> T_POW_EQUAL
%token <token> T_DIV_EQUAL
%token <token> T_CONCAT_EQUAL
%token <token> T_MOD_EQUAL
%token <token> T_AND_EQUAL
%token <token> T_OR_EQUAL
%token <token> T_XOR_EQUAL
%token <token> T_SL_EQUAL
%token <token> T_SR_EQUAL
%token <token> T_BOOLEAN_OR
%token <token> T_BOOLEAN_AND
%token <token> T_POW
%token <token> T_SL
%token <token> T_SR
%token <token> T_IS_IDENTICAL
%token <token> T_IS_NOT_IDENTICAL
%token <token> T_IS_EQUAL
%token <token> T_IS_NOT_EQUAL
%token <token> T_IS_SMALLER_OR_EQUAL
%token <token> T_IS_GREATER_OR_EQUAL
%token <token> '"' %token <token> '"'
%token <token> '`' %token <token> '`'
%token <token> '{' %token <token> '{'
@ -161,6 +184,15 @@ import (
%token <token> '~' %token <token> '~'
%token <token> '@' %token <token> '@'
%token <token> '$' %token <token> '$'
%token <token> ','
%token <token> '|'
%token <token> '='
%token <token> '^'
%token <token> '*'
%token <token> '/'
%token <token> '%'
%token <token> '<'
%token <token> '>'
%left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE %left T_INCLUDE T_INCLUDE_ONCE T_EVAL T_REQUIRE T_REQUIRE_ONCE
%left ',' %left ','

View File

@ -3,7 +3,6 @@ package php7
import ( import (
"io" "io"
"github.com/z7zmey/php-parser/comment"
"github.com/z7zmey/php-parser/errors" "github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser" "github.com/z7zmey/php-parser/parser"
@ -72,16 +71,6 @@ func (l *Parser) Parse() int {
return yyParse(l) return yyParse(l)
} }
func (l *Parser) listGetFirstNodeComments(list []node.Node) []*comment.Comment {
if len(list) == 0 {
return nil
}
node := list[0]
return l.comments[node]
}
// GetPath return path to file // GetPath return path to file
func (l *Parser) GetPath() string { func (l *Parser) GetPath() string {
return l.path return l.path
@ -106,3 +95,19 @@ func (l *Parser) GetComments() parser.Comments {
func (l *Parser) GetPositions() parser.Positions { func (l *Parser) GetPositions() parser.Positions {
return l.positions return l.positions
} }
// GetPositions returns positions list
func (l *Parser) setCommentsFromChildNode(n node.Node, c node.Node) {
l.comments.AddComments(n, l.comments[c])
delete(l.comments, c)
}
// helpers
func lastNode(nn []node.Node) node.Node {
return nn[len(nn)-1]
}
func firstNode(nn []node.Node) node.Node {
return nn[0]
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -370,32 +370,32 @@ const T_MINUS_EQUAL = 57460
// T_MUL_EQUAL token // T_MUL_EQUAL token
const T_MUL_EQUAL = 57461 const T_MUL_EQUAL = 57461
// T_POW_EQUAL token
const T_POW_EQUAL = 57462
// T_DIV_EQUAL token // T_DIV_EQUAL token
const T_DIV_EQUAL = 57462 const T_DIV_EQUAL = 57463
// T_CONCAT_EQUAL token // T_CONCAT_EQUAL token
const T_CONCAT_EQUAL = 57463 const T_CONCAT_EQUAL = 57464
// T_MOD_EQUAL token // T_MOD_EQUAL token
const T_MOD_EQUAL = 57464 const T_MOD_EQUAL = 57465
// T_AND_EQUAL token // T_AND_EQUAL token
const T_AND_EQUAL = 57465 const T_AND_EQUAL = 57466
// T_OR_EQUAL token // T_OR_EQUAL token
const T_OR_EQUAL = 57466 const T_OR_EQUAL = 57467
// T_XOR_EQUAL token // T_XOR_EQUAL token
const T_XOR_EQUAL = 57467 const T_XOR_EQUAL = 57468
// T_SL_EQUAL token // T_SL_EQUAL token
const T_SL_EQUAL = 57468 const T_SL_EQUAL = 57469
// T_SR_EQUAL token // T_SR_EQUAL token
const T_SR_EQUAL = 57469 const T_SR_EQUAL = 57470
// T_POW_EQUAL token
const T_POW_EQUAL = 57470
// T_BOOLEAN_OR token // T_BOOLEAN_OR token
const T_BOOLEAN_OR = 57471 const T_BOOLEAN_OR = 57471
@ -403,32 +403,32 @@ const T_BOOLEAN_OR = 57471
// T_BOOLEAN_AND token // T_BOOLEAN_AND token
const T_BOOLEAN_AND = 57472 const T_BOOLEAN_AND = 57472
// T_IS_EQUAL token // T_POW token
const T_IS_EQUAL = 57473 const T_POW = 57473
// T_IS_NOT_EQUAL token
const T_IS_NOT_EQUAL = 57474
// T_IS_IDENTICAL token
const T_IS_IDENTICAL = 57475
// T_IS_NOT_IDENTICAL token
const T_IS_NOT_IDENTICAL = 57476
// T_IS_SMALLER_OR_EQUAL token
const T_IS_SMALLER_OR_EQUAL = 57477
// T_IS_GREATER_OR_EQUAL token
const T_IS_GREATER_OR_EQUAL = 57478
// T_SL token // T_SL token
const T_SL = 57479 const T_SL = 57474
// T_SR token // T_SR token
const T_SR = 57480 const T_SR = 57475
// T_POW token // T_IS_IDENTICAL token
const T_POW = 57481 const T_IS_IDENTICAL = 57476
// T_IS_NOT_IDENTICAL token
const T_IS_NOT_IDENTICAL = 57477
// T_IS_EQUAL token
const T_IS_EQUAL = 57478
// T_IS_NOT_EQUAL token
const T_IS_NOT_EQUAL = 57479
// T_IS_SMALLER_OR_EQUAL token
const T_IS_SMALLER_OR_EQUAL = 57480
// T_IS_GREATER_OR_EQUAL token
const T_IS_GREATER_OR_EQUAL = 57481
// Lval parsers yySymType must implement this interface // Lval parsers yySymType must implement this interface
type Lval interface { type Lval interface {

View File

@ -107,8 +107,6 @@ func ExampleDumper() {
//| "Stmts": //| "Stmts":
//| [*stmt.Expression] //| [*stmt.Expression]
//| "Position": Pos{Line: 8-8 Pos: 124-128}; //| "Position": Pos{Line: 8-8 Pos: 124-128};
//| "Comments":
//| "// some comment\n"
//| "Expr": //| "Expr":
//| [*expr.Variable] //| [*expr.Variable]
//| "Position": Pos{Line: 8-8 Pos: 124-127}; //| "Position": Pos{Line: 8-8 Pos: 124-127};
@ -118,6 +116,4 @@ func ExampleDumper() {
//| [*node.Identifier] //| [*node.Identifier]
//| "Position": Pos{Line: 8-8 Pos: 124-127}; //| "Position": Pos{Line: 8-8 Pos: 124-127};
//| "Value": var; //| "Value": var;
//| "Comments":
//| "// some comment\n"
} }