From 1fd9186428b9e9ef7412c91cb1e882b0c62d9d73 Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Fri, 15 Feb 2019 09:48:47 +0100 Subject: [PATCH 1/3] emacs: initial ql-mode-base.el --- misc/emacs/README.md | 16 +++++++++ misc/emacs/ql-mode-base.el | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 misc/emacs/README.md create mode 100644 misc/emacs/ql-mode-base.el diff --git a/misc/emacs/README.md b/misc/emacs/README.md new file mode 100644 index 000000000000..1b0c5b54f7f0 --- /dev/null +++ b/misc/emacs/README.md @@ -0,0 +1,16 @@ +# QL syntax highlighting and file-type detection for Emacs + +To install, add this directory to the `load-path` and add load the mode in the Emacs init file. + +Example: + +```elisp +; ~/.emacs, ~/.emacs.el, or ~/.emacs.d/init.el + +; ... + +(add-to-list 'load-path "~/ql/misc/emacs") +(require 'ql-mode-base) + +; ... +``` diff --git a/misc/emacs/ql-mode-base.el b/misc/emacs/ql-mode-base.el new file mode 100644 index 000000000000..3f9ea4bba3f2 --- /dev/null +++ b/misc/emacs/ql-mode-base.el @@ -0,0 +1,74 @@ +;;; ql-mode-base.el --- A major mode for editing QL files + +;;; Commentary: +;; +;; A basic major mode for editing QL files, a more advanced major +;; mode is available for internal use at Semmle. +;; +;; Provides syntax highlightning, comment support, and a mode-specific +;; keymap. + +;;; Code: + +(defconst ql--at-type-regex "\\_<@\\w+\\>") +(defconst ql--predicate-regex "\\(\\_<\\w+\\(\\+\\|\\*\\)?\\_>\\)\\s-*(") +(defconst ql--primitive-type-regex (regexp-opt '("int" "string" "float" "boolean" "date") 'symbols)) +(defconst ql--annotation-regex (regexp-opt '("abstract" "cached" "external" "final" "transient" "library" "private" "deprecated" "override" "query" "language" "bindingset") 'words)) +(defconst ql--pragma-regex "\\ " (syntax-table)) + ;; /* Comments (style b) */ + (modify-syntax-entry ?* ". 23b" (syntax-table)) + (modify-syntax-entry ?@ "_" (syntax-table)) + + (set (make-local-variable 'comment-start) "//") + (set (make-local-variable 'comment-start-skip) "// ") + + (run-hooks 'ql-mode-base-hook) + + )) + "A basic major mode for QL files") + +(provide 'ql-mode-base) +;;; ql-mode-base.el ends here From 046c8c963f761395099361354af40f2da0fdafbc Mon Sep 17 00:00:00 2001 From: Esben Sparre Andreasen Date: Fri, 15 Feb 2019 11:35:18 +0100 Subject: [PATCH 2/3] emacs: generalize parameterized annotation highlightning --- misc/emacs/ql-mode-base.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/emacs/ql-mode-base.el b/misc/emacs/ql-mode-base.el index 3f9ea4bba3f2..8d0612d30fab 100644 --- a/misc/emacs/ql-mode-base.el +++ b/misc/emacs/ql-mode-base.el @@ -13,8 +13,8 @@ (defconst ql--at-type-regex "\\_<@\\w+\\>") (defconst ql--predicate-regex "\\(\\_<\\w+\\(\\+\\|\\*\\)?\\_>\\)\\s-*(") (defconst ql--primitive-type-regex (regexp-opt '("int" "string" "float" "boolean" "date") 'symbols)) -(defconst ql--annotation-regex (regexp-opt '("abstract" "cached" "external" "final" "transient" "library" "private" "deprecated" "override" "query" "language" "bindingset") 'words)) -(defconst ql--pragma-regex "\\ Date: Fri, 15 Feb 2019 12:45:36 +0100 Subject: [PATCH 3/3] emacs: restrict parameterized annotation highlightning --- misc/emacs/ql-mode-base.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/emacs/ql-mode-base.el b/misc/emacs/ql-mode-base.el index 8d0612d30fab..1fabf6953e5d 100644 --- a/misc/emacs/ql-mode-base.el +++ b/misc/emacs/ql-mode-base.el @@ -13,8 +13,8 @@ (defconst ql--at-type-regex "\\_<@\\w+\\>") (defconst ql--predicate-regex "\\(\\_<\\w+\\(\\+\\|\\*\\)?\\_>\\)\\s-*(") (defconst ql--primitive-type-regex (regexp-opt '("int" "string" "float" "boolean" "date") 'symbols)) -(defconst ql--annotation-regex (regexp-opt '("abstract" "cached" "external" "final" "transient" "library" "private" "deprecated" "override" "query") 'words)) -(defconst ql--parameterized-annotation-regex "\\<\\(pragma\\|language\\|bindingset\\) *\\[ *[a-z, ]*\\]") +(defconst ql--annotation-regex (regexp-opt '("abstract" "cached" "external" "final" "transient" "library" "private" "deprecated" "override" "query" "pragma" "language" "bindingset") 'words)) +(defconst ql--annotation-arg-regex (regexp-opt '("inline" "noinline" "nomagic" "noopt" "monotonicAggregates") 'words)) (defconst ql--keywords '("and" "any" "as" "asc" "avg" "boolean" "by" "class" "concat" "count" "date" "desc" "else" "exists" "extends" "false" "float" "forall" "forex" "from" "if" "implies" "import" "in" "instanceof" "int" "max" "min" "module" "not" "none" "or" "order" "predicate" "rank" "result" "select" "strictconcat" "strictcount" "strictsum" "string" "sum" "super" "then" "this" "true" "where" ) @@ -25,7 +25,7 @@ (,ql--primitive-type-regex . 'font-lock-type-face) (,ql--at-type-regex 0 'font-lock-type-face) (,ql--annotation-regex . 'font-lock-preprocessor-face) - (,ql--parameterized-annotation-regex . 'font-lock-preprocessor-face)) + (,ql--annotation-arg-regex . 'font-lock-keyword-face)) ) (defvar ql-mode-base-map