annotate lisp/nxml/rng-cmpct.el @ 91644:681a1b7488c2

(top-level): Move provide statement to end. (pcmpl-unix-group-file, pcmpl-unix-passwd-file): Remove leading `*' from doc-string. Allow to be nil. (pcmpl-ssh-known-hosts-file): Convert comment into expanded doc-string. Allow to be nil. Add :version. (pcmpl-ssh-hosts): Move definition before use. Handle lines without hostnames, and multiple hostnames per line.
author Glenn Morris <rgm@gnu.org>
date Fri, 08 Feb 2008 05:13:49 +0000
parents b9e8ab94c460
children d495d4d5452f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
1 ;;; rng-cmpct.el --- parsing of RELAX NG Compact Syntax schemas
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
2
87665
b9e8ab94c460 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86545
diff changeset
3 ;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
4
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
5 ;; Author: James Clark
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
6 ;; Keywords: XML, RelaxNG
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
7
86545
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
8 ;; This file is part of GNU Emacs.
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
9
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
12 ;; the Free Software Foundation; either version 3, or (at your option)
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
13 ;; any later version.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
14
86545
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
18 ;; GNU General Public License for more details.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
19
86545
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
20 ;; You should have received a copy of the GNU General Public License
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
839b5e8a3958 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 86379
diff changeset
23 ;; Boston, MA 02110-1301, USA.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
24
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
25 ;;; Commentary:
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
26
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
27 ;; This parses a RELAX NG Compact Syntax schema into the form
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
28 ;; specified in rng-pttrn.el.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
29 ;;
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
30 ;; RELAX NG Compact Syntax is specified by
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
31 ;; http://relaxng.org/compact.html
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
32 ;;
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
33 ;; This file uses the prefix "rng-c-".
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
34
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
35 ;;; Code:
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
36
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
37 (require 'nxml-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
38 (require 'rng-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
39 (require 'rng-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
40 (require 'rng-pttrn)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
41
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
42 ;;;###autoload
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
43 (defun rng-c-load-schema (filename)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
44 "Load a schema in RELAX NG compact syntax from FILENAME.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
45 Return a pattern."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
46 (rng-c-parse-file filename))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
47
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
48 ;;; Error handling
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
49
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
50 (put 'rng-c-incorrect-schema
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
51 'error-conditions
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
52 '(error rng-error nxml-file-parse-error rng-c-incorrect-schema))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
53
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
54 (put 'rng-c-incorrect-schema
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
55 'error-message
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
56 "Incorrect schema")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
57
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
58 (defun rng-c-signal-incorrect-schema (filename pos message)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
59 (nxml-signal-file-parse-error filename
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
60 pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
61 message
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
62 'rng-c-incorrect-schema))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
63
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
64 ;;; Lexing
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
65
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
66 (defconst rng-c-keywords
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
67 '("attribute"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
68 "default"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
69 "datatypes"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
70 "div"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
71 "element"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
72 "empty"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
73 "external"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
74 "grammar"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
75 "include"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
76 "inherit"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
77 "list"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
78 "mixed"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
79 "namespace"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
80 "notAllowed"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
81 "parent"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
82 "start"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
83 "string"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
84 "text"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
85 "token")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
86 "List of strings that are keywords in the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
87
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
88 (defconst rng-c-anchored-keyword-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
89 (concat "\\`\\(" (regexp-opt rng-c-keywords) "\\)\\'")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
90 "Regular expression to match a keyword in the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
91
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
92 (defvar rng-c-syntax-table nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
93 "Syntax table for parsing the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
94
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
95 (if rng-c-syntax-table
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
96 ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
97 (setq rng-c-syntax-table (make-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
98 (modify-syntax-entry ?# "<" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
99 (modify-syntax-entry ?\n ">" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
100 (modify-syntax-entry ?- "w" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
101 (modify-syntax-entry ?. "w" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
102 (modify-syntax-entry ?_ "w" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
103 (modify-syntax-entry ?: "_" rng-c-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
104
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
105 (defconst rng-c-literal-1-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
106 "'\\(''\\([^']\\|'[^']\\|''[^']\\)*''\\|[^'\n]*\\)'"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
107 "Regular expression to match a single-quoted literal.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
108
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
109 (defconst rng-c-literal-2-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
110 (replace-regexp-in-string "'" "\"" rng-c-literal-1-re)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
111 "Regular expression to match a double-quoted literal.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
112
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
113 (defconst rng-c-ncname-re "\\w+")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
114
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
115 (defconst rng-c-anchored-ncname-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
116 (concat "\\`" rng-c-ncname-re "\\'"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
117
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
118 (defconst rng-c-token-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
119 (concat "[&|]=" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
120 "[][()|&,*+?{}~=-]" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
121 rng-c-literal-1-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
122 rng-c-literal-2-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
123 rng-c-ncname-re "\\(:\\(\\*\\|" rng-c-ncname-re "\\)\\)?" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
124 "\\\\" rng-c-ncname-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
125 ">>")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
126 "Regular expression to match a token in the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
127
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
128 (defun rng-c-init-buffer ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
129 (setq case-fold-search nil) ; automatically becomes buffer-local when set
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
130 (set-buffer-multibyte t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
131 (set-syntax-table rng-c-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
132
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
133 (defvar rng-c-current-token nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
134 (make-variable-buffer-local 'rng-c-current-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
135
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
136 (defun rng-c-advance ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
137 (cond ((looking-at rng-c-token-re)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
138 (setq rng-c-current-token (match-string 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
139 (goto-char (match-end 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
140 (forward-comment (point-max)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
141 ((= (point) (point-max))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
142 (setq rng-c-current-token ""))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
143 (t (rng-c-error "Invalid token"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
144
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
145 (defconst rng-c-anchored-datatype-name-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
146 (concat "\\`" rng-c-ncname-re ":" rng-c-ncname-re "\\'"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
147
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
148 (defsubst rng-c-current-token-keyword-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
149 (string-match rng-c-anchored-keyword-re rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
150
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
151 (defsubst rng-c-current-token-prefixed-name-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
152 (string-match rng-c-anchored-datatype-name-re rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
153
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
154 (defsubst rng-c-current-token-literal-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
155 (string-match "\\`['\"]" rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
156
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
157 (defsubst rng-c-current-token-quoted-identifier-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
158 (string-match "\\`\\\\" rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
159
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
160 (defsubst rng-c-current-token-ncname-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
161 (string-match rng-c-anchored-ncname-re rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
162
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
163 (defsubst rng-c-current-token-ns-name-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
164 (let ((len (length rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
165 (and (> len 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
166 (= (aref rng-c-current-token (- len 1)) ?*))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
167
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
168 ;;; Namespaces
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
169
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
170 (defvar rng-c-inherit-namespace nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
171
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
172 (defvar rng-c-default-namespace nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
173
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
174 (defvar rng-c-default-namespace-declared nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
175
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
176 (defvar rng-c-namespace-decls nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
177 "Alist of namespace declarations.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
178
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
179 (defconst rng-c-no-namespace nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
180
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
181 (defun rng-c-declare-standard-namespaces ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
182 (setq rng-c-namespace-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
183 (cons (cons "xml" nxml-xml-namespace-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
184 rng-c-namespace-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
185 (when (and (not rng-c-default-namespace-declared)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
186 rng-c-inherit-namespace)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
187 (setq rng-c-default-namespace rng-c-inherit-namespace)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
188
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
189 (defun rng-c-expand-name (prefixed-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
190 (let ((i (string-match ":" prefixed-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
191 (rng-make-name (rng-c-lookup-prefix (substring prefixed-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
192 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
193 i))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
194 (substring prefixed-name (+ i 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
195
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
196 (defun rng-c-lookup-prefix (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
197 (let ((binding (assoc prefix rng-c-namespace-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
198 (or binding (rng-c-error "Undefined prefix %s" prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
199 (cdr binding)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
200
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
201 (defun rng-c-unqualified-namespace (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
202 (if attribute
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
203 rng-c-no-namespace
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
204 rng-c-default-namespace))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
205
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
206 (defun rng-c-make-context ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
207 (cons rng-c-default-namespace rng-c-namespace-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
208
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
209 ;;; Datatypes
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
210
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
211 (defconst rng-string-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
212 (rng-make-datatype rng-builtin-datatypes-uri "string"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
213
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
214 (defconst rng-token-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
215 (rng-make-datatype rng-builtin-datatypes-uri "token"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
216
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
217 (defvar rng-c-datatype-decls nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
218 "Alist of datatype declarations.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
219 Contains a list of pairs (PREFIX . URI) where PREFIX is a string
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
220 and URI is a symbol.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
221
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
222 (defun rng-c-declare-standard-datatypes ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
223 (setq rng-c-datatype-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
224 (cons (cons "xsd" rng-xsd-datatypes-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
225 rng-c-datatype-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
226
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
227 (defun rng-c-lookup-datatype-prefix (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
228 (let ((binding (assoc prefix rng-c-datatype-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
229 (or binding (rng-c-error "Undefined prefix %s" prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
230 (cdr binding)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
231
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
232 (defun rng-c-expand-datatype (prefixed-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
233 (let ((i (string-match ":" prefixed-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
234 (rng-make-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
235 (rng-c-lookup-datatype-prefix (substring prefixed-name 0 i))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
236 (substring prefixed-name (+ i 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
237
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
238 ;;; Grammars
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
239
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
240 (defvar rng-c-current-grammar nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
241 (defvar rng-c-parent-grammar nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
242
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
243 (defun rng-c-make-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
244 (make-hash-table :test 'equal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
245
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
246 (defconst rng-c-about-override-slot 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
247 (defconst rng-c-about-combine-slot 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
248
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
249 (defun rng-c-lookup-create (name grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
250 "Return a def object for NAME. A def object is a pair
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
251 \(ABOUT . REF) where REF is returned by `rng-make-ref'. ABOUT is a
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
252 two-element vector [OVERRIDE COMBINE]. COMBINE is either nil, choice
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
253 or interleave. OVERRIDE is either nil, require or t."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
254 (let ((def (gethash name grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
255 (if def
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
256 def
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
257 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
258 (setq def (cons (vector nil nil) (rng-make-ref name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
259 (puthash name def grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
260 def))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
261
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
262 (defun rng-c-make-ref (name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
263 (or rng-c-current-grammar
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
264 (rng-c-error "Reference not in a grammar"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
265 (cdr (rng-c-lookup-create name rng-c-current-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
266
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
267 (defun rng-c-make-parent-ref (name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
268 (or rng-c-parent-grammar
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
269 (rng-c-error "Reference to non-existent parent grammar"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
270 (cdr (rng-c-lookup-create name rng-c-parent-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
271
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
272 (defvar rng-c-overrides nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
273 "Contains a list of (NAME . DEF) pairs.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
274
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
275 (defun rng-c-merge-combine (def combine name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
276 (let* ((about (car def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
277 (current-combine (aref about rng-c-about-combine-slot)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
278 (if combine
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
279 (if current-combine
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
280 (or (eq combine current-combine)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
281 (rng-c-error "Inconsistent combine for %s" name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
282 (aset about rng-c-about-combine-slot combine))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
283 current-combine)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
284
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
285 (defun rng-c-prepare-define (name combine in-include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
286 (let* ((def (rng-c-lookup-create name rng-c-current-grammar))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
287 (about (car def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
288 (overridden (aref about rng-c-about-override-slot)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
289 (and in-include
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
290 (setq rng-c-overrides (cons (cons name def) rng-c-overrides)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
291 (cond (overridden (and (eq overridden 'require)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
292 (aset about rng-c-about-override-slot t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
293 nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
294 (t (setq combine (rng-c-merge-combine def combine name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
295 (and (rng-ref-get (cdr def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
296 (not combine)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
297 (rng-c-error "Duplicate definition of %s" name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
298 def))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
299
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
300 (defun rng-c-start-include (overrides)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
301 (mapcar (lambda (name-def)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
302 (let* ((def (cdr name-def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
303 (about (car def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
304 (save (aref about rng-c-about-override-slot)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
305 (aset about rng-c-about-override-slot 'require)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
306 (cons save name-def)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
307 overrides))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
308
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
309 (defun rng-c-end-include (overrides)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
310 (mapcar (lambda (o)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
311 (let* ((saved (car o))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
312 (name-def (cdr o))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
313 (name (car name-def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
314 (def (cdr name-def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
315 (about (car def)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
316 (and (eq (aref about rng-c-about-override-slot) 'require)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
317 (rng-c-error "Definition of %s in include did not override definition in included file" name))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
318 (aset about rng-c-about-override-slot saved)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
319 overrides))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
320
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
321 (defun rng-c-define (def value)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
322 (and def
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
323 (let ((current-value (rng-ref-get (cdr def))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
324 (rng-ref-set (cdr def)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
325 (if current-value
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
326 (if (eq (aref (car def) rng-c-about-combine-slot)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
327 'choice)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
328 (rng-make-choice (list current-value value))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
329 (rng-make-interleave (list current-value value)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
330 value)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
331
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
332 (defun rng-c-finish-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
333 (maphash (lambda (key def)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
334 (or (rng-ref-get (cdr def))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
335 (rng-c-error "Reference to undefined pattern %s" key)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
336 rng-c-current-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
337 (rng-ref-get (cdr (or (gethash 'start rng-c-current-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
338 (rng-c-error "No definition of start")))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
339
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
340 ;;; Parsing
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
341
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
342 (defvar rng-c-escape-positions nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
343 (make-variable-buffer-local 'rng-c-escape-positions)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
344
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
345 (defvar rng-c-file-name nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
346 (make-variable-buffer-local 'rng-c-file-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
347
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
348 (defvar rng-c-file-index nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
349
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
350 (defun rng-c-parse-file (filename &optional context)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
351 (save-excursion
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
352 (set-buffer (get-buffer-create (rng-c-buffer-name context)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
353 (erase-buffer)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
354 (rng-c-init-buffer)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
355 (setq rng-c-file-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
356 (car (insert-file-contents filename)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
357 (setq rng-c-escape-positions nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
358 (rng-c-process-escapes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
359 (rng-c-parse-top-level context)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
360
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
361 (defun rng-c-buffer-name (context)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
362 (concat " *RNC Input"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
363 (if context
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
364 (concat "<"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
365 (number-to-string (setq rng-c-file-index
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
366 (1+ rng-c-file-index)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
367 ">*")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
368 (setq rng-c-file-index 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
369 "*")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
370
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
371 (defun rng-c-process-escapes ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
372 ;; Check for any nuls, since we will use nul chars
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
373 ;; for internal purposes.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
374 (let ((pos (search-forward "\C-@" nil t)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
375 (and pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
376 (rng-c-error "Nul character found (binary file?)")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
377 (let ((offset 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
378 (while (re-search-forward "\\\\x+{\\([0-9a-fA-F]+\\)}"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
379 (point-max)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
380 t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
381 (let* ((ch (decode-char 'ucs (string-to-number (match-string 1) 16))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
382 (if (and ch (> ch 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
383 (let ((begin (match-beginning 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
384 (end (match-end 0)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
385 (delete-region begin end)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
386 ;; Represent an escaped newline by nul, so
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
387 ;; that we can distinguish it from a literal newline.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
388 ;; We will translate it back into a real newline later.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
389 (insert (if (eq ch ?\n) 0 ch))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
390 (setq offset (+ offset (- end begin 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
391 (setq rng-c-escape-positions
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
392 (cons (cons (point) offset)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
393 rng-c-escape-positions)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
394 (rng-c-error "Invalid character escape")))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
395 (goto-char 1))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
396
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
397 (defun rng-c-translate-position (pos)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
398 (let ((tem rng-c-escape-positions))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
399 (while (and tem
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
400 (> (caar tem) pos))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
401 (setq tem (cdr tem)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
402 (if tem
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
403 (+ pos (cdar tem))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
404 pos)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
405
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
406 (defun rng-c-error (&rest args)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
407 (rng-c-signal-incorrect-schema rng-c-file-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
408 (rng-c-translate-position (point))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
409 (apply 'format args)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
410
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
411 (defun rng-c-parse-top-level (context)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
412 (let ((rng-c-namespace-decls nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
413 (rng-c-default-namespace nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
414 (rng-c-datatype-decls nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
415 (goto-char (point-min))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
416 (forward-comment (point-max))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
417 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
418 (rng-c-parse-decls)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
419 (let ((p (if (eq context 'include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
420 (if (rng-c-implicit-grammar-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
421 (rng-c-parse-grammar-body "")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
422 (rng-c-parse-included-grammar))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
423 (if (rng-c-implicit-grammar-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
424 (rng-c-parse-implicit-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
425 (rng-c-parse-pattern)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
426 (or (string-equal rng-c-current-token "")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
427 (rng-c-error "Unexpected characters after pattern"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
428 p)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
429
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
430 (defun rng-c-parse-included-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
431 (or (string-equal rng-c-current-token "grammar")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
432 (rng-c-error "Included schema is not a grammar"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
433 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
434 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
435 (rng-c-parse-grammar-body "}"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
436
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
437 (defun rng-c-implicit-grammar-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
438 (or (and (or (rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
439 (rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
440 (and (rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
441 (not (rng-c-current-token-keyword-p))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
442 (looking-at "\\["))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
443 (and (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
444 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
445 nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
446 (member rng-c-current-token '("div" "include" ""))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
447 (looking-at "[|&]?=")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
448
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
449 (defun rng-c-parse-decls ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
450 (setq rng-c-default-namespace-declared nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
451 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
452 (let ((binding
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
453 (assoc rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
454 '(("namespace" . rng-c-parse-namespace)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
455 ("datatypes" . rng-c-parse-datatypes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
456 ("default" . rng-c-parse-default)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
457 (if binding
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
458 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
459 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
460 (funcall (cdr binding))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
461 t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
462 nil))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
463 (rng-c-declare-standard-datatypes)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
464 (rng-c-declare-standard-namespaces))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
465
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
466 (defun rng-c-parse-datatypes ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
467 (let ((prefix (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
468 (or (not (assoc prefix rng-c-datatype-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
469 (rng-c-error "Duplicate datatypes declaration for prefix %s" prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
470 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
471 (setq rng-c-datatype-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
472 (cons (cons prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
473 (rng-make-datatypes-uri (rng-c-parse-literal)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
474 rng-c-datatype-decls))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
475
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
476 (defun rng-c-parse-namespace ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
477 (rng-c-declare-namespace nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
478 (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
479
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
480 (defun rng-c-parse-default ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
481 (rng-c-expect "namespace")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
482 (rng-c-declare-namespace t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
483 (if (string-equal rng-c-current-token "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
484 nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
485 (rng-c-parse-identifier-or-keyword))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
486
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
487 (defun rng-c-declare-namespace (declare-default prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
488 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
489 (let ((ns (cond ((string-equal rng-c-current-token "inherit")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
490 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
491 rng-c-inherit-namespace)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
492 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
493 (nxml-make-namespace (rng-c-parse-literal))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
494 (and prefix
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
495 (or (not (assoc prefix rng-c-namespace-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
496 (rng-c-error "Duplicate namespace declaration for prefix %s"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
497 prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
498 (setq rng-c-namespace-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
499 (cons (cons prefix ns) rng-c-namespace-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
500 (and declare-default
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
501 (or (not rng-c-default-namespace-declared)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
502 (rng-c-error "Duplicate default namespace declaration"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
503 (setq rng-c-default-namespace-declared t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
504 (setq rng-c-default-namespace ns))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
505
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
506 (defun rng-c-parse-implicit-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
507 (let* ((rng-c-parent-grammar rng-c-current-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
508 (rng-c-current-grammar (rng-c-make-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
509 (rng-c-parse-grammar-body "")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
510 (rng-c-finish-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
511
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
512 (defun rng-c-parse-grammar-body (close-token &optional in-include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
513 (while (not (string-equal rng-c-current-token close-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
514 (cond ((rng-c-current-token-keyword-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
515 (let ((kw (intern rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
516 (cond ((eq kw 'start)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
517 (rng-c-parse-define 'start in-include))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
518 ((eq kw 'div)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
519 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
520 (rng-c-parse-div in-include))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
521 ((eq kw 'include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
522 (and in-include
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
523 (rng-c-error "Nested include"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
524 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
525 (rng-c-parse-include))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
526 (t (rng-c-error "Invalid grammar keyword")))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
527 ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
528 (if (looking-at "\\[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
529 (rng-c-parse-annotation-element)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
530 (rng-c-parse-define rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
531 in-include)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
532 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
533 (if (looking-at "\\[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
534 (rng-c-parse-annotation-element)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
535 (rng-c-parse-define (substring rng-c-current-token 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
536 in-include)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
537 ((rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
538 (rng-c-parse-annotation-element))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
539 ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
540 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
541 (and (string-equal rng-c-current-token close-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
542 (rng-c-error "Missing annotation subject"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
543 (and (looking-at "\\[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
544 (rng-c-error "Leading annotation applied to annotation")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
545 (t (rng-c-error "Invalid grammar content"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
546 (or (string-equal rng-c-current-token "")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
547 (rng-c-advance)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
548
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
549 (defun rng-c-parse-div (in-include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
550 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
551 (rng-c-parse-grammar-body "}" in-include))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
552
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
553 (defun rng-c-parse-include ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
554 (let* ((filename (rng-c-expand-file (rng-c-parse-literal)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
555 (rng-c-inherit-namespace (rng-c-parse-opt-inherit))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
556 overrides)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
557 (cond ((string-equal rng-c-current-token "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
558 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
559 (let ((rng-c-overrides nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
560 (rng-c-parse-grammar-body "}" t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
561 (setq overrides rng-c-overrides))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
562 (setq overrides (rng-c-start-include overrides))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
563 (rng-c-parse-file filename 'include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
564 (rng-c-end-include overrides))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
565 (t (rng-c-parse-file filename 'include)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
566
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
567 (defun rng-c-parse-define (name in-include)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
568 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
569 (let ((assign (assoc rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
570 '(("=" . nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
571 ("|=" . choice)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
572 ("&=" . interleave)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
573 (or assign
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
574 (rng-c-error "Expected assignment operator"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
575 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
576 (let ((ref (rng-c-prepare-define name (cdr assign) in-include)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
577 (rng-c-define ref (rng-c-parse-pattern)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
578
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
579 (defvar rng-c-had-except nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
580
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
581 (defun rng-c-parse-pattern ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
582 (let* ((rng-c-had-except nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
583 (p (rng-c-parse-repeated))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
584 (op (assoc rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
585 '(("|" . rng-make-choice)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
586 ("," . rng-make-group)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
587 ("&" . rng-make-interleave)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
588 (if op
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
589 (if rng-c-had-except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
590 (rng-c-error "Parentheses required around pattern using -")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
591 (let* ((patterns (cons p nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
592 (tail patterns)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
593 (connector rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
594 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
595 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
596 (let ((newcdr (cons (rng-c-parse-repeated) nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
597 (setcdr tail newcdr)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
598 (setq tail newcdr))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
599 (string-equal rng-c-current-token connector)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
600 (funcall (cdr op) patterns)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
601 p)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
602
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
603 (defun rng-c-parse-repeated ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
604 (let ((p (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
605 (rng-c-parse-primary)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
606 (op (assoc rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
607 '(("*" . rng-make-zero-or-more)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
608 ("+" . rng-make-one-or-more)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
609 ("?" . rng-make-optional)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
610 (if op
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
611 (if rng-c-had-except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
612 (rng-c-error "Parentheses required around pattern using -")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
613 (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
614 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
615 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
616 (funcall (cdr op) p))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
617 p)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
618
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
619 (defun rng-c-parse-primary ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
620 "Parse a primary expression. The current token must be the first
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
621 token of the expression. After parsing the current token should be
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
622 token following the primary expression."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
623 (cond ((rng-c-current-token-keyword-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
624 (let ((parse-function (get (intern rng-c-current-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
625 'rng-c-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
626 (or parse-function
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
627 (rng-c-error "Keyword %s does not introduce a pattern"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
628 rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
629 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
630 (funcall parse-function)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
631 ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
632 (rng-c-advance-with (rng-c-make-ref rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
633 ((string-equal rng-c-current-token "(")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
634 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
635 (let ((p (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
636 (rng-c-expect ")")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
637 p))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
638 ((rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
639 (let ((name (rng-c-expand-datatype rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
640 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
641 (rng-c-parse-data name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
642 ((rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
643 (rng-make-value rng-token-datatype (rng-c-parse-literal) nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
644 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
645 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
646 (rng-c-make-ref (substring rng-c-current-token 1))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
647 ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
648 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
649 (rng-c-parse-primary))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
650 (t (rng-c-error "Invalid pattern"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
651
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
652 (defun rng-c-parse-parent ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
653 (and (rng-c-current-token-keyword-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
654 (rng-c-error "Keyword following parent was not quoted"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
655 rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
656 (rng-c-make-parent-ref (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
657
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
658 (defun rng-c-parse-literal ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
659 (rng-c-fix-escaped-newlines
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
660 (apply 'concat (rng-c-parse-literal-segments))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
661
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
662 (defun rng-c-parse-literal-segments ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
663 (let ((str (rng-c-parse-literal-segment)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
664 (cons str
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
665 (cond ((string-equal rng-c-current-token "~")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
666 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
667 (rng-c-parse-literal-segments))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
668 (t nil)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
669
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
670 (defun rng-c-parse-literal-segment ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
671 (or (rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
672 (rng-c-error "Expected a literal"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
673 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
674 (let ((n (if (and (>= (length rng-c-current-token) 6)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
675 (eq (aref rng-c-current-token 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
676 (aref rng-c-current-token 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
677 3
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
678 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
679 (substring rng-c-current-token n (- n)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
680
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
681 (defun rng-c-fix-escaped-newlines (str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
682 (let ((pos 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
683 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
684 (let ((n (string-match "\C-@" str pos)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
685 (and n
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
686 (aset str n ?\n)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
687 (setq pos (1+ n)))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
688 str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
689
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
690 (defun rng-c-parse-identifier-or-keyword ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
691 (cond ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
692 (rng-c-advance-with rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
693 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
694 (rng-c-advance-with (substring rng-c-current-token 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
695 (t (rng-c-error "Expected identifier or keyword"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
696
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
697 (put 'string 'rng-c-pattern 'rng-c-parse-string)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
698 (put 'token 'rng-c-pattern 'rng-c-parse-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
699 (put 'element 'rng-c-pattern 'rng-c-parse-element)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
700 (put 'attribute 'rng-c-pattern 'rng-c-parse-attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
701 (put 'list 'rng-c-pattern 'rng-c-parse-list)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
702 (put 'mixed 'rng-c-pattern 'rng-c-parse-mixed)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
703 (put 'text 'rng-c-pattern 'rng-c-parse-text)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
704 (put 'empty 'rng-c-pattern 'rng-c-parse-empty)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
705 (put 'notAllowed 'rng-c-pattern 'rng-c-parse-not-allowed)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
706 (put 'grammar 'rng-c-pattern 'rng-c-parse-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
707 (put 'parent 'rng-c-pattern 'rng-c-parse-parent)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
708 (put 'external 'rng-c-pattern 'rng-c-parse-external)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
709
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
710 (defun rng-c-parse-element ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
711 (let ((name-class (rng-c-parse-name-class nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
712 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
713 (let ((pattern (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
714 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
715 (rng-make-element name-class pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
716
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
717 (defun rng-c-parse-attribute ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
718 (let ((name-class (rng-c-parse-name-class 'attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
719 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
720 (let ((pattern (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
721 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
722 (rng-make-attribute name-class pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
723
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
724 (defun rng-c-parse-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
725 (let* ((rng-c-had-except nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
726 (name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
727 (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
728 (rng-c-parse-primary-name-class attribute))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
729 (if (string-equal rng-c-current-token "|")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
730 (let* ((name-classes (cons name-class nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
731 (tail name-classes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
732 (or (not rng-c-had-except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
733 (rng-c-error "Parentheses required around name-class using - operator"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
734 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
735 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
736 (let ((newcdr
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
737 (cons (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
738 (rng-c-parse-primary-name-class attribute))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
739 nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
740 (setcdr tail newcdr)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
741 (setq tail newcdr))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
742 (string-equal rng-c-current-token "|")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
743 (rng-make-choice-name-class name-classes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
744 name-class)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
745
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
746 (defun rng-c-parse-primary-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
747 (cond ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
748 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
749 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
750 (rng-make-name (rng-c-unqualified-namespace attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
751 rng-c-current-token))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
752 ((rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
753 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
754 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
755 (rng-c-expand-name rng-c-current-token))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
756 ((string-equal rng-c-current-token "*")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
757 (let ((except (rng-c-parse-opt-except-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
758 (if except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
759 (rng-make-any-name-except-name-class except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
760 (rng-make-any-name-name-class))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
761 ((rng-c-current-token-ns-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
762 (let* ((ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
763 (rng-c-lookup-prefix (substring rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
764 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
765 -2)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
766 (except (rng-c-parse-opt-except-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
767 (if except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
768 (rng-make-ns-name-except-name-class ns except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
769 (rng-make-ns-name-name-class ns))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
770 ((string-equal rng-c-current-token "(")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
771 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
772 (let ((name-class (rng-c-parse-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
773 (rng-c-expect ")")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
774 name-class))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
775 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
776 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
777 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
778 (rng-make-name (rng-c-unqualified-namespace attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
779 (substring rng-c-current-token 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
780 ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
781 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
782 (rng-c-parse-primary-name-class attribute))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
783 (t (rng-c-error "Bad name class"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
784
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
785 (defun rng-c-parse-opt-except-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
786 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
787 (and (string-equal rng-c-current-token "-")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
788 (or (not rng-c-had-except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
789 (rng-c-error "Parentheses required around name-class using - operator"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
790 (setq rng-c-had-except t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
791 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
792 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
793 (rng-c-parse-primary-name-class attribute))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
794
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
795 (defun rng-c-parse-mixed ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
796 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
797 (let ((pattern (rng-make-mixed (rng-c-parse-pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
798 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
799 pattern))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
800
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
801 (defun rng-c-parse-list ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
802 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
803 (let ((pattern (rng-make-list (rng-c-parse-pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
804 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
805 pattern))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
806
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
807 (defun rng-c-parse-text ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
808 (rng-make-text))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
809
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
810 (defun rng-c-parse-empty ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
811 (rng-make-empty))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
812
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
813 (defun rng-c-parse-not-allowed ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
814 (rng-make-not-allowed))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
815
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
816 (defun rng-c-parse-string ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
817 (rng-c-parse-data rng-string-datatype))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
818
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
819 (defun rng-c-parse-token ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
820 (rng-c-parse-data rng-token-datatype))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
821
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
822 (defun rng-c-parse-data (name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
823 (if (rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
824 (rng-make-value name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
825 (rng-c-parse-literal)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
826 (and (car name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
827 (rng-c-make-context)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
828 (let ((params (rng-c-parse-optional-params)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
829 (if (string-equal rng-c-current-token "-")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
830 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
831 (if rng-c-had-except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
832 (rng-c-error "Parentheses required around pattern using -")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
833 (setq rng-c-had-except t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
834 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
835 (rng-make-data-except name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
836 params
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
837 (rng-c-parse-primary)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
838 (rng-make-data name params)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
839
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
840 (defun rng-c-parse-optional-params ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
841 (and (string-equal rng-c-current-token "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
842 (let* ((head (cons nil nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
843 (tail head))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
844 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
845 (while (not (string-equal rng-c-current-token "}"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
846 (and (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
847 (rng-c-parse-lead-annotation))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
848 (let ((name (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
849 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
850 (let ((newcdr (cons (cons (intern name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
851 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
852 nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
853 (setcdr tail newcdr)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
854 (setq tail newcdr))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
855 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
856 (cdr head))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
857
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
858 (defun rng-c-parse-external ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
859 (let* ((filename (rng-c-expand-file (rng-c-parse-literal)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
860 (rng-c-inherit-namespace (rng-c-parse-opt-inherit)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
861 (rng-c-parse-file filename 'external)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
862
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
863 (defun rng-c-expand-file (uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
864 (condition-case err
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
865 (rng-uri-file-name (rng-uri-resolve uri
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
866 (rng-file-name-uri rng-c-file-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
867 (rng-uri-error
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
868 (rng-c-error (cadr err)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
869
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
870 (defun rng-c-parse-opt-inherit ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
871 (cond ((string-equal rng-c-current-token "inherit")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
872 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
873 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
874 (rng-c-lookup-prefix (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
875 (t rng-c-default-namespace)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
876
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
877 (defun rng-c-parse-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
878 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
879 (let* ((rng-c-parent-grammar rng-c-current-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
880 (rng-c-current-grammar (rng-c-make-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
881 (rng-c-parse-grammar-body "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
882 (rng-c-finish-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
883
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
884 (defun rng-c-parse-lead-annotation ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
885 (rng-c-parse-annotation-body)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
886 (and (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
887 (rng-c-error "Multiple leading annotations")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
888
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
889 (defun rng-c-parse-follow-annotations (obj)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
890 (while (string-equal rng-c-current-token ">>")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
891 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
892 (if (rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
893 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
894 (rng-c-parse-identifier-or-keyword))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
895 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
896 obj)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
897
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
898 (defun rng-c-parse-annotation-element ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
899 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
900 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
901
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
902 ;; XXX need stricter checking of attribute names
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
903 ;; XXX don't allow attributes after text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
904
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
905 (defun rng-c-parse-annotation-body (&optional allow-text)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
906 "Current token is [. Parse up to matching ]. Current token after
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
907 parse is token following ]."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
908 (or (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
909 (rng-c-error "Expected ["))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
910 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
911 (while (not (string-equal rng-c-current-token "]"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
912 (cond ((rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
913 (or allow-text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
914 (rng-c-error "Out of place text within annotation"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
915 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
916 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
917 (if (rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
918 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
919 (rng-c-parse-identifier-or-keyword))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
920 (cond ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
921 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
922 ((string-equal rng-c-current-token "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
923 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
924 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
925 (t (rng-c-error "Expected = or ["))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
926 (rng-c-advance))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
927
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
928 (defun rng-c-advance-with (pattern)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
929 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
930 pattern)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
931
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
932 (defun rng-c-expect (str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
933 (or (string-equal rng-c-current-token str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
934 (rng-c-error "Expected `%s' but got `%s'" str rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
935 (rng-c-advance))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
936
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
937 (provide 'rng-cmpct)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
938
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
939 ;;; rng-cmpct.el
86379
2ac1a9b70580 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 86361
diff changeset
940
2ac1a9b70580 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 86361
diff changeset
941 ;; arch-tag: 90395eb1-283b-4146-bbc1-6d6ef1704e57