From 7bd2461c849b4626653a4744427c904b87354bd7 Mon Sep 17 00:00:00 2001 From: Linnnus Date: Thu, 10 Apr 2025 05:21:36 +0000 Subject: feat(core): Add tokenizer --- src/core/location.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/core/location.h (limited to 'src/core/location.h') diff --git a/src/core/location.h b/src/core/location.h new file mode 100644 index 0000000..c1ca3b8 --- /dev/null +++ b/src/core/location.h @@ -0,0 +1,33 @@ +#ifndef SAND_LOCATION_H +#define SAND_LOCATION_H + +// This module defines the location type. It represents a reference to a span of +// source text. They are carried throughout the compiler so error messages can +// make useful references to the user's source code. + +#include +#include + +// Uniquely, the fields of this struct should be considered public, though +// still read-only. +// +// Internally, regardless of presentation, line and column numbers are +// 0-indexed for consistensy. +typedef struct { + const char *filename; + unsigned start_line; + unsigned start_column; + unsigned end_line; + unsigned end_column; +} SandLocation; + +// Construct a new location which minimally encompasses both `a` and `b`. +// `a` must start before `b` ends. +// `a` and `b` must have the same `filename` (i.e. they obviously can't cross file boundaries). +SandLocation sand_location_encompassing(const SandLocation *a, const SandLocation *b); + +// Print the location to the given stream. +// The output will not contain newlines. +void sand_print_location(FILE *, const SandLocation *); + +#endif -- cgit v1.2.3