about summary refs log tree commit diff
path: root/boot/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/lex.c')
-rw-r--r--boot/lex.c25
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
 {