<commit_before>;;; futhark-mode.el --- major mode for editing Futhark source files

;; Copyright (C) DIKU 2013-2016, University of Copenhagen
;;   Written by <NAME> (<EMAIL>) in 2013.
;;   Improved by <NAME> (<EMAIL>) in 2014.
;;   Improved by <NAME> in 2015.
;;   Improved by <NAME> again in 2016.

;;; Commentary:
;; This mode provides syntax highlighting and automatic indentation for
;; Futhark source files.  There is sadly yet no automatic recompilation
;; or interactive environment, mostly because there is no good futharki
;; yet.
;;
;; This mode provides the following features for Futhark source files:
;;
;;   + syntax highlighting
;;   + automatic indentation
;;   + experimental flycheck support (currently disabled)
;;
;; To load futhark-mode automatically on Emacs startup, put this file in
;; your load path and require the mode, e.g. something like this:
;;
;;   (add-to-list 'load-path "~/.emacs.d/futhark-mode")
;;   (require 'futhark-mode)
;;
;; In this case, you have to create the directory
;; "~/.emacs.d/futhark-mode" and store this file in that directory.
;;
;; This will also tell your Emacs that ".fut" files are to be handled by
;; futhark-mode.
;;
;; Define your local keybindings in `futhark-mode-map', and add startup
;; functions to `futhark-mode-hook'.


;;; Code:

;;;; Basics.

(require 'cl) ; incf, some

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

(defvar futhark-mode-hook nil
  "Hook for futhark-mode.  Is run whenever the mode is entered.")

(defvar futhark-mode-map
  (make-keymap)
  "Keymap for futhark-mode.")

(defconst futhark-keywords
  '("if" "then" "else" "let" "loop" "in" "with" "type"
    "fun" "entry" "fn" "for" "while" "do" "do" "op" "not"
    "empty" "unsafe" "default" "include")
  "All Futhark keywords.")

(defconst futhark-builtin-functions
  '("pow" "iota" "shape" "replicate" "reshape" "transpose" "map"
    "reduce" "reduceComm" "zip" "unzip" "zipWith" "scan" "split"
    "concat" "filter" "partition" "redomap" "empty" "copy" "size"
    "write")
  "All Futhark builtin SOACs, functions, and non-symbolic operators.")

(defconst futhark-builtin-operators
  '("+" "*" "-" "/" "%" "//" "%%" "==" "!=" "<" "<=" "**" "^" "&"
    "|" ">>" "<<" ">>>")
  "All Futhark builtin symbolic operators.")

(defconst futhark-builtin-types
  '("i8" "i16" "i32" "i64"
    "u8" "u16" "u32" "u64"
    "f32" "f64"
    "int" "real" "bool")
  "A list of Futhark types.")

(defconst futhark-booleans
  '("True" "False")
  "All Futhark booleans.")

(defconst futhark-var
  "[_'[:alnum:]]+"
  "A regex describing a Futhark variable.")

