1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2008
21 * the Initial Developer. All Rights Reserved.
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
50 Token
Lexer::xmlAtomImpl()
55 compiler
->syntaxError(lineno
, SYNTAXERR_XML_EOI_IN_MARKUP
);
67 return xmlMarkup(T_XmlCDATA
);
69 if (idx
[2] == '-' && idx
[3] == '-') {
71 return xmlMarkup(T_XmlComment
);
73 compiler
->syntaxError(lineno
, SYNTAXERR_XML_INVALID_LEFTBANG
);
77 return xmlMarkup(T_XmlProcessingInstruction
);
81 return T_XmlLeftAngleSlash
;
85 return T_XmlLeftAngle
;
91 return T_XmlSlashRightAngle
;
93 compiler
->syntaxError(lineno
, SYNTAXERR_XML_INVALID_SLASH
);
97 return T_XmlRightAngle
;
101 return T_XmlLeftBrace
;
105 return T_XmlRightBrace
;
115 return xmlWhitespace();
122 if (isXmlNameStart(idx
[0]))
129 // Capture everything from the starting through the ending punctuation.
131 Token
Lexer::xmlMarkup(Token token
)
136 mark
= idx
-4; // "<!--"
139 mark
= idx
-9; // "<![CDATA["
141 case T_XmlProcessingInstruction
:
142 mark
= idx
-2; // "<?"
145 AvmAssert(!"Inconsistent internal state");
148 while (idx
< limit
) {
149 if (idx
[0] == '-' || idx
[0] == '?' || idx
[0] == ']') {
152 if (idx
[0] == '-' && idx
[1] == '-') {
153 // Done; we require > to follow but it's not part of the stop condition.
155 compiler
->syntaxError(lineno
, SYNTAXERR_XML_ILLEGAL_CHARS
);
161 if (idx
[0] == ']' && idx
[1] == ']' && idx
[2] == '>') {
167 case T_XmlProcessingInstruction
:
168 if (idx
[0] == '?' && idx
[1] == '>') {
194 compiler
->syntaxError(l
, SYNTAXERR_XML_UNTERMINATED
);
195 val
.s
= compiler
->intern(mark
, uint32_t(idx
-mark
));
199 Token
Lexer::xmlWhitespace()
202 while (idx
< limit
) {
221 val
.s
= compiler
->intern(mark
, uint32_t(idx
-mark
));
222 return T_XmlWhitespace
;
225 Token
Lexer::xmlName()
227 AvmAssert( isXmlNameStart(*idx
) );
229 while (isXmlNameSubsequent(*idx
))
231 val
.s
= compiler
->intern(mark
, uint32_t(idx
-mark
));
235 // mark has been set at the beginning of the starting punctuation,
236 // we wish to capture the ending punctuation as well.
238 Token
Lexer::xmlString()
240 wchar terminator
= *idx
;
244 while (idx
< limit
&& *idx
!= terminator
) {
251 else if (*idx
== '\n') {
260 compiler
->syntaxError(l
, SYNTAXERR_XML_UNTERMINATED
);
263 val
.s
= compiler
->intern(mark
, uint32_t(idx
-mark
));
267 // FIXME: E4X says to stop only at "{" and "<".
269 Token
Lexer::xmlText()
272 while (idx
< limit
) {
286 if (isXmlNameStart(*idx
))
292 val
.s
= compiler
->intern(mark
, uint32_t(idx
-mark
));
296 bool Lexer::isXmlNameStart(wchar c
)
298 return isUnicodeLetter(c
) || c
== ':' || c
== '_';
301 bool Lexer::isXmlNameSubsequent(wchar c
)
303 return isUnicodeLetter(c
) || isUnicodeDigit(c
) || c
== '_' || c
== ':' || c
== '.' || c
== '-';