Home | History | Annotate | Line # | Download | only in indent
psym_if_expr_stmt_else.c revision 1.5.2.1
      1  1.5.2.1  perseant /* $NetBSD: psym_if_expr_stmt_else.c,v 1.5.2.1 2025/08/02 05:58:13 perseant Exp $ */
      2      1.1    rillig 
      3      1.1    rillig /*
      4      1.1    rillig  * Tests for the parser symbol psym_if_expr_stmt_else, which represents the
      5      1.1    rillig  * parser state after reading the keyword 'if', the controlling expression,
      6      1.3    rillig  * the statement of the 'then' branch and the keyword 'else'.
      7      1.3    rillig  *
      8      1.3    rillig  * If the next token is an 'if', the formatting depends on the option '-ei' or
      9      1.3    rillig  * '-nei'.  Any other lookahead token completes the 'if' statement.
     10      1.1    rillig  */
     11      1.1    rillig 
     12      1.4    rillig //indent input
     13      1.3    rillig void
     14      1.3    rillig example(_Bool cond)
     15      1.3    rillig {
     16      1.3    rillig 	if (cond) {}
     17      1.3    rillig 	else if (cond) {}
     18      1.3    rillig 	else if (cond) i++;
     19      1.3    rillig 	else {}
     20      1.3    rillig }
     21      1.4    rillig //indent end
     22      1.1    rillig 
     23      1.4    rillig //indent run
     24      1.3    rillig void
     25      1.3    rillig example(_Bool cond)
     26      1.3    rillig {
     27      1.3    rillig 	if (cond) {
     28      1.5    rillig 	}
     29      1.5    rillig 	else if (cond) {
     30      1.5    rillig 	}
     31      1.5    rillig 	else if (cond)
     32      1.3    rillig 		i++;
     33      1.3    rillig 	else {
     34      1.3    rillig 	}
     35      1.3    rillig }
     36      1.4    rillig //indent end
     37      1.3    rillig 
     38      1.3    rillig /*
     39      1.3    rillig  * Combining the options '-bl' (place brace on the left margin) and '-ce'
     40      1.3    rillig  * (cuddle else) looks strange, but is technically correct.
     41      1.3    rillig  */
     42      1.4    rillig //indent run -bl
     43      1.3    rillig void
     44      1.3    rillig example(_Bool cond)
     45      1.3    rillig {
     46      1.3    rillig 	if (cond)
     47      1.3    rillig 	{
     48      1.3    rillig 	}
     49      1.3    rillig 	else if (cond)
     50      1.3    rillig 	{
     51      1.3    rillig 	}
     52      1.3    rillig 	else if (cond)
     53      1.3    rillig 		i++;
     54      1.3    rillig 	else
     55      1.3    rillig 	{
     56      1.3    rillig 	}
     57      1.3    rillig }
     58      1.4    rillig //indent end
     59      1.3    rillig 
     60      1.5    rillig //indent run-equals-prev-output -bl -nce
     61      1.5    rillig 
     62      1.3    rillig /*
     63      1.3    rillig  * Adding the option '-nei' (do not join 'else if') expands the code even
     64      1.3    rillig  * more.
     65      1.3    rillig  */
     66      1.4    rillig //indent run -bl -nce -nei
     67      1.3    rillig void
     68      1.3    rillig example(_Bool cond)
     69      1.3    rillig {
     70      1.3    rillig 	if (cond)
     71      1.3    rillig 	{
     72      1.3    rillig 	}
     73      1.3    rillig 	else
     74      1.3    rillig 		if (cond)
     75      1.3    rillig 		{
     76      1.3    rillig 		}
     77      1.3    rillig 		else
     78      1.3    rillig 			if (cond)
     79      1.3    rillig 				i++;
     80      1.3    rillig 			else
     81      1.3    rillig 			{
     82      1.3    rillig 			}
     83      1.3    rillig }
     84      1.4    rillig //indent end
     85  1.5.2.1  perseant 
     86  1.5.2.1  perseant 
     87  1.5.2.1  perseant /*
     88  1.5.2.1  perseant  * In many cases, an else-if sequence is written in a single line.
     89  1.5.2.1  perseant  * Occasionally, there are cases in which the code is clearer when the
     90  1.5.2.1  perseant  * 'else' and 'if' are in separate lines.  In such a case, the inner 'if'
     91  1.5.2.1  perseant  * statement should be indented like any other statement.
     92  1.5.2.1  perseant  */
     93  1.5.2.1  perseant //indent input
     94  1.5.2.1  perseant void
     95  1.5.2.1  perseant example(void)
     96  1.5.2.1  perseant {
     97  1.5.2.1  perseant 	if (cond)
     98  1.5.2.1  perseant 		stmt();
     99  1.5.2.1  perseant 	else
    100  1.5.2.1  perseant 		if (cond)
    101  1.5.2.1  perseant 			stmt();
    102  1.5.2.1  perseant }
    103  1.5.2.1  perseant //indent end
    104  1.5.2.1  perseant 
    105  1.5.2.1  perseant //indent run
    106  1.5.2.1  perseant void
    107  1.5.2.1  perseant example(void)
    108  1.5.2.1  perseant {
    109  1.5.2.1  perseant 	if (cond)
    110  1.5.2.1  perseant 		stmt();
    111  1.5.2.1  perseant 	else if (cond)
    112  1.5.2.1  perseant 		stmt();
    113  1.5.2.1  perseant }
    114  1.5.2.1  perseant //indent end
    115