diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 4c7008c..0000000 --- a/.clang-format +++ /dev/null @@ -1,3 +0,0 @@ ---- -BasedOnStyle: Mozilla -... diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3e1836c..9a3ce61 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,21 +7,24 @@ jobs: runs-on: ubuntu-24.04 steps: - name: Checkout Project - uses: actions/checkout@v4 - with: - submodules: "recursive" + uses: actions/checkout@v5 - name: Perform Commit Linting uses: wagoid/commitlint-github-action@v6 - - name: Check Clang Formatting - uses: RafikFarhad/clang-format-github-action@v6 + - name: Set up Go + uses: actions/setup-go@v6 + with: + go-version: '1.26.5' + + - name: Check Code Formatting + uses: wearerequired/lint-action@v2 with: - sources: "src/**/*.h,src/**/*.cpp" - style: file + gofmt: true + continue_on_error: false - - name: Build Project - uses: threeal/cmake-action@v2 + - name: Build + run: make build - - name: Test Project - uses: threeal/ctest-action@v1 \ No newline at end of file + - name: Test + run: make test \ No newline at end of file diff --git a/.gitignore b/.gitignore index de08f6d..2630238 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -cmake-build-* \ No newline at end of file +**/build \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index c0a83bd..1d9fd3f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "3rd/googletest"] - path = 3rd/googletest - url = git@github.com:google/googletest.git +[submodule "spec"] + path = spec + url = git@github.com:CollaborativeStateMachines/Spec.git diff --git a/3rd/CMakeLists.txt b/3rd/CMakeLists.txt deleted file mode 100644 index be75e8c..0000000 --- a/3rd/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# GoogleTest -if(WITH_TESTS) - set(BUILD_GMOCK ON CACHE BOOL "" FORCE) - set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) - set(GTEST_HAS_ABSL OFF CACHE BOOL "" FORCE) - - add_subdirectory(googletest) -endif() \ No newline at end of file diff --git a/3rd/googletest b/3rd/googletest deleted file mode 160000 index 52eb810..0000000 --- a/3rd/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 52eb8108c5bdec04579160ae17225d66034bd723 diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index c5e55f8..a047e66 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -6,9 +6,3 @@ contributions. --- ## 📦 Third-Party Libraries - -### GoogleTest -* **License:** BSD 3-Clause "New" or "Revised" License -* **Source:** https://github.com/google/googletest -* **Copyright:** (c) 2008, Google Inc. -* **Description:** Used for unit testing. \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index cde08e0..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.31) - -project(casem - LANGUAGES - CXX -) - -# Global variables -set(ROOT_PATH "${CMAKE_CURRENT_SOURCE_DIR}") -set(SOURCE_PATH "${ROOT_PATH}/src") -set(TEST_PATH "${ROOT_PATH}/test") - -# Add option definitions -include(CMakeOptions.txt) - -# Add third-party dependencies provided as sources -add_subdirectory(3rd) - -# Casem target -add_executable(casem) - -# Provide source files -add_subdirectory(src) - -# Provide test files -if(WITH_TESTS) - enable_testing() - include(GoogleTest) - add_subdirectory(test) -endif() \ No newline at end of file diff --git a/CMakeOptions.txt b/CMakeOptions.txt deleted file mode 100644 index 58daf38..0000000 --- a/CMakeOptions.txt +++ /dev/null @@ -1 +0,0 @@ -option(WITH_TESTS "Build tests" ON) \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 69b4435..4717a70 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,25 +7,11 @@ and procedural guidelines. Please ensure your contributions align with the follo ## 🛠 Engineering Standards -### C++ Style Guidelines -We adhere to a "good taste" philosophy. Beyond typical clean code practices, we enforce the following: - -* **RAII & Const-Correctness:** These are non-negotiable. Manage resources through object lifetime and ensure logical - constancy across the API. -* **Trailing Return Types:** All function declarations must use trailing return type syntax: - ```cpp - auto calculate_metrics(int value) -> double; - ``` -* **Exception Safety:** Mark all non-exception-throwing code paths as `noexcept`. -* **Early Escapes:** Avoid deeply nested branches. Prefer `if (condition) return;` to keep the primary logic at a - shallow indentation level. -* **Defensive Programming:** Write code that anticipates and handles invalid states or inputs gracefully. -* **Consistency:** Above all, match the surrounding code. New contributions should seat naturally into the existing - architecture. - ### Tooling -* **Formatting:** We use **Clang Format**. Before submitting, ensure your code matches the project's `.clang-format` - specification. +* **Formatting:** We use **gofmt**. Before submitting, ensure your code is formatted: + ```bash + go fmt ./... + ``` * **Originality:** We value the craft of programming. While Generative AI is a valid productivity tool, we expect you to understand and own the logic you submit. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b0aef65 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +.PHONY: test build clean run + +test: + go test ./... + +build: + @mkdir -p build/casem + go build -o build/casem/casem ./cmd/casem.go + +clean: + rm -rf build + +run: test build + ./build/casem/casem diff --git a/README.md b/README.md index e69de29..c8a898c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,19 @@ +# Casem + +## Project Strucutre + +```bash +Casem/ +├── ATTRIBUTION.md +├── cmd +│ └── casem.go # Application Entry Point +├── CONTRIBUTING.md +├── CONTRIBUTORS +├── csm # Public CSM Package: Defines API to implement CSM via Go +├── go.mod +├── internal # Internal Application Logic +├── LICENSE +├── Makefile +├── README.md +└── spec # Language Specification +``` diff --git a/cmd/casem.go b/cmd/casem.go new file mode 100644 index 0000000..0cb1dbd --- /dev/null +++ b/cmd/casem.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello Casem") +} diff --git a/csm/context_variable.go b/csm/context_variable.go new file mode 100644 index 0000000..c0c7fa1 --- /dev/null +++ b/csm/context_variable.go @@ -0,0 +1,33 @@ +package csm + +import ( + "errors" + "fmt" + "strings" +) + +type ContextVariable interface { + String() string +} + +type typedVariable[T any] struct { + name string + value T +} + +func NewContextVariable[T any](name string, value T) (ContextVariable, error) { + if strings.TrimSpace(name) == "" { + return nil, errors.New("name cannot be blank") + } + return &typedVariable[T]{ + name: name, + value: value, + }, nil +} + +func (cv *typedVariable[T]) String() string { + if cv == nil { + return "" + } + return fmt.Sprintf("ContextVariable(name=%q, value=%+v)", cv.name, cv.value) +} diff --git a/csm/context_variable_test.go b/csm/context_variable_test.go new file mode 100644 index 0000000..678439e --- /dev/null +++ b/csm/context_variable_test.go @@ -0,0 +1,14 @@ +package csm + +import "testing" + +func TestNewContextVariable(t *testing.T) { + _, err := NewContextVariable("a", 1) + if err != nil { + t.Errorf("Expected no error but received: %v", err) + } + _, err = NewContextVariable("", 1) + if err == nil { + t.Errorf("Expected error but received: %v", err) + } +} diff --git a/csm/event.go b/csm/event.go new file mode 100644 index 0000000..5b2a907 --- /dev/null +++ b/csm/event.go @@ -0,0 +1,46 @@ +package csm + +import "fmt" + +type EventChannel int + +const ( + Internal EventChannel = iota + External + Peripheral +) + +type Event struct { + Topic string + Channel EventChannel + Data []ContextVariable + Target string + Source string +} + +type ConditionalEvent struct { + Event + Provided Expression +} + +func (c EventChannel) String() string { + switch c { + case Internal: + return "Internal" + case External: + return "External" + case Peripheral: + return "Peripheral" + default: + return fmt.Sprintf("UnknownChannel(%d)", c) + } +} + +func (e Event) String() string { + return fmt.Sprintf("Event(topic=%q, channel=%s, target=%q, source=%q)", + e.Topic, e.Channel, e.Target, e.Source) +} + +func (e ConditionalEvent) String() string { + return fmt.Sprintf("ConditionalEvent(provided=%q, event=%+v)", e.Provided, e.Event) +} diff --git a/csm/expression.go b/csm/expression.go new file mode 100644 index 0000000..5c7e311 --- /dev/null +++ b/csm/expression.go @@ -0,0 +1,9 @@ +package csm + +import "fmt" + +type Expression string + +func (e Expression) String() string { + return fmt.Sprintf("expression=%v", string(e)) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4d64f38 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/CollaborativeStateMachines/Casem + +go 1.26.5 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e69de29 diff --git a/internal/util/utils.go b/internal/util/utils.go new file mode 100644 index 0000000..c7d8682 --- /dev/null +++ b/internal/util/utils.go @@ -0,0 +1 @@ +package util diff --git a/spec b/spec new file mode 160000 index 0000000..2771254 --- /dev/null +++ b/spec @@ -0,0 +1 @@ +Subproject commit 277125431dcc28e7b4abb43db8f3c77712e5c6ae diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 8377692..0000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -# Define sources -target_sources(casem - PRIVATE - "${SOURCE_PATH}/casem/main.cpp" -) \ No newline at end of file diff --git a/src/casem/main.cpp b/src/casem/main.cpp deleted file mode 100644 index b2703a7..0000000 --- a/src/casem/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// Stdlib -#include - -auto -main() noexcept -> int -{ - std::cout << "Hello World!" << std::endl; - return 0; -} \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt deleted file mode 100644 index 181677a..0000000 --- a/test/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -macro(package_add_test TESTNAME) - add_executable(${TESTNAME} ${ARGN}) - - target_link_libraries(${TESTNAME} gtest gmock gtest_main) - - gtest_discover_tests(${TESTNAME} - WORKING_DIRECTORY - ${ROOT_PATH} - ) -endmacro() - -package_add_test(test1 "${TEST_PATH}/casem/test.cpp") \ No newline at end of file diff --git a/test/casem/test.cpp b/test/casem/test.cpp deleted file mode 100644 index ffbdb75..0000000 --- a/test/casem/test.cpp +++ /dev/null @@ -1,7 +0,0 @@ -// GoogleTest -#include - -TEST(TestSuite, TestCase) -{ - ASSERT_TRUE(true); -} \ No newline at end of file