fix comments, add new keywords

This commit is contained in:
zongor 2025-10-17 12:55:26 -07:00
parent bfec1109a8
commit e5e235f95c
1 changed files with 101 additions and 95 deletions

52
undar-mode.el Normal file → Executable file
View File

@ -17,17 +17,17 @@
(defvar undar-keywords
'("function" "to" "in" "is" "as" "use" "if" "else" "default"
"for" "try" "catch" "while" "do" "exit" "switch"
"return" "const" "type" "this" "yield" "case"
"assert" "break" "mod" "not" "and" "or" "print" "let"
"band" "bor" "bxor" "srl" "sll")
"for" "try" "catch" "while" "do" "exit" "switch" "continue"
"return" "const" "type" "this" "yield" "case" "loop" "plex"
"assert" "break" "mod" "not" "and" "or" "print" "ref" "interface"
"implements" "impls" "band" "bor" "bxor" "srl" "sll")
"Keywords in Undar.")
(defvar undar-types
'("byte" "str" "real" "bool"
"int" "nat" "f32" "f64"
"u8" "u16" "u32" "u64"
"i8" "i16" "i32" "i64")
"int" "nat" "f32" "void"
"u8" "u16" "u32"
"i8" "i16" "i32")
"Types in Undar.")
(defvar undar-constants
@ -48,44 +48,50 @@
;; Structs: CamelCase identifiers
("\\b[A-Z][a-zA-Z0-9_]*\\b" . font-lock-type-face)
;; Function definitions: "fn name(...)"
("\\_<function\\>\\s-+\\(\\w+\\)(" (1 font-lock-function-name-face))
;; Function definitions: "function name(...)"
("\\_<function\\>\\s-+\\([\\w+\\)(" (1 font-lock-function-name-face))
;; Function calls: "name(...)"
("\\_<\\([a-zA-Z_][a-zA-Z0-9_]*\\)\\s-*(" (1 font-lock-function-name-face))
;; Floating point numbers
("\\b-?[0-9]+\\.[0-9]+\\b" . font-lock-constant-face)
;; Integers
("\\b-?[0-9]+\\b" . font-lock-constant-face)
;; Numbers (Integers and Floats)
("\\b-?[0-9]+\\(?:\\.[0-9]+\\)?\\(?:[eE][+-]?[0-9]+\\)?\\b" . font-lock-constant-face)
;; Strings with double quotes
("\"[^\"\n]*\"" . font-lock-string-face)
;; Strings with backticks
("`[^`]*`" . font-lock-string-face))
("`[^`\n]*`" . font-lock-string-face))
"Font lock keywords for Undar mode.")
(defvar undar-mode-syntax-table
(let ((st (make-syntax-table)))
;; '/' starts a comment
(modify-syntax-entry ?! "<" st)
;; C-style comments: // and /* */
;; Clear potential existing syntax for / and * if needed (though default is usually fine initially)
;; Clearing standard C++/C comment syntax if it was somehow set beforehand is generally not needed
;; unless explicitly overridden elsewhere, so we rely on the default being clean.
;; The crucial setup for both // and /* */ comments together:
;; / is punctuation and starts both // (1, 2) and /* (4) comments
(modify-syntax-entry ?\/ ". 124" st)
;; * is punctuation and part of /* */ (2, 3) and also part of // (b) comments (this is key for //)
(modify-syntax-entry ?* ". 23b" st)
;; Newline ends comments (>) and is part of // comments (b) - essential for // to end correctly
(modify-syntax-entry ?\n ">" st)
;; Strings
(modify-syntax-entry ?\" "\"" st)
(modify-syntax-entry ?` "\"" st)
st)
"Syntax table for Undar mode.")
"Syntax table for Undar mode, using C-style comments (// and /* */).")
(define-derived-mode undar-mode prog-mode "Undâr"
"Major mode for editing Undar code."
:syntax-table undar-mode-syntax-table
(setq-local font-lock-defaults '(undar-font-lock-keywords))
(setq-local comment-start "! ")
;; Set comment syntax for commands like M-; (comment-dwim)
(setq-local comment-start "// ")
(setq-local comment-end "")
(setq-local comment-start-skip "\\(//+\\|/\\*+\\)\\s *")
;; Ensure comments are ignored during parsing (e.g., for indentation)
(setq-local parse-sexp-ignore-comments t)
;; Use C-style indentation function
(setq-local indent-line-function 'c-indent-line))
;;;###autoload