From 7f7b1e6e0106d9c608df344d9a55caff0ea82220 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Mon, 1 Dec 2008 22:24:13 +1030 Subject: [PATCH] * wesnoth-mode.el (wesnoth-element): Removed FOREACH and NEXT. Interferes with other behaviour. (wesnoth-determine-context): Add FOREACH and NEXT when seaching. (wesnoth-check-wml): Added FOREACH and NEXT checking. --- wesnoth-mode.el | 57 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 18 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index ecf9a27..3138f1f 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -319,7 +319,7 @@ If LIMITED is non-nil, return a regexp which matches only the #define and #enddef preprocessors." (concat "^[\t ]*\\(\\[[/+]?\\(\\w\\|_\\)+\\]?\\|" (if limited - "#define \\|#enddef\\|{FOREACH .+}\\|{NEXT .+}" + "#define \\|#enddef" (substring wesnoth-preprocessor-regexp 5)) "\\)")) @@ -1073,22 +1073,25 @@ Creates and destroys a cache of macro definition details as necessary." POSITION is the buffer position of the element for which to determine the context." (save-excursion - (let ((match (or - (and (search-backward-regexp - (wesnoth-element t) (point-min) t) - (progn - (while (save-match-data - (looking-at "^[\t ]*\\[[^/].+\\]\\[/.+\\]")) - (search-backward-regexp (wesnoth-element t) - (point-min) t)) - t) - (match-string 1)) - "")) - (depth (wesnoth-within-define position))) + (let* ((elements (concat (subseq (wesnoth-element t) + 0 (- (length (wesnoth-element t)) 3)) + "\\|{FOREACH .+}\\|{NEXT .+}\\)")) + (match (or + (and (search-backward-regexp + elements (point-min) t) + (progn + (while (save-match-data + (looking-at "^[\t ]*\\[[^/].+\\]\\[/.+\\]")) + (search-backward-regexp elements + (point-min) t)) + t) + (match-string 1)) + "")) + (depth (wesnoth-within-define position))) (while (and (wesnoth-wml-start-pos) (> (wesnoth-within-define (point)) depth) (not (= (point) (wesnoth-wml-start-pos)))) - (search-backward-regexp (wesnoth-element t) + (search-backward-regexp elements (wesnoth-wml-start-pos) t) (setq match (match-string 1))) (when (and (wesnoth-wml-start-pos) @@ -1237,7 +1240,8 @@ the end of the region to place the overlay." (let ((unmatched '()) (outbuf (and (interactive-p) (get-buffer-create "*WML*"))) (last-match-pos 1) - (details nil)) + (details nil) + (foreach '())) (save-excursion (set-buffer outbuf) (let ((buffer (buffer-name)) @@ -1255,14 +1259,31 @@ the end of the region to place the overlay." (cond ((nth 3 (parse-partial-sexp last-match-pos (point))) nil) ((eql (car details) 'macro) - (dolist (macro (save-match-data (wesnoth-extract-macro-details - (match-string-no-properties 0)))) + (dolist (macro (save-match-data + (wesnoth-extract-macro-details + (match-string-no-properties 0)))) (unless (assoc macro (append (wesnoth-macro-arguments) wesnoth-local-macro-data wesnoth-macro-data)) (wesnoth-check-process "Unknown macro: '%s'" - macro)))) + macro))) + (save-match-data + (when + (looking-at + "{\\(FOREACH\\|NEXT\\).*[\t ]+\\(\\(?:\\w\\|_\\)+\\)}") + (if (string= (match-string-no-properties 1) "FOREACH") + (setq foreach + (cons (match-string-no-properties 2) foreach)) + (if (string= (match-string-no-properties 1) "NEXT") + (unless (string= (car foreach) + (match-string-no-properties 2)) + (wesnoth-check-process + (concat "NEXT does not match corresponding " + "FOREACH: '%s' found; '%s' expected.") + (match-string-no-properties 2) + (car foreach))) + (setq foreach (cdr foreach))))))) ((looking-at "[\t ]*\\[\\+?\\(\\(\\w\\|_\\)+\\)\\]") (unless (wesnoth-check-element-type 0) (wesnoth-check-process -- 2.11.4.GIT