authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-04 14:34:32-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-05-04 14:34:32-04:00
log8721eb68fc566ec5b71b3c8f90726fd815a3d45a
tree11a5b74713c14bafc5e5ebf36c7cb498fb6746e7
parentef3111be236fc389a696562d31bccd3a9b6d1c56

zig fmt: fix tokenization of float literal with exponent


2 files changed, 67 insertions(+), 59 deletions(-)

std/zig/parser_test.zig+6-7
...@@ -17,13 +17,12 @@...@@ -17,13 +17,12 @@
17//}17//}
1818
1919
20//TODO20test "zig fmt: float literal with exponent" {
21//test "zig fmt: number literals" {21 try testCanonical(
22// try testCanonical(22 \\pub const f64_true_min = 4.94065645841246544177e-324;
23// \\pub const f64_true_min = 4.94065645841246544177e-324;23 \\
24// \\24 );
25// );25}
26//}
2726
28test "zig fmt: line comments in struct initializer" {27test "zig fmt: line comments in struct initializer" {
29 try testCanonical(28 try testCanonical(
std/zig/tokenizer.zig+61-52
...@@ -6,60 +6,60 @@ pub const Token = struct {...@@ -6,60 +6,60 @@ pub const Token = struct {
6 start: usize,6 start: usize,
7 end: usize,7 end: usize,
88
9 const KeywordId = struct {9 const Keyword = struct {
10 bytes: []const u8,10 bytes: []const u8,
11 id: Id,11 id: Id,
12 };12 };
1313
14 const keywords = []KeywordId {14 const keywords = []Keyword {
15 KeywordId{.bytes="align", .id = Id.Keyword_align},15 Keyword{.bytes="align", .id = Id.Keyword_align},
16 KeywordId{.bytes="and", .id = Id.Keyword_and},16 Keyword{.bytes="and", .id = Id.Keyword_and},
17 KeywordId{.bytes="asm", .id = Id.Keyword_asm},17 Keyword{.bytes="asm", .id = Id.Keyword_asm},
18 KeywordId{.bytes="async", .id = Id.Keyword_async},18 Keyword{.bytes="async", .id = Id.Keyword_async},
19 KeywordId{.bytes="await", .id = Id.Keyword_await},19 Keyword{.bytes="await", .id = Id.Keyword_await},
20 KeywordId{.bytes="break", .id = Id.Keyword_break},20 Keyword{.bytes="break", .id = Id.Keyword_break},
21 KeywordId{.bytes="catch", .id = Id.Keyword_catch},21 Keyword{.bytes="catch", .id = Id.Keyword_catch},
22 KeywordId{.bytes="cancel", .id = Id.Keyword_cancel},22 Keyword{.bytes="cancel", .id = Id.Keyword_cancel},
23 KeywordId{.bytes="comptime", .id = Id.Keyword_comptime},23 Keyword{.bytes="comptime", .id = Id.Keyword_comptime},
24 KeywordId{.bytes="const", .id = Id.Keyword_const},24 Keyword{.bytes="const", .id = Id.Keyword_const},
25 KeywordId{.bytes="continue", .id = Id.Keyword_continue},25 Keyword{.bytes="continue", .id = Id.Keyword_continue},
26 KeywordId{.bytes="defer", .id = Id.Keyword_defer},26 Keyword{.bytes="defer", .id = Id.Keyword_defer},
27 KeywordId{.bytes="else", .id = Id.Keyword_else},27 Keyword{.bytes="else", .id = Id.Keyword_else},
28 KeywordId{.bytes="enum", .id = Id.Keyword_enum},28 Keyword{.bytes="enum", .id = Id.Keyword_enum},
29 KeywordId{.bytes="errdefer", .id = Id.Keyword_errdefer},29 Keyword{.bytes="errdefer", .id = Id.Keyword_errdefer},
30 KeywordId{.bytes="error", .id = Id.Keyword_error},30 Keyword{.bytes="error", .id = Id.Keyword_error},
31 KeywordId{.bytes="export", .id = Id.Keyword_export},31 Keyword{.bytes="export", .id = Id.Keyword_export},
32 KeywordId{.bytes="extern", .id = Id.Keyword_extern},32 Keyword{.bytes="extern", .id = Id.Keyword_extern},
33 KeywordId{.bytes="false", .id = Id.Keyword_false},33 Keyword{.bytes="false", .id = Id.Keyword_false},
34 KeywordId{.bytes="fn", .id = Id.Keyword_fn},34 Keyword{.bytes="fn", .id = Id.Keyword_fn},
35 KeywordId{.bytes="for", .id = Id.Keyword_for},35 Keyword{.bytes="for", .id = Id.Keyword_for},
36 KeywordId{.bytes="if", .id = Id.Keyword_if},36 Keyword{.bytes="if", .id = Id.Keyword_if},
37 KeywordId{.bytes="inline", .id = Id.Keyword_inline},37 Keyword{.bytes="inline", .id = Id.Keyword_inline},
38 KeywordId{.bytes="nakedcc", .id = Id.Keyword_nakedcc},38 Keyword{.bytes="nakedcc", .id = Id.Keyword_nakedcc},
39 KeywordId{.bytes="noalias", .id = Id.Keyword_noalias},39 Keyword{.bytes="noalias", .id = Id.Keyword_noalias},
40 KeywordId{.bytes="null", .id = Id.Keyword_null},40 Keyword{.bytes="null", .id = Id.Keyword_null},
41 KeywordId{.bytes="or", .id = Id.Keyword_or},41 Keyword{.bytes="or", .id = Id.Keyword_or},
42 KeywordId{.bytes="packed", .id = Id.Keyword_packed},42 Keyword{.bytes="packed", .id = Id.Keyword_packed},
43 KeywordId{.bytes="promise", .id = Id.Keyword_promise},43 Keyword{.bytes="promise", .id = Id.Keyword_promise},
44 KeywordId{.bytes="pub", .id = Id.Keyword_pub},44 Keyword{.bytes="pub", .id = Id.Keyword_pub},
45 KeywordId{.bytes="resume", .id = Id.Keyword_resume},45 Keyword{.bytes="resume", .id = Id.Keyword_resume},
46 KeywordId{.bytes="return", .id = Id.Keyword_return},46 Keyword{.bytes="return", .id = Id.Keyword_return},
47 KeywordId{.bytes="section", .id = Id.Keyword_section},47 Keyword{.bytes="section", .id = Id.Keyword_section},
48 KeywordId{.bytes="stdcallcc", .id = Id.Keyword_stdcallcc},48 Keyword{.bytes="stdcallcc", .id = Id.Keyword_stdcallcc},
49 KeywordId{.bytes="struct", .id = Id.Keyword_struct},49 Keyword{.bytes="struct", .id = Id.Keyword_struct},
50 KeywordId{.bytes="suspend", .id = Id.Keyword_suspend},50 Keyword{.bytes="suspend", .id = Id.Keyword_suspend},
51 KeywordId{.bytes="switch", .id = Id.Keyword_switch},51 Keyword{.bytes="switch", .id = Id.Keyword_switch},
52 KeywordId{.bytes="test", .id = Id.Keyword_test},52 Keyword{.bytes="test", .id = Id.Keyword_test},
53 KeywordId{.bytes="this", .id = Id.Keyword_this},53 Keyword{.bytes="this", .id = Id.Keyword_this},
54 KeywordId{.bytes="true", .id = Id.Keyword_true},54 Keyword{.bytes="true", .id = Id.Keyword_true},
55 KeywordId{.bytes="try", .id = Id.Keyword_try},55 Keyword{.bytes="try", .id = Id.Keyword_try},
56 KeywordId{.bytes="undefined", .id = Id.Keyword_undefined},56 Keyword{.bytes="undefined", .id = Id.Keyword_undefined},
57 KeywordId{.bytes="union", .id = Id.Keyword_union},57 Keyword{.bytes="union", .id = Id.Keyword_union},
58 KeywordId{.bytes="unreachable", .id = Id.Keyword_unreachable},58 Keyword{.bytes="unreachable", .id = Id.Keyword_unreachable},
59 KeywordId{.bytes="use", .id = Id.Keyword_use},59 Keyword{.bytes="use", .id = Id.Keyword_use},
60 KeywordId{.bytes="var", .id = Id.Keyword_var},60 Keyword{.bytes="var", .id = Id.Keyword_var},
61 KeywordId{.bytes="volatile", .id = Id.Keyword_volatile},61 Keyword{.bytes="volatile", .id = Id.Keyword_volatile},
62 KeywordId{.bytes="while", .id = Id.Keyword_while},62 Keyword{.bytes="while", .id = Id.Keyword_while},
63 };63 };
6464
65 fn getKeyword(bytes: []const u8) ?Id {65 fn getKeyword(bytes: []const u8) ?Id {
...@@ -912,10 +912,10 @@ pub const Tokenizer = struct {...@@ -912,10 +912,10 @@ pub const Tokenizer = struct {
912 },912 },
913 },913 },
914 State.FloatFraction => switch (c) {914 State.FloatFraction => switch (c) {
915 'p', 'P' => {915 'p', 'P', 'e', 'E' => {
916 state = State.FloatExponentUnsigned;916 state = State.FloatExponentUnsigned;
917 },917 },
918 '0'...'9', 'a'...'f', 'A'...'F' => {},918 '0'...'9' => {},
919 else => break,919 else => break,
920 },920 },
921 State.FloatExponentUnsigned => switch (c) {921 State.FloatExponentUnsigned => switch (c) {
...@@ -1108,6 +1108,15 @@ test "tokenizer" {...@@ -1108,6 +1108,15 @@ test "tokenizer" {
1108 });1108 });
1109}1109}
11101110
1111test "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
1111test "tokenizer - chars" {1120test "tokenizer - chars" {
1112 testTokenize("'c'", []Token.Id {Token.Id.CharLiteral});1121 testTokenize("'c'", []Token.Id {Token.Id.CharLiteral});
1113}1122}