vickenty / lang-c

Lightweight C parser for Rust
Apache License 2.0
202 stars 30 forks source link

Convert span offsets to the one in the pre pre-process file #43

Closed HKalbasi closed 10 months ago

HKalbasi commented 11 months ago

Is it possible to convert an Span of this library to a (Filename, Span) in the original files in the disk? I'm trying to show some info about the C code using ariadne crate, and I'm currently using the pre-processed text using the source field of Parse, but I would like to do that conversion to make the spans show correct line number and file names.

vickenty commented 10 months ago

Sorry for the late reply.

I don't think there is a way to extract original byte positions of tokens - the external preprocessor only provides line numbers. There is a way to map spans to filename and line number though, see https://docs.rs/lang-c/latest/lang_c/loc/fn.get_location_for_offset.html