diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 0a7ad43..b8a9515 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -3,5 +3,6 @@
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d7ef64..50eb413 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
-project(floc VERSION 0.0.8)
+project(floc VERSION 0.0.9)
include(FetchContent)
@@ -19,6 +19,10 @@ FetchContent_Declare(ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/ftxui
GIT_TAG v5.0.0
)
+FetchContent_Declare(json
+ GIT_REPOSITORY https://github.com/nlohmann/json.git
+ GIT_TAG v3.11.3
+)
FetchContent_GetProperties(ftxui)
if(NOT ftxui_POPULATED)
@@ -26,11 +30,12 @@ if(NOT ftxui_POPULATED)
add_subdirectory(${ftxui_SOURCE_DIR} ${ftxui_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
-target_link_libraries(floc ${BLT_TARGET})
+target_link_libraries(floc PRIVATE BLT)
target_link_libraries(floc
PRIVATE ftxui::screen
PRIVATE ftxui::dom
PRIVATE ftxui::component
+ PRIVATE json
)
target_compile_options(floc PRIVATE -Wall -Werror -Wpedantic -Wno-comment)
diff --git a/include/blt/floc/analyzer.h b/include/blt/floc/analyzer.h
index 7240363..bfbaf3b 100644
--- a/include/blt/floc/analyzer.h
+++ b/include/blt/floc/analyzer.h
@@ -19,6 +19,13 @@
#ifndef BLT_FLOC_ANALYZER_H
#define BLT_FLOC_ANALYZER_H
+#include
+#include
+#include
+#include
+#include
+#include
+
/*
* This file provides an analyzer class for counting lines of code in a file along with a recursive parser for finding files
* it also provides a utility class to build a structure which mimics the file system directories alongside relevant code
@@ -26,4 +33,72 @@
* maybe split this into a few header files?
*/
+namespace blt::floc
+{
+ static inline const constexpr auto EMPTY_FUNCTION = [](std::string_view contents) {
+ return true;
+ };
+
+ struct associated_file_t
+ {
+ std::string file_extension;
+ std::string file_name;
+
+ associated_file_t() = default;
+
+ associated_file_t(std::string_view file_extension, std::string_view file_name): file_extension(file_extension), file_name(file_name)
+ {}
+ };
+
+ class language_t
+ {
+ private:
+ // extension -> file name
+ blt::hashmap_t language_files;
+ std::function matches_func;
+ public:
+ language_t(): matches_func(EMPTY_FUNCTION)
+ {}
+
+ explicit language_t(std::function matches_func): matches_func(std::move(matches_func))
+ {}
+
+ inline bool matches(std::string_view file_extension, std::string_view file_contents)
+ {
+ return language_files.find(std::string(file_extension)) != language_files.end() && matches_func(file_contents);
+ }
+
+ inline language_t& add(const associated_file_t& file)
+ {
+ language_files[file.file_extension] = file.file_name;
+ return *this;
+ }
+
+ inline language_t& add(std::string_view extension, std::string_view name)
+ {
+ return add(associated_file_t{extension, name});
+ }
+
+ inline language_t& add(const std::vector& extensions, std::string_view name)
+ {
+ for (const auto& v : extensions)
+ add(v, name);
+ return *this;
+ }
+ };
+
+ static inline const std::vector BASE_LANGUAGES = {
+ language_t().add("c", "C Source").add("h", "C/C++ Header"),
+ language_t().add({"cpp", "cxx", "cc"}, "C++ Source").add("h", "C/C++ Header").add("hpp", "C++ Header"),
+ language_t().add("java", "Java Source"),
+ language_t().add("rs", "Rust Source"),
+ language_t().add({"py", "pyo"}, "Python Source"),
+ language_t().add("rb", "Ruby Source"),
+ language_t().add("pl", "Perl Source"),
+
+ };
+
+
+}
+
#endif // BLT_FLOC_ANALYZER_H