319 Commits

Author SHA1 Message Date
Jacob G-W
5d94e754f4 fmt: fix #8974
also add a regression test
2021-06-04 10:49:05 +03:00
Isaac Freund
4a582734fd
zig fmt: replace callconv(.Inline) with the inline keyword 2021-05-20 17:13:47 +02:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
LemonBoy
eabf378a56 zig fmt: Automagically fix block-less suspend exprs 2021-04-24 15:37:55 +02:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Andrew Kelley
e315120b79 AstGen: implement array initialization expressions 2021-04-19 23:23:24 -07:00
Isaac Freund
4081e0a475 zig fmt: bypass auto indentation for // zig fmt: on
Currently an indented `// zig fmt: on` will be indented an additional
time on every run of zig fmt.
2021-04-17 20:10:20 -04:00
Isaac Freund
5b9ea5dd1e zig fmt: fix line comment detection
Previously hasComment() would consider a string literal "//" to be a
line comment. Fix this by only searching the bytes between tokens.
2021-04-10 23:10:24 +02:00
Lewis Gaul
ecf555c693
zig fmt: render array init on one line if no trailing comma
Continue to insert a trailing comma if there is a comment or multiline
string literal present.
2021-04-10 16:39:26 +02:00
LemonBoy
5ebcd8ccaf zig fmt: Fix rendering of arrays with single row
rowSize used to return null if all the elements were placed on the same
line as the right brace, making the rendering logic skip the whole set
of elements.

Given the usage of rowSize let's just drop the null and always return
the number of elements.

Fixes #8423
2021-04-09 10:03:45 -07:00
Isaac Freund
8111453cc1
astgen: implement array types 2021-03-22 14:54:13 +01:00
Lewis Gaul
6787f163eb
zig fmt: don't add trailing whitespace on switch case 2021-03-16 09:26:28 +01:00
LemonBoy
5ecf8bddae
zig fmt: Respect line breaks in struct default value decls
Bring this in line with how variable declarations are handled.

Open a new indentation level for the initialization expression to handle
nested expressions like blocks.

Closes #7618
2021-03-16 09:22:16 +01:00
Isaac Freund
48efa3bcb6 zig fmt: simplify and improve consistency of if/for/while handling
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes https://github.com/ziglang/zig/issues/6114
Fixes https://github.com/ziglang/zig/issues/8022
2021-03-15 14:55:34 +01:00
Lewis Gaul
b4db03d8bb zig fmt: fix extra newline before if nested in for
Add failing testcase to reproduce issue 8088

Tidy up renderWhile(), factoring out renderWhilePayload()

Ensure correct newline is used before 'then' token in while/for/if

Handle indents for 'if' inside 'for' or 'while'

Stop special-casing 'if' compared to 'for' and 'while'
2021-03-15 14:55:34 +01:00
Isaac Freund
b988815bf0 parser: fix parsing/rendering of a[b.. :c] slicing
The modification to the grammar in the comment is in line with the
grammar in the zig-spec repo.

Note: checking if the previous token is a colon is insufficent to tell
if a block has a label, the identifier must be checked for as well. This
can be seen in sentinel terminated slicing: `foo[0..1:{}]`
2021-03-08 01:37:28 +01:00
Isaac Freund
3ad9cb8b47 zig fmt: allow and trim whitespace around zig fmt: (off|on)
Currently `//  zig fmt: off` does not work as there are two spaces
after the `//` instead of one. This can cause confusion, so allow
arbitrary whitespace before the `zig fmt: (off|on)` in the comment but
trim this whitespace to the canonical single space in the output.
2021-03-03 01:06:09 +01:00
Andrew Kelley
9b8a94265a zig fmt: fix extern function with missing param name
Regressed in d7049fc8e0709619b8aa6766b37abeae946703b2.
2021-02-24 21:50:57 -07:00
Isaac Freund
52c45bf44d
zig fmt: rework single statement if/while/for indentation
This approach properly handles nesting unlike the approach in the
previous commit.
2021-02-24 17:28:29 +01:00
Isaac Freund
371b21bdfb
zig fmt: fix comment indent after multiline single statement if/while/for 2021-02-24 13:46:11 +01:00
Isaac Freund
15c7c6ab97
zig fmt: handle comments in switch case value list 2021-02-24 12:29:17 +01:00
Andrew Kelley
4420fe97be zig fmt: for loop with ptr payload and index 2021-02-23 18:33:13 -07:00
Andrew Kelley
988f1c6a6f zig fmt: fn proto end with anytype and comma
also

