lsym_rbrace.c revision 1.5
1/* $NetBSD: lsym_rbrace.c,v 1.5 2023/06/03 21:44:08 rillig Exp $ */ 2 3/* 4 * Tests for the token lsym_rbrace, which represents a '}' in these contexts: 5 * 6 * In an initializer, '}' ends an inner group of initializers, usually to 7 * initialize a nested struct, union or array. 8 * 9 * In a function body, '}' ends a block. 10 * 11 * In an expression like '(type){...}', '}' ends a compound literal, which is 12 * typically used in an assignment to a struct or array. 13 * 14 * In macro arguments, a '}' is an ordinary character, it does not need to be 15 * balanced. This is in contrast to '(' and ')', which must be balanced. 16 * 17 * TODO: try to split this token into lsym_rbrace_block and lsym_rbrace_init. 18 * 19 * See also: 20 * lsym_lbrace.c 21 */ 22 23/* Brace level in an initializer */ 24//indent input 25void 26function(void) 27{ 28 struct person p = { 29 .name = "Name", 30 .age = {{{35}}}, /* C11 6.7.9 allows this. */ 31 }; 32} 33//indent end 34 35//indent run-equals-input 36 37 38/* Begin of a block of statements */ 39//indent input 40void function(void) {{{ body(); }}} 41//indent end 42 43//indent run 44void 45function(void) 46{ 47 { 48 { 49 body(); 50 } 51 } 52} 53//indent end 54 55 56/* Compound literal */ 57//indent input 58struct point 59origin(void) 60{ 61 return (struct point){ 62 .x = 0, 63 .y = 0, 64 }; 65} 66//indent end 67 68//indent run 69struct point 70origin(void) 71{ 72 return (struct point){ 73 .x = 0, 74/* $ FIXME: All initializers must be indented to the same level. */ 75 .y = 0, 76 }; 77} 78//indent end 79