Skip to content

refactor(libobs): extract the cf lexer into cf-tokenizer.c (#6) - #42

Merged
zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:refactor/cf-lexer-extract
Oct 10, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
b7216309-jpg:refactor/cf-lexer-extract

Conversation

@b7216309-jpg

@b7216309-jpg b7216309-jpg commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Refs #43 (Phase 3 tracking; #6 closed when #33 merged)

A behavior-neutral extraction ahead of porting the cf lexer, following "Extracting a function before porting it" in the testing policy. The precedent is #5 (path-extension.c). This PR contains no Rust.

  • cf_literal_to_str, cf_lexer_init, cf_lexer_free and cf_lexer_lex, with their static helpers (lines 22–451 of cf-lexer.c), move verbatim into the new libobs/util/cf-tokenizer.c.
  • cf-lexer.c keeps the preprocessor (cf_preprocess*, defines, includes, macro expansion).
  • No header, signature or behavior changes. The new file is always compiled, and test_cf_lexer is untouched.

Why split here: the tokenizer is a pure text → tokens transformation and maps cleanly onto a safe Rust core. The preprocessor opens files (os_fopen), evaluates #if through sscanf, and the shader/effect parsers walk its token arrays in place, so it is a separate, later step.

Verification

  • Updated after libobs/util: Drop the closing quote in cf_literal_to_str #54 merged: master was merged in, and the split was redone verbatim from master's cf-lexer.c, so cf-tokenizer.c carries the libobs/util: Drop the closing quote in cf_literal_to_str #54 cf_literal_to_str fix. Both halves diff clean against master again.
  • Both halves are byte-identical to the original lines: diff of git show HEAD:…/cf-lexer.c lines 22–451 against cf-tokenizer.c, and of lines 453–end against the new cf-lexer.c.
  • Both files compile with MSVC (C11, warnings on). ./lint passes (clang-format, gersemi).
  • Not run locally: the cmocka suite (no Docker here). test_cf_lexer exercises both halves through libobs.

🤖 Generated with Claude Code

Behavior-neutral move, as the function-extraction policy requires.
cf_literal_to_str, cf_lexer_init, cf_lexer_free and cf_lexer_lex, with
their static helpers (lines 22-448 of cf-lexer.c), move verbatim into
util/cf-tokenizer.c. cf-lexer.c keeps the preprocessor. No header,
signature or behavior changes, and the new file is always compiled.

This lets ENABLE_RUST_LIBOBS swap the tokenizer for a Rust port while
the preprocessor, which drives file I/O and walks the token arrays
directly, stays in C.

Refs obs-rust#6

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…xtract

# Conflicts:
#	libobs/util/cf-lexer.c
@zackees
zackees merged commit 6ef951d into obs-rust:master Oct 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants