サンプル
pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
検証済みサンプル — pypi pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError. python 3.12 · linux…
sha256:6cc14a356c0e73eff0829b186a2d10670a40864c0da5619ce62125b9c29a3cc2
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 3
- ビルドした署名鍵
- 3
宣言された環境
python linux x64 python python pip
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| python 3.12 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-17 |
| python 3.12 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1 |
2026-08-18 |
| python 3.12 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · python@1python:3.12-slim@sha256:09f7da3bc104… |
2026-09-08 |
ケース
HOW- ゴール
- Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
- パッケージ
- シンボル
-
- pycparser.c_parser.CParser
- pycparser.plyparser.ParseError
- 環境
- python
- 作成日
- 2026-08-17T19:21:56Z
コントラクト
- CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include <stdio.h>, rather than successfully ignoring or processing it.
ファイル
- NOTES.md
- contract.py
- csx.json
- requirements.txt
ソース
# pycparser Preprocessor Directives
When querying for `pycparser` behaviour regarding C preprocessor macros and includes, the known solution (`sha256:3c5ca6f4d0fbebc7e9f426b8ff85289533a86a2af0b05839306773534fb7b397`) demonstrated basic C99 source parsing into an AST, node traversal, formatting, and `ParseError` on syntax errors.
However, a common trap is assuming `pycparser` will automatically handle or skip standard C preprocessor directives such as `#include`. Since it is a pure C parser without an integrated preprocessor, attempting to parse code with an `#include` directive (or other macros) does not gracefully skip it or raise a generic syntax error.
Instead, at release `2.22`, `CParser().parse()` explicitly raises a `ParseError` with the message "Directives not supported yet". This loudly breaks any code that naively passes unpreprocessed C headers to the library expecting them to be ignored.
from pycparser import c_parser
from pycparser.plyparser import ParseError
code = """#include <stdio.h>
int main() {
printf("Hello");
return 0;
}
"""
parser = c_parser.CParser()
try:
parser.parse(code)
assert False, "Expected ParseError but parsing succeeded"
except ParseError as e:
assert "Directives not supported yet" in str(e), f"Unexpected error message: {e}"
{"case":{"believed":"pycparser can automatically skip or handle standard preprocessor directives like #include when parsing C source.","caseId":"case:sha256:96be3970aced415d2cad4c1a0be05a4a81fae3da2ed2304ce0436647d3671ad2","contract":["CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include \u003cstdio.h\u003e, rather than successfully ignoring or processing it."],"goal":"Attempting to parse C code containing preprocessor directives like #include raises a ParseError.","kind":"HOW","packages":["pkg:pypi/pycparser@2.22"],"schemaVersion":1,"symbols":["pycparser.c_parser.CParser","pycparser.plyparser.ParseError"]},"contractCommand":["python","contract.py"],"environment":{"arch":"x64","ecosystem":"pypi","executionContext":"python","language":"python","os":"linux","packageManager":"pip","runtime":"python","schemaVersion":1},"license":"MIT-0","packages":["pkg:pypi/pycparser@2.22"],"schemaVersion":1,"symbols":["pycparser.c_parser.CParser","pycparser.plyparser.ParseError"],"verifierAdapter":"python@1"}
pycparser==2.22