#include "parse.h" #include // Using this as a reference: // https://en.cppreference.com/c/language/translation_phases typedef struct { int line; int col; } Loc; // Phase 1 already happens when the file is read. typedef struct { Loc loc; char ch; } CannonicalChar; typedef struct { const char* text; size_t idx; Loc loc; } NewlineCanonicalizer; CannonicalChar next_cannonical_char(NewlineCanonicalizer* iter) { Loc loc = iter->loc; char ch = iter->text[iter->idx]; if (ch == '\0') return (CannonicalChar) { loc, ch }; do { if (ch == '\n') { } else { } iter->loc.col += 1; } while (iter->text[iter->idx]); } // Phase 2 is an iterator that handles escaped newlines. typedef struct { /// when this is '\0', it means EOF char ch; int line; int col; } Char; typedef struct { const char* text; size_t idx; int line; int col; } CharIter; static Char next_src_char(CharIter* iter) { if (!iter->text[iter->idx]) return (Char) { .ch = '\0', iter->line, iter->col }; char ch = iter->text[iter->idx]; iter->idx += 1; while (ch == '\\' &&) }