Skip to content

Commit

Permalink
CMake: new parser
Browse files Browse the repository at this point in the history
As mentioned in issue #1816, this is a CMake file parser using the optlib
multitable regex feature.
  • Loading branch information
hadrielk committed Aug 12, 2018
1 parent 9ffe430 commit 806f296
Show file tree
Hide file tree
Showing 23 changed files with 609 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Units/parser-cmake.r/cmake-comments.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
another_good_target input.cmake /^add_library(another_good_target# <-- target$/;" t
good_target input.cmake /^ good_target# this is legal comment placement set(NO_TAG foo)$/;" t
tag_this input.cmake /^]]set(tag_this)$/;" v
17 changes: 17 additions & 0 deletions Units/parser-cmake.r/cmake-comments.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# this is a test of comments set(DO_NOT_TAG "foo")

#[[
multi-linecomments
option(DO_NOT_TAG "foo" OFF)
] not the end
]]set(tag_this)

add_custom_target(# comment set(NO_TAG "foo")
# anothe rline comment
good_target# this is legal comment placement set(NO_TAG foo)
ALL)

add_library(another_good_target# <-- target
SHARED # set(NO_TAG bar)
gmock-all.cc
)
5 changes: 5 additions & 0 deletions Units/parser-cmake.r/cmake-function.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bfunctiontag_this_2 input.cmake /^ function( Bfunctiontag_this_2 ${BAR})$/;" f
cxx_shared_library input.cmake /^function(cxx_shared_library name cxx_flags)$/;" f
d_ALSO_Tag_this input.cmake /^ d_ALSO_Tag_this$/;" f
eLastlyTagThis_ input.cmake /^eLastlyTagThis_ "hello")$/;" f
tag_this1 input.cmake /^function(tag_this1)$/;" f
19 changes: 19 additions & 0 deletions Units/parser-cmake.r/cmake-function.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function(tag_this1)
endfunction(tag_this1)
function( Bfunctiontag_this_2 ${BAR})

function(cxx_shared_library name cxx_flags)
cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
endfunction()

FUNCTION (
d_ALSO_Tag_this
true)

Function(
eLastlyTagThis_ "hello")

function(${not_this} foo)
function(not-this foo)
function(not.this foo)
function(1notthis foo)
5 changes: 5 additions & 0 deletions Units/parser-cmake.r/cmake-macro.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bmacrotag_this_2 input.cmake /^ macro( Bmacrotag_this_2 ${BAR})$/;" m
cxx_shared_library input.cmake /^macro(cxx_shared_library name cxx_flags)$/;" m
d_ALSO_Tag_this input.cmake /^ d_ALSO_Tag_this$/;" m
eLastlyTagThis_ input.cmake /^eLastlyTagThis_ "hello")$/;" m
tag_this1 input.cmake /^macro(tag_this1)$/;" m
19 changes: 19 additions & 0 deletions Units/parser-cmake.r/cmake-macro.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
macro(tag_this1)
endmacro(tag_this1)
macro( Bmacrotag_this_2 ${BAR})

macro(cxx_shared_library name cxx_flags)
cxx_library_with_type(${name} SHARED "${cxx_flags}" ${ARGN})
endmacro()

MACRO (
d_ALSO_Tag_this
true)

Macro(
eLastlyTagThis_ "hello")

macro(${not_this} foo)
macro(not-this foo)
macro(not.this foo)
macro(1not_this foo)
5 changes: 5 additions & 0 deletions Units/parser-cmake.r/cmake-option.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1_tag_this input.cmake /^option(1_tag_this foo)$/;" D
B-option-tag_this_2 input.cmake /^option(B-option-tag_this_2 ${BAR})$/;" D
c_TAG_THIS input.cmake /^ option ( c_TAG_THIS but_not_this)$/;" D
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this$/;" D
e.LastlyTagThis input.cmake /^e.LastlyTagThis "hello")$/;" D
15 changes: 15 additions & 0 deletions Units/parser-cmake.r/cmake-option.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
option(1_tag_this foo)
option(B-option-tag_this_2 ${BAR})

