diff options
| author | Juanma Barranquero | 2003-07-14 20:45:43 +0000 |
|---|---|---|
| committer | Juanma Barranquero | 2003-07-14 20:45:43 +0000 |
| commit | 2d42509a3a7fb7f5ecec8fbd31b52424f9dcf859 (patch) | |
| tree | 823b18d0ea963e951985df1e6822fa957d3ba0e6 | |
| parent | b4dd5c9ca599e6d54056f0116cada2780becaf98 (diff) | |
| download | emacs-2d42509a3a7fb7f5ecec8fbd31b52424f9dcf859.tar.gz emacs-2d42509a3a7fb7f5ecec8fbd31b52424f9dcf859.zip | |
(xml-parse-tag): Namespace support.
(xml-parse-file): Namespace suport.
(xml-parse-region): Namespace suport.
| -rw-r--r-- | lisp/ChangeLog | 84 | ||||
| -rw-r--r-- | lisp/xml.el | 160 |
2 files changed, 111 insertions, 133 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 302cf8c4a3b..7f8665f2ad6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2003-07-14 Mark A. Hershberger <mah@everybody.org> | ||
| 2 | |||
| 3 | * xml.el (xml-parse-tag, xml-parse-file, xml-parse-region): | ||
| 4 | Namespace support. | ||
| 5 | |||
| 1 | 2003-07-13 Juanma Barranquero <lektu@terra.es> | 6 | 2003-07-13 Juanma Barranquero <lektu@terra.es> |
| 2 | 7 | ||
| 3 | * frame.el (modify-all-frames-parameters): Reinstalled (copyright | 8 | * frame.el (modify-all-frames-parameters): Reinstalled (copyright |
| @@ -19,85 +24,6 @@ | |||
| 19 | (Man-translate-references): Call `Man-translate-cleanup' to clean | 24 | (Man-translate-references): Call `Man-translate-cleanup' to clean |
| 20 | leading, trailing and middle spaces. | 25 | leading, trailing and middle spaces. |
| 21 | 26 | ||
| 22 | 2003-07-13 Michael Mauger <mmaug@yahoo.com> | ||
| 23 | |||
| 24 | Version 1.8.0 of sql-mode. | ||
| 25 | |||
| 26 | Simplify selection of SQL products to define highlighting and | ||
| 27 | interactive mode. Includes detailed instructions on adding support | ||
| 28 | for new products. | ||
| 29 | |||
| 30 | * progmodes/sql.el (sql-product): New variable. Identifies SQL | ||
| 31 | product for use in highlighting and interactive mode. | ||
| 32 | (sql-interactive-product): New variable. SQL product for | ||
| 33 | sql-interactive-mode. | ||
| 34 | (sql-product-support): New variable. Specifies product-specific | ||
| 35 | parameters to drive highlighting and interactive mode. | ||
| 36 | (sql-imenu-generic-expression): Add more object types. | ||
| 37 | (sql-sqlite-options): Correct comment. | ||
| 38 | (sql-ms-program): Use "osql" rather than "isql". | ||
| 39 | (sql-prompt-regexp, sql-prompt-length): Update comment. | ||
| 40 | (sql-mode-menu): Add "Start SQLi session" entry. Replace | ||
| 41 | Highlighting submenu with Product menu. Fix Send Region entry. | ||
| 42 | (sql-mode-abbrev-table): Add abbreviations. Support of SYSTEM-FLAG | ||
| 43 | on define-abbrev. Support was removed with last check-in; it now | ||
| 44 | handles older Emacsen without the SYSTEM-FLAG. | ||
| 45 | (sql-mode-font-lock-object-name): Add font-lock pattern for object | ||
| 46 | names. | ||
| 47 | (sql-mode-ansi-font-lock-keywords): Set as default value. | ||
| 48 | (sql-mode-oracle-font-lock-keywords): Set as default value. Support | ||
| 49 | Oracle 9i keywords. | ||
| 50 | (sql-mode-postgres-font-lock-keywords): Set as default value. | ||
| 51 | (sql-mode-linter-font-lock-keywords): Set as default value. | ||
| 52 | (sql-mode-ms-font-lock-keywords): New variable. Support Microsoft | ||
| 53 | SQLServer 2000. | ||
| 54 | (sql-mode-sybase-font-lock-keywords) | ||
| 55 | (sql-mode-interbase-font-lock-keywords) | ||
| 56 | (sql-mode-sqlite-font-lock-keywords) | ||
| 57 | (sql-mode-strong-font-lock-keywords) | ||
| 58 | (sql-mode-mysql-font-lock-keywords) | ||
| 59 | (sql-mode-db2-font-lock-keywords): New variables. Default to ANSI | ||
| 60 | keywords. | ||
| 61 | (sql-mode-font-lock-defaults): Update comment. | ||
| 62 | (sql-product-feature): New function. Returns feature associated | ||
| 63 | with a product from `sql-product-support' alist. | ||
| 64 | (sql-product-font-lock): New function. Set font-lock support based | ||
| 65 | on `sql-product'. | ||
| 66 | (sql-add-product-keywords): New function. Add font-lock rules to | ||
| 67 | product-specific keyword variables. | ||
| 68 | (sql-set-product): New function. Set `sql-product' and apply | ||
| 69 | appropriate font-lock highlighting. | ||
| 70 | (sql-highlight-product): New function. Set font-lock support based | ||
| 71 | on a product. Also set mode name to include product name. | ||
| 72 | (sql-highlight-ansi-keywords, sql-highlight-oracle-keywords) | ||
| 73 | (sql-highlight-postgres-keywords, sql-highlight-linter-keywords): | ||
| 74 | Use `sql-set-product'. | ||
| 75 | (sql-highlight-ms-keywords) | ||
| 76 | (sql-highlight-sybase-keywords) | ||
| 77 | (sql-highlight-interbase-keywords) | ||
| 78 | (sql-highlight-strong-keywords) | ||
| 79 | (sql-highlight-mysql-keywords) | ||
| 80 | (sql-highlight-sqlite-keywords) | ||
| 81 | (sql-highlight-db2-keywords): New functions. Use `sql-set-product'. | ||
| 82 | (sql-get-login): Prompt in the same order as the tokens. | ||
| 83 | (sql-mode): Uses `sql-product-highlight' and | ||
| 84 | `sql-product-font-lock'. | ||
| 85 | (sql-product-interactive): New function. Common portions of | ||
| 86 | product-specific interactive mode wrappers. | ||
| 87 | (sql-interactive-mode): Rewritten to use product features. | ||
| 88 | (sql-oracle, sql-sybase, sql-informix, sql-sqlite, sql-mysql) | ||
| 89 | (sql-solid, sql-ingres, sql-ms, sql-postgres, sql-interbase) | ||
| 90 | (sql-db2, sql-linter): Use `sql-product-interactive'. | ||
| 91 | (sql-connect-oracle, sql-connect-sybase, sql-connect-informix) | ||
| 92 | (sql-connect-sqlite, sql-connect-mysql, sql-connect-solid) | ||
| 93 | (sql-connect-ingres, sql-connect-postgres) | ||
| 94 | (sql-connect-interbase, sql-connect-db2, sql-connect-linter): New | ||
| 95 | functions. Format command line parameters and invoke comint on the | ||
| 96 | appropriate interpreter. Code was in the corresponding `sql-xyz' | ||
| 97 | function before. | ||
| 98 | (sql-connect-ms): New function. Support -E argument to use | ||
| 99 | operating system credentials for authentication. | ||
| 100 | |||
| 101 | 2003-07-13 Lars Hansen <larsh@math.ku.dk> | 27 | 2003-07-13 Lars Hansen <larsh@math.ku.dk> |
| 102 | 28 | ||
| 103 | * desktop.el (desktop-buffer-dired-misc-data, desktop-buffer-dired): | 29 | * desktop.el (desktop-buffer-dired-misc-data, desktop-buffer-dired): |
diff --git a/lisp/xml.el b/lisp/xml.el index f62b70fceb4..55c8fca23aa 100644 --- a/lisp/xml.el +++ b/lisp/xml.el | |||
| @@ -121,11 +121,12 @@ An empty string is returned if the attribute was not found." | |||
| 121 | ;;******************************************************************* | 121 | ;;******************************************************************* |
| 122 | 122 | ||
| 123 | ;;;###autoload | 123 | ;;;###autoload |
| 124 | (defun xml-parse-file (file &optional parse-dtd) | 124 | (defun xml-parse-file (file &optional parse-dtd parse-ns) |
| 125 | "Parse the well-formed XML file FILE. | 125 | "Parse the well-formed XML file FILE. |
| 126 | If FILE is already visited, use its buffer and don't kill it. | 126 | If FILE is already visited, use its buffer and don't kill it. |
| 127 | Returns the top node with all its children. | 127 | Returns the top node with all its children. |
| 128 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped." | 128 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped. |
| 129 | If PARSE-NS is non-nil, then QNAMES are expanded." | ||
| 129 | (let ((keep)) | 130 | (let ((keep)) |
| 130 | (if (get-file-buffer file) | 131 | (if (get-file-buffer file) |
| 131 | (progn | 132 | (progn |
| @@ -137,7 +138,7 @@ If PARSE-DTD is non-nil, the DTD is parsed rather than skipped." | |||
| 137 | (let ((xml (xml-parse-region (point-min) | 138 | (let ((xml (xml-parse-region (point-min) |
| 138 | (point-max) | 139 | (point-max) |
| 139 | (current-buffer) | 140 | (current-buffer) |
| 140 | parse-dtd))) | 141 | parse-dtd parse-ns))) |
| 141 | (if keep | 142 | (if keep |
| 142 | (goto-char keep) | 143 | (goto-char keep) |
| 143 | (kill-buffer (current-buffer))) | 144 | (kill-buffer (current-buffer))) |
| @@ -184,13 +185,14 @@ If PARSE-DTD is non-nil, the DTD is parsed rather than skipped." | |||
| 184 | ;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? | 185 | ;; prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? |
| 185 | 186 | ||
| 186 | ;;;###autoload | 187 | ;;;###autoload |
| 187 | (defun xml-parse-region (beg end &optional buffer parse-dtd) | 188 | (defun xml-parse-region (beg end &optional buffer parse-dtd parse-ns) |
| 188 | "Parse the region from BEG to END in BUFFER. | 189 | "Parse the region from BEG to END in BUFFER. |
| 189 | If BUFFER is nil, it defaults to the current buffer. | 190 | If BUFFER is nil, it defaults to the current buffer. |
| 190 | Returns the XML list for the region, or raises an error if the region | 191 | Returns the XML list for the region, or raises an error if the region |
| 191 | is not a well-formed XML file. | 192 | is not well-formed XML. |
| 192 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped, | 193 | If PARSE-DTD is non-nil, the DTD is parsed rather than skipped, |
| 193 | and returned as the first element of the list." | 194 | and returned as the first element of the list. |
| 195 | If PARSE-NS is non-nil, then QNAMES are expanded." | ||
| 194 | (save-restriction | 196 | (save-restriction |
| 195 | (narrow-to-region beg end) | 197 | (narrow-to-region beg end) |
| 196 | ;; Use fixed syntax table to ensure regexp char classes and syntax | 198 | ;; Use fixed syntax table to ensure regexp char classes and syntax |
| @@ -209,7 +211,7 @@ and returned as the first element of the list." | |||
| 209 | (if xml | 211 | (if xml |
| 210 | ;; translation of rule [1] of XML specifications | 212 | ;; translation of rule [1] of XML specifications |
| 211 | (error "XML files can have only one toplevel tag") | 213 | (error "XML files can have only one toplevel tag") |
| 212 | (setq result (xml-parse-tag parse-dtd)) | 214 | (setq result (xml-parse-tag parse-dtd parse-ns)) |
| 213 | (cond | 215 | (cond |
| 214 | ((null result)) | 216 | ((null result)) |
| 215 | ((listp (car result)) | 217 | ((listp (car result)) |
| @@ -224,57 +226,108 @@ and returned as the first element of the list." | |||
| 224 | (nreverse xml))))))) | 226 | (nreverse xml))))))) |
| 225 | 227 | ||
| 226 | 228 | ||
| 227 | (defun xml-parse-tag (&optional parse-dtd) | 229 | (defun xml-parse-tag (&optional parse-dtd parse-ns) |
| 228 | "Parse the tag at point. | 230 | "Parse the tag at point. |
| 229 | If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and | 231 | If PARSE-DTD is non-nil, the DTD of the document, if any, is parsed and |
| 230 | returned as the first element in the list. | 232 | returned as the first element in the list. |
| 233 | If PARSE-NS is non-nil, then QNAMES are expanded. | ||
| 231 | Returns one of: | 234 | Returns one of: |
| 232 | - a list : the matching node | 235 | - a list : the matching node |
| 233 | - nil : the point is not looking at a tag. | 236 | - nil : the point is not looking at a tag. |
| 234 | - a pair : the first element is the DTD, the second is the node." | 237 | - a pair : the first element is the DTD, the second is the node." |
| 235 | (cond | 238 | (let ((xml-ns (if (consp parse-ns) |
| 236 | ;; Processing instructions (like the <?xml version="1.0"?> tag at the | 239 | parse-ns |
| 237 | ;; beginning of a document). | 240 | (if parse-ns |
| 238 | ((looking-at "<\\?") | 241 | (list |
| 239 | (search-forward "?>") | 242 | ;; Default no namespace |
| 240 | (skip-syntax-forward " ") | 243 | (cons "" "") |
| 241 | (xml-parse-tag parse-dtd)) | 244 | ;; We need to seed the xmlns namespace |
| 242 | ;; Character data (CDATA) sections, in which no tag should be interpreted | 245 | (cons "xmlns" "http://www.w3.org/2000/xmlns/")))))) |
| 243 | ((looking-at "<!\\[CDATA\\[") | 246 | (cond |
| 244 | (let ((pos (match-end 0))) | 247 | ;; Processing instructions (like the <?xml version="1.0"?> tag at the |
| 245 | (unless (search-forward "]]>" nil t) | 248 | ;; beginning of a document). |
| 246 | (error "CDATA section does not end anywhere in the document")) | 249 | ((looking-at "<\\?") |
| 247 | (buffer-substring pos (match-beginning 0)))) | 250 | (search-forward "?>") |
| 248 | ;; DTD for the document | 251 | (skip-syntax-forward " ") |
| 249 | ((looking-at "<!DOCTYPE") | 252 | (xml-parse-tag parse-dtd xml-ns)) |
| 250 | (let (dtd) | 253 | ;; Character data (CDATA) sections, in which no tag should be interpreted |
| 251 | (if parse-dtd | 254 | ((looking-at "<!\\[CDATA\\[") |
| 252 | (setq dtd (xml-parse-dtd)) | 255 | (let ((pos (match-end 0))) |
| 253 | (xml-skip-dtd)) | 256 | (unless (search-forward "]]>" nil t) |
| 257 | (error "CDATA section does not end anywhere in the document")) | ||
| 258 | (buffer-substring pos (match-beginning 0)))) | ||
| 259 | ;; DTD for the document | ||
| 260 | ((looking-at "<!DOCTYPE") | ||
| 261 | (let (dtd) | ||
| 262 | (if parse-dtd | ||
| 263 | (setq dtd (xml-parse-dtd)) | ||
| 264 | (xml-skip-dtd)) | ||
| 254 | (skip-syntax-forward " ") | 265 | (skip-syntax-forward " ") |
| 255 | (if dtd | 266 | (if dtd |
| 256 | (cons dtd (xml-parse-tag)) | 267 | (cons dtd (xml-parse-tag nil xml-ns)) |
| 257 | (xml-parse-tag)))) | 268 | (xml-parse-tag nil xml-ns)))) |
| 258 | ;; skip comments | 269 | ;; skip comments |
| 259 | ((looking-at "<!--") | 270 | ((looking-at "<!--") |
| 260 | (search-forward "-->") | 271 | (search-forward "-->") |
| 261 | nil) | 272 | nil) |
| 262 | ;; end tag | 273 | ;; end tag |
| 263 | ((looking-at "</") | 274 | ((looking-at "</") |
| 264 | '()) | 275 | '()) |
| 265 | ;; opening tag | 276 | ;; opening tag |
| 266 | ((looking-at "<\\([^/>[:space:]]+\\)") | 277 | ((looking-at "<\\([^/>[:space:]]+\\)") |
| 267 | (goto-char (match-end 1)) | 278 | (goto-char (match-end 1)) |
| 268 | (let* ((node-name (match-string 1)) | 279 | (let* ((node-name (match-string 1)) |
| 269 | ;; Parse the attribute list. | 280 | ;; Parse the attribute list. |
| 270 | (children (list (xml-parse-attlist) (intern node-name))) | 281 | (children (list (xml-parse-attlist) (intern node-name))) |
| 271 | pos) | 282 | pos) |
| 272 | 283 | ||
| 273 | ;; is this an empty element ? | 284 | ;; add the xmlns:* attrs to our cache |
| 274 | (if (looking-at "/>") | 285 | (when (consp xml-ns) |
| 275 | (progn | 286 | (mapcar |
| 276 | (forward-char 2) | 287 | (lambda (attr) |
| 277 | (nreverse children)) | 288 | (let* ((splitup (split-string (symbol-name (car attr)) ":")) |
| 289 | (prefix (nth 0 splitup)) | ||
| 290 | (lname (nth 1 splitup))) | ||
| 291 | (when (string= "xmlns" prefix) | ||
| 292 | (setq xml-ns (append (list (cons (if lname | ||
| 293 | lname | ||
| 294 | "") | ||
| 295 | (cdr attr))) | ||
| 296 | xml-ns))))) | ||
| 297 | (car children)) | ||
| 298 | |||
| 299 | ;; expand element names | ||
| 300 | (let* ((splitup (split-string (symbol-name (cadr children)) ":")) | ||
| 301 | (lname (or (nth 1 splitup) | ||
| 302 | (nth 0 splitup))) | ||
| 303 | (prefix (if (nth 1 splitup) | ||
| 304 | (nth 0 splitup) | ||
| 305 | ""))) | ||
| 306 | (setcdr children (list | ||
| 307 | (intern (concat "{" | ||
| 308 | (cdr (assoc-string prefix xml-ns)) | ||
| 309 | "}" lname))))) | ||
| 310 | |||
| 311 | ;; expand attribute names | ||
| 312 | (mapcar | ||
| 313 | (lambda (attr) | ||
| 314 | (let* ((splitup (split-string (symbol-name (car attr)) ":")) | ||
| 315 | (lname (or (nth 1 splitup) | ||
| 316 | (nth 0 splitup))) | ||
| 317 | (prefix (if (nth 1 splitup) | ||
| 318 | (nth 0 splitup) | ||
| 319 | (caar xml-ns)))) | ||
| 320 | |||
| 321 | (setcar attr (intern (concat "{" | ||
| 322 | (cdr (assoc-string prefix xml-ns)) | ||
| 323 | "}" lname))))) | ||
| 324 | (car children))) | ||
| 325 | |||
| 326 | ;; is this an empty element ? | ||
| 327 | (if (looking-at "/>") | ||
| 328 | (progn | ||
| 329 | (forward-char 2) | ||
| 330 | (nreverse children)) | ||
| 278 | 331 | ||
| 279 | ;; is this a valid start tag ? | 332 | ;; is this a valid start tag ? |
| 280 | (if (eq (char-after) ?>) | 333 | (if (eq (char-after) ?>) |
| @@ -289,7 +342,7 @@ Returns one of: | |||
| 289 | (error "XML: Invalid end tag (expecting %s) at pos %d" | 342 | (error "XML: Invalid end tag (expecting %s) at pos %d" |
| 290 | node-name (point))) | 343 | node-name (point))) |
| 291 | ((= (char-after) ?<) | 344 | ((= (char-after) ?<) |
| 292 | (let ((tag (xml-parse-tag))) | 345 | (let ((tag (xml-parse-tag nil xml-ns))) |
| 293 | (when tag | 346 | (when tag |
| 294 | (push tag children)))) | 347 | (push tag children)))) |
| 295 | (t | 348 | (t |
| @@ -320,12 +373,11 @@ Returns one of: | |||
| 320 | (nreverse children)) | 373 | (nreverse children)) |
| 321 | ;; This was an invalid start tag | 374 | ;; This was an invalid start tag |
| 322 | (error "XML: Invalid attribute list"))))) | 375 | (error "XML: Invalid attribute list"))))) |
| 323 | (t ;; This is not a tag. | 376 | (t ;; This is not a tag. |
| 324 | (error "XML: Invalid character")))) | 377 | (error "XML: Invalid character"))))) |
| 325 | 378 | ||
| 326 | (defun xml-parse-attlist () | 379 | (defun xml-parse-attlist () |
| 327 | "Return the attribute-list after point. | 380 | "Return the attribute-list after point.Leave point at the first non-blank character after the tag." |
| 328 | Leave point at the first non-blank character after the tag." | ||
| 329 | (let ((attlist ()) | 381 | (let ((attlist ()) |
| 330 | start-pos name) | 382 | start-pos name) |
| 331 | (skip-syntax-forward " ") | 383 | (skip-syntax-forward " ") |