Skip to content

C parser/preprocessing - #14

Merged
saidctb merged 1 commit into
c-parser/mainfrom
c-parser/preprocessing
May 22, 2026
Merged

C parser/preprocessing#14
saidctb merged 1 commit into
c-parser/mainfrom
c-parser/preprocessing

Conversation

@saidctb

@saidctb saidctb commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds the first C parser Phase 4 foundation for raw source handling and metadata extraction.

This PR introduces:

  • C lexer/source normalization helpers
  • safe // and /* ... */ comment stripping while preserving line/column accounting
  • string and character literal awareness during comment stripping
  • backslash-newline logical record folding
  • lightweight C tokens with source locations
  • raw #include collection for quoted and system includes
  • local include resolution relative to the parsed file
  • simple object-like #define macro collection
  • function-like macro metadata plus non-fatal unsupported diagnostics
  • parser/API wiring so parse_c_file populates raw includes, macros, and metadata diagnostics
  • CLI JSON coverage for the new C metadata output
  • updated C parser docs/checklist for implemented behavior and future macro policy

Declaration, function, struct, typedef, and project-resolution parsing remain intentionally deferred.

C Macro And Preprocessing Policy

Clarifies that the C parser is preprocessor-aware, not a C preprocessor:

  • raw C mode only normalizes source and records directive metadata
  • raw mode parses only declarations already visible as ordinary C
  • raw mode must not expand macros, select #if/#ifdef branches, or treat macro-generated declarations as parsed API
  • macro-heavy APIs require future compiler-preprocessed input
  • preprocessed input must preserve #line/linemarker mapping so diagnostics and source_location fields point back to the original .h/.c

Tests

  • python3 -m pytest -q tests/parser/c/test_c_public_api_skeleton.py tests/parser/c/test_c_lexer_preprocessor.py tests/parser/c/test_c_cli_skeleton.py
  • python3 -m pytest -q
  • git diff --check

@codecov

codecov Bot commented May 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.59864% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
c_parser/preprocessor.py 91.52% 2 Missing and 3 partials ⚠️
Flag Coverage Δ
py312 92.56% <96.59%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
c_parser/lexer.py 100.00% <100.00%> (ø)
c_parser/parser.py 90.83% <ø> (ø)
c_parser/preprocessor.py 91.52% <91.52%> (+91.52%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@saidctb
saidctb merged commit 583be8e into c-parser/main May 22, 2026
5 of 6 checks passed
@saidctb
saidctb deleted the c-parser/preprocessing branch May 22, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant