Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do I use TiParser lexer? #1157

Open
david-sail opened this issue Jan 17, 2021 · 2 comments
Open

how do I use TiParser lexer? #1157

david-sail opened this issue Jan 17, 2021 · 2 comments
Labels
question Further information is requested

Comments

@david-sail
Copy link

david-sail commented Jan 17, 2021

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()
@tangenta
Copy link
Contributor

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 tangenta added the question Further information is requested label Apr 22, 2021
@zjcxc
Copy link

zjcxc commented Sep 13, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants