Kumo

A hand-rolled game engine.

git clone https://git.sentomk.me/Kumo.git
commit b5226c31c59b74a3e09153b4091ec767ee52b86a
parent bb8187159700af59ea02c09a7fab21262ec85ca7
Author: sentomk <sentomk@proton.me>
Date:   Wed,  7 Oct 2026 17:33:14 +0800

fix: reject duplicate tables and avoid backslashes in doc comments

Opening the same table twice in kumo.toml, e.g. two [mac] tables, was
accepted; as in TOML it is now an error with the line of the second one.
The error for `src = "."` now says the project directory itself is not
allowed, like the one for `out`.

Reword the doc comments that contained a raw backslash. Doxygen reads
sequences such as `\dir` and `\file` as commands.

Diffstat:
Mkumo_builder.cpp | 29+++++++++++++++++++++--------
1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/kumo_builder.cpp b/kumo_builder.cpp @@ -15,7 +15,8 @@ /// clang++ -std=c++20 kumo_builder.cpp -o kumoko.exe # Windows /// @endcode /// -/// Usage (always from the project root; on Windows run `.\kumoko`): +/// Usage (always from the project root; on Windows type `kumoko` without the +/// leading `./`): /// @code /// ./kumoko # incremental build /// ./kumoko run # incremental build, then run the executable @@ -127,8 +128,9 @@ static const fs::path CONFIG_FILE = "kumo.toml"; /// The file is a small subset of TOML (https://toml.io). The builder has no /// dependencies, so it parses the file itself, and accepts only this: /// - `#` starts a comment that runs to the end of the line; -/// - `key = "text"` assigns a string; inside double quotes only `\\` and `\"` -/// are escapes, and single quotes (`'C:\dir'`) take everything literally; +/// - `key = "text"` assigns a string; inside double quotes the only escapes +/// are a backslash followed by a backslash or by a double quote, and single +/// quotes take everything literally, backslashes included; /// - `key = ["a", "b"]` assigns a list of strings; it may span several lines, /// end with a comma and contain comments; /// - `[mac]`, `[linux]` and `[windows]` start a table whose keys apply to that @@ -213,9 +215,17 @@ class ConfigParser { Table parse() { Table table; std::string section; // the table being filled; empty at the top level + std::vector<std::string> tables_seen; for (skip_blank(true); pos_ < text_.size(); skip_blank(true)) { if (text_[pos_] == '[') { section = parse_header(); + // A table may be opened only once, as in TOML, so that its keys are + // never split over two places. + if (std::find(tables_seen.begin(), tables_seen.end(), section) != + tables_seen.end()) { + config_error(line_here(), "duplicate table '[" + section + "]'"); + } + tables_seen.push_back(section); } else { parse_pair(section, table); } @@ -237,10 +247,11 @@ class ConfigParser { config_error(line_here(), msg); } - /// @brief The next character, or `'\0'` at the end of the text. + /// @brief The next character, or a null character at the end of the text. char peek() const { return pos_ < text_.size() ? text_[pos_] : '\0'; } - /// @brief Skips spaces, `\r` and comments, and newlines too if asked. + /// @brief Skips spaces, carriage returns and comments, and newlines too if + /// asked. /// /// A comment stops before its newline, so with @p newlines false the parser /// ends up at the end of the line. @@ -478,7 +489,9 @@ static Config load_config() { // `clean` deletes the whole of `out`, so it must be a directory of its own: // not the project, not the sources, and not something holding them. if (!is_inside_project(cfg.src_dir)) { - config_error(0, "'src' must be a relative path inside the project"); + config_error(0, + "'src' must be a relative path inside the project, and " + "not the project directory itself"); } if (!is_inside_project(cfg.out_dir)) { config_error(0, @@ -729,8 +742,8 @@ static bool run(const Cmd& cmd) { return run_all({cmd}, 1); } /// - the dependency list starts after the first `": "`; /// - dependencies are separated by whitespace or a line continuation; /// - a space inside a path is escaped with a backslash; -/// - any other backslash is part of the path, which is how Windows paths such -/// as `C:\dir\file.h` appear. +/// - any other backslash is part of the path, which is how Windows paths +/// appear: a drive letter, then names separated by backslashes. /// /// @param path Path of the `.d` file. /// @return Every dependency listed in the file; empty if it cannot be parsed.