From 6ee6974e633f99b35e86c5e457bc953e0dafe9ee Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Tue, 30 Jan 2024 13:11:55 +0800 Subject: [PATCH] feat(cmake): add CMakefile example and usage in CMakeAnalyser #24 This commit adds a CMakefile example and demonstrates the usage of the CMakeAnalyser class in the README.md file. The example shows how to analyze a CMakeLists.txt file and extract relevant information using the CMakeAnalyser class. --- chapi-parser-cmake/README.md | 2 ++ .../main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt | 10 ++++++++++ .../chapi/parser/cmake/CMakeBasicListenerTest.kt | 1 - 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 chapi-parser-cmake/README.md diff --git a/chapi-parser-cmake/README.md b/chapi-parser-cmake/README.md new file mode 100644 index 00000000..51a2cf72 --- /dev/null +++ b/chapi-parser-cmake/README.md @@ -0,0 +1,2 @@ +# CMakefile + diff --git a/chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt b/chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt index 30beb719..5d0693b6 100644 --- a/chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt +++ b/chapi-parser-cmake/src/main/kotlin/chapi/parser/cmake/CMakeAnalyser.kt @@ -9,6 +9,16 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker /** * The `CMakeAnalyser` class is a CMakelists.txt parser that implements the `Analyser` interface. * It provides a method to analyze the given code and extract relevant information from it. + * + * ```kotlin + * val cmakeCode = """ + * cmake_minimum_required(VERSION 3.0) + * project(HelloWorld) + * add_executable(HelloWorld HelloWorld.cpp) + * """.trimIndent() + * val container = CMakeAnalyser().analysis(cmakeCode, "CMakeLists.txt") + * println(container.Fields.size) // 3 + * ``` */ class CMakeAnalyser : Analyser { override fun analysis(code: String, filePath: String): CodeContainer { diff --git a/chapi-parser-cmake/src/test/kotlin/chapi/parser/cmake/CMakeBasicListenerTest.kt b/chapi-parser-cmake/src/test/kotlin/chapi/parser/cmake/CMakeBasicListenerTest.kt index 51fc13d6..0e4acdc7 100644 --- a/chapi-parser-cmake/src/test/kotlin/chapi/parser/cmake/CMakeBasicListenerTest.kt +++ b/chapi-parser-cmake/src/test/kotlin/chapi/parser/cmake/CMakeBasicListenerTest.kt @@ -1,6 +1,5 @@ package chapi.parser.cmake; -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test