Skip to content

Commit

Permalink
[Bugfix] Allow spaces in prefixes in R[] directives
Browse files Browse the repository at this point in the history
  • Loading branch information
Sirraide committed Nov 13, 2023
1 parent ba71a59 commit a536462
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.20)
project(fchk VERSION 3.0.0 LANGUAGES CXX)
project(fchk VERSION 3.0.1 LANGUAGES CXX)

## ============================================================================
## Global CMake Variables.
Expand Down
23 changes: 10 additions & 13 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1061,21 +1061,14 @@ void Context::CollectDirectives(PrefixState& state) {
auto ReadDirectiveArg = [&] { return chfile.at("\n") ? "" : Trim(chfile.skip_to_ws().skip_ws().read_to("\n")); };

/// Find all directives in the file.
for (;;) {
/// Read directive.
auto dir = Trim(
chfile
.skip_to(state.prefix)
.skip_to_ws()
.skip_ws()
.read_to_any(" \t\v\f\r\n", true)
);
if (dir.empty()) break;
while (not chfile.empty()) {
chfile.skip_to(state.prefix).skip(state.prefix.size()).skip_ws();

/// Handle run directives.
if (dir.starts_with(detail::RunWithPrefixDirectiveNameStart) and dir.ends_with(']')) {
auto prefix = dir.substr(detail::RunWithPrefixDirectiveNameStart.size());
prefix.remove_suffix(1);
if (chfile.at(detail::RunWithPrefixDirectiveNameStart)) {
auto prefix = Trim(chfile.read_to_any("]\r\n", true));
if (not chfile.at("]")) continue;
prefix.remove_prefix(detail::RunWithPrefixDirectiveNameStart.size());

/// If there currently is no state for this prefix, create it.
PrefixState* new_state;
Expand All @@ -1096,6 +1089,10 @@ void Context::CollectDirectives(PrefixState& state) {
continue;
}

/// Read directive.
auto dir = Trim(chfile.read_to_any(" \t\v\f\r\n", true));
if (dir.empty()) continue;

/// Check if this really is a directive.
auto it = detail::NameDirectiveMap.find(dir);
if (it == detail::NameDirectiveMap.end()) continue;
Expand Down
6 changes: 3 additions & 3 deletions test/basic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,6 @@ Y
## parameter that the `fchk` prefix is set to when executing that program.
##
##
## R[??] echo foo ; echo bar baz
?? * foo
?? + bar baz
## R[? ?] echo foo ; echo bar baz
? ? * foo
? ? + bar baz

0 comments on commit a536462

Please sign in to comment.