Skip to content

Refactor Syntax Highlighting for multi-lingual support #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Mar 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a6af4f2
✨ Feature: Reintroduce Syntax class for custom syntax highlighting
chrisdedman Mar 27, 2025
e65b1a3
✨ Feature: Add SyntaxCpp class for C/C++ syntax highlighting
chrisdedman Mar 27, 2025
51cbcf9
✨ Feature: Add SyntaxGo foundation class for Go syntax highlighting
chrisdedman Mar 27, 2025
2038876
✨ Feature: Reintroduce Syntax class with highlightBlock and addPatter…
chrisdedman Mar 27, 2025
d515736
✨ Feature: Implement SyntaxCpp class for C++ syntax highlighting with…
chrisdedman Mar 27, 2025
c4ec1a0
✨ Feature: Add foundation SyntaxGo implementation for Go syntax highl…
chrisdedman Mar 27, 2025
b3d0340
✨ Feature: Add QSyntaxHighlighter member to FileManager for syntax hi…
chrisdedman Mar 27, 2025
d9ed3f0
✨ Refactor: Remove unused Syntax member from MainWindow class
chrisdedman Mar 27, 2025
70cd4fb
✨ Feature: Add SyntaxManager class for dynamic syntax highlighter cre…
chrisdedman Mar 27, 2025
7f67166
✨ Feature: Integrate dynamic syntax highlighting in FileManager for l…
chrisdedman Mar 27, 2025
a71c04f
✨ Feature: Organize syntax-related files into a dedicated Syntax dire…
chrisdedman Mar 27, 2025
884ce77
✨ Update README.md to include supported languages for syntax highligh…
chrisdedman Mar 27, 2025
8200c9b
✨ Refactor: Remove obsolete syntax highlighter classes for C++, Go, a…
chrisdedman Mar 29, 2025
27b36c9
✨ Refactor: Remove obsolete syntax highlighter classes for C++ and Go
chrisdedman Mar 29, 2025
221d8eb
✨ Refactor: Update Syntax class constructor to accept YAML configurat…
chrisdedman Mar 29, 2025
4fb7f24
✨ Refactor: Simplify SyntaxManager class by consolidating highlighter…
chrisdedman Mar 29, 2025
c4d4ad9
✨ Refactor: Consolidate test executable definitions and ensure proper…
chrisdedman Mar 29, 2025
0edee19
:white_check_mark: Test: Add unit tests for Syntax class to validate …
chrisdedman Mar 29, 2025
67e2423
✨ Add syntax configuration files for C++, Go, Markdown, Python, and Y…
chrisdedman Mar 29, 2025
ce5053d
:recycle: Refactor: Update CMake configuration to improve YAML file h…
chrisdedman Mar 29, 2025
7de9a8b
:recycle: Update: Enhance output messages in Makefile for clarity dur…
chrisdedman Mar 29, 2025
2fe8aa5
:recycle: Update: Add libyaml-cpp-dev to Dockerfile dependencies for …
chrisdedman Mar 29, 2025
d1f7288
:fire: Remove: Delete Syntax class header file as part of codebase cl…
chrisdedman Mar 29, 2025
90eb445
:recycle: Refactor: Moved Syntax.h out of the syntax directory (remov…
chrisdedman Mar 29, 2025
b4e531f
:recycle: Refactor: Update include paths for Syntax.h to maintain con…
chrisdedman Mar 29, 2025
e6f30d5
:heavy_plus_sign: Add: Implement Syntax class for syntax highlighting…
chrisdedman Mar 29, 2025
ec1a7f9
:heavy_plus_sign: Add: Implement SyntaxManager class for managing syn…
chrisdedman Mar 29, 2025
b29b908
Update: Add libyaml-cpp-dev dependency for C++ environment setup in C…
chrisdedman Mar 29, 2025
6ce010f
Add: Specify 'runs-on' for docker job in CI workflow
chrisdedman Mar 29, 2025
2b211df
Update: Modify project installation step to avoid desktop shortcut on…
chrisdedman Mar 29, 2025
ba58bd2
Update: Remove redundant library linking for test executables in CMak…
chrisdedman Mar 29, 2025
51f84cc
Update: Simplify project installation step in CI workflow by removing…
chrisdedman Mar 29, 2025
195a4f9
Update: Remove explicit linking of yaml-cpp library for test_syntax e…
chrisdedman Mar 29, 2025
c3ec142
Update: Add Test CI badge to README for improved visibility of test s…
chrisdedman Mar 29, 2025
d753cb5
Update: Add color comments for syntax highlighting in YAML configurat…
chrisdedman Mar 29, 2025
0da7f7d
Update: Enhance markdown syntax highlighting configuration with addit…
chrisdedman Mar 29, 2025
ffae7e3
Update: Add comments to color definitions in YAML syntax highlighting…
chrisdedman Mar 29, 2025
87aad45
Update: Simplify project installation step in CI workflow by removing…
chrisdedman Mar 29, 2025
1950334
Update: Remove desktop shortcut creation and removal from installatio…
chrisdedman Mar 29, 2025
e1a0b8f
Update: Add Markdown and YAML to supported languages in syntax highli…
chrisdedman Mar 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y g++ make cmake
sudo apt-get install -y g++ make cmake libyaml-cpp-dev
g++ --version
cmake --version
make --version

- name: Set up C++ environment (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install make cmake
brew install make cmake yaml-cpp
echo 'export PATH="/usr/local/opt/gcc/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
g++ --version
Expand Down Expand Up @@ -83,15 +83,8 @@ jobs:
- name: Build project
run: make build

# Install the Project with desktop shortcut
- name: Install project (Mac/Windows)
if: matrix.os != 'ubuntu-latest'
# Install the Project
- name: Install project
run: |
cd ${{ github.workspace }}
echo "y" | make install

# Install the Project without desktop shortcut (Linux)
# This is a work around for Linux shortcut bug
- name: Install project (Linux)
if: matrix.os == 'ubuntu-latest'
run: echo "n" | make install
make install
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y g++ make cmake
sudo apt-get install -y g++ make cmake libyaml-cpp-dev
g++ --version
cmake --version
make --version

- name: Set up C++ environment (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install make cmake
brew install make cmake yaml-cpp
echo 'export PATH="/usr/local/opt/gcc/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
g++ --version
Expand Down Expand Up @@ -84,6 +84,7 @@ jobs:
run: make test

docker:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down
55 changes: 45 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Set default build output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR})

# Detect operating system
if(WIN32)
Expand Down Expand Up @@ -47,31 +48,59 @@ endif()
# Set Qt path for find_package
set(CMAKE_PREFIX_PATH ${Qt_DIR})

# Find Qt Widgets
find_package(Qt${QT_MAJOR_VERSION} COMPONENTS Widgets Test REQUIRED)
# Find Qt components
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Widgets Test)

