comparison lisp/progmodes/awk-mode.el @ 39833:c6e48d7cdb07

(awk-mode-syntax-table): / has string syntax. (awk-font-lock-syntactic-keywords): New var. (awk-mode): Use it.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 12 Oct 2001 17:29:30 +0000
parents 19d92160ddac
children
comparison
equal deleted inserted replaced
39832:83fb14b6775e 39833:c6e48d7cdb07
27 ;; Sets up C-mode with support for awk-style #-comments and a lightly 27 ;; Sets up C-mode with support for awk-style #-comments and a lightly
28 ;; hacked syntax table. 28 ;; hacked syntax table.
29 29
30 ;;; Code: 30 ;;; Code:
31 31
32 (defvar awk-mode-syntax-table nil 32 (defvar awk-mode-syntax-table
33 "Syntax table in use in Awk-mode buffers.") 33 (let ((st (make-syntax-table)))
34 34 (modify-syntax-entry ?\\ "\\" st)
35 (if awk-mode-syntax-table 35 (modify-syntax-entry ?\n "> " st)
36 () 36 (modify-syntax-entry ?\f "> " st)
37 (setq awk-mode-syntax-table (make-syntax-table)) 37 (modify-syntax-entry ?\# "< " st)
38 (modify-syntax-entry ?\\ "\\" awk-mode-syntax-table) 38 ;; / can delimit regexes or be a division operator. We assume that it is
39 (modify-syntax-entry ?\n "> " awk-mode-syntax-table) 39 ;; more commonly used for regexes and fix the remaining cases with
40 (modify-syntax-entry ?\f "> " awk-mode-syntax-table) 40 ;; `font-lock-syntactic-keywords'.
41 (modify-syntax-entry ?\# "< " awk-mode-syntax-table) 41 (modify-syntax-entry ?/ "\"" st)
42 (modify-syntax-entry ?/ "." awk-mode-syntax-table) 42 (modify-syntax-entry ?* "." st)
43 (modify-syntax-entry ?* "." awk-mode-syntax-table) 43 (modify-syntax-entry ?+ "." st)
44 (modify-syntax-entry ?+ "." awk-mode-syntax-table) 44 (modify-syntax-entry ?- "." st)
45 (modify-syntax-entry ?- "." awk-mode-syntax-table) 45 (modify-syntax-entry ?= "." st)
46 (modify-syntax-entry ?= "." awk-mode-syntax-table) 46 (modify-syntax-entry ?% "." st)
47 (modify-syntax-entry ?% "." awk-mode-syntax-table) 47 (modify-syntax-entry ?< "." st)
48 (modify-syntax-entry ?< "." awk-mode-syntax-table) 48 (modify-syntax-entry ?> "." st)
49 (modify-syntax-entry ?> "." awk-mode-syntax-table) 49 (modify-syntax-entry ?& "." st)
50 (modify-syntax-entry ?& "." awk-mode-syntax-table) 50 (modify-syntax-entry ?| "." st)
51 (modify-syntax-entry ?| "." awk-mode-syntax-table) 51 (modify-syntax-entry ?_ "_" st)
52 (modify-syntax-entry ?_ "_" awk-mode-syntax-table) 52 (modify-syntax-entry ?\' "\"" st)
53 (modify-syntax-entry ?\' "\"" awk-mode-syntax-table)) 53 st)
54 "Syntax table in use in `awk-mode' buffers.")
54 55
55 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>. 56 ;; Regexps written with help from Peter Galbraith <galbraith@mixing.qc.dfo.ca>.
56 (defconst awk-font-lock-keywords 57 (defconst awk-font-lock-keywords
57 (eval-when-compile 58 (eval-when-compile
58 (list 59 (list
85 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~")) 86 (cons (regexp-opt '("&&" "||" "<=" "<" ">=" ">" "==" "!=" "!~" "~"))
86 'font-lock-constant-face) 87 'font-lock-constant-face)
87 )) 88 ))
88 "Default expressions to highlight in AWK mode.") 89 "Default expressions to highlight in AWK mode.")
89 90
91 (require 'syntax)
92
93 (defconst awk-font-lock-syntactic-keywords
94 ;; `/' is mostly used for /.../ regular expressions, but is also
95 ;; used as a division operator. Distinguishing between the two is
96 ;; a pain in the youknowwhat.
97 ;; '(("\\(^\\|[<=>-+*%/!^,~(?:|&]\\)\\s-*\\(/\\)\\([^/\n\\]\\|\\\\.\\)*\\(/\\)"
98 ;; (2 "\"") (4 "\"")))
99 '(("[^<=>-+*%/!^,~(?:|& \t\n\f]\\s-*\\(/\\)"
100 (1 (unless (nth 3 (syntax-ppss (match-beginning 1))) "."))))
101 "Syntactic keywords for `awk-mode'.")
102
90 ;;;###autoload 103 ;;;###autoload
91 (define-derived-mode awk-mode c-mode "AWK" 104 (define-derived-mode awk-mode c-mode "AWK"
92 "Major mode for editing AWK code. 105 "Major mode for editing AWK code.
93 This is much like C mode except for the syntax of comments. Its keymap 106 This is much like C mode except for the syntax of comments. Its keymap
94 inherits from C mode's and it has the same variables for customizing 107 inherits from C mode's and it has the same variables for customizing
98 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter)) 111 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
99 (set (make-local-variable 'paragraph-separate) paragraph-start) 112 (set (make-local-variable 'paragraph-separate) paragraph-start)
100 (set (make-local-variable 'comment-start) "# ") 113 (set (make-local-variable 'comment-start) "# ")
101 (set (make-local-variable 'comment-end) "") 114 (set (make-local-variable 'comment-end) "")
102 (set (make-local-variable 'comment-start-skip) "#+ *") 115 (set (make-local-variable 'comment-start-skip) "#+ *")
103 (setq font-lock-defaults '(awk-font-lock-keywords nil nil ((?_ . "w"))))) 116 (setq font-lock-defaults '(awk-font-lock-keywords
117 nil nil ((?_ . "w")) nil
118 (parse-sexp-lookup-properties . t)
119 (font-lock-syntactic-keywords
120 . awk-font-lock-syntactic-keywords))))
104 121
105 (provide 'awk-mode) 122 (provide 'awk-mode)
106 123
107 ;;; awk-mode.el ends here 124 ;;; awk-mode.el ends here