Skip to content

Commit 8721eb6

Browse files
committedMay 4, 2018
zig fmt: fix tokenization of float literal with exponent
·
0.15.20.3.0
1 parent ef3111b commit 8721eb6

File tree

2 files changed

+67
-59
lines changed

2 files changed

+67
-59
lines changed
 

‎std/zig/parser_test.zig‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
//}
1818

1919

20-
//TODO
21-
//test "zig fmt: number literals" {
22-
// try testCanonical(
23-
// \\pub const f64_true_min = 4.94065645841246544177e-324;
24-
// \\
25-
// );
26-
//}
20+
test "zig fmt: float literal with exponent" {
21+
try testCanonical(
22+
\\pub const f64_true_min = 4.94065645841246544177e-324;
23+
\\
24+
);
25+
}
2726

2827
test "zig fmt: line comments in struct initializer" {
2928
try testCanonical(

‎std/zig/tokenizer.zig‎

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,60 @@ pub const Token = struct {
66
start: usize,
77
end: usize,
88

9-
const KeywordId = struct {
9+
const Keyword = struct {
1010
bytes: []const u8,
1111
id: Id,
1212
};
1313

14-
const keywords = []KeywordId {
15-
KeywordId{.bytes="align", .id = Id.Keyword_align},
16-
KeywordId{.bytes="and", .id = Id.Keyword_and},
17-
KeywordId{.bytes="asm", .id = Id.Keyword_asm},
18-
KeywordId{.bytes="async", .id = Id.Keyword_async},
19-
KeywordId{.bytes="await", .id = Id.Keyword_await},
20-
KeywordId{.bytes="break", .id = Id.Keyword_break},
21-
KeywordId{.bytes="catch", .id = Id.Keyword_catch},
22-
KeywordId{.bytes="cancel", .id = Id.Keyword_cancel},
23-
KeywordId{.bytes="comptime", .id = Id.Keyword_comptime},
24-
KeywordId{.bytes="const", .id = Id.Keyword_const},
25-
KeywordId{.bytes="continue", .id = Id.Keyword_continue},
26-
KeywordId{.bytes="defer", .id = Id.Keyword_defer},
27-
KeywordId{.bytes="else", .id = Id.Keyword_else},
28-
KeywordId{.bytes="enum", .id = Id.Keyword_enum},
29-
KeywordId{.bytes="errdefer", .id = Id.Keyword_errdefer},
30-
KeywordId{.bytes="error", .id = Id.Keyword_error},
31-
KeywordId{.bytes="export", .id = Id.Keyword_export},
32-
KeywordId{.bytes="extern", .id = Id.Keyword_extern},
33-
KeywordId{.bytes="false", .id = Id.Keyword_false},
34-
KeywordId{.bytes="fn", .id = Id.Keyword_fn},
35-
KeywordId{.bytes="for", .id = Id.Keyword_for},
36-
KeywordId{.bytes="if", .id = Id.Keyword_if},
37-
KeywordId{.bytes="inline", .id = Id.Keyword_inline},
38-
KeywordId{.bytes="nakedcc", .id = Id.Keyword_nakedcc},
39-
KeywordId{.bytes="noalias", .id = Id.Keyword_noalias},
40-
KeywordId{.bytes="null", .id = Id.Keyword_null},
41-
KeywordId{.bytes="or", .id = Id.Keyword_or},
42-
KeywordId{.bytes="packed", .id = Id.Keyword_packed},
43-
KeywordId{.bytes="promise", .id = Id.Keyword_promise},
44-
KeywordId{.bytes="pub", .id = Id.Keyword_pub},
45-
KeywordId{.bytes="resume", .id = Id.Keyword_resume},
46-
KeywordId{.bytes="return", .id = Id.Keyword_return},
47-
KeywordId{.bytes="section", .id = Id.Keyword_section},
48-
KeywordId{.bytes="stdcallcc", .id = Id.Keyword_stdcallcc},
49-
KeywordId{.bytes="struct", .id = Id.Keyword_struct},
50-
KeywordId{.bytes="suspend", .id = Id.Keyword_suspend},
51-
KeywordId{.bytes="switch", .id = Id.Keyword_switch},
52-
KeywordId{.bytes="test", .id = Id.Keyword_test},
53-
KeywordId{.bytes="this", .id = Id.Keyword_this},
54-
KeywordId{.bytes="true", .id = Id.Keyword_true},
55-
KeywordId{.bytes="try", .id = Id.Keyword_try},
56-
KeywordId{.bytes="undefined", .id = Id.Keyword_undefined},
57-
KeywordId{.bytes="union", .id = Id.Keyword_union},
58-
KeywordId{.bytes="unreachable", .id = Id.Keyword_unreachable},
59-
KeywordId{.bytes="use", .id = Id.Keyword_use},
60-
KeywordId{.bytes="var", .id = Id.Keyword_var},
61-
KeywordId{.bytes="volatile", .id = Id.Keyword_volatile},
62-
KeywordId{.bytes="while", .id = Id.Keyword_while},
14+
const keywords = []Keyword {
15+
Keyword{.bytes="align", .id = Id.Keyword_align},
16+
Keyword{.bytes="and", .id = Id.Keyword_and},
17+
Keyword{.bytes="asm", .id = Id.Keyword_asm},
18+
Keyword{.bytes="async", .id = Id.Keyword_async},
19+
Keyword{.bytes="await", .id = Id.Keyword_await},
20+
Keyword{.bytes="break", .id = Id.Keyword_break},
21+
Keyword{.bytes="catch", .id = Id.Keyword_catch},
22+
Keyword{.bytes="cancel", .id = Id.Keyword_cancel},
23+
Keyword{.bytes="comptime", .id = Id.Keyword_comptime},
24+
Keyword{.bytes="const", .id = Id.Keyword_const},
25+
Keyword{.bytes="continue", .id = Id.Keyword_continue},
26+
Keyword{.bytes="defer", .id = Id.Keyword_defer},
27+
Keyword{.bytes="else", .id = Id.Keyword_else},
28+
Keyword{.bytes="enum", .id = Id.Keyword_enum},
29+
Keyword{.bytes="errdefer", .id = Id.Keyword_errdefer},
30+
Keyword{.bytes="error", .id = Id.Keyword_error},
31+
Keyword{.bytes="export", .id = Id.Keyword_export},
32+
Keyword{.bytes="extern", .id = Id.Keyword_extern},
33+
Keyword{.bytes="false", .id = Id.Keyword_false},
34+
Keyword{.bytes="fn", .id = Id.Keyword_fn},
35+
Keyword{.bytes="for", .id = Id.Keyword_for},
36+
Keyword{.bytes="if", .id = Id.Keyword_if},
37+
Keyword{.bytes="inline", .id = Id.Keyword_inline},
38+
Keyword{.bytes="nakedcc", .id = Id.Keyword_nakedcc},
39+
Keyword{.bytes="noalias", .id = Id.Keyword_noalias},
40+
Keyword{.bytes="null", .id = Id.Keyword_null},
41+
Keyword{.bytes="or", .id = Id.Keyword_or},
42+
Keyword{.bytes="packed", .id = Id.Keyword_packed},
43+
Keyword{.bytes="promise", .id = Id.Keyword_promise},
44+
Keyword{.bytes="pub", .id = Id.Keyword_pub},
45+
Keyword{.bytes="resume", .id = Id.Keyword_resume},
46+
Keyword{.bytes="return", .id = Id.Keyword_return},
47+
Keyword{.bytes="section", .id = Id.Keyword_section},
48+
Keyword{.bytes="stdcallcc", .id = Id.Keyword_stdcallcc},
49+
Keyword{.bytes="struct", .id = Id.Keyword_struct},
50+
Keyword{.bytes="suspend", .id = Id.Keyword_suspend},
51+
Keyword{.bytes="switch", .id = Id.Keyword_switch},
52+
Keyword{.bytes="test", .id = Id.Keyword_test},
53+
Keyword{.bytes="this", .id = Id.Keyword_this},
54+
Keyword{.bytes="true", .id = Id.Keyword_true},
55+
Keyword{.bytes="try", .id = Id.Keyword_try},
56+
Keyword{.bytes="undefined", .id = Id.Keyword_undefined},
57+
Keyword{.bytes="union", .id = Id.Keyword_union},
58+
Keyword{.bytes="unreachable", .id = Id.Keyword_unreachable},
59+
Keyword{.bytes="use", .id = Id.Keyword_use},
60+
Keyword{.bytes="var", .id = Id.Keyword_var},
61+
Keyword{.bytes="volatile", .id = Id.Keyword_volatile},
62+
Keyword{.bytes="while", .id = Id.Keyword_while},
6363
};
6464

6565
fn getKeyword(bytes: []const u8) ?Id {
@@ -912,10 +912,10 @@ pub const Tokenizer = struct {
912912
},
913913
},
914914
State.FloatFraction => switch (c) {
915-
'p', 'P' => {
915+
'p', 'P', 'e', 'E' => {
916916
state = State.FloatExponentUnsigned;
917917
},
918-
'0'...'9', 'a'...'f', 'A'...'F' => {},
918+
'0'...'9' => {},
919919
else => break,
920920
},
921921
State.FloatExponentUnsigned => switch (c) {
@@ -1108,6 +1108,15 @@ test "tokenizer" {
11081108
});
11091109
}
11101110

1111+
test "tokenizer - float literal" {
1112+
testTokenize("a = 4.94065645841246544177e-324;\n", []Token.Id {
1113+
Token.Id.Identifier,
1114+
Token.Id.Equal,
1115+
Token.Id.FloatLiteral,
1116+
Token.Id.Semicolon,
1117+
});
1118+
}
1119+
11111120
test "tokenizer - chars" {
11121121
testTokenize("'c'", []Token.Id {Token.Id.CharLiteral});
11131122
}

0 commit comments

Comments
 (0)
Please sign in to comment.