Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C support #663

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add C support #663

wants to merge 4 commits into from

Conversation

jtojnar
Copy link

@jtojnar jtojnar commented Dec 18, 2021

Just a basic C parsing support (no tags) based on tree-sitter/haskell-tree-sitter#294.

You can try it by checking out the haskell-tree-sitter branch from tree-sitter/haskell-tree-sitter#294, setting the path in cabal.project.local in the semantic root (e.g. packages: ../haskell-tree-sitter/tree-sitter-c) and then run RUNFILES_DIR=path/to/haskell-tree-sitter cabal run semantic-ast -- --rootdir=. --language=C (I have no idea to make Bazel use local Haskell packages).

Recent revisions of C++ support UTF-8, UTF-16 and UTF-32 literals:
https://en.cppreference.com/w/cpp/language/string_literal

Since the UTF-16 and UTF-32 literals only differ in case,
they produce the same identifiers:

src/Language/C/AST.hs:5543:1: error:
    Multiple declarations of ‘AnonymousUDQuote’
    Declared at: src/Language/C/AST.hs:4694:1
                 src/Language/C/AST.hs:5543:1
     |
5543 | type AnonymousUDQuote = AST.Token.Token "u\"" 114
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/Language/C/AST.hs:5545:1: error:
    Multiple declarations of ‘AnonymousUSQuote’
    Declared at: src/Language/C/AST.hs:4696:1
                 src/Language/C/AST.hs:5545:1
     |
5545 | type AnonymousUSQuote = AST.Token.Token "u'" 108
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It is still documented in the README and much more convenient than Bazel.
Just basic parsing support, no tags.
@patrickt
Copy link
Contributor

patrickt commented Jan 3, 2022

This is very cool. How does the tree-sitter-c package handle #include facilities and the like? The preprocessor is a harsh mistress.

@jtojnar
Copy link
Author

jtojnar commented Jan 3, 2022

Not sure, I never managed to get it working because tree sitter itself was segfaulting for me half the time so I switched to Coccinelle.

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.

None yet

2 participants