test scalar string

This commit is contained in:
vadim 2017-12-04 12:40:36 +02:00
parent 1c1926516e
commit 7c3d593097
10 changed files with 549 additions and 549 deletions

21
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,21 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true
}
]
}

View File

@ -4,7 +4,7 @@
# blame: jnml, labs.nic.cz # blame: jnml, labs.nic.cz
all: parser.go scanner.go all: ./parser/parser.go ./parser/scanner.go
rm -f y.output rm -f y.output
gofmt -l -s -w *.go gofmt -l -s -w *.go
go build go build
@ -12,14 +12,11 @@ all: parser.go scanner.go
run: all run: all
./php-parser example.php ./php-parser example.php
scanner.go: scanner.l test: all
go test ./test/...
./parser/scanner.go: ./parser/scanner.l
golex -o $@ $< golex -o $@ $<
parser.go: parser.y ./parser/parser.go: ./parser/parser.y
goyacc -o $@ $< goyacc -o $@ $<
clean:
rm -f php-parser.go lex.yy.go y.output *~
nuke: clean
rm -f example

View File

@ -1,43 +1 @@
<?php <? "test";
namespace z7zmey\Example {
use \Exception;
use z7zmey\Foo\{Bar, function Baz};
abstract class Foo extends Bar implements Buz, Buzz {
use \z7zmey\_Trait;
public const CC = 0;
public function &test(bool $a, string $b = null): ?void {
}
}
}
namespace z7zmey\Example2;
if ($a === true) {
} elseif ($a === false) {
} elseif ($a === null) {
} else {
}
$a = "string
with $var
";
$a = "string
with out \$var";
$a = <<<test
string $var
test;
`test
$var
`;
?>
<?= $b = 22; $b ?>

View File

@ -7,12 +7,10 @@ import (
"os" "os"
"github.com/yookoala/realpath" "github.com/yookoala/realpath"
"github.com/z7zmey/php-parser/parser"
) )
func main() { func main() {
yyDebug = 0
yyErrorVerbose = true
flag.Parse() flag.Parse()
for _, path := range flag.Args() { for _, path := range flag.Args() {
@ -21,7 +19,7 @@ func main() {
fmt.Printf("\n==> %s", real) fmt.Printf("\n==> %s", real)
src, _ := os.Open(string(real)) src, _ := os.Open(string(real))
rootnode := parse(src, real) rootnode := parser.Parse(src, real)
fmt.Println(rootnode) fmt.Println(rootnode)
} }
} }

View File

@ -1,4 +1,4 @@
package main package parser
import ( import (
"bufio" "bufio"

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
%{ %{
package main package parser
import ( import (
"io" "io"
@ -9,7 +9,7 @@ import (
var rootnode = node.SimpleNode("Root") var rootnode = node.SimpleNode("Root")
func parse(src io.Reader, fName string) node.Node { func Parse(src io.Reader, fName string) node.Node {
yyDebug = 0 yyDebug = 0
yyErrorVerbose = true yyErrorVerbose = true
rootnode = node.SimpleNode("Root") //reset rootnode = node.SimpleNode("Root") //reset

View File

@ -6,11 +6,12 @@
// blame: jnml, labs.nic.cz // blame: jnml, labs.nic.cz
package main package parser
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"github.com/z7zmey/php-parser/token" "github.com/z7zmey/php-parser/token"
) )

View File

@ -5,7 +5,7 @@
// blame: jnml, labs.nic.cz // blame: jnml, labs.nic.cz
package main package parser
import ( import (
"fmt" "fmt"

View File

@ -0,0 +1,25 @@
package test
import (
"bytes"
"reflect"
"testing"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/token"
)
func TestNewNodeScalarString(t *testing.T) {
src := `<? "test";`
strToken := token.NewToken([]byte("\"test\""), 1, 1)
strNode := node.NewNodeScalarString(strToken)
expected := node.SimpleNode("Statements").Append(strNode)
node := parser.Parse(bytes.NewBufferString(src), "test.php")
if !reflect.DeepEqual(expected, node) {
t.Error("Not equal")
}
}