[refactoring] update ast structure of "Lnumber" and "Dnumber" nodes

This commit is contained in:
Vadym Slizov 2020-11-20 23:08:30 +02:00
parent 7e2965f53b
commit e3ad9747f4
No known key found for this signature in database
GPG Key ID: AEA2A9388EF42A4A
5 changed files with 53 additions and 38 deletions

BIN
internal/php5/php5.go generated

Binary file not shown.

View File

@ -4493,23 +4493,23 @@ ctor_arguments:
common_scalar:
T_LNUMBER
{
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_DNUMBER
{
$$ = &ast.ScalarDnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_CONSTANT_ENCAPSED_STRING
{
@ -6146,7 +6146,13 @@ encaps_var_offset:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string($1.Value)); err == nil {
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
} else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value}
}

BIN
internal/php7/php7.go generated

Binary file not shown.

View File

@ -3940,23 +3940,23 @@ dereferencable_scalar:
scalar:
T_LNUMBER
{
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_DNUMBER
{
$$ = &ast.ScalarDnumber{ast.Node{}, $1.Value}
// save position
$$.GetNode().Position = position.NewTokenPosition($1)
// save comments
yylex.(*Parser).setFreeFloating($$, token.Start, $1.SkippedTokens)
$$ = &ast.ScalarDnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
}
| T_LINE
{
@ -4785,7 +4785,13 @@ encaps_var_offset:
{
// TODO: add option to handle 64 bit integer
if _, err := strconv.Atoi(string($1.Value)); err == nil {
$$ = &ast.ScalarLnumber{ast.Node{}, $1.Value}
$$ = &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($1),
},
NumberTkn: $1,
Value: $1.Value,
}
} else {
$$ = &ast.ScalarString{ast.Node{}, $1.Value}
}
@ -4798,13 +4804,17 @@ encaps_var_offset:
}
| '-' T_NUM_STRING
{
var lnumber *ast.ScalarLnumber
// TODO: add option to handle 64 bit integer
_, err := strconv.Atoi(string($2.Value));
isInt := err == nil
if isInt {
lnumber = &ast.ScalarLnumber{ast.Node{}, $2.Value}
lnumber := &ast.ScalarLnumber{
Node: ast.Node{
Position: position.NewTokenPosition($2),
},
NumberTkn: $2,
Value: $2.Value,
}
$$ = &ast.ExprUnaryMinus{ast.Node{}, lnumber}
} else {
$2.Value = append([]byte("-"), $2.Value...)
@ -4812,9 +4822,6 @@ encaps_var_offset:
}
// save position
if isInt {
lnumber.GetNode().Position = position.NewTokensPosition($1, $2)
}
$$.GetNode().Position = position.NewTokensPosition($1, $2)
// save comments

View File

@ -115,7 +115,8 @@ func (n *Argument) Accept(v NodeVisitor) {
// ScalarDnumber node
type ScalarDnumber struct {
Node
Value []byte
NumberTkn *token.Token
Value []byte
}
func (n *ScalarDnumber) Accept(v NodeVisitor) {
@ -156,7 +157,8 @@ func (n *ScalarHeredoc) Accept(v NodeVisitor) {
// ScalarLnumber node
type ScalarLnumber struct {
Node
Value []byte
NumberTkn *token.Token
Value []byte
}
func (n *ScalarLnumber) Accept(v NodeVisitor) {