add Heredoc node
This commit is contained in:
322
php5/php5.go
322
php5/php5.go
File diff suppressed because it is too large
Load Diff
12
php5/php5.y
12
php5/php5.y
@@ -2720,13 +2720,17 @@ common_scalar:
|
||||
}
|
||||
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC
|
||||
{
|
||||
$$ = scalar.NewString($2.Value)
|
||||
positions.AddPosition($$, positionBuilder.NewTokensPosition($1, $3))/* TODO: mark as Heredoc*/
|
||||
encapsed := scalar.NewEncapsedStringPart($2.Value)
|
||||
positions.AddPosition(encapsed, positionBuilder.NewTokenPosition($2))
|
||||
comments.AddComments(encapsed, $2.Comments())
|
||||
|
||||
$$ = scalar.NewHeredoc($1.Value, []node.Node{encapsed})
|
||||
positions.AddPosition($$, positionBuilder.NewTokensPosition($1, $3))
|
||||
comments.AddComments($$, $1.Comments())
|
||||
}
|
||||
| T_START_HEREDOC T_END_HEREDOC
|
||||
{
|
||||
$$ = scalar.NewEncapsed(nil)
|
||||
$$ = scalar.NewHeredoc($1.Value, nil)
|
||||
positions.AddPosition($$, positionBuilder.NewTokensPosition($1, $2))
|
||||
comments.AddComments($$, $1.Comments())
|
||||
}
|
||||
@@ -3066,7 +3070,7 @@ scalar:
|
||||
}
|
||||
| T_START_HEREDOC encaps_list T_END_HEREDOC
|
||||
{
|
||||
$$ = scalar.NewEncapsed($2)
|
||||
$$ = scalar.NewHeredoc($1.Value, $2)
|
||||
positions.AddPosition($$, positionBuilder.NewTokensPosition($1, $3))
|
||||
comments.AddComments($$, $1.Comments())
|
||||
}
|
||||
|
||||
@@ -45,30 +45,6 @@ func TestPhp5(t *testing.T) {
|
||||
function(bar $bar=null, baz &...$baz) {};
|
||||
static function(bar $bar=null, baz &...$baz) {};
|
||||
|
||||
"test";
|
||||
"\$test";
|
||||
"
|
||||
test
|
||||
";
|
||||
'$test';
|
||||
'
|
||||
$test
|
||||
';
|
||||
<<<CAD
|
||||
CAD;
|
||||
<<<CAD
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello $world
|
||||
CAD;
|
||||
<<<'CAD'
|
||||
hello $world
|
||||
CAD;
|
||||
|
||||
1234567890123456789;
|
||||
12345678901234567890;
|
||||
0.;
|
||||
@@ -545,42 +521,6 @@ CAD;
|
||||
Stmts: []node.Node{},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"test\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"\\$test\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"\n\t\t\ttest\n\t\t\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "'$test'"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "'\n\t\t\t$test\n\t\t'"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Encapsed{},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\thello\n"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\thello\n"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Encapsed{
|
||||
Parts: []node.Node{
|
||||
&scalar.EncapsedStringPart{Value: "\thello "},
|
||||
&expr.Variable{VarName: &node.Identifier{Value: "world"}},
|
||||
&scalar.EncapsedStringPart{Value: "\n"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\thello $world\n"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Lnumber{Value: "1234567890123456789"},
|
||||
},
|
||||
@@ -3678,3 +3618,106 @@ CAD;
|
||||
actual, _, _ := php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp5Strings(t *testing.T) {
|
||||
src := `<?
|
||||
"test";
|
||||
"\$test";
|
||||
"
|
||||
test
|
||||
";
|
||||
'$test';
|
||||
'
|
||||
$test
|
||||
';
|
||||
`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"test\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"\\$test\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "\"\n\t\t\ttest\n\t\t\""},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "'$test'"},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.String{Value: "'\n\t\t\t$test\n\t\t'"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp5Heredoc(t *testing.T) {
|
||||
src := `<?
|
||||
<<<CAD
|
||||
CAD;
|
||||
<<<CAD
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello
|
||||
CAD;
|
||||
<<<"CAD"
|
||||
hello $world
|
||||
CAD;
|
||||
<<<'CAD'
|
||||
hello $world
|
||||
CAD;
|
||||
`
|
||||
|
||||
expected := &stmt.StmtList{
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Heredoc{
|
||||
Label: "CAD",
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Heredoc{
|
||||
Label: "CAD",
|
||||
Parts: []node.Node{
|
||||
&scalar.EncapsedStringPart{Value: "\thello\n"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Heredoc{
|
||||
Label: "\"CAD\"",
|
||||
Parts: []node.Node{
|
||||
&scalar.EncapsedStringPart{Value: "\thello\n"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Heredoc{
|
||||
Label: "\"CAD\"",
|
||||
Parts: []node.Node{
|
||||
&scalar.EncapsedStringPart{Value: "\thello "},
|
||||
&expr.Variable{VarName: &node.Identifier{Value: "world"}},
|
||||
&scalar.EncapsedStringPart{Value: "\n"},
|
||||
},
|
||||
},
|
||||
},
|
||||
&stmt.Expression{
|
||||
Expr: &scalar.Heredoc{
|
||||
Label: "'CAD'",
|
||||
Parts: []node.Node{
|
||||
&scalar.EncapsedStringPart{Value: "\thello $world\n"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
actual, _, _ := php5.Parse(bytes.NewBufferString(src), "test.php")
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user