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

parser: fix lexer that treat 9eTSs as a float #208

Merged
merged 5 commits into from Feb 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lexer.go
Expand Up @@ -656,7 +656,13 @@ func startWithNumber(s *Scanner) (tok int, pos Pos, lit string) {
s.scanDigits()
ch0 = s.r.peek()
if ch0 == '.' || ch0 == 'e' || ch0 == 'E' {
return s.scanFloat(&pos)
s.r.inc()
ch1 := s.r.peek()
if isDigit(ch1) || ch1 == '+' || ch1 == '-' {
return s.scanFloat(&pos)
}
// 9eTSs is an identifier rather than number, fall through.
tok = identifier
}

// Identifiers may begin with a digit but unless quoted may not consist solely of digits.
Expand Down
3 changes: 3 additions & 0 deletions lexer_test.go
Expand Up @@ -113,6 +113,7 @@ func (s *testLexerSuite) TestLiteral(c *C) {
{"132.313", decLit},
{"132.3e231", floatLit},
{"132.3e-231", floatLit},
{"001e-12", floatLit},
{"23416", intLit},
{"123test", identifier},
{"123" + string(unicode.ReplacementChar) + "xxx", identifier},
Expand Down Expand Up @@ -232,6 +233,8 @@ func (s *testLexerSuite) TestIdentifier(c *C) {
{"1_x", "1_x"},
{"0_x", "0_x"},
{replacementString, replacementString},
{"9e", "9e"},
{"9eTSs", "9eTSs"},
tiancaiamao marked this conversation as resolved.
Show resolved Hide resolved
{fmt.Sprintf("t1%cxxx", 0), "t1"},
}
l := &Scanner{}
Expand Down