CodeSampleX

Ejemplo

pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError.

Muestra verificada para pypi pycparser 2.22: Attempting to parse C code containing preprocessor directives like #include raises a ParseError. El contrato se…

sha256:6cc14a356c0e73eff0829b186a2d10670a40864c0da5619ce62125b9c29a3cc2

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
3
Claves de firma que lo compilaron
3
Entorno declarado python linux x64 python python pip

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
Attempting to parse C code containing preprocessor directives like #include raises a ParseError.
Paquetes
Símbolos
  • pycparser.c_parser.CParser
  • pycparser.plyparser.ParseError
Entorno
python
Creado
2026-08-17T19:21:56Z

Contrato

  1. CParser().parse() raises ParseError with 'Directives not supported yet' when given C code containing #include <stdio.h>, rather than successfully ignoring or processing it.

Archivos

  • NOTES.md
  • contract.py
  • csx.json
  • requirements.txt

Descargar el artefacto de código fuente (tar.gz)

Código fuente

NOTES.md
# 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.
contract.py
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}"
csx.json
{"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"}
requirements.txt
pycparser==2.22

Seeder de origen

csx-seed