# Locate yaml-cpp
if(APPLE)
set(yaml-cpp_DIR "/opt/homebrew/Cellar/yaml-cpp/0.8.0/lib/cmake/yaml-cpp")
endif()
find_package(yaml-cpp REQUIRED CONFIG)

# Copy YAML files to the build directory (non-macOS case)
set(YAML_SOURCE_DIR ${CMAKE_SOURCE_DIR}/config)
set(YAML_DEST_DIR ${CMAKE_BINARY_DIR}/config)
file(MAKE_DIRECTORY ${YAML_DEST_DIR})
file(GLOB YAML_FILES "${YAML_SOURCE_DIR}/*.yaml")

foreach(YAML_FILE ${YAML_FILES})
file(COPY ${YAML_FILE} DESTINATION ${YAML_DEST_DIR})
endforeach()

# Create the CodeAstra library
add_library(${TARGET_NAME}
src/MainWindow.cpp
src/CodeEditor.cpp
src/Syntax.cpp
src/Tree.cpp
src/FileManager.cpp
src/Syntax.cpp
src/SyntaxManager.cpp
include/MainWindow.h
include/CodeEditor.h
include/Syntax.h
include/Tree.h
include/LineNumberArea.h
include/FileManager.h
include/SyntaxManager.h
include/Syntax.h
)

# Link YAML-CPP to the CodeAstra library
target_link_libraries(${TARGET_NAME} PRIVATE yaml-cpp)

# Create the executable for the application
add_executable(${EXECUTABLE_NAME}
src/main.cpp
)
add_executable(${EXECUTABLE_NAME} src/main.cpp)

# Ensure YAML config files are copied into macOS app bundle
# if(APPLE)
# add_custom_command(TARGET ${EXECUTABLE_NAME} POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
# COMMAND ${CMAKE_COMMAND} -E copy_directory "${YAML_SOURCE_DIR}" "$<TARGET_BUNDLE_DIR:${EXECUTABLE_NAME}>/Contents/Resources/config"
# COMMENT "Copying YAML config files into macOS app bundle..."
# )
# endif()

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

