From: Alan M. <ac...@mu...> - 2011-11-20 13:23:03
|
Hello, Eric. On Thu, Nov 17, 2011 at 10:03:44AM -0600, Eric Pement wrote: > I am using GNU Emacs version 23.3.1 for Windows, executed with > "--no-init-file", and cc-mode version 5.32.2. > GNU awk version 4.0 offers the switch statement as a gawk extension. > However, when cc-mode v5.32.2 is active while editing an awk script, > the switch statement is not properly managed in AWK mode, for both > syntax highlighting and for line indentation. Ah. AWK now has switch statements. ;-) > In syntax highlighting, the statement "switch (somename) { ...}" > improperly changes font color and highlighting for "h (' in the > statement name and left parenthesis. AWK Mode was interpreting "switch" as a user defined function name. This triggered the feature which warns about a space between the function name and the opening parenthesis. > In line indentation, following a "case /pattern/:" directive, the > first line is properly indented, but second, third, and successive > lines are out-dented without recognition that the "case" directive is > still active and thus these additional lines should continue > indentation. This should be fixed in the patch below. > To demonstrate the problem, I have attached a JPG image, > "cc-mode_error_on_switch.jpg" to show this. > If images are not supported in bug reports, name the following block > "switch-statement-error.awk" and load it into Emacs. > BEGIN { > var = "foo" > switch (var) { > case "food": > x = 1; > break; > default: > y = 1; > break; > } > } Thanks for reporting this bug, and even more thanks that your report was of such high quality. Please try the following patch. I hope it implements AWK's switch properly. When you compile the files, note that cc-langs.el must be compiled first, and cc-engine.el and cc-mode.el must also be compiled as well as cc-awk.el. Or just compile the whole lot. :-) Please let me know how it performs. *** orig/cc-awk.el 2011-11-20 11:10:37.000000000 +0000 --- cc-awk.el 2011-11-20 12:41:37.000000000 +0000 *************** *** 897,903 **** (regexp-opt '("BEGIN" "END" "break" "continue" "delete" "do" "else" "exit" "for" "getline" "if" "in" "next" "nextfile" ! "return" "while") t) "\\>") ;; Builtins. --- 897,903 ---- (regexp-opt '("BEGIN" "END" "break" "continue" "delete" "do" "else" "exit" "for" "getline" "if" "in" "next" "nextfile" ! "return" "switch" "while") t) "\\>") ;; Builtins. *** orig/cc-langs.el 2011-11-20 11:10:37.000000000 +0000 --- cc-langs.el 2011-11-20 12:54:35.000000000 +0000 *************** *** 2235,2242 **** (c-lang-defconst c-label-kwds "Keywords introducing colon terminated labels in blocks." ! t '("case" "default") ! awk nil) (c-lang-defconst c-label-kwds-regexp ;; Adorned regexp matching any keyword that introduces a label. --- 2235,2241 ---- (c-lang-defconst c-label-kwds "Keywords introducing colon terminated labels in blocks." ! t '("case" "default")) (c-lang-defconst c-label-kwds-regexp ;; Adorned regexp matching any keyword that introduces a label. *************** *** 2990,3007 **** tested at the beginning of every sexp in a suspected label, i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat - ;; Don't allow string literals. Character constants are OK. - "\"\\|" ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) (append (c-lang-const c-label-kwds) (c-lang-const c-protection-kwds)) :test 'string-equal))) ;; Also check for open parens in C++, to catch member init lists in ;; constructors. We normally allow it so that macros with arguments ;; work in labels. ! c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key))) (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key)) (c-lang-defconst c-nonlabel-token-2-key --- 2989,3007 ---- tested at the beginning of every sexp in a suspected label, i.e. before \":\". Only used if `c-recognize-colon-labels' is set." t (concat ;; All keywords except `c-label-kwds' and `c-protection-kwds'. (c-make-keywords-re t (set-difference (c-lang-const c-keywords) (append (c-lang-const c-label-kwds) (c-lang-const c-protection-kwds)) :test 'string-equal))) + ;; Don't allow string literals, except in AWK. Character constants are OK. + (c objc java pike idl) (concat "\"\\|" + (c-lang-const c-nonlabel-token-key)) ;; Also check for open parens in C++, to catch member init lists in ;; constructors. We normally allow it so that macros with arguments ;; work in labels. ! c++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key))) (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key)) (c-lang-defconst c-nonlabel-token-2-key > Kind regards, > Eric Pement - eri...@gm... -- Alan Mackenzie (Nuremberg, Germany). |