Skip to content

Commit

Permalink
lexer: higher coverage of the 'SET Syntax'
Browse files Browse the repository at this point in the history
  • Loading branch information
qazbnm456 committed Jul 10, 2018
1 parent 70cf8ea commit ad40fd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 3 additions & 5 deletions parser/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ func startWithAt(s *Scanner) (tok int, pos Pos, lit string) {
} else {
tok = int('@')
}
} else if isIdentChar(ch1) {
s.r.incAsLongAs(isIdentChar)
} else if isUserVarChar(ch1) {
s.r.incAsLongAs(isUserVarChar)
tok, lit = singleAtIdentifier, s.r.data(&pos)
} else if ch1 == '@' {
s.r.inc()
Expand All @@ -452,10 +452,8 @@ func startWithAt(s *Scanner) (tok int, pos Pos, lit string) {
}
s.r.incAsLongAs(isIdentChar)
tok, lit = doubleAtIdentifier, s.r.data(&pos)
} else if ch1 == ' ' || ch1 == ':' || ch1 == '=' {
tok, lit = singleAtIdentifier, s.r.data(&pos)
} else {
tok = int('@')
tok, lit = singleAtIdentifier, s.r.data(&pos)
}
return
}
Expand Down
6 changes: 5 additions & 1 deletion parser/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ func (s *testLexerSuite) TestAtLeadingIdentifier(c *C) {
{"@", singleAtIdentifier},
{"@''", singleAtIdentifier},
{"@1", singleAtIdentifier},
{"@.1_", singleAtIdentifier},
{"@-1.", singleAtIdentifier},
{"@~", singleAtIdentifier},
{"@$", singleAtIdentifier},
{"@a_3cbbc", singleAtIdentifier},
{"@`a_3cbbc`", singleAtIdentifier},
{"@-3cbbc", int('@')},
{"@-3cbbc", singleAtIdentifier},
{"@!3cbbc", singleAtIdentifier},
{"@@global.test", doubleAtIdentifier},
{"@@session.test", doubleAtIdentifier},
{"@@local.test", doubleAtIdentifier},
Expand Down
4 changes: 4 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func isIdentExtend(ch rune) bool {
return ch >= 0x80 && ch <= '\uffff'
}

func isUserVarChar(ch rune) bool {
return isLetter(ch) || isDigit(ch) || ch == '_' || ch == '$' || ch == '.' || isIdentExtend(ch)
}

type trieNode struct {
childs [256]*trieNode
token int
Expand Down

0 comments on commit ad40fd0

Please sign in to comment.