Skip to content

Commit

Permalink
feat(syntax): basic syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
adamperkowski committed Feb 2, 2025
1 parent 9d0a93a commit bf524e9
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 10 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/emacs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: CI

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
push:
pull_request:
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v4
- uses: jcs090218/setup-emacs@master
with:
version: 29.4
- run: make .PHONY
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**/*~
**/\#*\#
**/*.out
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NAME = jule-mode

EMACS ?= emacs
JULEC = julec

.PHONY: all
40 changes: 30 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,63 @@
# Jule for Emacs
Official [Jule](https://github.com/julelang/jule) mode for Emacs.

> [!WARNING]
> The mode is in early development stage and may not work as expected.
> Please check out the [TODO](#todo) section and report any issues you encounter.
___

- [Features](#features)
- [Installation](#installation)
<!--
- [Configuration](#configuration)
- [Code formatting](#code-formatting)
-->
- [Development](#development)
- [Requirements](#requirements)
- [Setup](#setup)
- [Execution](#execution)
- [TODO](#todo)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

___

## Features
- Syntax highlighting
- Code formatting ([julefmt](https://github.com/julelang/julefmt))
- [x] Syntax highlighting (partial, see [TODO](#todo))
- [ ] Code formatting ([julefmt](https://github.com/julelang/julefmt))

## Installation
<!--
### MELPA
The package is available on [MELPA](https://melpa.org) and can be installed with:
```elisp
(setq package-archives '(("melpa" . "https://melpa.org/packages/")))
(package-initialize)
(package-refresh-contents)
```
<kbd>M-x</kbd> `package-install` <kbd>RET</kbd> `jule-mode` <kbd>RET</kbd>
-->

### Manual
1. Clone the repository:
```sh
git clone https://github.com/julelang/jule-mode.el.git
```
2. Add the following to your Emacs configuration:
```elisp
(add-to-list 'load-path "/path/to/jule-mode.el")
(require 'jule-mode)
```

<!--
## Configuration
### Code formatting
-->

## Development
### Requirements

### Setup

### Execution
### TODO
- string escape sequences highlighting
- comments highlighting
- operator highlighting
- delimiter highlighting

## Code of Conduct
See the [Julenour Code of Conduct](https://jule.dev/code-of-conduct)
Expand Down
Empty file added jule-julefmt.el
Empty file.
90 changes: 90 additions & 0 deletions jule-mode.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

;;; jule-mode.el --- Official Jule mode for Emacs

;; Author: Adam Perkowski <adas1per@protonmail.com>
;; Version: 0.0.1
;; Keywords: languages
;; URL: https://github.com/julelang/jule-mode.el
;; Package-Requires: ((emacs "29.4"))

;; This file is distributed under the terms of the BSD 3-Clause License.
;; See the LICENSE file for details.
;; It is not part of GNU Emacs.

;;; Commentary:

;; This package provides a major mode for editing Jule code.

;;; Code:
(defconst jule-keywords
'("chan" "map" "error" "use" "fn" "struct" "byte" "rune" "enum" "unsafe"
"let" "match" "defer" "if" "else" "for" "in" "impl" "trait" "break"
"continue" "goto" "cpp" "type" "ret" "fall" "co" "let" "select"))

(defconst jule-types
'("int" "uint" "uintptr" "i8" "i16" "i32" "i64" "u8" "u16" "u32" "u64" "f32" "f64" "bool" "str" "any" "byte" "rune"))

(defconst jule-storage
'("static" "const" "mut" "self"))

(defconst jule-constants
'("true" "false" "nil"))

(defvar jule-font-lock-keywords
(append
`(
;; directives (e.g. `#pass`)
;; regex: a `#` followed by a sequence of word characters
(,(rx bol "#" (1+ word)) . font-lock-preprocessor-face)

;; code keywords
(,(regexp-opt jule-keywords 'symbols) . font-lock-keyword-face)

;; type keywords
(,(regexp-opt jule-types 'symbols) . font-lock-type-face)

;; storage keywords
(,(regexp-opt jule-storage 'symbols) . font-lock-keyword-face)

;; constants
(,(regexp-opt jule-constants 'symbols) . font-lock-constant-face)

;; function names
;; regex: a word followed by either `(` or `[`, but not including `(` or `[`
(,(rx word-start (group (1+ word)) word-end (0+ space) "(") 1 font-lock-function-name-face)
(,(rx word-start (group (1+ word)) (0+ space) "[" (0+ nonl) "]" (0+ space) "(") 1 font-lock-function-name-face)

;; numbers
;; regex: regex: a sequence of 0 or 1 digits starting with `0b`, possibly separated by `_`
(,(rx word-start "0b" (group (1+ (or "0" "1" "_"))) word-end) . font-lock-constant-face)
;; regex: regex: a sequence of 0-7 digits starting with `0o`, possibly separated by `_`
(,(rx word-start "0o" (group (1+ (or (any "0-7") "_"))) word-end) . font-lock-constant-face)
;; regex: a sequence of 0-9 digits and letters `a-f` or `A-F` starting with `0x`
(,(rx word-start "0x" (group (1+ (or (or any "0-9" "a-f" "A-F") "_"))) word-end) . font-lock-constant-face)
;; regex: a sequence of digits, possibly separated by `_`, followed by a dot,
;; followed by a sequence of digits, possibly separated by `_`, followed by an
;; optional exponent (e.g. `123.456`, `123_456.789`, `123.456e789`, `123.456e+789`)
(,(rx word-start
(group (1+ (or digit "_")) (opt (seq "." (1+ (or digit "_")))))
(opt (seq (any "eE") (opt (any "-+")) (1+ digit)))
word-end)
. font-lock-constant-face)

;; strings
;; regex: a sequence of characters enclosed in single quotes
(,(rx "'" (group (0+ (not (any "'")))) "'") . font-lock-string-face)
;; regex: a sequence of characters enclosed in double quotes
(,(rx "\"" (group (0+ (not (any "\"")))) "\"") . font-lock-string-face)
;; regex: a sequence of characters enclosed in backticks
(,(rx "`" (group (0+ (not (any "`")))) "`") . font-lock-string-face)
)))

(define-derived-mode jule-mode prog-mode "jule"
"Major mode for editing Jule code."
(setq indent-tabs-mode t)
(setq font-lock-defaults '(jule-font-lock-keywords)))

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.jule\\'" . jule-mode))

(provide 'jule-mode)
Empty file added test/project/jule.mod
Empty file.
27 changes: 27 additions & 0 deletions test/project/main.jule
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* this file tests the syntax highlighting */

#pass "-v" // this is a comment :)

const TEST_DATA: str = "test data"
const _0 = "test data\n"
const _1 = 'h'
const _2 = `world\n`

// number tests
const _3 = 123
const _4 = 123.456
const _5 = 123_456
const _6 = 123_456.789e012
const _7 = 0b0101
const _8 = 0b0101_01
const _9 = 0o123
const _10 = 0o123_456
const _11 = 0xfff
const _12 = 0xfff_0a1

fn main() {
thoseGuys(TEST_DATA)
println(TEST_DATA)
}

fn thoseGuys[T](test: T) {}

0 comments on commit bf524e9

Please sign in to comment.