Skip to content

Instantly share code, notes, and snippets.

@jstaursky
Last active December 3, 2021 04:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jstaursky/0a6cfe7ef5a6871c36a044f8edd23b7b to your computer and use it in GitHub Desktop.
Save jstaursky/0a6cfe7ef5a6871c36a044f8edd23b7b to your computer and use it in GitHub Desktop.
;; Adapted from https://github.com/rurban/picat-lang/blob/master/picat-mode.el
;; mostly the same but this one works..
;;
(eval-when-compile
(require 'generic)
(require 'font-lock)
(require 'regexp-opt))
(defmacro picat-match-symbol (&rest symbols)
"Convert a word-list into a font-lock regexp."
(concat "\\_<" (regexp-opt symbols t) "\\_>"))
(setf picat-keywords '("in" "not" "fail" "pass" "true" "false"))
;;;###autoload
(define-generic-mode picat-mode
'("%" ("/*" . "*/")) ;comments
picat-keywords
`( ;font-lock-list
;; block delimiters
("[.:]" . font-lock-preprocessor-face)
;; arrays, structs
("\\[\\|\\]\\|\{\\|\}" . font-lock-warning-face)
(,(concat
;; one-char operators
"[,()|?=+~*%<>=!&^-]"
;; multi-char operators
"\\|\\("
"\\+\\+\\|--\\|\\*\\*\\|<<\\|>>\\|<=\\|>=\\|==\\|!=\\|=>\\|<=>\\|&&\\|||"
"\\)")
. font-lock-builtin-face)
;; slash is magical
("\\(/\\) " 1 font-lock-builtin-face)
;; numeric constants
("\\_<[0-9]+\\(\\.[0-9]*\\)?\\([Ee][+-]?[0-9]+\\)?\\_>" . font-lock-constant-face)
("0x[a-fA-F0-9]+" . font-lock-constant-face)
;; attributes
;("/\\(?:\\sw\\|\\s_\\)+\\_>" . font-lock-variable-name-face)
;; control constructs
(,(picat-match-symbol
"if" "then" "elseif" "else" "end" "loop" "while" "in" "foreach" "..")
. font-lock-keyword-face)
;; core functions (XXX some overlap with operators)
(,(picat-match-symbol
"%" "*" "**" "+" "+" "-" "/" "<<" ">>" "abs" "append" "apply" "arity"
"attr" "call" "chr" "clone" "close" "code" "compile"
"eval" "exit" "first" "float" "here" "integer"
"join" "last" "length" "import" "length" "list" "load"
"name" "new_struct" "new_array" "new_map"
"number" "ord" "pop" "print" "println" "push" "put" "rand" "read"
"remove" "reverse" "self" "send" "slice" "sqrt" "srand" "string"
"text" "to" "tree" "write" "~") . font-lock-builtin-face)
)
'("\\.pi$") ;file extension
'((lambda () ;other setup work
(modify-syntax-entry ?' "\"")
(modify-syntax-entry ?: "(.")
(modify-syntax-entry ?\. "):"))
;; Setup extremely primitive indentation (less annoying than default 'indent-relative).
(lambda ()
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
)
)
"Major mode for editing picat-lang."
)
(provide 'picat-mode)
@jstaursky
Copy link
Author

If you use spacemacs, you probably will have trouble with adding local packages easily (this is not on melpa). I get around this by adding the following to my init.el,

  (use-package picat-mode
    :load-path "~/.spacemacs.d/local-packages/picat-mode"
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment