From a91bd145008432fb8c5d91d94ab6f50473a277f5 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 27 Oct 2026 13:55:36 +0000 Subject: feat(preprocessor): add file-local conditional switches Co-Authored-By: Claude Opus 5.5 --- include/cps/Lexer.h | 8 +++++++- include/cps/Preprocessor.h | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 include/cps/Preprocessor.h (limited to 'include') diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h index bec1233..05fb857 100644 --- a/include/cps/Lexer.h +++ b/include/cps/Lexer.h @@ -113,7 +113,13 @@ enum Token { tok_try = -700, tok_catch = -701, tok_endtry = -702, - tok_throw = -703 + tok_throw = -703, + + tok_pp_define = -710, + tok_pp_undef = -711, + tok_pp_ifdef = -712, + tok_pp_ifndef = -713, + tok_pp_endif = -714 }; class Lexer { diff --git a/include/cps/Preprocessor.h b/include/cps/Preprocessor.h new file mode 100644 index 0000000..ebc2806 --- /dev/null +++ b/include/cps/Preprocessor.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include + +namespace cps { + +struct PreprocessedSource { + std::string Text; + // One entry per original source line, before processing that line's directive. + std::vector LibraryLines; + bool HadError = false; +}; + +// Switches and conditional nesting belong to this input only. Masked lines retain +// their byte lengths and line endings so the lexer sees original source locations. +PreprocessedSource preprocess(std::istream &Input); + +} -- cgit v1.3.1-4-g156e