Repository navigation
feat: preprocessor for text configs - #50
Merged
Merged
Conversation
Text configs ignored every line starting with #, so macros were left unexpanded and #include was dropped. - rap::Preprocessor: #define (arguments, variadic __VA_* macros, # and ##, multi-line), #undef, #if/#ifdef/#ifndef/#else/#endif, #include, __has_include and the __XXX__ built-ins. - Follows the game where it differs from C: arguments are expanded before # and ##, arguments are not trimmed, ## keeps the whitespace around it, single-quoted strings are expanded, double-quoted not. - Includes go through IncludeResolver: FsIncludeResolver for files on disk, or any closure, with join_include_path for virtual paths. - Cfg::parse_config and Cfg::read preprocess first, #include without a resolver is an error. Cfg::parse_config_with and Cfg::parse_path take a preprocessor.
/tmp/x/config.cpp on Linux was taken for a path of the game (\a3\...) and only looked up in the include directories.
Codecov Report❌ Patch coverage is
... and 2 files with indirect coverage changes 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Text configs treated every line starting with
#as a comment: macros were left unexpanded (and failed to parse),#includewas silently dropped. This adds the preprocessor, following PreProcessor Commands:#definewith arguments, variadic macros (__VA_ARGS__,__VA_OPT__,__VA_OPT_INV__,__VA_APPLY__,__VA_SELECT__),#and##, multi-line bodies.#undef.#if(comparisons, plus&&,||,!,defined()),#ifdef,#ifndef,#else,#endif, also#elif. Nesting works.#include "..."/<...>, relative and\absolute paths,... Nesting is limited to 32 levels, which also stops include cycles.__has_include,__LINE__,__FILE__,__FILE_NAME__,__FILE_SHORT__,__COUNTER__,__COUNTER_RESET__, the date/time macros (UTC),__RAND_*.__ARMA__and__ARMA3__are predefined; game-dependent ones (__GAME_VER_MAJ__,__A3_DEBUG__, ...) can be set withPreprocessor::define.Where the game differs from C, it follows the game:
#and##:QUOTE(GVAR(x))gives"cba_main_x".FORMATexample output).##only removes itself, the whitespace around it stays: ACE'sclass ##weapongivesclass weapon.#in a body that isn't followed by an argument is dropped.Not copied: the game drops commas inside quoted macro arguments (
MACRO("a, b")→"a b"), this keeps them.API:
Preprocessor::new().with_resolver(...),define,undefine,preprocess(src, path),preprocess_path(path).IncludeResolver:FsIncludeResolverfor files on disk (include dirs like a P drive), or any closureFn(&str, Option<&str>) -> io::Result<Option<IncludeFile>>;join_include_pathresolves virtual paths for closures serving PBO contents.Cfg::parse_config_with(src, path, &mut pp)andCfg::parse_path(path, &mut pp).Cfg::parse_configandCfg::readnow preprocess first.#includewithout a resolver is aPreprocessErrorinstead of being skipped.Checked against all 220
config.cppof CBA_A3 and ACE3 (with\a3\ui_fincludes stubbed as empty): all preprocess, in 1.8 s total, with no unexpanded macros left. 121 parse; the other 99 fail in the config parser on+=, arithmetic, numbers with leading zeros, hex numbers and class names starting with a digit, which comes next.