annotate lisp/nxml/rng-cmpct.el @ 98517:04d30d4471c2

(vc-cvs-dir-status-heuristic): New function. (vc-cvs-dir-status): Respect vc-stay-local-p. (Bug#1046)
author Glenn Morris <rgm@gnu.org>
date Sat, 04 Oct 2008 19:54:48 +0000
parents e374c747704b
children a9dc0e7c3f2b
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
94666
d495d4d5452f Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87665
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
86545
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
94666
d495d4d5452f Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87665
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
d495d4d5452f Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87665
diff changeset
13 ;; (at your option) 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
94666
d495d4d5452f Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87665
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
22
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
23 ;;; Commentary:
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 ;; 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
26 ;; specified in rng-pttrn.el.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
27 ;;
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
28 ;; RELAX NG Compact Syntax is specified by
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
29 ;; http://relaxng.org/compact.html
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
30 ;;
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
31 ;; This file uses the prefix "rng-c-".
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 ;;; Code:
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 (require 'nxml-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
36 (require 'rng-util)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
37 (require 'rng-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
38 (require 'rng-pttrn)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
39
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
40 ;;;###autoload
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
41 (defun rng-c-load-schema (filename)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
42 "Load a schema in RELAX NG compact syntax from FILENAME.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
43 Return a pattern."
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
44 (rng-c-parse-file filename))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
45
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
46 ;;; Error handling
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 (put 'rng-c-incorrect-schema
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
49 'error-conditions
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
50 '(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
51
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
52 (put 'rng-c-incorrect-schema
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
53 'error-message
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
54 "Incorrect schema")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
55
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
56 (defun rng-c-signal-incorrect-schema (filename pos message)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
57 (nxml-signal-file-parse-error filename
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
58 pos
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
59 message
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
60 'rng-c-incorrect-schema))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
61
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
62 ;;; Lexing
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 (defconst rng-c-keywords
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
65 '("attribute"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
66 "default"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
67 "datatypes"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
68 "div"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
69 "element"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
70 "empty"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
71 "external"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
72 "grammar"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
73 "include"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
74 "inherit"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
75 "list"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
76 "mixed"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
77 "namespace"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
78 "notAllowed"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
79 "parent"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
80 "start"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
81 "string"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
82 "text"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
83 "token")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
84 "List of strings that are keywords in the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
85
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
86 (defconst rng-c-anchored-keyword-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
87 (concat "\\`\\(" (regexp-opt rng-c-keywords) "\\)\\'")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
88 "Regular expression to match a keyword in the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
89
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
90 (defvar rng-c-syntax-table nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
91 "Syntax table for parsing the compact syntax.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
92
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
93 (if rng-c-syntax-table
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 (setq rng-c-syntax-table (make-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
96 (modify-syntax-entry ?# "<" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
97 (modify-syntax-entry ?\n ">" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
98 (modify-syntax-entry ?- "w" rng-c-syntax-table)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
99 (modify-syntax-entry ?. "w" 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 ?: "_" rng-c-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
102
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
103 (defconst rng-c-literal-1-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
104 "'\\(''\\([^']\\|'[^']\\|''[^']\\)*''\\|[^'\n]*\\)'"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
105 "Regular expression to match a single-quoted literal.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
106
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
107 (defconst rng-c-literal-2-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
108 (replace-regexp-in-string "'" "\"" rng-c-literal-1-re)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
109 "Regular expression to match a double-quoted literal.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
110
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
111 (defconst rng-c-ncname-re "\\w+")
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-anchored-ncname-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
114 (concat "\\`" rng-c-ncname-re "\\'"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
115
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
116 (defconst rng-c-token-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
117 (concat "[&|]=" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
118 "[][()|&,*+?{}~=-]" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
119 rng-c-literal-1-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
120 rng-c-literal-2-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
121 rng-c-ncname-re "\\(:\\(\\*\\|" rng-c-ncname-re "\\)\\)?" "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
122 "\\\\" rng-c-ncname-re "\\|"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
123 ">>")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
124 "Regular expression to match a token in the compact syntax.")
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 (defun rng-c-init-buffer ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
127 (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
128 (set-buffer-multibyte t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
129 (set-syntax-table rng-c-syntax-table))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
130
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
131 (defvar rng-c-current-token nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
132 (make-variable-buffer-local 'rng-c-current-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
133
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
134 (defun rng-c-advance ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
135 (cond ((looking-at rng-c-token-re)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
136 (setq rng-c-current-token (match-string 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
137 (goto-char (match-end 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
138 (forward-comment (point-max)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
139 ((= (point) (point-max))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
140 (setq rng-c-current-token ""))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
141 (t (rng-c-error "Invalid token"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
142
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
143 (defconst rng-c-anchored-datatype-name-re
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
144 (concat "\\`" rng-c-ncname-re ":" rng-c-ncname-re "\\'"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
145
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
146 (defsubst rng-c-current-token-keyword-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
147 (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
148
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
149 (defsubst rng-c-current-token-prefixed-name-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
150 (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
151
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
152 (defsubst rng-c-current-token-literal-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
153 (string-match "\\`['\"]" rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
154
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
155 (defsubst rng-c-current-token-quoted-identifier-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
156 (string-match "\\`\\\\" rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
157
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
158 (defsubst rng-c-current-token-ncname-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
159 (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
160
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
161 (defsubst rng-c-current-token-ns-name-p ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
162 (let ((len (length rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
163 (and (> len 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
164 (= (aref rng-c-current-token (- len 1)) ?*))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
165
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
166 ;;; Namespaces
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 (defvar rng-c-inherit-namespace nil)
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-default-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-declared 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-namespace-decls nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
175 "Alist of namespace declarations.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
176
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
177 (defconst rng-c-no-namespace nil)
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 (defun rng-c-declare-standard-namespaces ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
180 (setq rng-c-namespace-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
181 (cons (cons "xml" nxml-xml-namespace-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
182 rng-c-namespace-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
183 (when (and (not rng-c-default-namespace-declared)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
184 rng-c-inherit-namespace)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
185 (setq rng-c-default-namespace rng-c-inherit-namespace)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
186
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
187 (defun rng-c-expand-name (prefixed-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
188 (let ((i (string-match ":" prefixed-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
189 (rng-make-name (rng-c-lookup-prefix (substring prefixed-name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
190 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
191 i))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
192 (substring prefixed-name (+ i 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
193
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
194 (defun rng-c-lookup-prefix (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
195 (let ((binding (assoc prefix rng-c-namespace-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
196 (or binding (rng-c-error "Undefined prefix %s" prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
197 (cdr binding)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
198
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
199 (defun rng-c-unqualified-namespace (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
200 (if attribute
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
201 rng-c-no-namespace
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
202 rng-c-default-namespace))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
203
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
204 (defun rng-c-make-context ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
205 (cons rng-c-default-namespace rng-c-namespace-decls))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
206
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
207 ;;; Datatypes
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 (defconst rng-string-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
210 (rng-make-datatype rng-builtin-datatypes-uri "string"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
211
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
212 (defconst rng-token-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
213 (rng-make-datatype rng-builtin-datatypes-uri "token"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
214
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
215 (defvar rng-c-datatype-decls nil
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
216 "Alist of datatype declarations.
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
217 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
218 and URI is a symbol.")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
219
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
220 (defun rng-c-declare-standard-datatypes ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
221 (setq rng-c-datatype-decls
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
222 (cons (cons "xsd" rng-xsd-datatypes-uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
223 rng-c-datatype-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
224
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
225 (defun rng-c-lookup-datatype-prefix (prefix)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
226 (let ((binding (assoc prefix rng-c-datatype-decls)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
227 (or binding (rng-c-error "Undefined prefix %s" prefix))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
228 (cdr binding)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
229
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
230 (defun rng-c-expand-datatype (prefixed-name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
231 (let ((i (string-match ":" prefixed-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
232 (rng-make-datatype
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
233 (rng-c-lookup-datatype-prefix (substring prefixed-name 0 i))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
234 (substring prefixed-name (+ i 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
235
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
236 ;;; Grammars
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 (defvar rng-c-current-grammar nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
239 (defvar rng-c-parent-grammar nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
240
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
241 (defun rng-c-make-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
242 (make-hash-table :test 'equal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
243
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
244 (defconst rng-c-about-override-slot 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
245 (defconst rng-c-about-combine-slot 1)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
246
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
247 (defun rng-c-lookup-create (name grammar)
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
248 "Return a def object for NAME.
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
249 A def object is a pair \(ABOUT . REF) where REF is returned by
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
250 `rng-make-ref'.
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
251 ABOUT is a two-element vector [OVERRIDE COMBINE].
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
252 COMBINE is either nil, choice or interleave.
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
253 OVERRIDE is either nil, require or t."
86361
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
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
257 (progn
86361
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))))
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
475
86361
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")
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
482 (rng-c-declare-namespace t
86361
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 ()
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
620 "Parse a primary expression.
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
621 The current token must be the first token of the expression.
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
622 After parsing the current token should be the token following
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
623 the primary expression."
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
624 (cond ((rng-c-current-token-keyword-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
625 (let ((parse-function (get (intern rng-c-current-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
626 'rng-c-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
627 (or parse-function
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
628 (rng-c-error "Keyword %s does not introduce a pattern"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
629 rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
630 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
631 (funcall parse-function)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
632 ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
633 (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
634 ((string-equal rng-c-current-token "(")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
635 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
636 (let ((p (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
637 (rng-c-expect ")")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
638 p))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
639 ((rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
640 (let ((name (rng-c-expand-datatype rng-c-current-token)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
641 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
642 (rng-c-parse-data name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
643 ((rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
644 (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
645 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
646 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
647 (rng-c-make-ref (substring rng-c-current-token 1))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
648 ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
649 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
650 (rng-c-parse-primary))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
651 (t (rng-c-error "Invalid pattern"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
652
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
653 (defun rng-c-parse-parent ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
654 (and (rng-c-current-token-keyword-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
655 (rng-c-error "Keyword following parent was not quoted"
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
656 rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
657 (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
658
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
659 (defun rng-c-parse-literal ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
660 (rng-c-fix-escaped-newlines
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
661 (apply 'concat (rng-c-parse-literal-segments))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
662
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
663 (defun rng-c-parse-literal-segments ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
664 (let ((str (rng-c-parse-literal-segment)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
665 (cons str
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
666 (cond ((string-equal rng-c-current-token "~")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
667 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
668 (rng-c-parse-literal-segments))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
669 (t nil)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
670
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
671 (defun rng-c-parse-literal-segment ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
672 (or (rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
673 (rng-c-error "Expected a literal"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
674 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
675 (let ((n (if (and (>= (length rng-c-current-token) 6)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
676 (eq (aref rng-c-current-token 0)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
677 (aref rng-c-current-token 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
678 3
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
679 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
680 (substring rng-c-current-token n (- n)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
681
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
682 (defun rng-c-fix-escaped-newlines (str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
683 (let ((pos 0))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
684 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
685 (let ((n (string-match "\C-@" str pos)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
686 (and n
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
687 (aset str n ?\n)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
688 (setq pos (1+ n)))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
689 str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
690
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
691 (defun rng-c-parse-identifier-or-keyword ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
692 (cond ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
693 (rng-c-advance-with rng-c-current-token))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
694 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
695 (rng-c-advance-with (substring rng-c-current-token 1)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
696 (t (rng-c-error "Expected identifier or keyword"))))
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
697
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
698 (put 'string 'rng-c-pattern 'rng-c-parse-string)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
699 (put 'token 'rng-c-pattern 'rng-c-parse-token)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
700 (put 'element 'rng-c-pattern 'rng-c-parse-element)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
701 (put 'attribute 'rng-c-pattern 'rng-c-parse-attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
702 (put 'list 'rng-c-pattern 'rng-c-parse-list)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
703 (put 'mixed 'rng-c-pattern 'rng-c-parse-mixed)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
704 (put 'text 'rng-c-pattern 'rng-c-parse-text)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
705 (put 'empty 'rng-c-pattern 'rng-c-parse-empty)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
706 (put 'notAllowed 'rng-c-pattern 'rng-c-parse-not-allowed)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
707 (put 'grammar 'rng-c-pattern 'rng-c-parse-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
708 (put 'parent 'rng-c-pattern 'rng-c-parse-parent)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
709 (put 'external 'rng-c-pattern 'rng-c-parse-external)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
710
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
711 (defun rng-c-parse-element ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
712 (let ((name-class (rng-c-parse-name-class nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
713 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
714 (let ((pattern (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
715 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
716 (rng-make-element name-class pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
717
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
718 (defun rng-c-parse-attribute ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
719 (let ((name-class (rng-c-parse-name-class 'attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
720 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
721 (let ((pattern (rng-c-parse-pattern)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
722 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
723 (rng-make-attribute name-class pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
724
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
725 (defun rng-c-parse-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
726 (let* ((rng-c-had-except nil)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
727 (name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
728 (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
729 (rng-c-parse-primary-name-class attribute))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
730 (if (string-equal rng-c-current-token "|")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
731 (let* ((name-classes (cons name-class nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
732 (tail name-classes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
733 (or (not rng-c-had-except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
734 (rng-c-error "Parentheses required around name-class using - operator"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
735 (while (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
736 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
737 (let ((newcdr
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
738 (cons (rng-c-parse-follow-annotations
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
739 (rng-c-parse-primary-name-class attribute))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
740 nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
741 (setcdr tail newcdr)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
742 (setq tail newcdr))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
743 (string-equal rng-c-current-token "|")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
744 (rng-make-choice-name-class name-classes))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
745 name-class)))
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
746
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
747 (defun rng-c-parse-primary-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
748 (cond ((rng-c-current-token-ncname-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
749 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
750 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
751 (rng-make-name (rng-c-unqualified-namespace attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
752 rng-c-current-token))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
753 ((rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
754 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
755 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
756 (rng-c-expand-name rng-c-current-token))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
757 ((string-equal rng-c-current-token "*")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
758 (let ((except (rng-c-parse-opt-except-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
759 (if except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
760 (rng-make-any-name-except-name-class except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
761 (rng-make-any-name-name-class))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
762 ((rng-c-current-token-ns-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
763 (let* ((ns
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
764 (rng-c-lookup-prefix (substring rng-c-current-token
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
765 0
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
766 -2)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
767 (except (rng-c-parse-opt-except-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
768 (if except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
769 (rng-make-ns-name-except-name-class ns except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
770 (rng-make-ns-name-name-class ns))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
771 ((string-equal rng-c-current-token "(")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
772 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
773 (let ((name-class (rng-c-parse-name-class attribute)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
774 (rng-c-expect ")")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
775 name-class))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
776 ((rng-c-current-token-quoted-identifier-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
777 (rng-c-advance-with
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
778 (rng-make-name-name-class
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
779 (rng-make-name (rng-c-unqualified-namespace attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
780 (substring rng-c-current-token 1)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
781 ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
782 (rng-c-parse-lead-annotation)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
783 (rng-c-parse-primary-name-class attribute))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
784 (t (rng-c-error "Bad name class"))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
785
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
786 (defun rng-c-parse-opt-except-name-class (attribute)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
787 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
788 (and (string-equal rng-c-current-token "-")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
789 (or (not rng-c-had-except)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
790 (rng-c-error "Parentheses required around name-class using - operator"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
791 (setq rng-c-had-except t)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
792 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
793 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
794 (rng-c-parse-primary-name-class attribute))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
795
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
796 (defun rng-c-parse-mixed ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
797 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
798 (let ((pattern (rng-make-mixed (rng-c-parse-pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
799 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
800 pattern))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
801
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
802 (defun rng-c-parse-list ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
803 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
804 (let ((pattern (rng-make-list (rng-c-parse-pattern))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
805 (rng-c-expect "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
806 pattern))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
807
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
808 (defun rng-c-parse-text ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
809 (rng-make-text))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
810
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
811 (defun rng-c-parse-empty ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
812 (rng-make-empty))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
813
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
814 (defun rng-c-parse-not-allowed ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
815 (rng-make-not-allowed))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
816
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
817 (defun rng-c-parse-string ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
818 (rng-c-parse-data rng-string-datatype))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
819
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
820 (defun rng-c-parse-token ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
821 (rng-c-parse-data rng-token-datatype))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
822
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
823 (defun rng-c-parse-data (name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
824 (if (rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
825 (rng-make-value name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
826 (rng-c-parse-literal)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
827 (and (car name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
828 (rng-c-make-context)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
829 (let ((params (rng-c-parse-optional-params)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
830 (if (string-equal rng-c-current-token "-")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
831 (progn
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
832 (if rng-c-had-except
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
833 (rng-c-error "Parentheses required around pattern using -")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
834 (setq rng-c-had-except t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
835 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
836 (rng-make-data-except name
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
837 params
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
838 (rng-c-parse-primary)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
839 (rng-make-data name params)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
840
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
841 (defun rng-c-parse-optional-params ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
842 (and (string-equal rng-c-current-token "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
843 (let* ((head (cons nil nil))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
844 (tail head))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
845 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
846 (while (not (string-equal rng-c-current-token "}"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
847 (and (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
848 (rng-c-parse-lead-annotation))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
849 (let ((name (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
850 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
851 (let ((newcdr (cons (cons (intern name)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
852 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
853 nil)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
854 (setcdr tail newcdr)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
855 (setq tail newcdr))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
856 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
857 (cdr head))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
858
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
859 (defun rng-c-parse-external ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
860 (let* ((filename (rng-c-expand-file (rng-c-parse-literal)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
861 (rng-c-inherit-namespace (rng-c-parse-opt-inherit)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
862 (rng-c-parse-file filename 'external)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
863
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
864 (defun rng-c-expand-file (uri)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
865 (condition-case err
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
866 (rng-uri-file-name (rng-uri-resolve uri
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
867 (rng-file-name-uri rng-c-file-name)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
868 (rng-uri-error
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
869 (rng-c-error (cadr err)))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
870
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
871 (defun rng-c-parse-opt-inherit ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
872 (cond ((string-equal rng-c-current-token "inherit")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
873 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
874 (rng-c-expect "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
875 (rng-c-lookup-prefix (rng-c-parse-identifier-or-keyword)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
876 (t rng-c-default-namespace)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
877
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
878 (defun rng-c-parse-grammar ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
879 (rng-c-expect "{")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
880 (let* ((rng-c-parent-grammar rng-c-current-grammar)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
881 (rng-c-current-grammar (rng-c-make-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
882 (rng-c-parse-grammar-body "}")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
883 (rng-c-finish-grammar)))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
884
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
885 (defun rng-c-parse-lead-annotation ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
886 (rng-c-parse-annotation-body)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
887 (and (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
888 (rng-c-error "Multiple leading annotations")))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
889
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
890 (defun rng-c-parse-follow-annotations (obj)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
891 (while (string-equal rng-c-current-token ">>")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
892 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
893 (if (rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
894 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
895 (rng-c-parse-identifier-or-keyword))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
896 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
897 obj)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
898
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
899 (defun rng-c-parse-annotation-element ()
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
900 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
901 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
902
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
903 ;; XXX need stricter checking of attribute names
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
904 ;; XXX don't allow attributes after text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
905
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
906 (defun rng-c-parse-annotation-body (&optional allow-text)
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
907 "Current token is [. Parse up to matching ].
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
908 Current token after parse is token following ]."
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
909 (or (string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
910 (rng-c-error "Expected ["))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
911 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
912 (while (not (string-equal rng-c-current-token "]"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
913 (cond ((rng-c-current-token-literal-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
914 (or allow-text
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
915 (rng-c-error "Out of place text within annotation"))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
916 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
917 (t
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
918 (if (rng-c-current-token-prefixed-name-p)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
919 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
920 (rng-c-parse-identifier-or-keyword))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
921 (cond ((string-equal rng-c-current-token "[")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
922 (rng-c-parse-annotation-body t))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
923 ((string-equal rng-c-current-token "=")
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
924 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
925 (rng-c-parse-literal))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
926 (t (rng-c-error "Expected = or ["))))))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
927 (rng-c-advance))
96496
e374c747704b Fix typos, and general docstring cleanup.
Juanma Barranquero <lekktu@gmail.com>
parents: 94666
diff changeset
928
86361
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
929 (defun rng-c-advance-with (pattern)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
930 (rng-c-advance)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
931 pattern)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
932
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
933 (defun rng-c-expect (str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
934 (or (string-equal rng-c-current-token str)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
935 (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
936 (rng-c-advance))
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
937
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
938 (provide 'rng-cmpct)
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
939
38f93f3d00a2 Initial merge of nxml
Mark A. Hershberger <mah@everybody.org>
parents:
diff changeset
940 ;;; rng-cmpct.el
86379
2ac1a9b70580 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 86361
diff changeset
941
2ac1a9b70580 Add arch tagline
Miles Bader <miles@gnu.org>
parents: 86361
diff changeset
942 ;; arch-tag: 90395eb1-283b-4146-bbc1-6d6ef1704e57