diff options
Diffstat (limited to 'boot/lex.c')
| -rw-r--r-- | boot/lex.c | 93 |
1 files changed, 0 insertions, 93 deletions
diff --git a/boot/lex.c b/boot/lex.c index 594905f..18f8690 100644 --- a/boot/lex.c +++ b/boot/lex.c @@ -13,99 +13,6 @@ #define MAX_CHAR_BUFFER_SIZE 256 -// byte position within a file. -typedef uint64 Pos; - -// an extent of text within a file, -// defined by its start and end byte positions. -struct Span -{ - Pos start; - Pos end; -}; - -struct Span -span_new(Pos start, Pos end) -{ - return (struct Span){ .start = start, .end = 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 }; -} - -// create a span which encompasses two spans. -struct Span -span_merge(struct Span a, struct Span b) -{ - return (struct Span){ - .start = a.start < b.start ? a.start : b.start, - .end = a.end > b.end ? a.end : b.end, - }; -} - -// expand a span by a number of bytes. -// negative number expands the span to the left, -// positive number expands the span to the right. -struct Span -span_expand(struct Span span, integer by) -{ - uint start_expand = by < 0 ? -by : 0; - uint end_expand = by > 0 ? by : 0; - return (struct Span){ - .start = span.start - start_expand, - .end = span.end + end_expand, - }; -} - -// check if two spans are equal. -bool -span_equals(struct Span a, struct Span b) -{ - return a.start == b.start && a.end == b.end; -} - -// check if span equals = { 0, 0 }. -bool -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 -{ - uint line; - 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 { |