(defconst futhark-type
  (concat "\\(?:\\(?:\\[[^]]+\\]\\)\\|\\(?:{[^}]+}\\)\\|" futhark-var "\\)")
  "A regex describing a Futhark type, built-in or user-specified.
Does not recognise nested tuples or nested arrays.")


;;; Highlighting

(defvar futhark-font-lock
  `(

    ;; Function declarations
    (,(concat "fun[[:space:]\n]+" futhark-type
              "[[:space:]\n]+\\(" futhark-var "\\)")
     . '(1 font-lock-function-name-face))

    ;; Variable and tuple declarations
    (,(concat "let[[:space:]\n]+\\(" futhark-var "\\)")
     . '(1 font-lock-variable-name-face))
    (,(concat "let[[:space:]\n]+{\\([^}]+\\)")
     . '(1 font-lock-variable-name-face))

    ;; Keywords
    (,(regexp-opt futhark-keywords 'words)
     . font-lock-keyword-face)

    ;; Types
    (,(regexp-opt futhark-builtin-types 'words)
     . font-lock-type-face)

    ;; Builtins<commit_msg>Update futhark-mode.el to the new tuple syntax.<commit_after>;;; futhark-mode.el --- major mode for editing Futhark source files

;; Copyright (C) DIKU 2013-2016, University of Copenhagen
;;   Written by <NAME> (<EMAIL>) in 2013.
;;   Improved by <NAME> (<EMAIL>) in 2014.
;;   Improved by <NAME> in 2015.
;;   Improved by <NAME> again in 2016.

;;; Commentary:
;; This mode provides syntax highlighting and automatic indentation for
;; Futhark source files.  There is sadly yet no automatic recompilation
;; or interactive environment, mostly because there is no good futharki
;; yet.
;;
;; This mode provides the following features for Futhark source files:
;;
;;   + syntax highlighting
;;   + automatic indentation
;;   + experimental flycheck support (currently disabled)
;;
;; To load futhark-mode automatically on Emacs startup, put this file in
;; your load path and require the mode, e.g. something like this:
;;
;;   (add-to-list 'load-path "~/.emacs.d/futhark-mode")
;;   (require 'futhark-mode)
;;
;; In this case, you have to create the directory
;; "~/.emacs.d/futhark-mode" and store this file in that directory.
;;
;; This will also tell your Emacs that ".fut" files are to be handled by
;; futhark-mode.
;;
;; Define your local keybindings in `futhark-mode-map', and add startup
;; functions to `futhark-mode-hook'.


;;; Code:

;;;; Basics.

(require 'cl) ; incf, some

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

(defvar futhark-mode-hook nil
  "Hook for futhark-mode.  Is run whenever the mode is entered.")

(defvar futhark-mode-map
  (make-keymap)
  "Keymap for futhark-mode.")

(defconst futhark-keywords
  '("if" "then" "else" "let" "loop" "in" "with" "type"
    "fun" "entry" "fn" "for" "while" "do" "do" "op" "not"
    "empty" "unsafe" "default" "include")
  "All Futhark keywords.")

(defconst futhark-builtin-functions
  '("pow" "iota" "shape" "replicate" "reshape" "transpose" "map"
    "reduce" "reduceComm" "zip" "unzip" "zipWith" "scan" "split"
    "concat" "filter" "partition" "redomap" "empty" "copy" "size"
    "write")
  "All Futhark builtin SOACs, functions, and non-symbolic operators.")

(defconst futhark-builtin-operators
  '("+" "*" "-" "/" "%" "//" "%%" "==" "!=" "<" "<=" "**" "^" "&"
    "|" ">>" "<<" ">>>")
  "All Futhark builtin symbolic operators.")

(defconst futhark-builtin-types
  '("i8" "i16" "i32" "i64"
    "u8" "u16" "u32" "u64"
    "f32" "f64"
    "int" "real" "bool")
  "A list of Futhark types.")

(defconst futhark-booleans
  '("True" "False")
  "All Futhark booleans.")

(defconst futhark-var
  "[_'[:alnum:]]+"
  "A regex describing a Futhark variable.")

(defconst futhark-type
  (concat "\\(?:\\(?:\\[[^]]+\\]\\)\\|\\(?:([^)]+)\\)\\|" futhark-var "\\)")
  "A regex describing a Futhark type, built-in or user-specified.
Does not recognise nested tuples or nested arrays.")


;;; Highlighting

(defvar futhark-font-lock
  `(

    ;; Function declarations
    (,(concat "fun[[:space:]\n]+" futhark-type
              "[[:space:]\n]+\\(" futhark-var "\\)")
     . '(1 font-lock-function-name-face))

    ;; Variable and tuple declarations
    (,(concat "let[[:space:]\n]+\\(" futhark-var "\\)")
     . '(1 font-lock-variable-name-face))
    (,(concat "let[[:space:]\n]+(\\([^)]+\\)")
     . '(1 font-lock-variable-name-face))

    ;; Keywords
    (,(regexp-opt futhark-keywords 'words)
     . font-lock-keyword-face)

    ;; Types
    (,(regexp-opt futhark-builtin-types 'words)
     . font-lock-type-face)

    ;; Builtins
{'fraction_non_alphanumeric': 0.1951741861793261, 'fraction_numerical': 0.012849800114220445, 'mean_word_length': 3.5193548387096776, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3999741', 'n_tokens_mistral': 2662, 'n_tokens_neox': 2530, 'n_words': 701}