summaryrefslogtreecommitdiff
path: root/src/core/location.h
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2025-04-10 05:21:36 +0000
committerLinnnus <[email protected]>2025-04-15 00:54:43 +0000
commit7bd2461c849b4626653a4744427c904b87354bd7 (patch)
tree38ee0e0ac9408c989f3c50c0c6ff28492faf497d /src/core/location.h
parent8dd0c4f27aae02dd60f029db4cf03f9902cba26f (diff)
feat(core): Add tokenizer
Diffstat (limited to 'src/core/location.h')
-rw-r--r--src/core/location.h33
1 files changed, 33 insertions, 0 deletions
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 <stddef.h>
+#include <stdio.h>
+
+// 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