Skip to content

Kab1r/elsa-lambda-calculus-mode

Repository files navigation

Major Mode for Elsa

Overview

This major-mode implements syntax highlighting for Elsa, a tiny lambda calculus language and evaluator.

Header

;;; elsa-lambda-calculus-mode.el --- Major Mode for Elsa

;; Copyright (C) 2022 Kabir Kwatra
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU Affero General Public License as
;; published by the Free Software Foundation, either version 3 of the
;; License, or (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;; Author: Kabir Kwatra <kabir@kwatra.me>
;; Keywords: languages, lambda, calculus, elsa
;; License: AGPL-3.0-only
;; Version: 1.0
;; URL: https://github.com/Kab1r/elsa-lambda-calculus-mode

Commentary

;;; Commentary:

;; This is a major mode implements syntax highlighting for Elsa:
;; a lambda calculus evaluator.

Code

;;; Code:

Regular Expressions

(defconst elsa-lambda-calculus-keywords-regexp  (regexp-opt '("let" "eval" ":" "\\")))
(defconst elsa-lambda-calculus-comments-regexp  "--.*$")
(defconst elsa-lambda-calculus-step-regexp "=[abd*~]\>")
(defconst elsa-lambda-calculus-operators-regexp (regexp-opt '("\=" "-\>")))
(defconst elsa-lambda-calculus-variables-regexp "[a-z]+?[0-9]*?_?[a-z]?[0-9]*")
(defconst elsa-lambda-calculus-constants-regexp "[A-Z0-9]+")

(defconst elsa-lambda-calculus-font-lock-keywords
      `((,elsa-lambda-calculus-comments-regexp  . font-lock-comment-face)
        (,elsa-lambda-calculus-keywords-regexp  . font-lock-keyword-face)
        (,elsa-lambda-calculus-step-regexp      . font-lock-keyword-face)
        (,elsa-lambda-calculus-variables-regexp . font-lock-variable-name-face)
        (,elsa-lambda-calculus-constants-regexp . font-lock-constant-face)
        (,elsa-lambda-calculus-operators-regexp . font-lock-keyword-face)))

Define Major Mode

;;;###autoload
(define-derived-mode elsa-lambda-calculus-mode
  prog-mode
  "Elsa"
  "Major Mode for the tiny lambda calculus evaluator."

  (setq font-lock-defaults '((elsa-lambda-calculus-font-lock-keywords))))

Auto-load Major Mode for .lc Files

;;;###autoload
(add-to-list 'auto-mode-alist '("\\.lc\\'" . elsa-lambda-calculus-mode))

(provide 'elsa-lambda-calculus-mode)

Footer

;; Local Variables:
;; coding: utf-8
;; End:

;;; elsa-lambda-calculus-mode.el ends here