(defvar awk-mode-syntax-table
(let ((st (make-syntax-table)))
(modify-syntax-entry ?\\ "\\" st)
(modify-syntax-entry ?\n "> " st)
(modify-syntax-entry ?\f "> " st)
(modify-syntax-entry ?\# "< " st)
(modify-syntax-entry ?/ "\"" st)
(modify-syntax-entry ?* "." st)
(modify-syntax-entry ?+ "." st)
(modify-syntax-entry ?- "." st)
(modify-syntax-entry ?= "." st)
(modify-syntax-entry ?% "." st)
(modify-syntax-entry ?< "." st)
(modify-syntax-entry ?> "." st)
(modify-syntax-entry ?& "." st)
(modify-syntax-entry ?| "." st)
(modify-syntax-entry ?_ "_" st)
(modify-syntax-entry ?\' "\"" st)
st)
"Syntax table in use in `awk-mode' buffers.")
(defconst awk-font-lock-keywords
(eval-when-compile
(list
'("^[ \t]*\\(function\\)\\>[ \t]*\\(\\sw+\\)?"
(1 font-lock-keyword-face) (2 font-lock-function-name-face nil t))
(cons (regexp-opt
'("ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO"
"FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR"
"OFMT" "OFS" "ORS" "RLENGTH" "RS" "RSTART" "SUBSEP") 'words)
'font-lock-variable-name-face)
(regexp-opt
'("BEGIN" "END" "break" "continue" "delete" "do" "exit" "else" "for"
"getline" "if" "next" "print" "printf" "return" "while") 'words)
(list (regexp-opt
'("atan2" "close" "cos" "ctime" "exp" "gsub" "index" "int"
"length" "log" "match" "rand" "sin" "split" "sprintf"
"sqrt" "srand" "sub" "substr" "system" "time"
"tolower" "toupper") 'words)
1 'font-lock-builtin-face)
(cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
'font-lock-constant-face)
))
"Default expressions to highlight in AWK mode.")
(require 'syntax)
(defconst awk-font-lock-syntactic-keywords
'(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)"
(1 (unless (nth 3 (syntax-ppss (match-beginning 1))) "."))))
"Syntactic keywords for `awk-mode'.")
(define-derived-mode awk-mode c-mode "AWK"
"Major mode for editing AWK code.
This is much like C mode except for the syntax of comments. Its keymap
inherits from C mode's and it has the same variables for customizing
indentation. It has its own abbrev table and its own syntax table.
Turning on AWK mode runs `awk-mode-hook'."
(set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
(set (make-local-variable 'paragraph-separate) paragraph-start)
(set (make-local-variable 'comment-start) "# ")
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'comment-start-skip) "#+ *")
(setq font-lock-defaults '(awk-font-lock-keywords
nil nil ((?_ . "w")) nil
(parse-sexp-lookup-properties . t)
(font-lock-syntactic-keywords
. awk-font-lock-syntactic-keywords))))
(provide 'awk-mode)