mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(treesitter): bundle Lua parser and queries
parser from https://github.com/MunifTanjim/tree-sitter-lua queries from nvim-treesitter
This commit is contained in:
parent
21dad0dcf3
commit
905dd49fec
@ -208,6 +208,9 @@ set(LIBICONV_SHA256 ccf536620a45458d26ba83887a983b96827001e92a13847b45e4925cc891
|
|||||||
set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz)
|
set(TREESITTER_C_URL https://github.com/tree-sitter/tree-sitter-c/archive/v0.20.2.tar.gz)
|
||||||
set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2 )
|
set(TREESITTER_C_SHA256 af66fde03feb0df4faf03750102a0d265b007e5d957057b6b293c13116a70af2 )
|
||||||
|
|
||||||
|
set(TREESITTER_LUA_URL https://github.com/MunifTanjim/tree-sitter-lua/archive/v0.0.12.tar.gz)
|
||||||
|
set(TREESITTER_LUA_SHA256 b6d7c6d04e9101a2e589d25f1d61668301e776c0b8defa6eae8dd86272e9e7c3)
|
||||||
|
|
||||||
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.7.tar.gz)
|
set(TREESITTER_URL https://github.com/tree-sitter/tree-sitter/archive/v0.20.7.tar.gz)
|
||||||
set(TREESITTER_SHA256 b355e968ec2d0241bbd96748e00a9038f83968f85d822ecb9940cbe4c42e182e)
|
set(TREESITTER_SHA256 b355e968ec2d0241bbd96748e00a9038f83968f85d822ecb9940cbe4c42e182e)
|
||||||
|
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
ExternalProject_Add(treesitter-c
|
function(BuildTSParser LANG TS_URL TS_SHA256 TS_CMAKE_FILE)
|
||||||
PREFIX ${DEPS_BUILD_DIR}
|
set(NAME treesitter-${LANG})
|
||||||
URL ${TREESITTER_C_URL}
|
ExternalProject_Add(${NAME}
|
||||||
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/treesitter-c
|
PREFIX ${DEPS_BUILD_DIR}
|
||||||
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
URL ${TREESITTER_C_URL}
|
||||||
-DPREFIX=${DEPS_BUILD_DIR}
|
DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/${NAME}
|
||||||
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/treesitter-c
|
DOWNLOAD_COMMAND ${CMAKE_COMMAND}
|
||||||
-DURL=${TREESITTER_C_URL}
|
-DPREFIX=${DEPS_BUILD_DIR}
|
||||||
-DEXPECTED_SHA256=${TREESITTER_C_SHA256}
|
-DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/${NAME}
|
||||||
-DTARGET=treesitter-c
|
-DURL=${TS_URL}
|
||||||
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
-DEXPECTED_SHA256=${TS_SHA256}
|
||||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
-DTARGET=${NAME}
|
||||||
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
|
-DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/TreesitterParserCMakeLists.txt
|
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
|
||||||
${DEPS_BUILD_DIR}/src/treesitter-c/CMakeLists.txt
|
PATCH_COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
CMAKE_ARGS
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${TS_CMAKE_FILE}
|
||||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
${DEPS_BUILD_DIR}/src/${NAME}/CMakeLists.txt
|
||||||
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
|
CMAKE_ARGS
|
||||||
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
|
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
||||||
${BUILD_TYPE_STRING}
|
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
|
||||||
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
|
${BUILD_TYPE_STRING}
|
||||||
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_ALT_SEP}
|
-DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
|
||||||
# Pass toolchain
|
# Pass toolchain
|
||||||
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
|
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
|
||||||
-DPARSERLANG=c
|
-DPARSERLANG=${LANG})
|
||||||
|
endfunction()
|
||||||
|
|
||||||
BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
|
BuildTSParser(c ${TREESITTER_C_URL} ${TREESITTER_C_SHA256} TreesitterParserCMakeLists.txt)
|
||||||
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE}
|
BuildTSParser(lua ${TREESITTER_LUA_URL} ${TREESITTER_LUA_SHA256} TreesitterParserCMakeLists.txt)
|
||||||
LIST_SEPARATOR |)
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
# some parsers have c++ scanner, problem?
|
project(parser C)
|
||||||
project(parser C) # CXX
|
|
||||||
|
file(GLOB source_files src/*.c)
|
||||||
|
|
||||||
add_library(parser
|
add_library(parser
|
||||||
MODULE
|
MODULE
|
||||||
src/parser.c
|
${source_files}
|
||||||
)
|
)
|
||||||
set_target_properties(
|
set_target_properties(
|
||||||
parser
|
parser
|
||||||
|
@ -123,7 +123,7 @@ foreach(PROG ${RUNTIME_PROGRAMS})
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
globrecurse_wrapper(RUNTIME_FILES ${CMAKE_CURRENT_SOURCE_DIR}
|
globrecurse_wrapper(RUNTIME_FILES ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
*.vim *.lua *.dict *.py *.rb *.ps *.spl *.tutor *.tutor.json)
|
*.vim *.lua *.scm *.dict *.py *.rb *.ps *.spl *.tutor *.tutor.json)
|
||||||
|
|
||||||
foreach(F ${RUNTIME_FILES})
|
foreach(F ${RUNTIME_FILES})
|
||||||
get_filename_component(BASEDIR ${F} DIRECTORY)
|
get_filename_component(BASEDIR ${F} DIRECTORY)
|
||||||
|
192
runtime/queries/lua/highlights.scm
Normal file
192
runtime/queries/lua/highlights.scm
Normal file
@ -0,0 +1,192 @@
|
|||||||
|
;; Keywords
|
||||||
|
|
||||||
|
"return" @keyword.return
|
||||||
|
|
||||||
|
[
|
||||||
|
"goto"
|
||||||
|
"in"
|
||||||
|
"local"
|
||||||
|
] @keyword
|
||||||
|
|
||||||
|
(label_statement) @label
|
||||||
|
|
||||||
|
(break_statement) @keyword
|
||||||
|
|
||||||
|
(do_statement
|
||||||
|
[
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @keyword)
|
||||||
|
|
||||||
|
(while_statement
|
||||||
|
[
|
||||||
|
"while"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(repeat_statement
|
||||||
|
[
|
||||||
|
"repeat"
|
||||||
|
"until"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(if_statement
|
||||||
|
[
|
||||||
|
"if"
|
||||||
|
"elseif"
|
||||||
|
"else"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(elseif_statement
|
||||||
|
[
|
||||||
|
"elseif"
|
||||||
|
"then"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(else_statement
|
||||||
|
[
|
||||||
|
"else"
|
||||||
|
"end"
|
||||||
|
] @conditional)
|
||||||
|
|
||||||
|
(for_statement
|
||||||
|
[
|
||||||
|
"for"
|
||||||
|
"do"
|
||||||
|
"end"
|
||||||
|
] @repeat)
|
||||||
|
|
||||||
|
(function_declaration
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"end"
|
||||||
|
] @keyword.function)
|
||||||
|
|
||||||
|
(function_definition
|
||||||
|
[
|
||||||
|
"function"
|
||||||
|
"end"
|
||||||
|
] @keyword.function)
|
||||||
|
|
||||||
|
;; Operators
|
||||||
|
|
||||||
|
[
|
||||||
|
"and"
|
||||||
|
"not"
|
||||||
|
"or"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
|
[
|
||||||
|
"+"
|
||||||
|
"-"
|
||||||
|
"*"
|
||||||
|
"/"
|
||||||
|
"%"
|
||||||
|
"^"
|
||||||
|
"#"
|
||||||
|
"=="
|
||||||
|
"~="
|
||||||
|
"<="
|
||||||
|
">="
|
||||||
|
"<"
|
||||||
|
">"
|
||||||
|
"="
|
||||||
|
"&"
|
||||||
|
"~"
|
||||||
|
"|"
|
||||||
|
"<<"
|
||||||
|
">>"
|
||||||
|
"//"
|
||||||
|
".."
|
||||||
|
] @operator
|
||||||
|
|
||||||
|
;; Punctuations
|
||||||
|
|
||||||
|
[
|
||||||
|
";"
|
||||||
|
":"
|
||||||
|
","
|
||||||
|
"."
|
||||||
|
] @punctuation.delimiter
|
||||||
|
|
||||||
|
;; Brackets
|
||||||
|
|
||||||
|
[
|
||||||
|
"("
|
||||||
|
")"
|
||||||
|
"["
|
||||||
|
"]"
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
;; Variables
|
||||||
|
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
((identifier) @variable.builtin
|
||||||
|
(#eq? @variable.builtin "self"))
|
||||||
|
|
||||||
|
;; Constants
|
||||||
|
|
||||||
|
((identifier) @constant
|
||||||
|
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
|
||||||
|
|
||||||
|
(vararg_expression) @constant
|
||||||
|
|
||||||
|
(nil) @constant.builtin
|
||||||
|
|
||||||
|
[
|
||||||
|
(false)
|
||||||
|
(true)
|
||||||
|
] @boolean
|
||||||
|
|
||||||
|
;; Tables
|
||||||
|
|
||||||
|
(field name: (identifier) @field)
|
||||||
|
|
||||||
|
(dot_index_expression field: (identifier) @field)
|
||||||
|
|
||||||
|
(table_constructor
|
||||||
|
[
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @constructor)
|
||||||
|
|
||||||
|
;; Functions
|
||||||
|
|
||||||
|
(parameters (identifier) @parameter)
|
||||||
|
|
||||||
|
(function_call name: (identifier) @function.call)
|
||||||
|
(function_declaration name: (identifier) @function)
|
||||||
|
|
||||||
|
(function_call name: (dot_index_expression field: (identifier) @function.call))
|
||||||
|
(function_declaration name: (dot_index_expression field: (identifier) @function))
|
||||||
|
|
||||||
|
(method_index_expression method: (identifier) @method)
|
||||||
|
|
||||||
|
(function_call
|
||||||
|
(identifier) @function.builtin
|
||||||
|
(#any-of? @function.builtin
|
||||||
|
;; built-in functions in Lua 5.1
|
||||||
|
"assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs"
|
||||||
|
"load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print"
|
||||||
|
"rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable"
|
||||||
|
"tonumber" "tostring" "type" "unpack" "xpcall"))
|
||||||
|
|
||||||
|
;; Others
|
||||||
|
|
||||||
|
(comment) @comment
|
||||||
|
|
||||||
|
(hash_bang_line) @comment
|
||||||
|
|
||||||
|
(number) @number
|
||||||
|
|
||||||
|
(string) @string
|
||||||
|
|
||||||
|
;; Error
|
||||||
|
(ERROR) @error
|
Loading…
Reference in New Issue
Block a user