help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex Problem => "overlapping words"


From: Tim Johnson
Subject: Re: Regex Problem => "overlapping words"
Date: Sat, 3 Dec 2005 14:09:48 -0900
User-agent: Mutt/1.4.2.1i

* Stefan Monnier <monnier@iro.umontreal.ca> [051203 13:20]:
> > There is still a problem tho': Emacs seems to think that "-" is a
> > word or symbol boundary.
> 
> This depends on the syntax-table settings.
> 
> Please don't change the syntax of ?- in the main syntax-table, but only in
> the syntax-table used during font-locking:
> 
>   Take a look at the place where font-lock-defaults is set.
>   Then look at the docstring of font-lock-defaults.
>   Then locate the SYNTAX-ALIST element and set it so that the character ?-
>   has syntax "w".

    Thanks Stefan: Below are the two elisp forms that contain the symbol
    'font-lock-defaults:
     (make-local-variable 'font-lock-defaults)
     (setq font-lock-defaults '(rebol-font-lock-keywords nil nil))

     ;; there does not appear to be a docstring and there is no
     ;; symbol syntax-alist (or SYNTAX-ALIST) in the mode file
     
I'm going to put a copy of the code that I believe sets the mode-specific
syntax table at the end of this message, but I am beginning to suspect that the
problem may remain at the regex stage.

Let me first describe the functionality and the symptoms: Rebol uses a sort of
lambda calculus and subroutines are themselves subroutines (sort of like
'defmacro in lisp), and can be defined with different interfaces and scope
rules. Adding a colon to any symbol binds that symbol to definitions that
follow. A colon must immediately follow the symbol with no intervening
whitespace.

Bearing in mind that the keywords for creating subroutines in rebol are as
follows (for my setup) "def" "does" "function" "func" "has" "sub", then we
define a symbol as one of these subroutine constructs in the following example:

hello: def[S][print ["hello " S]]

so that 
hello "Stefan" => "hello Stefan"

The specific highlight occurs when a colon and a space precede that keyword.

Now if I type another keyword, say 'print which is defined with another
font-lock group and *then* add a hyphen, the highlight for the symbol is turned
off (as it should be). Because I can only partially follow the code in the
syntax-table, this is my long-winded way of saying that perhaps this remains a
regex problem.

So.... following is the regex form as I now have it coded
**********************************************************************************************************************************
'("\\([^][ \t\r\n{}()]+\\):[ 
]*\\(d\\(?:ef\\|oes\\)\\|func\\(?:tion\\)?\\|has\\|sub\\)\\>" (1 prepend) (2 
font-lock-keyword-face)) 
**********************************************************************************************************************************
  My thanks again. This is no big deal, just helping to edify me about 
  elisp.        
;; syntax table code follows
(defvar rebol-mode-syntax-table nil 
  "Syntax table for REBOL buffers.")

(if (not rebol-mode-syntax-table)
    (let ((i 0))
      (setq rebol-mode-syntax-table (make-syntax-table))
      (set-syntax-table rebol-mode-syntax-table)

      ;; Default is `word' constituent.
      (while (< i 256)
        (modify-syntax-entry i "_   ")
        (setq i (1+ i)))

      ;; Digits are word components.
      (setq i ?0)
      (while (<= i ?9)
        (modify-syntax-entry i "w   ")
        (setq i (1+ i)))

      ;; As are upper and lower case.
      (setq i ?A)
      (while (<= i ?Z)
        (modify-syntax-entry i "w   ")
        (setq i (1+ i)))
      (setq i ?a)
      (while (<= i ?z)
        (modify-syntax-entry i "w   ")
        (setq i (1+ i)))

      ;; Whitespace
      (modify-syntax-entry ?\t "    ")
      (modify-syntax-entry ?\n ">   ")
      (modify-syntax-entry ?\f "    ")
      (modify-syntax-entry ?\r "    ")
      (modify-syntax-entry ?  "    ")

      ;; Delimiters
      (modify-syntax-entry ?[ "(]  ")
      (modify-syntax-entry ?] ")[  ")
      (modify-syntax-entry ?\( "()  ")
      (modify-syntax-entry ?\) ")(  ")

      ;; comments
      (modify-syntax-entry ?\; "<   ")
      (modify-syntax-entry ?\" "\"    ")
      (modify-syntax-entry ?{ "    ")
      (modify-syntax-entry ?} "    ")
      (modify-syntax-entry ?' "  p")
      (modify-syntax-entry ?` "  p")

      (modify-syntax-entry ?^ "\\   ")))
-- 
Tim Johnson <tim@johnsons-web.com>
      http://www.alaska-internet-solutions.com




reply via email to

[Prev in Thread] Current Thread [Next in Thread]