Skip to content

Commit 2568a83

Browse files
authored
Merge pull request #27 from sandbox-science/update/structure/syntax
Refactor Syntax Highlighting for multi-lingual support
2 parents ca15903 + e1a0b8f commit 2568a83

21 files changed

+554
-205
lines changed

.github/workflows/cpp.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ jobs:
3131
if: matrix.os == 'ubuntu-latest'
3232
run: |
3333
sudo apt-get update
34-
sudo apt-get install -y g++ make cmake
34+
sudo apt-get install -y g++ make cmake libyaml-cpp-dev
3535
g++ --version
3636
cmake --version
3737
make --version
3838
3939
- name: Set up C++ environment (macOS)
4040
if: matrix.os == 'macos-latest'
4141
run: |
42-
brew install make cmake
42+
brew install make cmake yaml-cpp
4343
echo 'export PATH="/usr/local/opt/gcc/bin:$PATH"' >> ~/.bash_profile
4444
source ~/.bash_profile
4545
g++ --version
@@ -83,15 +83,8 @@ jobs:
8383
- name: Build project
8484
run: make build
8585

86-
# Install the Project with desktop shortcut
87-
- name: Install project (Mac/Windows)
88-
if: matrix.os != 'ubuntu-latest'
86+
# Install the Project
87+
- name: Install project
8988
run: |
9089
cd ${{ github.workspace }}
91-
echo "y" | make install
92-
93-
# Install the Project without desktop shortcut (Linux)
94-
# This is a work around for Linux shortcut bug
95-
- name: Install project (Linux)
96-
if: matrix.os == 'ubuntu-latest'
97-
run: echo "n" | make install
90+
make install

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ jobs:
2828
if: matrix.os == 'ubuntu-latest'
2929
run: |
3030
sudo apt-get update
31-
sudo apt-get install -y g++ make cmake
31+
sudo apt-get install -y g++ make cmake libyaml-cpp-dev
3232
g++ --version
3333
cmake --version
3434
make --version
3535
3636
- name: Set up C++ environment (macOS)
3737
if: matrix.os == 'macos-latest'
3838
run: |
39-
brew install make cmake
39+
brew install make cmake yaml-cpp
4040
echo 'export PATH="/usr/local/opt/gcc/bin:$PATH"' >> ~/.bash_profile
4141
source ~/.bash_profile
4242
g++ --version

CMakeLists.txt

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
1717

1818
# Set default build output directories
1919
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
20+
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})
2021

2122
# Detect operating system
2223
if(WIN32)
@@ -47,31 +48,59 @@ endif()
4748
# Set Qt path for find_package
4849
set(CMAKE_PREFIX_PATH ${Qt_DIR})
4950

50-
# Find Qt Widgets
51-
find_package(Qt${QT_MAJOR_VERSION} COMPONENTS Widgets Test REQUIRED)
51+
# Find Qt components
52+
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Widgets Test)
53+
54+
# Locate yaml-cpp
55+
if(APPLE)
56+
set(yaml-cpp_DIR "/opt/homebrew/Cellar/yaml-cpp/0.8.0/lib/cmake/yaml-cpp")
57+
endif()
58+
find_package(yaml-cpp REQUIRED CONFIG)
59+
60+
# Copy YAML files to the build directory (non-macOS case)
61+
set(YAML_SOURCE_DIR ${CMAKE_SOURCE_DIR}/config)
62+
set(YAML_DEST_DIR ${CMAKE_BINARY_DIR}/config)
63+
file(MAKE_DIRECTORY ${YAML_DEST_DIR})
64+
file(GLOB YAML_FILES "${YAML_SOURCE_DIR}/*.yaml")
65+
66+
foreach(YAML_FILE ${YAML_FILES})
67+
file(COPY ${YAML_FILE} DESTINATION ${YAML_DEST_DIR})
68+
endforeach()
5269

5370
# Create the CodeAstra library
5471
add_library(${TARGET_NAME}
5572
src/MainWindow.cpp
5673
src/CodeEditor.cpp
57-
src/Syntax.cpp
5874
src/Tree.cpp
5975
src/FileManager.cpp
76+
src/Syntax.cpp
77+
src/SyntaxManager.cpp
6078
include/MainWindow.h
6179
include/CodeEditor.h
62-
include/Syntax.h
6380
include/Tree.h
6481
include/LineNumberArea.h
6582
include/FileManager.h
83+
include/SyntaxManager.h
84+
include/Syntax.h
6685
)
6786

