GNU bug report logs - #13541
24.2.92; awk-mode: wrong font locking regexp literals

Previous Next

Packages: cc-mode, emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Thu, 24 Jan 2013 11:44:02 UTC

Severity: minor

Found in version 24.2.92

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #23 received at 13541 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Leo Liu <sdl.web <at> gmail.com>
Cc: bug-cc-mode <at> gnu.org, Glenn Morris <rgm <at> gnu.org>, 13541 <at> debbugs.gnu.org
Subject: Re: bug#13541: 24.2.92; awk-mode: wrong font locking regexp literals
Date: Fri, 25 Jan 2013 17:50:57 +0000
Hi, Leo.

On Thu, Jan 24, 2013 at 07:43:06PM +0800, Leo Liu wrote:
> In an awk buffer having the following text:

> #--BEGIN--
> NF { /xyz/ }

> NF {
>     /xyz/
> }
> #--END--

> I have the second regexp properly font-locked but not the first one.

Yes.

Could you please try out, fairly thoroughly, the following patch, and let
me know how it goes.  It aims to fontify a /regexp/ wherever one might
occur.




=== modified file 'lisp/progmodes/cc-awk.el'
*** lisp/progmodes/cc-awk.el	2013-01-01 09:11:05 +0000
--- lisp/progmodes/cc-awk.el	2013-01-25 17:47:38 +0000
***************
*** 211,217 ****
  ;; division sign.
  (defconst c-awk-neutral-re
  ;  "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)+") ; changed, 2003/6/7
!   "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)")
  ;;   A "neutral" char(pair).  Doesn't change the "state" of a subsequent /.
  ;; This is space/tab, braces, an auto-increment/decrement operator or an
  ;; escaped character.  Or one of the (invalid) characters @ or `.  But NOT an
--- 211,217 ----
  ;; division sign.
  (defconst c-awk-neutral-re
  ;  "\\([{}@` \t]\\|\\+\\+\\|--\\|\\\\.\\)+") ; changed, 2003/6/7
!   "\\([}@` \t]\\|\\+\\+\\|--\\|\\\\\\(.\\|[\n\r]\\)\\)")
  ;;   A "neutral" char(pair).  Doesn't change the "state" of a subsequent /.
  ;; This is space/tab, braces, an auto-increment/decrement operator or an
  ;; escaped character.  Or one of the (invalid) characters @ or `.  But NOT an
***************
*** 231,237 ****
  ;; will only work when there won't be a preceding " or / before the sought /
  ;; to foul things up.
  (defconst c-awk-non-arith-op-bra-re
!   "[[\(&=:!><,?;'~|]")
  ;;   Matches an opening BRAcket, round or square, or any operator character
  ;; apart from +,-,/,*,%.  For the purpose at hand (detecting a / which is a
  ;; regexp bracket) these arith ops are unnecessary and a pain, because of "++"
--- 231,237 ----
  ;; will only work when there won't be a preceding " or / before the sought /
  ;; to foul things up.
  (defconst c-awk-non-arith-op-bra-re
!   "[[\({&=:!><,?;'~|]")
  ;;   Matches an opening BRAcket, round or square, or any operator character
  ;; apart from +,-,/,*,%.  For the purpose at hand (detecting a / which is a
  ;; regexp bracket) these arith ops are unnecessary and a pain, because of "++"
***************
*** 242,247 ****
--- 242,257 ----
  ;; bracket, in a context where an immediate / would be a division sign.  This
  ;; will only work when there won't be a preceding " or / before the sought /
  ;; to foul things up.
+ (defconst c-awk-pre-exp-alphanum-kwd-re
+   (concat "\\(^\\|[^_\n\r]\\)\\<"
+ 	  (regexp-opt '("print" "return" "case") t)
+ 	  "\\>\\([^_\n\r]\\|$\\)"))
+ ;;   Matches all AWK keywords which can precede expressions (including
+ ;; /regexp/).
+ (defconst c-awk-kwd-regexp-sign-re
+   (concat c-awk-pre-exp-alphanum-kwd-re c-awk-neutrals*-re "/"))
+ ;;   Matches a piece of AWK buffer ending in <kwd> /, where <kwd> is a keyword
+ ;; which can precede an expression.
  
  ;; REGEXPS USED FOR FINDING THE POSITION OF A "virtual semicolon"
  (defconst c-awk-_-harmless-nonws-char-re "[^#/\"\\\\\n\r \t]")
***************
*** 721,729 ****
      (goto-char anchor)
      ;; Analyze the line to find out what the / is.
      (if (if anchor-state-/div
!             (not (search-forward-regexp c-awk-regexp-sign-re (1+ /point) t))
!           (search-forward-regexp c-awk-div-sign-re (1+ /point) t))
!         ;; A division sign.
  	(progn (goto-char (1+ /point)) nil)
        ;; A regexp opener
        ;; Jump over the regexp innards, setting the match data.
--- 731,740 ----
      (goto-char anchor)
      ;; Analyze the line to find out what the / is.
      (if (if anchor-state-/div
! 	    (not (search-forward-regexp c-awk-regexp-sign-re (1+ /point) t))
! 	  (and (not (search-forward-regexp c-awk-kwd-regexp-sign-re (1+ /point) t))
! 	       (search-forward-regexp c-awk-div-sign-re (1+ /point) t)))
! 	;; A division sign.
  	(progn (goto-char (1+ /point)) nil)
        ;; A regexp opener
        ;; Jump over the regexp innards, setting the match data.


> Leo

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 12 years and 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.