Skip to content

Commit 7554108

Browse files
committed
Treat operator and operator symbol as a single identifier token
For example, `operator+ : (a: mytype, b:mytype) = { /*... */}` makes `operator +` a single identifier token. That seemed to be the simplest and most elegant way to have the rest of the compiler downstream just treat it as a single identifier. Do a pass tidying up the grammar, particularly to make keywords/operators distinct now that there's an _operator_ production and an `operator` keyword.
1 parent 4d9d52d commit 7554108

File tree

4 files changed

+338
-187
lines changed

4 files changed

+338
-187
lines changed

source/common.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,31 +138,36 @@ struct error
138138
//-----------------------------------------------------------------------
139139
//
140140

141-
//G binary-digit: one of
142-
//G 0 1
141+
//G binary-digit:
142+
//G one of '0' '1'
143143
//G
144144
auto is_binary_digit(char c) -> bool
145145
{
146146
return c == '0' || c == '1';
147147
}
148148

149-
//G hexadecimal-digit: one of
150-
//G 0 1 2 3 4 5 6 7 8 9 A B C D E F
149+
//G digit: one of
150+
//G binary-digit
151+
//G one of '2' '3' '4' '5' '6' '7' '8' '9'
151152
//G
152-
auto is_hexadecimal_digit(char c) -> bool
153+
auto is_digit(char c) -> bool
153154
{
154-
return isxdigit(c);
155+
return isdigit(c);
155156
}
156157

157-
//G digit: one of
158-
//G 0 1 2 3 4 5 6 7 8 9
158+
//G hexadecimal-digit:
159+
//G digit
160+
//G one of 'A' 'B' 'C' 'D' 'E' 'F'
159161
//G
160-
auto is_digit(char c) -> bool
162+
auto is_hexadecimal_digit(char c) -> bool
161163
{
162-
return isdigit(c);
164+
return isxdigit(c);
163165
}
164166

165-
//G nondigit: { a..z | A..Z | _ }
167+
//G nondigit:
168+
//G one of 'a'..'z'
169+
//G one of 'A'..'Z'
170+
//G _
166171
//G
167172
auto is_nondigit(char c) -> bool
168173
{
@@ -186,7 +191,10 @@ auto is_identifier_continue(char c) -> bool
186191
return is_digit(c) || is_nondigit(c);
187192
}
188193

189-
//G identifier: identifier-start { identifier-continue }*
194+
//G identifier:
195+
//G identifier-start
196+
//G identifier identifier-continue
197+
//G 'operator' operator
190198
//G
191199
auto starts_with_identifier(std::string_view s) -> int
192200
{

0 commit comments

Comments
 (0)