87+
# Link YAML-CPP to the CodeAstra library
88+
target_link_libraries(${TARGET_NAME} PRIVATE yaml-cpp)
89+
6890
# Create the executable for the application
69-
add_executable(${EXECUTABLE_NAME}
70-
src/main.cpp
71-
)
91+
add_executable(${EXECUTABLE_NAME} src/main.cpp)
92+
93+
# Ensure YAML config files are copied into macOS app bundle
94+
# if(APPLE)
95+
# add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
96+
# COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
97+
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${YAML_SOURCE_DIR}" "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
98+
# COMMENT "Copying YAML config files into macOS app bundle..."
99+
# )
100+
# endif()
72101

73102
# Link the main executable with the CodeAstra library and Qt libraries
74-
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${TARGET_NAME} Qt${QT_MAJOR_VERSION}::Widgets)
103+
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${TARGET_NAME} Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets)
75104

76105
# Add the tests subdirectory
77106
add_subdirectory(tests)
@@ -85,7 +114,7 @@ if(MSVC)
85114
target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /WX)
86115
elseif(APPLE)
87116
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
88-
set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
117+
# set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
89118
else()
90119
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
91120
endif()
@@ -103,4 +132,10 @@ set_target_properties(${EXECUTABLE_NAME} PROPERTIES
103132
)
104133

