Skip to content

Commit

Permalink
Don't break 12e+34 into 12e + 34
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum committed Nov 21, 2024
1 parent be1c24c commit eba8a0f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
24 changes: 18 additions & 6 deletions build/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,24 @@ func (in *input) Lex(val *yySymType) int {
}

// Scan over alphanumeric identifier.
for {
c := in.peekRune()
if !isIdent(c) {
break
}
c := in.peekRune()
isInt := c >= '0' && c <= '9'
if isIdent(c) {
readSign := false
in.readRune()
for {
c := in.peekRune()
if isInt && c == 'e' {
readSign = true
} else if !isIdent(c) {
if readSign && (c == '+' || c == '-') {
readSign = false
} else {
break
}
}
in.readRune()
}
}

// Call endToken to set val.tok to identifier we just scanned,
Expand All @@ -638,7 +650,7 @@ func (in *input) Lex(val *yySymType) int {
case "continue":
return _CONTINUE
}
if len(val.tok) > 0 && val.tok[0] >= '0' && val.tok[0] <= '9' {
if isInt {
return _INT
}
return _IDENT
Expand Down
12 changes: 12 additions & 0 deletions build/testdata/003.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ numbers = [
123.,
.456,
1.23e45,
-1,
+1,
0.0,
-0.0,
1.0,
-1.0,
+1.0,
1e6,
-1e6,
-1.23e-45,
3.539537889086625e+24,
3539537889086624823140625,
]
12 changes: 12 additions & 0 deletions build/testdata/003.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ numbers = [
123.,
.456,
1.23e45,
-1,
+1,
0.0,
-0.0,
1.0,
-1.0,
+1.0,
1e6,
-1e6,
-1.23e-45,
3.539537889086625e+24,
3539537889086624823140625,
]

0 comments on commit eba8a0f

Please sign in to comment.