option ( c_TAG_THIS but_not_this)

OPTION (
d-ALSO-Tag.this
true)

Option(
e.LastlyTagThis "hello")

option(${not_this} foo)
option(${ not_this } foo)
option(not~this foo)
5 changes: 5 additions & 0 deletions Units/parser-cmake.r/cmake-project.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1_tag_this input.cmake /^project(1_tag_this)$/;" p
B-project-tag_this_2 input.cmake /^project(B-project-tag_this_2 ${BAR})$/;" p
c_TAG_THIS input.cmake /^ project ( c_TAG_THIS but_not_this)$/;" p
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this$/;" p
e.LastlyTagThis input.cmake /^e.LastlyTagThis "hello")$/;" p
15 changes: 15 additions & 0 deletions Units/parser-cmake.r/cmake-project.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
project(1_tag_this)
project(B-project-tag_this_2 ${BAR})

project ( c_TAG_THIS but_not_this)

PROJECT (
d-ALSO-Tag.this
)

Project(
e.LastlyTagThis "hello")

project(${not_this})
project(${ not_this })
project(not/this)
6 changes: 6 additions & 0 deletions Units/parser-cmake.r/cmake-simple.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BUILD_GMOCK input.cmake /^option(BUILD_GMOCK "Builds the googlemock subproject" ON)$/;" D
BUILD_GTEST input.cmake /^option(BUILD_GTEST "Builds the googletest subproject" OFF)$/;" D
CMAKE_INSTALL_BINDIR input.cmake /^ set(CMAKE_INSTALL_BINDIR "bin" CACHE STRING "User executables (bin)")$/;" v
CMAKE_INSTALL_INCLUDEDIR input.cmake /^ set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE STRING "C header files (include)")$/;" v
CMAKE_INSTALL_LIBDIR input.cmake /^ set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}" CACHE STRING "Object code libraries (lib)")$/;" v
googletest-distribution input.cmake /^project( googletest-distribution )$/;" p
34 changes: 34 additions & 0 deletions Units/parser-cmake.r/cmake-simple.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# taken from https://github.com/google/googletest/blob/master/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.4)

if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)

project( googletest-distribution )

enable_testing()

include(CMakeDependentOption)
if (CMAKE_VERSION VERSION_LESS 2.8.5)
set(CMAKE_INSTALL_BINDIR "bin" CACHE STRING "User executables (bin)")
set(CMAKE_INSTALL_LIBDIR "lib${LIB_SUFFIX}" CACHE STRING "Object code libraries (lib)")
set(CMAKE_INSTALL_INCLUDEDIR "include" CACHE STRING "C header files (include)")
mark_as_advanced(CMAKE_INSTALL_BINDIR CMAKE_INSTALL_LIBDIR CMAKE_INSTALL_INCLUDEDIR)
else()
include(GNUInstallDirs)
endif()

option(BUILD_GTEST "Builds the googletest subproject" OFF)

#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON)

cmake_dependent_option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON "BUILD_GTEST OR BUILD_GMOCK" OFF)
cmake_dependent_option(INSTALL_GMOCK "Enable installation of googlemock. (Projects embedding googlemock may want to turn this OFF.)" ON "BUILD_GMOCK" OFF)