105134
# Link necessary Qt libraries to CodeAstra library
106-
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Widgets)
135+
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets)
136+
137+
# Ensure correct linking of yaml-cpp (macOS)
138+
if(APPLE)
139+
target_include_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/include)
140+
target_link_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/lib)
141+
endif()

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ RUN apt-get install -y --no-install-recommends \
1313
qt6-base-dev \
1414
x11-utils \
1515
x11-xserver-utils \
16-
xvfb
16+
xvfb \
17+
libyaml-cpp-dev
1718
RUN rm -rf /var/lib/apt/lists/*
1819

1920
# Copy CodeAstra into the container

Makefile

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ all: build install
1010

1111
# Run CMake to build the project
1212
build:
13-
@echo "Building project with CMake..."
13+
@echo "Building $(PROJECT) with CMake..."
1414
@mkdir -p $(BUILD_DIR)
1515
@cd $(BUILD_DIR) && cmake $(CMAKE_OPTIONS)
1616

@@ -21,59 +21,13 @@ clean:
2121

2222
# Uninstalling the software
2323
uninstall: clean
24-
@echo "Uninstalling the software..."
24+
@echo "Uninstalling $(PROJECT)..."
2525
@rm -rf $(EXECUTABLE).app $(EXECUTABLE)d.app
26-
@OS_NAME=$(shell uname -s 2>/dev/null || echo "Windows"); \
27-
if [ "$$OS_NAME" = "Darwin" ]; then \
28-
rm -rf "$(HOME)/Desktop/$(EXECUTABLE).app"; \
29-
echo "MacOS: Shortcut removed..."; \
30-
elif [ "$$OS_NAME" = "Linux" ] && grep -qi "microsoft" /proc/version 2>/dev/null; then \
31-
rm -rf "$(HOME)/Desktop/$(EXECUTABLE)"; \
32-
echo "WSL: Shortcut removed..."; \
33-
elif [ "$$OS_NAME" = "Linux" ]; then \
34-
rm -rf "$(HOME)/Desktop/$(EXECUTABLE)"; \
35-
echo "Linux: Shortcut removed..."; \
36-
elif echo "$$OS_NAME" | grep -qE "CYGWIN|MINGW|MSYS"; then \
37-
rm -f "$(USERPROFILE)/Desktop/$(EXECUTABLE).exe"; \
38-
echo "Cygwin/Mingw/MSYS: Shortcut removed..."; \
39-
elif [ "$$OS_NAME" = "Windows" ]; then \
40-
if [ -n "$$USERPROFILE" ]; then \
41-
cmd /c "if exist \"$$USERPROFILE\\Desktop\\$(EXECUTABLE).exe\" del /f /q \"$$USERPROFILE\\Desktop\\$(EXECUTABLE).exe\"" && echo "Windows: Shortcut removed..."; \
42-
else \
43-
echo "Windows: Could not determine user profile directory."; \
44-
fi \
45-
fi
4626

4727
# Install the project
4828
install: build
4929
@echo "Installing $(PROJECT)..."
5030
@cd $(BUILD_DIR) && make
51-
@echo "Do you want to create a shortcut on the desktop? (Y/n)"
52-
@read choice; \
53-
if [ "$$choice" = "y" ] || [ "$$choice" = "Y" ]; then \
54-
echo "Creating shortcut..."; \
55-
OS_NAME=$(shell uname -s); \
56-
if [ "$$OS_NAME" = "Darwin" ]; then \
57-
echo "MacOS Detected..."; \
58-
cp -R $(EXECUTABLE).app ~/Desktop/; \
59-
elif [ "$$OS_NAME" = "Linux" ] && grep -qi "microsoft" /proc/version 2>/dev/null; then \
60-
echo "WSL Detected..."; \
61-
cp $(EXECUTABLE) ~/Desktop/; \
62-
elif [ "$$OS_NAME" = "Linux" ]; then \
63-
echo "Linux Detected..."; \
64-
cp $(EXECUTABLE) ~/Desktop/; \
65-
elif echo "$$OS_NAME" | grep -qE "CYGWIN|MINGW|MSYS"; then \
66-
echo "Windows-like Environment Detected (Cygwin/MSYS)..."; \
67-
cp $(EXECUTABLE).exe "$$USERPROFILE/Desktop/"; \
68-
elif [ "$$OS_NAME" = "Windows" ]; then \
69-
echo "Native Windows Detected..."; \
70-
if [ -n "$$USERPROFILE" ]; then \
71-
cp $(EXECUTABLE).exe "$$USERPROFILE/Desktop/"; \
72-
else \
73-
echo "Windows: Could not determine user profile directory."; \
74-
fi \
75-
fi \
76-
fi
7731
@echo "$(PROJECT) installed."
7832

7933
build_tests: build

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<!-- C++ CI Badge -->
88
[![C++ CI](https://github.com/sandbox-science/CodeAstra/actions/workflows/cpp.yml/badge.svg)](https://github.com/sandbox-science/CodeAstra/actions/workflows/cpp.yml)
9+
[![Test CI](https://github.com/sandbox-science/CodeAstra/actions/workflows/test.yml/badge.svg)](https://github.com/sandbox-science/CodeAstra/actions/workflows/test.yml)
910

1011
<!-- CodeAstra Latest Release Badge -->
1112
<a href="https://github.com/sandbox-science/CodeAstra/releases">
@@ -51,6 +52,14 @@ Please, check the [wiki](https://github.com/sandbox-science/CodeAstra/wiki) for
5152
- [ ] Create a new file ~ in progress
5253
- [x] File tree navigation
5354
- [ ] Syntax highlighting ~ in progress
55+
- Supported Languagues:
56+
- [x] Markdown (**foundation**)
57+
- [x] YAML (**foundation**)
58+
- [ ] C/C++ (**in progress**)
59+
- [ ] Golang (**in progress**)
60+
- [ ] Python (**Backlog**)
61+
- [ ] Elixir (**Backlog**)
62+
- more to come ... ([contribution welcomed](https://github.com/sandbox-science/CodeAstra/issues/4))
5463
- [ ] Plugin system
5564

5665
## To-Do

config/cpp.syntax.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
extensions: [cpp, c, h, hpp]
2+
3+
keywords:
4+
keyword:
5+
- regex: "\\b(char|class|const|double|enum|explicit|friend|inline|int|long|namespace|operator|private|protected|public|short|signals|signed|slots|static|struct|template|typedef|typename|union|unsigned|virtual|void|volatile|foreach)\\b"
6+
color: "#003478" # Dark Blue
7+
bold: "true"
8+
- regex: "\\b(for|while|do|if|else)\\b"
9+
color: "#D9001D" # Bright Red
10+
- regex: "(?<!\\w)#include(?!\\w)"
11+
color: "#800080" # Purple
12+
13+
comment:
14+
- regex: "//[^\n]*"
15+
color: "#336934" # Dark Green
16+
italic: "true"
17+
18+
string:
19+
- regex: "\"(\\\\.|[^\"\\\\])*\""
20+
color: "#E37100" # Orange
21+
- regex: "\\\\"
22+
color: "#FFDE00" # Yellow
23+
24+
number:
25+
- regex: "\\b\\d+\\b"
26+
color: "#0000FF" # Blue
27+
28+
parenthesis:
29+
- regex: "[()]"
30+
color: "#6495ED" # Cornflower Blue
31+
32+
function:
33+
- regex: "\\b(?!for\\b|if\\b|else\\b|while\\b|do\\b)[a-zA-Z_][a-zA-Z0-9_]*(?=\\s*\\()"
34+
color: "#DBA800" # Golden Yellow
35+
36+
qualifiedName:
37+
- regex: "\\b\\w+(?=\\s*::)"
38+
color: "#309676" # Teal Green

config/go.syntax.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extensions: [go]
2+
3+
keywords:
4+
comment:
5+
- regex: "\"(\\\\.|[^\"\\\\])*\""
6+
color: "#808080" # Gray
7+
8+
string:
9+
- regex: "\"(\\\\.|[^\"\\\\])*\""
10+
color: "#E37100" # Orange
11+
12+
number:
13+
- regex: "\\b\\d+\\b"
14+
color: "#0000FF" # Blue

config/markdown.syntax.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
extensions: [md]
2+
3+
keywords:
4+
comment:
5+
- regex: "#[^\n]*"
6+
color: "#336934" # Dark Green
7+
italic: "true"
8+
9+
heading:
10+
- regex: "^#{1,6}\\s+.*"
11+
color: "#003478" # Dark Blue
12+
bold: "true"
13+
14+
bold:
15+
- regex: "(?<!\\*)\\*\\*([^*]+)\\*\\*(?!\\*)|(?<!_)__([^_]+)__(?!_)"
16+
color: "#D9001D" # Bright Red
17+
bold: "true"
18+
19+
italic:
20+
- regex: "(?<!\\*)\\*([^*]+)\\*(?!\\*)|(?<!_)_([^_]+)_(?!_)"
21+
color: "#D97706" # Orange
22+
italic: "true"
23+
24+
link:
25+
- regex: "\\[([^\\]]+)\\]\\(([^\\)]+)\\)"
26+
color: "#005FFF" # Bright Blue
27+
28+
inline_code:
29+
- regex: "`([^`]+)`"
30+
color: "#E37100" # Orange
31+
32+
list:
33+
- regex: "^(\\s*[-+*]\\s+|\\s*\\d+\\.\\s+)"
34+
color: "#309676" # Teal Green
35+
36+
blockquote:
37+
- regex: "^>\\s+.*"
38+
color: "#B48EAD" # Light Purple
39+
italic: "true"
40+
41+
todo:
42+
- regex: "- \\[ \\]"
43+
color: "#FF8C00" # Orange for unchecked tasks
44+
- regex: "- \\[x\\]"
45+
color: "#32CD32" # Green for completed tasks
46+
- regex: "(?<=\\[)[^\\]]*(?=\\])"
47+
color: "#E37100"

config/python.syntax.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extensions: [py]
2+
3+
keywords:
4+
keyword:
5+
- regex: "\\bimport\\b"
6+
color: "#FF1493" # Deep Pink
7+
- regex: "\\bdef\\b"
8+
color: "#800080" # Purple
9+
- regex: "\\bclass\\b"
10+
color: "#008000" # Green
11+
bold: "true"
12+
13+
comment:
14+
- regex: "#[^\n]*"
15+
color: "#808080" # Gray
16+
italic: "true"
17+
18+
string:
19+
- regex: "\"(\\\\.|[^\"\\\\])*\""
20+
color: "#E37100" # Orange
21+
22+
number:
23+
- regex: "\\b\\d+\\b"
24+
color: "#0000FF" # Blue

0 commit comments

Comments
 (0)