parser icon indicating copy to clipboard operation
parser copied to clipboard

how do I use TiParser lexer?

Open david-sail opened this issue 4 years ago • 2 comments

Question

how do I call TiParser lexer for sql word split just like vitess token not ast parser, the sample code is as follows

var tokens []Token
tkn := sqlparser.NewStringTokenizer(sql)
typ, val := tkn.Scan()

david-sail avatar Jan 17 '21 14:01 david-sail

Here is an example:

cat example_test.go
package parser

import (
	"fmt"
	. "github.com/pingcap/check"
)

var _ = Suite(&testExampleSuite{})

type testExampleSuite struct {
}

func (s *testExampleSuite) TestExample(c *C) {
	l := NewScanner("create table t (a int);")
	var v yySymType
	for {
		result := l.Lex(&v)
		if result == 0 || result == invalid {
			break
		}
		fmt.Printf("%d\n", result)
	}
}
go test -v github.com/pingcap/parser -check.f TestExample
=== RUN   TestT
57382
57531
57346
40
57346
57446
41
59
PASS: example_test.go:13: testExampleSuite.TestExample  0.001s

The meaning of these numbers can be found in parser.go.

tangenta avatar Jan 21 '21 07:01 tangenta

yySymType is a private struct, how can i use it in my program?

zjcxc avatar Sep 13 '22 06:09 zjcxc