4 ms·
An important point here is that for certain languages, using the original grammar is pretty much impossible. In particular, for C, you want to do diffing and me
by Sesse__ 2y ago
An important point here is that for certain languages, using the original grammar is pretty much impossible. In particular, for C, you want to do diffing and merging on the un-preprocessed source, but the language's grammar very much assumes the source has gone through the preprocessor.
Of course, the existence of the preprocessor means there are situations where it's completely impossible to know what the correct parse is; it will necessarily be heuristic in some cases.
- yencabulator 2y agoYou can ask Clang for an AST that contains macro definitions and invocations as nodes. https://docs.rs/clang/latest/clang/struct.Parser.html#method.detailed_preprocessing_record https://docs.rs/clang/latest/clang/struct.Parser.html#method... https://docs.rs/clang/latest/clang/enum.EntityKind.html#variant.MacroExpansion https://docs.rs/clang/latest/clang/enum.EntityKind.html#vari... https://docs.rs/clang/latest/clang/enum.EntityKind.html#variant.MacroDefinition https://docs.rs/clang/latest/clang/enum.EntityKind.html#vari...
- Sesse__ 2y agoUsing clangd for this very much assumes that you have all include files and build flags available at the point of merge resolution, which is often pretty much impossible.
- yencabulator 2y agoAgreed, it's not very robust the way tree-sitter is. I just thought that libclang trick was very useful for extracting semantic information from C source.