if(BUILD_GMOCK)
add_subdirectory( googlemock )
elseif(BUILD_GTEST)
add_subdirectory( googletest )
endif()
15 changes: 15 additions & 0 deletions Units/parser-cmake.r/cmake-target.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1_tag_this input.cmake /^add_custom_target(1_tag_this)$/;" t
1_tag_this input.cmake /^add_executable(1_tag_this)$/;" t
1_tag_this input.cmake /^add_library(1_tag_this)$/;" t
B-add_custom_target-tag_this_2 input.cmake /^add_custom_target(B-add_custom_target-tag_this_2 ${BAR})$/;" t
B-add_executable-tag_this_2 input.cmake /^add_executable(B-add_executable-tag_this_2 ${BAR})$/;" t
B-add_library-tag_this_2 input.cmake /^add_library(B-add_library-tag_this_2 ${BAR})$/;" t
c_TAG_THIS input.cmake /^ add_custom_target ( c_TAG_THIS but_not_this)$/;" t
c_TAG_THIS input.cmake /^ add_executable ( c_TAG_THIS but_not_this)$/;" t
c_TAG_THIS input.cmake /^ add_library ( c_TAG_THIS but_not_this)$/;" t
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this$/;" t
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this $/;" t
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this$/;" t
e.LastlyTagThis input.cmake /^e.LastlyTagThis "CustomTarget")$/;" t
e.LastlyTagThis input.cmake /^e.LastlyTagThis "Executable")$/;" t
e.LastlyTagThis input.cmake /^e.LastlyTagThis "Library")$/;" t
49 changes: 49 additions & 0 deletions Units/parser-cmake.r/cmake-target.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
add_custom_target(1_tag_this)
add_custom_target(B-add_custom_target-tag_this_2 ${BAR})

add_custom_target ( c_TAG_THIS but_not_this)

ADD_CUSTOM_TARGET (
d-ALSO-Tag.this
)

Add_Custom_target(
e.LastlyTagThis "CustomTarget")

add_custom_target(${not_this})
add_custom_target(${ not_this })
add_custom_target(not/this)


add_executable(1_tag_this)
add_executable(B-add_executable-tag_this_2 ${BAR})

add_executable ( c_TAG_THIS but_not_this)

ADD_EXECUTABLE (
d-ALSO-Tag.this
)

Add_Executable(
e.LastlyTagThis "Executable")

add_executable(${not_this})
add_executable(${ not_this })
add_executable(not/this)


add_library(1_tag_this)
add_library(B-add_library-tag_this_2 ${BAR})

add_library ( c_TAG_THIS but_not_this)

ADD_LIBRARY (
d-ALSO-Tag.this
)

Add_Library(
e.LastlyTagThis "Library")

add_library(${not_this})
add_library(${ not_this })
add_library(not/this)
5 changes: 5 additions & 0 deletions Units/parser-cmake.r/cmake-variable.d/expected.tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1_tag_this input.cmake /^set(1_tag_this foo)$/;" v
B-set-tag_this_2 input.cmake /^set(B-set-tag_this_2 ${BAR})$/;" v
c_TAG_THIS input.cmake /^ set ( c_TAG_THIS but_not_this)$/;" v
d-ALSO-Tag.this input.cmake /^ d-ALSO-Tag.this$/;" v
e.LastlyTagThis input.cmake /^e.LastlyTagThis "hello")$/;" v
13 changes: 13 additions & 0 deletions Units/parser-cmake.r/cmake-variable.d/input.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(1_tag_this foo)
set(B-set-tag_this_2 ${BAR})

set ( c_TAG_THIS but_not_this)

SET (
d-ALSO-Tag.this
true)

Set(
e.LastlyTagThis "hello")

set(${not_this} foo)
1 change: 1 addition & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ The following parsers have been added:
* Automake
* AutoIt
* Clojure
* CMake *optlib*
* CSS
* Ctags option library *optlib*
* CUDA
Expand Down
1 change: 1 addition & 0 deletions main/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
BasicParser, \
BetaParser, \
ClojureParser, \
CMakeParser, \
CParser, \
CppParser, \
CPreProParser, \
Expand Down
5 changes: 3 additions & 2 deletions makefiles/translator_input.mak
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -*- makefile -*-
TRANSLATOR_INPUT = \
optlib/RSpec.ctags \
optlib/RSpec.ctags \
optlib/cmake.ctags \
optlib/ctags-optlib.ctags \
optlib/elm.ctags \
optlib/elm.ctags \
optlib/gdbinit.ctags \
optlib/man.ctags \
optlib/markdown.ctags \
Expand Down
Loading

0 comments on commit 806f296

Please sign in to comment.