diff options
author | Linnnus <[email protected]> | 2025-04-11 23:42:02 +0000 |
---|---|---|
committer | Linnnus <[email protected]> | 2025-04-15 01:08:23 +0000 |
commit | d15dd976b98b4c39a899b3d68047dc752699dca7 (patch) | |
tree | 2291c13817e0359d2f116e76e7b66c9ae8f0c590 /src/cli | |
parent | 31eacdeefe6099e68dd8596faab8108671e4c6a5 (diff) |
feat(core,cli): Add diagnostic handler to SandConfig
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/main.c | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/cli/main.c b/src/cli/main.c index db42a14..cbecf50 100644 --- a/src/cli/main.c +++ b/src/cli/main.c @@ -140,15 +140,38 @@ static void print_help(FILE *stream, const char *argv0) { } static void print_handler(const char *message, size_t message_length) { - fprintf(stderr, message, message_length); + fprintf(stdout, message, message_length); +} + +void diagnostic_handler(const SandLocation *location, SandDiagnosticLevel level, const char *message, size_t message_length) { + sand_print_location(stderr, location); + switch (level) { + case SAND_DIAGNOSTIC_INFO: fprintf(stderr, ": info"); break; + case SAND_DIAGNOSTIC_WARNING: fprintf(stderr, ": warning"); break; + case SAND_DIAGNOSTIC_ERROR: fprintf(stderr, ": error"); break; + } + fprintf(stderr, ": %.*s\n", (int)message_length, message); } int main(int argc, char *argv[]) { SandConfig config = { .print_handler = print_handler, + .diagnostic_handler = diagnostic_handler, }; SandState state = sand_create_state(config); + // TEMP + SandLocation loc = { + .filename = "fake.sand", + .start_line = 0, + .start_column = 0, + .end_line = 0, + .end_column = 5, + }; + sand_print_diagnostic(&state, &loc, SAND_DIAGNOSTIC_INFO, "This is a test info message"); + sand_print_diagnostic(&state, &loc, SAND_DIAGNOSTIC_WARNING, "oh no the number is %d", 5); + sand_print_diagnostic(&state, &loc, SAND_DIAGNOSTIC_ERROR, "gaide gad error here %d", 5); + if (argc == 1) { repl(&state); } else if (argc == 2 && strcmp(argv[1], "--help") == 0) { |