# Add the tests subdirectory
add_subdirectory(tests)
Expand All @@ -85,7 +114,7 @@ if(MSVC)
target_compile_options(${EXECUTABLE_NAME} PRIVATE /W4 /WX)
elseif(APPLE)
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
# set_target_properties(${EXECUTABLE_NAME} PROPERTIES MACOSX_BUNDLE TRUE)
else()
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Wextra -pedantic -Werror)
endif()
Expand All @@ -103,4 +132,10 @@ set_target_properties(${EXECUTABLE_NAME} PROPERTIES
)

# Link necessary Qt libraries to CodeAstra library
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Widgets)
target_link_libraries(${TARGET_NAME} PRIVATE Qt${QT_MAJOR_VERSION}::Core Qt${QT_MAJOR_VERSION}::Widgets)

# Ensure correct linking of yaml-cpp (macOS)
if(APPLE)
target_include_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/include)
target_link_directories(${EXECUTABLE_NAME} PRIVATE /opt/homebrew/lib)
endif()
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ RUN apt-get install -y --no-install-recommends \
qt6-base-dev \
x11-utils \
x11-xserver-utils \
xvfb
xvfb \
libyaml-cpp-dev
RUN rm -rf /var/lib/apt/lists/*

# Copy CodeAstra into the container
Expand Down
50 changes: 2 additions & 48 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all: build install

# Run CMake to build the project
build:
@echo "Building project with CMake..."
@echo "Building $(PROJECT) with CMake..."
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && cmake $(CMAKE_OPTIONS)

Expand All @@ -21,59 +21,13 @@ clean:

# Uninstalling the software
uninstall: clean
@echo "Uninstalling the software..."
@echo "Uninstalling $(PROJECT)..."
@rm -rf $(EXECUTABLE).app $(EXECUTABLE)d.app
@OS_NAME=$(shell uname -s 2>/dev/null || echo "Windows"); \
if [ "$$OS_NAME" = "Darwin" ]; then \
rm -rf "$(HOME)/Desktop/$(EXECUTABLE).app"; \
echo "MacOS: Shortcut removed..."; \
elif [ "$$OS_NAME" = "Linux" ] && grep -qi "microsoft" /proc/version 2>/dev/null; then \
rm -rf "$(HOME)/Desktop/$(EXECUTABLE)"; \
echo "WSL: Shortcut removed..."; \
elif [ "$$OS_NAME" = "Linux" ]; then \
rm -rf "$(HOME)/Desktop/$(EXECUTABLE)"; \
echo "Linux: Shortcut removed..."; \
elif echo "$$OS_NAME" | grep -qE "CYGWIN|MINGW|MSYS"; then \
rm -f "$(USERPROFILE)/Desktop/$(EXECUTABLE).exe"; \
echo "Cygwin/Mingw/MSYS: Shortcut removed..."; \
elif [ "$$OS_NAME" = "Windows" ]; then \
if [ -n "$$USERPROFILE" ]; then \
cmd /c "if exist \"$$USERPROFILE\\Desktop\\$(EXECUTABLE).exe\" del /f /q \"$$USERPROFILE\\Desktop\\$(EXECUTABLE).exe\"" && echo "Windows: Shortcut removed..."; \
else \
echo "Windows: Could not determine user profile directory."; \
fi \
fi

# Install the project
install: build
@echo "Installing $(PROJECT)..."
@cd $(BUILD_DIR) && make
@echo "Do you want to create a shortcut on the desktop? (Y/n)"
@read choice; \
if [ "$$choice" = "y" ] || [ "$$choice" = "Y" ]; then \
echo "Creating shortcut..."; \
OS_NAME=$(shell uname -s); \
if [ "$$OS_NAME" = "Darwin" ]; then \
echo "MacOS Detected..."; \
cp -R $(EXECUTABLE).app ~/Desktop/; \
elif [ "$$OS_NAME" = "Linux" ] && grep -qi "microsoft" /proc/version 2>/dev/null; then \
echo "WSL Detected..."; \
cp $(EXECUTABLE) ~/Desktop/; \
elif [ "$$OS_NAME" = "Linux" ]; then \
echo "Linux Detected..."; \
cp $(EXECUTABLE) ~/Desktop/; \
elif echo "$$OS_NAME" | grep -qE "CYGWIN|MINGW|MSYS"; then \
echo "Windows-like Environment Detected (Cygwin/MSYS)..."; \
cp $(EXECUTABLE).exe "$$USERPROFILE/Desktop/"; \
elif [ "$$OS_NAME" = "Windows" ]; then \
echo "Native Windows Detected..."; \
if [ -n "$$USERPROFILE" ]; then \
cp $(EXECUTABLE).exe "$$USERPROFILE/Desktop/"; \
else \
echo "Windows: Could not determine user profile directory."; \
fi \
fi \
fi
@echo "$(PROJECT) installed."

build_tests: build
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

<!-- CodeAstra Latest Release Badge -->
<a href="https://github.com/sandbox-science/CodeAstra/releases">
Expand Down Expand Up @@ -51,6 +52,14 @@ Please, check the [wiki](https://github.com/sandbox-science/CodeAstra/wiki) for
- [ ] Create a new file ~ in progress
- [x] File tree navigation
- [ ] Syntax highlighting ~ in progress
- Supported Languagues:
- [x] Markdown (**foundation**)
- [x] YAML (**foundation**)
- [ ] C/C++ (**in progress**)
- [ ] Golang (**in progress**)
- [ ] Python (**Backlog**)
- [ ] Elixir (**Backlog**)
- more to come ... ([contribution welcomed](https://github.com/sandbox-science/CodeAstra/issues/4))
- [ ] Plugin system

## To-Do
Expand Down
38 changes: 38 additions & 0 deletions config/cpp.syntax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extensions: [cpp, c, h, hpp]

keywords:
keyword:
- 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"
color: "#003478" # Dark Blue
bold: "true"
- regex: "\\b(for|while|do|if|else)\\b"
color: "#D9001D" # Bright Red
- regex: "(?<!\\w)#include(?!\\w)"
color: "#800080" # Purple

comment:
- regex: "//[^\n]*"
color: "#336934" # Dark Green
italic: "true"

string:
- regex: "\"(\\\\.|[^\"\\\\])*\""
color: "#E37100" # Orange
- regex: "\\\\"
color: "#FFDE00" # Yellow

number:
- regex: "\\b\\d+\\b"
color: "#0000FF" # Blue

parenthesis:
- regex: "[()]"
color: "#6495ED" # Cornflower Blue

function:
- regex: "\\b(?!for\\b|if\\b|else\\b|while\\b|do\\b)[a-zA-Z_][a-zA-Z0-9_]*(?=\\s*\\()"
color: "#DBA800" # Golden Yellow

qualifiedName:
- regex: "\\b\\w+(?=\\s*::)"
color: "#309676" # Teal Green
14 changes: 14 additions & 0 deletions config/go.syntax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extensions: [go]

keywords:
comment:
- regex: "\"(\\\\.|[^\"\\\\])*\""
color: "#808080" # Gray

string:
- regex: "\"(\\\\.|[^\"\\\\])*\""
color: "#E37100" # Orange

number:
- regex: "\\b\\d+\\b"
color: "#0000FF" # Blue
47 changes: 47 additions & 0 deletions config/markdown.syntax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
extensions: [md]

keywords:
comment:
- regex: "#[^\n]*"
color: "#336934" # Dark Green
italic: "true"

heading:
- regex: "^#{1,6}\\s+.*"
color: "#003478" # Dark Blue
bold: "true"

bold:
- regex: "(?<!\\*)\\*\\*([^*]+)\\*\\*(?!\\*)|(?<!_)__([^_]+)__(?!_)"
color: "#D9001D" # Bright Red
bold: "true"

italic:
- regex: "(?<!\\*)\\*([^*]+)\\*(?!\\*)|(?<!_)_([^_]+)_(?!_)"
color: "#D97706" # Orange
italic: "true"

link:
- regex: "\\[([^\\]]+)\\]\\(([^\\)]+)\\)"
color: "#005FFF" # Bright Blue

inline_code:
- regex: "`([^`]+)`"
color: "#E37100" # Orange

list:
- regex: "^(\\s*[-+*]\\s+|\\s*\\d+\\.\\s+)"
color: "#309676" # Teal Green

blockquote:
- regex: "^>\\s+.*"
color: "#B48EAD" # Light Purple
italic: "true"

todo:
- regex: "- \\[ \\]"
color: "#FF8C00" # Orange for unchecked tasks
- regex: "- \\[x\\]"
color: "#32CD32" # Green for completed tasks
- regex: "(?<=\\[)[^\\]]*(?=\\])"
color: "#E37100"
24 changes: 24 additions & 0 deletions config/python.syntax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
extensions: [py]

keywords:
keyword:
- regex: "\\bimport\\b"
color: "#FF1493" # Deep Pink
- regex: "\\bdef\\b"
color: "#800080" # Purple
- regex: "\\bclass\\b"
color: "#008000" # Green
bold: "true"

comment:
- regex: "#[^\n]*"
color: "#808080" # Gray
italic: "true"

string:
- regex: "\"(\\\\.|[^\"\\\\])*\""
color: "#E37100" # Orange

number:
- regex: "\\b\\d+\\b"
color: "#0000FF" # Blue
Loading
Loading