@@ -24,6 +24,7 @@ import string_list;
2424import string_pool;
2525import token local;
2626import utf8;
27+ import warning_flags;
2728
2829import string;
2930import stdlib;
@@ -265,6 +266,8 @@ public type Tokenizer struct {
265266
266267 string_pool.Pool* pool; // no ownership
267268 string_buffer.Buf* buf; // no ownership, used for strings and character constants
269+ const warning_flags.Flags* warnings;
270+
268271 HandlerFn on_error;
269272 HandlerFn on_warning;
270273 void* fn_arg;
@@ -278,7 +281,7 @@ public type Tokenizer struct {
278281
279282 char[256] error_msg;
280283}
281- static_assert(416 , sizeof(Tokenizer));
284+ static_assert(424 , sizeof(Tokenizer));
282285
283286public fn void Tokenizer.init(Tokenizer* t,
284287 string_pool.Pool* pool,
@@ -287,6 +290,7 @@ public fn void Tokenizer.init(Tokenizer* t,
287290 SrcLoc loc_start,
288291 const keywords.Info* kwinfo,
289292 const string_list.List* features,
293+ const warning_flags.Flags* warnings,
290294 HandlerFn on_error,
291295 HandlerFn on_warning,
292296 void* fn_arg,
@@ -301,6 +305,7 @@ public fn void Tokenizer.init(Tokenizer* t,
301305 t.line_start = input;
302306 t.pool = pool;
303307 t.buf = buf;
308+ t.warnings = warnings;
304309 t.on_error = on_error;
305310 t.on_warning = on_warning;
306311 t.fn_arg = fn_arg;
@@ -687,6 +692,15 @@ fn void Tokenizer.error(Tokenizer* t, Token* result, const char* format @(printf
687692 if (t.on_error) t.on_error(t.fn_arg, result.loc);
688693}
689694
695+ fn void Tokenizer.warning(Tokenizer* t, SrcLoc loc, const char* format @(printf_format), ...) {
696+ va_list args;
697+ va_start(args, format);
698+ vsnprintf(t.error_msg, sizeof(t.error_msg), format, args);
699+ va_end(args);
700+
701+ if (t.on_warning) t.on_warning(t.fn_arg, loc);
702+ }
703+
690704// generate an error but keep parsing
691705fn void Tokenizer.num_error(Tokenizer* t, Token* result, const char* p, const char* format @(printf_format), ...) {
692706 va_list args;
@@ -722,9 +736,8 @@ fn void Tokenizer.lex_identifier(Tokenizer* t, Token* result) {
722736 while (Identifier_char[(u8)(*end)]) end++;
723737
724738 usize len = (usize)(end - start);
725- if (len > constants.MaxIdentifierLen && !t.raw_mode) {
726- t.error(result, "identifier too long (max %d chars)", constants.MaxIdentifierLen);
727- return;
739+ if (len > constants.MaxIdentifierLen && !t.raw_mode && t.warnings && !t.warnings.no_max_identifier_length) {
740+ t.warning(result.loc, "identifier too long (max %d chars)", constants.MaxIdentifierLen);
728741 }
729742 t.cur += len;
730743 result.name_idx = t.pool.add(start, len, true);
0 commit comments