summaryrefslogtreecommitdiff
path: root/tests/usr.bin/indent/lsym_word.c
blob: afc449edaa6c0e5c9ac64e2c4ce84a6997dee7d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* $NetBSD: lsym_word.c,v 1.7 2023/06/17 22:09:24 rillig Exp $ */

/*
 * Tests for the token lsym_word, which represents a constant, a string
 * literal or an identifier.
 *
 * See also:
 *	lsym_funcname.c		for an identifier followed by '('
 */

// TODO: Is '"string"(' syntactically valid in any context?
// TODO: Is '123(' syntactically valid in any context?
// TODO: Would the output of the above depend on -pcs/-npcs?
// TODO: Add more systematic tests.
// TODO: Completely cover each state transition in lex_number_state.

// TODO: Consider splitting this token into lsym_name and lsym_value, to
// TODO: make it easier to skip tokens during lookahead, for example since
// TODO: L"" is not an identifier but a string literal.

//indent input
// TODO: add input
//indent end

//indent run-equals-input


/*
 * Since 2019-04-04 and before NetBSD lexi.c 1.149 from 2021-11-20, the first
 * character after a backslash continuation was always considered part of a
 * word, no matter whether it was a word character or not.
 */
//indent input
int var\
+name = 4;
//indent end

//indent run
int		var + name = 4;
//indent end


//indent input
wchar_t wide_string[] = L"wide string";
//indent end

/*
 * Regardless of the line length, the 'L' must never be separated from the
 * string literal.  Before lexi.c 1.167 from 2021-11-28, the 'L' was a
 * separate token, which could have resulted in accidental spacing between the
 * 'L' and the following "".
 */
//indent run-equals-input -di0

//indent run-equals-input -di0 -l25

//indent run-equals-input -di0 -l1


//indent input
wchar_t wide_char[] = L'w';
//indent end

//indent run-equals-input -di0


/* Binary number literals, a GCC extension that was added in C11. */
//indent input
#define b00101010 -1
void t(void) {
	unsigned a[] = {0b00101010, 0x00005678, 02, 17U};
	float x[] = {.7f, 0.7f};
	unsigned long ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL};

	if (0 b00101010)
		return;
	/* $ '0r' is not a number base prefix, so the tokens are split. */
	if (0r12345)
		return;
}
//indent end

//indent run
#define b00101010 -1
void
t(void)
{
	unsigned	a[] = {0b00101010, 0x00005678, 02, 17U};
	float		x[] = {.7f, 0.7f};
	unsigned long	ul[] = {0b00001111UL, 0x01010101UL, 02UL, 17UL};

	if (0 b00101010)
		return;
	if (0 r12345)
		return;
}
//indent end


/* Floating point numbers. */
//indent input
void t(void) {
	unsigned long x = 314UL;
	double y[] = {0x1P+9F, 0.3, .1, 1.2f, 0xa.p01f, 3.14f, 2.L};
	int z = 0b0101;
	DO_NOTHING;
	x._y = 5;
}
//indent end

//indent run
void
t(void)
{
	unsigned long	x = 314UL;
	double		y[] = {0x1P+9F, 0.3, .1, 1.2f, 0xa.p01f, 3.14f, 2.L};
	int		z = 0b0101;
	DO_NOTHING;
	x._y = 5;
}
//indent end


/*
 * Test identifiers containing '$', which some compilers support as an
 * extension to the C standard.
 */
//indent input
int $		= jQuery;			// just kidding
const char SYS$LOGIN[]="$HOME";
//indent end

//indent run
int		$ = jQuery;	// just kidding
const char	SYS$LOGIN[] = "$HOME";
//indent end


/*
 * Test the tokenizer for number constants.
 *
 * When the tokenizer reads a character that makes a token invalid (such as
 * '0x') but may later be extended to form a valid token (such as '0x123'),
 * indent does not care about this invalid prefix and returns it nevertheless.
 */
//indent input
int unfinished_hex_prefix = 0x;
double unfinished_hex_float = 0x123p;
//indent end

//indent run-equals-input -di0