Skip to content

Commit db9b353

Browse files
authored
Unreserved 8 keywords (pingcap#851)
* parser.y: unreserve 8 keywords * consistent_test: added an optional test to check against MySQL keywords
1 parent 417ce33 commit db9b353

File tree

7 files changed

+7936
-7828
lines changed

7 files changed

+7936
-7828
lines changed

consistent_test.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,51 @@ import (
2727
var _ = Suite(&testConsistentSuite{})
2828

2929
type testConsistentSuite struct {
30+
content string
31+
32+
reservedKeywords []string
33+
unreservedKeywords []string
34+
notKeywordTokens []string
35+
tidbKeywords []string
3036
}
3137

32-
func (s *testConsistentSuite) TestKeywordConsistent(c *C) {
38+
func (s *testConsistentSuite) SetUpSuite(c *C) {
3339
_, filename, _, _ := runtime.Caller(0)
3440
parserFilename := path.Join(path.Dir(filename), "parser.y")
3541
parserFile, err := os.Open(parserFilename)
3642
c.Assert(err, IsNil)
3743
data, err := ioutil.ReadAll(parserFile)
3844
c.Assert(err, IsNil)
39-
content := string(data)
45+
s.content = string(data)
4046

4147
reservedKeywordStartMarker := "\t/* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */"
4248
unreservedKeywordStartMarker := "\t/* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */"
4349
notKeywordTokenStartMarker := "\t/* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */"
4450
tidbKeywordStartMarker := "\t/* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */"
4551
identTokenEndMarker := "%token\t<item>"
4652

47-
reservedKeywords := extractKeywords(content, reservedKeywordStartMarker, unreservedKeywordStartMarker)
48-
49-
unreservedKeywords := extractKeywords(content, unreservedKeywordStartMarker, notKeywordTokenStartMarker)
50-
51-
notKeywordTokens := extractKeywords(content, notKeywordTokenStartMarker, tidbKeywordStartMarker)
52-
53-
tidbKeywords := extractKeywords(content, tidbKeywordStartMarker, identTokenEndMarker)
53+
s.reservedKeywords = extractKeywords(s.content, reservedKeywordStartMarker, unreservedKeywordStartMarker)
54+
s.unreservedKeywords = extractKeywords(s.content, unreservedKeywordStartMarker, notKeywordTokenStartMarker)
55+
s.notKeywordTokens = extractKeywords(s.content, notKeywordTokenStartMarker, tidbKeywordStartMarker)
56+
s.tidbKeywords = extractKeywords(s.content, tidbKeywordStartMarker, identTokenEndMarker)
57+
}
5458

59+
func (s *testConsistentSuite) TestKeywordConsistent(c *C) {
5560
for k, v := range aliases {
56-
c.Assert(k != v, IsTrue)
61+
c.Assert(k, Not(Equals), v)
5762
c.Assert(tokenMap[k], Equals, tokenMap[v])
5863
}
59-
keywordCount := len(reservedKeywords) + len(unreservedKeywords) + len(notKeywordTokens) + len(tidbKeywords)
64+
keywordCount := len(s.reservedKeywords) + len(s.unreservedKeywords) + len(s.notKeywordTokens) + len(s.tidbKeywords)
6065
c.Assert(len(tokenMap)-len(aliases), Equals, keywordCount-len(windowFuncTokenMap))
6166

62-
unreservedCollectionDef := extractKeywordsFromCollectionDef(content, "\nUnReservedKeyword:")
63-
c.Assert(unreservedKeywords, DeepEquals, unreservedCollectionDef)
67+
unreservedCollectionDef := extractKeywordsFromCollectionDef(s.content, "\nUnReservedKeyword:")
68+
c.Assert(s.unreservedKeywords, DeepEquals, unreservedCollectionDef)
6469

65-
notKeywordTokensCollectionDef := extractKeywordsFromCollectionDef(content, "\nNotKeywordToken:")
66-
c.Assert(notKeywordTokens, DeepEquals, notKeywordTokensCollectionDef)
70+
notKeywordTokensCollectionDef := extractKeywordsFromCollectionDef(s.content, "\nNotKeywordToken:")
71+
c.Assert(s.notKeywordTokens, DeepEquals, notKeywordTokensCollectionDef)
6772

68-
tidbKeywordsCollectionDef := extractKeywordsFromCollectionDef(content, "\nTiDBKeyword:")
69-
c.Assert(tidbKeywords, DeepEquals, tidbKeywordsCollectionDef)
73+
tidbKeywordsCollectionDef := extractKeywordsFromCollectionDef(s.content, "\nTiDBKeyword:")
74+
c.Assert(s.tidbKeywords, DeepEquals, tidbKeywordsCollectionDef)
7075
}
7176

7277
func extractMiddle(str, startMarker, endMarker string) string {

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ require (
77
github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8
88
github.com/cznic/strutil v0.0.0-20171016134553-529a34b1c186
99
github.com/cznic/y v0.0.0-20170802143616-045f81c6662a
10-
github.com/golang/protobuf v1.3.2 // indirect
10+
github.com/go-sql-driver/mysql v1.5.0
1111
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8
1212
github.com/pingcap/errors v0.11.4
1313
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9
14-
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330
1514
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237 // indirect
1615
go.uber.org/zap v1.12.0
1716
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ github.com/cznic/y v0.0.0-20170802143616-045f81c6662a/go.mod h1:1rk5VM7oSnA4vjp+
1515
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1616
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1717
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
18-
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
19-
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
18+
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
19+
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
2020
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
2121
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
2222
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
@@ -31,8 +31,6 @@ github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4
3131
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
3232
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 h1:AJD9pZYm72vMgPcQDww9rkZ1DnWfl0pXV3BOWlkYIjA=
3333
github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8=
34-
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330 h1:rRMLMjIMFulCX9sGKZ1hoov/iROMsKyC8Snc02nSukw=
35-
github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330/go.mod h1:RtkHW8WbcNxj8lsbzjaILci01CtYnYbIkQhjyZWrWVI=
3634
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
3735
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
3836
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)