diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 08:45:26 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 08:50:57 +0100 |
| commit | b16ae0960b396c8c20e4711eabfe4b826a039d7e (patch) | |
| tree | 8e1688a956c98f3fee7218f5664ef1ac61100477 /CompilerKit/ParserKit.hpp | |
| parent | 8d7c9c7296e9b2e2afb79ce19d2560ab218d77aa (diff) | |
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 <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerKit/ParserKit.hpp')
| -rw-r--r-- | CompilerKit/ParserKit.hpp | 23 |
1 files changed, 20 insertions, 3 deletions
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 |
