From 02ebae28c671ec3596ba5b2017d4e34df391750d Mon Sep 17 00:00:00 2001 From: Abhishek Sudhakaran Date: Fri, 21 Jun 2024 13:27:24 +0530 Subject: [PATCH] feat: add support for QmlJs via tree-sitter-qmljs --- .gitmodules | 3 +++ 3RDPARTY.md | 6 ++++++ 3rdparty/CMakeLists.txt | 12 ++++++++++++ 3rdparty/tree-sitter-qmljs | 1 + src/treesitter/CMakeLists.txt | 10 ++++++++-- src/treesitter/languages.h | 1 + 6 files changed, 31 insertions(+), 2 deletions(-) create mode 160000 3rdparty/tree-sitter-qmljs diff --git a/.gitmodules b/.gitmodules index 0784987c..90f233d9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -23,6 +23,9 @@ [submodule "3rdparty/tree-sitter-cpp"] path = 3rdparty/tree-sitter-cpp url = https://github.com/tree-sitter/tree-sitter-cpp +[submodule "3rdparty/tree-sitter-qmljs"] + path = 3rdparty/tree-sitter-qmljs + url = https://github.com/yuja/tree-sitter-qmljs.git [submodule "3rdparty/mfc-utils"] path = 3rdparty-kdab/mfc-utils url = ssh://codereview.kdab.com:29418/kdab/mfc-utils diff --git a/3RDPARTY.md b/3RDPARTY.md index b3fff7a0..5257eb90 100644 --- a/3RDPARTY.md +++ b/3RDPARTY.md @@ -54,6 +54,12 @@ C++ grammar for tree-sitter.
[Home page](https://github.com/tree-sitter/tree-sitter-cpp)
[MIT licensed](LICENSES/MIT.txt) +### tree-sitter-qmljs + +QML grammar for the tree-sitter parsing library.
+[Home page](https://github.com/yuja/tree-sitter-qmljs)
+[MIT licensed](LICENSES/MIT.txt) + ## Build-time / CI tests 3rdparty These dependencies are only used during build or other CI purposes like running tests. diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index c948ab51..256b8650 100644 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -79,3 +79,15 @@ target_link_libraries(${PROJECT_NAME} PRIVATE TreeSitter) # Always build tree-sitter with optimizations enabled. We shouldn't have to # debug it and it's performance critical. target_compile_options(${PROJECT_NAME} PRIVATE -O3) + +# TreeSitterQmlJs +# ############################################################################## +check_submodule(tree-sitter-qmljs tree-sitter-qmljs) +project(TreeSitterQmlJs LANGUAGES C) + +add_library(${PROJECT_NAME} STATIC tree-sitter-qmljs/src/parser.c + tree-sitter-qmljs/src/scanner.c) +target_link_libraries(${PROJECT_NAME} PRIVATE TreeSitter) +# Always build tree-sitter with optimizations enabled. We shouldn't have to +# debug it and it's performance critical. +target_compile_options(${PROJECT_NAME} PRIVATE -O3) diff --git a/3rdparty/tree-sitter-qmljs b/3rdparty/tree-sitter-qmljs new file mode 160000 index 00000000..febf48a5 --- /dev/null +++ b/3rdparty/tree-sitter-qmljs @@ -0,0 +1 @@ +Subproject commit febf48a5b6928600cd8fb2a01254743af550780d diff --git a/src/treesitter/CMakeLists.txt b/src/treesitter/CMakeLists.txt index 1cdcdeb0..6c40dee6 100644 --- a/src/treesitter/CMakeLists.txt +++ b/src/treesitter/CMakeLists.txt @@ -14,7 +14,13 @@ set(PROJECT_SOURCES node.cpp parser.cpp predicates.cpp query.cpp transformation.cpp tree.cpp) add_library(${PROJECT_NAME} STATIC ${PROJECT_SOURCES}) -target_link_libraries(${PROJECT_NAME} TreeSitter TreeSitterCpp kdalgorithms - knut-utils Qt${QT_VERSION_MAJOR}::Core) +target_link_libraries( + ${PROJECT_NAME} + TreeSitter + TreeSitterCpp + TreeSitterQmlJs + kdalgorithms + knut-utils + Qt${QT_VERSION_MAJOR}::Core) target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/treesitter/languages.h b/src/treesitter/languages.h index 1723b775..34a0a9b8 100644 --- a/src/treesitter/languages.h +++ b/src/treesitter/languages.h @@ -14,4 +14,5 @@ struct TSLanguage; extern "C" { TSLanguage *tree_sitter_cpp(); +TSLanguage *tree_sitter_qmljs(); }