zig fmt: space after top level doc comment
2021-02-23 18:23:49 -07:00
Andrew Kelley
08107a555e zig fmt: fix inline assembly test cases
All zig fmt test cases are now passing again in this branch.
2021-02-23 17:19:01 -07:00
Andrew Kelley
bb89c619ed zig fmt: multiline string literals + array init 2021-02-23 17:00:33 -07:00
Andrew Kelley
6f4a1bafcf zig fmt: fn call with comments and multiline strings
forcing the parameters over multiple lines
2021-02-23 16:09:51 -07:00
Isaac Freund
4ee368c4b3
zig fmt: comments/line breaks in field access chain 2021-02-23 23:17:38 +01:00
Isaac Freund
b028a92a60
zig fmt: handle comments in array type/init/access 2021-02-23 19:56:56 +01:00
Isaac Freund
6b9f19a644
zig fmt: remove stray std.debug.print() 2021-02-23 19:18:36 +01:00
Isaac Freund
0f24b61ed5
zig fmt: insert trailing comma in struct init with comment 2021-02-23 19:17:11 +01:00
Isaac Freund
5820bd0e64
zig fmt: insert trailing comma in fn params with comment 2021-02-23 19:11:50 +01:00
Isaac Freund
5306b1a9ab
zig fmt: container doc comments 2021-02-23 18:32:47 +01:00
Andrew Kelley
1e3a200ba6 zig fmt: array literal with hint
This regresses the test case of `zig fmt` deleting empty line comments.
Two open questions here:

 * What should the rules be about deleting empty line comments?
   It makes sense usually, but for array initization, empty line
   comments cause a line break, affecting the row/column alignment.
   Perhaps we should therefore respect all empty line comments?
   Or should we special case array initializations?

 * If we decide to special case some kinds of line comments to respect
   them (which is status quo!), how should that be implemented?
2021-02-22 23:25:12 -07:00
Andrew Kelley
8379fff804 zig fmt: alignment in anonymous literal 2021-02-22 21:04:22 -07:00
Andrew Kelley
a6038f0375 zig fmt: function params should align nicely 2021-02-22 18:17:26 -07:00
Andrew Kelley
fec51ad7c5 zig fmt: while 2021-02-22 17:55:19 -07:00
Andrew Kelley
20cfa0b5b6 zig fmt: if condition has line break, no fn call comma 2021-02-22 17:34:30 -07:00
Andrew Kelley
ec987a7a46 zig fmt: if condition has line break but must not wrap 2021-02-22 16:39:50 -07:00
Andrew Kelley
b301999cd3 zig fmt: if condition wraps 2021-02-22 16:21:19 -07:00
Andrew Kelley
253906fb93 zig fmt: 2nd arg multiline string 2021-02-22 16:00:21 -07:00
Isaac Freund
550688f427
zig fmt: insert trailing comma in switches 2021-02-22 23:51:54 +01:00
Isaac Freund
f3ee10b454
zig fmt: fix comments ending with EOF after decls
Achieve this by reducing the amount of special casing to handle EOF so
that the already correct logic for normal comments does not need to be
duplicated.
2021-02-22 18:32:37 +01:00
Veikka Tuominen
928790364a
zig fmt: correct Node.firstToken for .fn_decl, add error for missing container 2021-02-22 17:39:41 +02:00
Veikka Tuominen
69d5a106da
render: handle comments ending in EOF 2021-02-22 16:59:44 +02:00
Andrew Kelley
621ad241d6 zig fmt: if nested 2021-02-21 20:25:31 -07:00
Andrew Kelley
c6efb23796 zig fmt: rewrite inline functions as callconv(.Inline) 2021-02-21 18:20:46 -07:00
Andrew Kelley
15603f403c AST: use fn_proto not fn_decl for extern decls
saves a few bytes per extern function declaration
2021-02-21 16:01:22 -07:00
Veikka Tuominen
d672c20b8a
Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Andrew Kelley
9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Andrew Kelley
c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00