From b16ae0960b396c8c20e4711eabfe4b826a039d7e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Jan 2024 08:45:26 +0100 Subject: CompilerDriver: new preprocessor tool, bpp. Syntax rules of bpp: - prefixed with % - looks like C preprocessor %ifdef, %if, %elif, %else, %endif - #define is %def. - can't call other defines in %def, so %define foo __false doesn't work. bpp is a new preprocessor for masm and bccl. Signed-off-by: Amlal El Mahrouss --- CompilerKit/ParserKit.hpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'CompilerKit/ParserKit.hpp') diff --git a/CompilerKit/ParserKit.hpp b/CompilerKit/ParserKit.hpp index 6748df3..58c9516 100644 --- a/CompilerKit/ParserKit.hpp +++ b/CompilerKit/ParserKit.hpp @@ -85,9 +85,26 @@ namespace ParserKit not_part_of_word(index + needle.size()); } - inline bool find_word_strict(const std::string& haystack, const std::string& needle) noexcept + /// find a word within strict conditions and returns a range of it. + /// \param haystack + /// \param needle + /// \return position of needle. + inline std::size_t find_word_range(const std::string& haystack, const std::string& needle) noexcept { - return ParserKit::find_word(haystack, needle) && - isspace(haystack[haystack.find(needle) + needle.size() + 1]); + auto index = haystack.find(needle); + + // check for needle validity. + if (index == std::string::npos) + return false; + + if (!isalnum((haystack[index + needle.size() + 1])) && + !isdigit(haystack[index + needle.size() + 1]) && + !isalnum((haystack[index - needle.size() - 1])) && + !isdigit(haystack[index - needle.size() - 1])) + { + return index; + } + + return false; } } \ No newline at end of file -- cgit v1.2.3