diff --git a/main.go b/main.go index d71eec2..a0a2dc1 100644 --- a/main.go +++ b/main.go @@ -25,7 +25,7 @@ var wg sync.WaitGroup var usePhp5 *bool var dumpType string var profiler string -var withMeta *bool +var withFreeFloating *bool var showResolvedNs *bool var printBack *bool @@ -36,7 +36,7 @@ type file struct { func main() { usePhp5 = flag.Bool("php5", false, "parse as PHP5") - withMeta = flag.Bool("meta", false, "show meta") + withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings") showResolvedNs = flag.Bool("r", false, "resolve names") printBack = flag.Bool("pb", false, "print AST back into the parsed file") flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]") @@ -110,8 +110,8 @@ func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) { parserWorker = php7.NewParser(src, f.path) } - if *withMeta { - parserWorker.WithMeta() + if *withFreeFloating { + parserWorker.WithFreeFloating() } parserWorker.Parse() diff --git a/parser/parser.go b/parser/parser.go index 7fb233b..f2a583c 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -11,5 +11,5 @@ type Parser interface { GetPath() string GetRootNode() node.Node GetErrors() []*errors.Error - WithMeta() + WithFreeFloating() } diff --git a/php5/parser.go b/php5/parser.go index a45b602..df3d665 100644 --- a/php5/parser.go +++ b/php5/parser.go @@ -57,8 +57,8 @@ func (l *Parser) Error(msg string) { l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, pos)) } -func (l *Parser) WithMeta() { - l.Lexer.WithMeta = true +func (l *Parser) WithFreeFloating() { + l.Lexer.WithFreeFloating = true } // Parse the php7 Parser entrypoint @@ -106,7 +106,7 @@ func isDollar(r rune) bool { } func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -119,7 +119,7 @@ func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) { } func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings []freefloating.String) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -136,7 +136,7 @@ func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings } func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return []freefloating.String{} } @@ -144,7 +144,7 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String { } func (l *Parser) addDollarToken(v node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -163,7 +163,7 @@ func (l *Parser) addDollarToken(v node.Node) { } func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } diff --git a/php7/parser.go b/php7/parser.go index 159b2eb..a161e52 100644 --- a/php7/parser.go +++ b/php7/parser.go @@ -56,8 +56,8 @@ func (l *Parser) Error(msg string) { l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, pos)) } -func (l *Parser) WithMeta() { - l.Lexer.WithMeta = true +func (l *Parser) WithFreeFloating() { + l.Lexer.WithFreeFloating = true } // Parse the php7 Parser entrypoint @@ -105,7 +105,7 @@ func isDollar(r rune) bool { } func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -118,7 +118,7 @@ func (l *Parser) MoveFreeFloating(src node.Node, dst node.Node) { } func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings []freefloating.String) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -135,7 +135,7 @@ func (l *Parser) setFreeFloating(dst node.Node, p freefloating.Position, strings } func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return []freefloating.String{} } @@ -143,7 +143,7 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []freefloating.String { } func (l *Parser) addDollarToken(v node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } @@ -162,7 +162,7 @@ func (l *Parser) addDollarToken(v node.Node) { } func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode node.Node, prevNode node.Node) { - if l.Lexer.WithMeta == false { + if l.Lexer.WithFreeFloating == false { return } diff --git a/printer/printer_parsed_php5_test.go b/printer/printer_parsed_php5_test.go index 7c074f9..a860ee2 100644 --- a/printer/printer_parsed_php5_test.go +++ b/printer/printer_parsed_php5_test.go @@ -11,7 +11,7 @@ import ( func parsePhp5(src string) node.Node { php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") - php5parser.WithMeta() + php5parser.WithFreeFloating() php5parser.Parse() return php5parser.GetRootNode() diff --git a/printer/printer_parsed_php7_test.go b/printer/printer_parsed_php7_test.go index 7aaa088..7585e2c 100644 --- a/printer/printer_parsed_php7_test.go +++ b/printer/printer_parsed_php7_test.go @@ -30,7 +30,7 @@ abstract class Bar extends Baz // parse php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() rootNode := php7parser.GetRootNode() @@ -62,7 +62,7 @@ abstract class Bar extends Baz func parse(src string) node.Node { php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() return php7parser.GetRootNode() diff --git a/scanner/lexer.go b/scanner/lexer.go index d8b08cc..52d47c7 100644 --- a/scanner/lexer.go +++ b/scanner/lexer.go @@ -31,15 +31,15 @@ type Lval interface { // Lexer php lexer type Lexer struct { *lex.Lexer - StateStack []int - PhpDocComment string - FreeFloating []freefloating.String - heredocLabel string - tokenBytesBuf *bytes.Buffer - TokenPool *TokenPool - WithMeta bool - lastToken *Token - Errors []*errors.Error + StateStack []int + PhpDocComment string + FreeFloating []freefloating.String + heredocLabel string + tokenBytesBuf *bytes.Buffer + TokenPool *TokenPool + WithFreeFloating bool + lastToken *Token + Errors []*errors.Error } // Rune2Class returns the rune integer id @@ -163,10 +163,10 @@ func (l *Lexer) tokenString(chars []lex.Char) string { return string(l.tokenBytesBuf.Bytes()) } -// meta +// free-floating func (l *Lexer) addFreeFloating(t freefloating.StringType, chars []lex.Char) { - if !l.WithMeta { + if !l.WithFreeFloating { return } diff --git a/scanner/scanner_test.go b/scanner/scanner_test.go index a4bf5fc..9bcaf2f 100644 --- a/scanner/scanner_test.go +++ b/scanner/scanner_test.go @@ -414,7 +414,7 @@ func TestTokens(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -550,7 +550,7 @@ func TestTeplateStringTokens(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -636,7 +636,7 @@ func TestBackquoteStringTokens(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -731,7 +731,7 @@ CAT; } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -803,7 +803,7 @@ CAT } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -842,7 +842,7 @@ CAT; } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -875,7 +875,7 @@ func TestInlineHtmlNopTokens(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} actual := []string{} @@ -985,7 +985,7 @@ func TestCommentEnd(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1017,7 +1017,7 @@ func TestCommentNewLine(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1049,7 +1049,7 @@ func TestCommentNewLine1(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1081,7 +1081,7 @@ func TestCommentNewLine2(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1114,7 +1114,7 @@ func TestCommentWithPhpEndTag(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1147,7 +1147,7 @@ func TestInlineComment(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1180,7 +1180,7 @@ func TestInlineComment2(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1218,7 +1218,7 @@ func TestEmptyInlineComment(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1251,7 +1251,7 @@ func TestEmptyInlineComment2(t *testing.T) { } lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} lexer.Lex(lv) @@ -1266,7 +1266,7 @@ func TestMethodCallTokens(t *testing.T) { $a -> bar ( '' ) ;` lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} expected := []freefloating.String{ @@ -1357,7 +1357,7 @@ func TestYieldFromTokens(t *testing.T) { yield from $a` lexer := scanner.NewLexer(bytes.NewBufferString(src), "test.php") - lexer.WithMeta = true + lexer.WithFreeFloating = true lv := &lval{} expected := []freefloating.String{ diff --git a/visitor/dumper_test.go b/visitor/dumper_test.go index d3aea69..c5dc4d4 100644 --- a/visitor/dumper_test.go +++ b/visitor/dumper_test.go @@ -22,7 +22,7 @@ func ExampleDumper() { }` php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() nodes := php7parser.GetRootNode() diff --git a/visitor/go_dumper_test.go b/visitor/go_dumper_test.go index fe467a3..d7cf0ef 100644 --- a/visitor/go_dumper_test.go +++ b/visitor/go_dumper_test.go @@ -22,7 +22,7 @@ func ExampleGoDumper() { }` php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() nodes := php7parser.GetRootNode() diff --git a/visitor/json_dumper_test.go b/visitor/json_dumper_test.go index 20b1c47..13243c2 100644 --- a/visitor/json_dumper_test.go +++ b/visitor/json_dumper_test.go @@ -23,7 +23,7 @@ func ExampleJsonDumper() { }` php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() nodes := php7parser.GetRootNode() diff --git a/visitor/pretty_json_dumper_test.go b/visitor/pretty_json_dumper_test.go index d5b66e4..180efff 100644 --- a/visitor/pretty_json_dumper_test.go +++ b/visitor/pretty_json_dumper_test.go @@ -28,7 +28,7 @@ func ExamplePrettyJsonDumper() { ` php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") - php7parser.WithMeta() + php7parser.WithFreeFloating() php7parser.Parse() nodes := php7parser.GetRootNode()