From df6a2c3e995d2837ffc303523b72316b017d2134 Mon Sep 17 00:00:00 2001 From: theMackabu Date: Thu, 9 Apr 2026 11:55:31 -0700 Subject: [PATCH] multi-line highlighter comment parsing --- AGENTS.md | 13 ++++++++----- examples/demo/highlight.js | 12 ++++++++++++ maidfile.toml | 2 +- src/highlight/iter.c | 10 ++++++++-- tests/test_highlight_comments.cjs | 11 +++++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 tests/test_highlight_comments.cjs diff --git a/AGENTS.md b/AGENTS.md index f747a9d..1fa7e8f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,13 +18,13 @@ entire repository into context. ## Fast Path +- Start here for most changes: `maid preflight` - Build from an existing configured tree: `meson compile -C build` - Fresh local setup: `maid setup` - Run a focused test file: `./build/ant tests/test_.cjs` - Run the spec suite: `./build/ant examples/spec/run.js` -- Validate repo knowledge docs: `maid knowledge` -- Validate changed-file boundaries: `maid structure` -- Route the current diff to the right checks: `maid validate_changes` +- Run the individual harness steps when needed: + `maid validate_changes`, `maid structure`, `maid knowledge` ## Codebase Map @@ -48,14 +48,17 @@ guidance. ## Change Rules - Prefer changes in `src/`, `include/`, `meson/`, `tests/`, `tools/`, and `.github/agents/`. -- Treat `vendor/`, `build/ as generated or third-party surfaces. - Only edit them when the task explicitly requires it. +- Treat `vendor/` and `build/` as generated or third-party surfaces. Only edit + them when the task explicitly requires it. - Keep durable design notes and execution history in versioned markdown under `docs/`. Treat `todo/` as scratch space, not the source of truth. - Add or update tests when behavior changes. - When touching build or runtime invariants, document the reasoning in [docs/exec-plans/index.md](docs/exec-plans/index.md) or a linked plan if the work spans multiple steps. +- Before finalizing most code changes, run `maid preflight` and then execute any + additional build or spec commands it recommends, or explain why they were not + run. ## Which Doc To Open Next diff --git a/examples/demo/highlight.js b/examples/demo/highlight.js index 7651e3a..aaec7de 100644 --- a/examples/demo/highlight.js +++ b/examples/demo/highlight.js @@ -1,6 +1,10 @@ const hl = Ant.highlight; const render = hl.render; +function assertEq(actual, expected, label) { + if (actual !== expected) throw new Error(`${label}: expected ${JSON.stringify(expected)} got ${JSON.stringify(actual)}`); +} + console.log(render('Red text and back to normal')); console.log(render('Green, Blue, Yellow')); @@ -34,3 +38,11 @@ function greet(name) { }`; console.log(hl(code)); + +const lineComment = hl.tags('//hello\nworld'); +assertEq(lineComment, '<#758CA3>//hello\nworld', 'line comment stops at newline'); + +const blockComment = hl.tags('/*hello\nworld'); +assertEq(blockComment, '<#758CA3>/*hello\nworld', 'block comment continues across newline'); + +console.log('highlight comment specs ok'); diff --git a/maidfile.toml b/maidfile.toml index dbe028c..cf77577 100644 --- a/maidfile.toml +++ b/maidfile.toml @@ -23,7 +23,7 @@ script = [".github/download.sh", "open .github/artifacts"] [tasks.run] script = ["maid build -q", "./build/ant %{arg.1}"] -[tasks.check] +[tasks.preflight] script = "ant .github/agents/check_all.js" [tasks.knowledge] diff --git a/src/highlight/iter.c b/src/highlight/iter.c index 404e4bb..276f7e8 100644 --- a/src/highlight/iter.c +++ b/src/highlight/iter.c @@ -333,6 +333,10 @@ static bool is_function_argument_identifier(const char *input, size_t input_len, return is_likely_function_param_paren(input, input_len, open_paren, close_paren); } +static inline bool is_line_comment_terminator(unsigned char c) { + return c == '\n' || c == '\r'; +} + bool hl_iter_next(hl_iter *it, hl_span *out) { const char *input = it->input; size_t input_len = it->input_len; @@ -421,8 +425,10 @@ bool hl_iter_next(hl_iter *it, hl_span *out) { if (c == '/' && i + 1 < input_len && input[i + 1] == '/') { it->ctx = HL_CTX_NONE; - *out = (hl_span){ i, input_len - i, HL_COMMENT }; - it->pos = input_len; + size_t start = i; i += 2; + while (i < input_len && !is_line_comment_terminator((unsigned char)input[i])) i++; + *out = (hl_span){ start, i - start, HL_COMMENT }; + it->pos = i; return true; } diff --git a/tests/test_highlight_comments.cjs b/tests/test_highlight_comments.cjs new file mode 100644 index 0000000..2de6c06 --- /dev/null +++ b/tests/test_highlight_comments.cjs @@ -0,0 +1,11 @@ +function assertEq(actual, expected, label) { + if (actual !== expected) throw new Error(`${label}: expected ${JSON.stringify(expected)} got ${JSON.stringify(actual)}`); +} + +const lineComment = Ant.highlight.tags('//hello\nworld'); +assertEq(lineComment, '<#758CA3>//hello\nworld', 'line comment stops at newline'); + +const blockComment = Ant.highlight.tags('/*hello\nworld'); +assertEq(blockComment, '<#758CA3>/*hello\nworld', 'block comment continues across newline'); + +console.log('ok'); -- 2.51.2