diff options
| author | Mel <mel@rnrd.eu> | 2025-07-09 04:46:58 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-07-09 04:46:58 +0200 |
| commit | efa510e6b58ce13c53e94f13a5be0007240e9dcc (patch) | |
| tree | 7bcebe71e6d90d7e0004be1f975e5028b3c1b530 /boot/lex.c | |
| parent | 3620cabd1d722e4acc761c7278aa44aba902006c (diff) | |
| download | catskill-efa510e6b58ce13c53e94f13a5be0007240e9dcc.tar.zst catskill-efa510e6b58ce13c53e94f13a5be0007240e9dcc.zip | |
Display human-readable, informative parser error messages w/ source snippet
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/lex.c')
| -rw-r--r-- | boot/lex.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/boot/lex.c b/boot/lex.c index c705f26..2efb33d 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -31,6 +31,12 @@ span_new(Pos start, Pos end) } struct Span +span_empty(void) +{ + return (struct Span){ 0, 0 }; +} + +struct Span span_width(Pos start, uint width) { return (struct Span){ .start = start, .end = start + width }; @@ -74,6 +80,13 @@ span_is_empty(struct Span span) return span_equals(span, (struct Span){ 0, 0 }); } +uint +span_length(struct Span span) +{ + uint length = span.end - span.start; + return length == 0 ? 1 : length; +} + // a cursor position placed within a text file. struct Cursor { @@ -81,6 +94,18 @@ struct Cursor uint column; }; +struct Cursor +cursor_new(uint line, uint column) +{ + return (struct Cursor){ .line = line, .column = column }; +} + +struct Cursor +cursor_empty(void) +{ + return cursor_new(0, 0); +} + // what kind of token is it? enum Token_Kind { |
