summaryrefslogtreecommitdiffstats
path: root/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
diff options
context:
space:
mode:
authorSteve Block <steveblock@google.com>2010-02-05 14:27:46 +0000
committerSteve Block <steveblock@google.com>2010-02-15 10:49:50 +0000
commit5e2bc6953fe6923165b8a5d7679939693a1d58d6 (patch)
tree6ccb8c24bc2bf5e8f413e6cfae250b729b426631 /WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
parent4a00f4fccc3cb7e9996749a05631f5d7b9de756e (diff)
downloadexternal_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.zip
external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.gz
external_webkit-5e2bc6953fe6923165b8a5d7679939693a1d58d6.tar.bz2
Merge webkit.org at r54340 : Initial merge by git
Change-Id: Ib489d2ff91186ea3652522e1d586e54416a2cf44
Diffstat (limited to 'WebCore/inspector/front-end/SourceHTMLTokenizer.re2js')
-rw-r--r--WebCore/inspector/front-end/SourceHTMLTokenizer.re2js174
1 files changed, 92 insertions, 82 deletions
diff --git a/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js b/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
index e56f3ff..89c535a 100644
--- a/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
+++ b/WebCore/inspector/front-end/SourceHTMLTokenizer.re2js
@@ -44,72 +44,81 @@ WebInspector.SourceHTMLTokenizer = function()
{
WebInspector.SourceTokenizer.call(this);
+ // The order is determined by the generated code.
this._lexConditions = {
INITIAL: 0,
COMMENT: 1,
- DSTRING: 2,
- SSTRING: 3
+ DOCTYPE: 2,
+ TAG: 3,
+ DSTRING: 4,
+ SSTRING: 5
};
+ this.case_INITIAL = 1000;
+ this.case_COMMENT = 1001;
+ this.case_DOCTYPE = 1002;
+ this.case_TAG = 1003;
+ this.case_DSTRING = 1004;
+ this.case_SSTRING = 1005;
this._parseConditions = {
INITIAL: 0,
- TAG: 1,
- ATTRIBUTE: 2,
- ATTRIBUTE_VALUE: 3,
- SCRIPT: 4,
- SCRIPT_ATTRIBUTE: 5,
- SCRIPT_ATTRIBUTE_VALUE: 6,
- DOCTYPE: 7
+ ATTRIBUTE: 1,
+ ATTRIBUTE_VALUE: 2,
+ LINKIFY: 4,
+ A_NODE: 8,
+ SCRIPT: 16
};
- this.case_INITIAL = 1000;
- this.case_COMMENT = 1001;
- this.case_DSTRING = 1002;
- this.case_SSTRING = 1003;
-
this.initialCondition = { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
}
WebInspector.SourceHTMLTokenizer.prototype = {
- _isAttribute: function()
+ _isExpectingAttribute: function()
{
- return this._parseCondition === this._parseConditions.ATTRIBUTE || this._parseCondition === this._parseConditions.SCRIPT_ATTRIBUTE;
+ return this._parseCondition & this._parseConditions.ATTRIBUTE;
},
- _isAttributeValue: function()
+ _isExpectingAttributeValue: function()
{
- return this._parseCondition === this._parseConditions.ATTRIBUTE_VALUE || this._parseCondition === this._parseConditions.SCRIPT_ATTRIBUTE_VALUE;
+ return this._parseCondition & this._parseConditions.ATTRIBUTE_VALUE;
},
- _setAttributeValue: function()
+ _setExpectingAttribute: function()
{
- if (this._parseCondition === this._parseConditions.ATTRIBUTE)
- this._parseCondition = this._parseConditions.ATTRIBUTE_VALUE;
- else if (this._parseCondition === this._parseConditions.SCRIPT_ATTRIBUTE)
- this._parseCondition = this._parseConditions.SCRIPT_ATTRIBUTE_VALUE;
+ if (this._isExpectingAttributeValue())
+ this._parseCondition ^= this._parseConditions.ATTRIBUTE_VALUE;
+ this._parseCondition |= this._parseConditions.ATTRIBUTE;
},
- _setAttribute: function()
+ _setExpectingAttributeValue: function()
{
- if (this._parseCondition === this._parseConditions.ATTRIBUTE_VALUE)
- this._parseCondition = this._parseConditions.ATTRIBUTE;
- else if (this._parseCondition === this._parseConditions.SCRIPT_ATTRIBUTE_VALUE)
- this._parseCondition = this._parseConditions.SCRIPT_ATTRIBUTE;
+ if (this._isExpectingAttribute())
+ this._parseCondition ^= this._parseConditions.ATTRIBUTE;
+ this._parseCondition |= this._parseConditions.ATTRIBUTE_VALUE;
},
_stringToken: function(cursor, stringEnds)
{
- if (this._isAttributeValue()) {
- this.tokenType = "html-attr-value";
- if (stringEnds)
- this._setAttribute();
- } else if (this._parseCondition === this._parseConditions.DOCTYPE)
- this.tokenType = "html-doctype";
- else
+ if (!this._isExpectingAttributeValue()) {
this.tokenType = null;
+ return cursor;
+ }
+ this.tokenType = this._attrValueTokenType();
+ if (stringEnds)
+ this._setExpectingAttribute();
return cursor;
},
+ _attrValueTokenType: function()
+ {
+ if (this._parseCondition & this._parseConditions.LINKIFY) {
+ if (this._parseCondition & this._parseConditions.A_NODE)
+ return "html-external-link";
+ return "html-resource-link";
+ }
+ return "html-attribute-value";
+ },
+
nextToken: function(cursor)
{
var cursorOnEnter = cursor;
@@ -134,7 +143,9 @@ WebInspector.SourceHTMLTokenizer.prototype = {
CommentStart = "<!--" CommentContent [\r\n];
CommentEnd = CommentContent "-->";
- DocTypeLT = "<!" [Dd] [Oo] [Cc] [Tt] [Yy] [Pp] [Ee];
+ DocTypeStart = "<!" [Dd] [Oo] [Cc] [Tt] [Yy] [Pp] [Ee];
+ DocTypeContent = [^\r\n>]*;
+
ScriptStart = "<" [Ss] [Cc] [Rr] [Ii] [Pp] [Tt];
ScriptEnd = "</" [Ss] [Cc] [Rr] [Ii] [Pp] [Tt];
@@ -150,101 +161,100 @@ WebInspector.SourceHTMLTokenizer.prototype = {
SingleStringStart = "'" SingleStringContent [\r\n];
SingleStringEnd = SingleStringContent "'";
- Identifier = [_a-zA-Z0-9\x80-\xFF]+;
+ Identifier = [^ \r\n"'<>\[\]=]+;
<INITIAL> Comment { this.tokenType = "html-comment"; return cursor; }
<INITIAL> CommentStart => COMMENT { this.tokenType = "html-comment"; return cursor; }
<COMMENT> CommentContent => COMMENT { this.tokenType = "html-comment"; return cursor; }
<COMMENT> CommentEnd => INITIAL { this.tokenType = "html-comment"; return cursor; }
- <INITIAL> DocTypeLT => INITIAL
- {
- this.tokenType = "html-doctype";
- this._parseCondition = this._parseConditions.DOCTYPE;
- return cursor;
- }
+ <INITIAL> DocTypeStart => DOCTYPE { this.tokenType = "html-doctype"; return cursor; }
+ <DOCTYPE> DocTypeContent => DOCTYPE { this.tokenType = "html-doctype"; return cursor; }
+ <DOCTYPE> GT => INITIAL { this.tokenType = "html-doctype"; return cursor; }
- <INITIAL> ScriptStart => INITIAL
+ <INITIAL> ScriptStart => TAG
{
this.tokenType = "html-tag";
- this._parseCondition = this._parseConditions.SCRIPT_ATTRIBUTE;
+ this._parseCondition = this._parseConditions.SCRIPT;
+ this._setExpectingAttribute();
return cursor;
}
- <INITIAL> ScriptEnd => INITIAL
+ <INITIAL> ScriptEnd => TAG
{
this.tokenType = "html-tag";
this._parseCondition = this._parseConditions.INITIAL;
return cursor;
}
- <INITIAL> LT => INITIAL
+ <INITIAL> LT => TAG
{
- if (this._parseCondition === this._parseConditions.SCRIPT) {
+ if (this._parseCondition & this._parseConditions.SCRIPT) {
+ // Do not tokenize script tag contents, keep lexer state although processing "<".
+ this.setLexCondition(this._lexConditions.INITIAL);
this.tokenType = null;
return cursor;
}
+ this._parseCondition = this._parseConditions.INITIAL;
this.tokenType = "html-tag";
- this._parseCondition = this._parseConditions.TAG;
return cursor;
}
- <INITIAL> GT => INITIAL
+ <TAG> GT => INITIAL
{
- if (this._parseCondition === this._parseConditions.SCRIPT) {
+ if (this._parseCondition & this._parseConditions.SCRIPT) {
+ // Do not tokenize script tag contents.
this.tokenType = null;
return cursor;
}
- if (this._parseCondition === this._parseConditions.DOCTYPE)
- this.tokenType = "html-doctype";
- else
- this.tokenType = "html-tag";
-
- if (this._parseCondition === this._parseConditions.SCRIPT_ATTRIBUTE)
- this._parseCondition = this._parseConditions.SCRIPT;
- else
- this._parseCondition = this._parseConditions.INITIAL;
+ this._parseCondition = this._parseConditions.INITIAL;
+ this.tokenType = "html-tag";
return cursor;
}
- <INITIAL> StringLiteral { return this._stringToken(cursor, true); }
- <INITIAL> DoubleStringStart => DSTRING { return this._stringToken(cursor); }
+ <TAG> StringLiteral { return this._stringToken(cursor, true); }
+ <TAG> DoubleStringStart => DSTRING { return this._stringToken(cursor); }
<DSTRING> DoubleStringContent => DSTRING { return this._stringToken(cursor); }
- <DSTRING> DoubleStringEnd => INITIAL { return this._stringToken(cursor, true); }
- <INITIAL> SingleStringStart => SSTRING { return this._stringToken(cursor); }
+ <DSTRING> DoubleStringEnd => TAG { return this._stringToken(cursor, true); }
+ <TAG> SingleStringStart => SSTRING { return this._stringToken(cursor); }
<SSTRING> SingleStringContent => SSTRING { return this._stringToken(cursor); }
- <SSTRING> SingleStringEnd => INITIAL { return this._stringToken(cursor, true); }
+ <SSTRING> SingleStringEnd => TAG { return this._stringToken(cursor, true); }
- <INITIAL> EqualSign => INITIAL
+ <TAG> EqualSign => TAG
{
- if (this._isAttribute()) {
- this.tokenType = null;
- this._setAttributeValue();
- } else if (this._parseCondition === this._parseConditions.DOCTYPE)
- this.tokenType = "html-doctype";
- else
- this.tokenType = null;
+ if (this._isExpectingAttribute())
+ this._setExpectingAttributeValue();
+ this.tokenType = null;
return cursor;
}
- <INITIAL> Identifier
+ <TAG> Identifier
{
if (this._parseCondition === this._parseConditions.SCRIPT) {
+ // Fall through if expecting attributes.
this.tokenType = null;
return cursor;
}
- if (this._parseCondition === this._parseConditions.TAG) {
+ if (this._parseCondition === this._parseConditions.INITIAL) {
this.tokenType = "html-tag";
- this._parseCondition = this._parseConditions.ATTRIBUTE;
- } else if (this._isAttribute())
- this.tokenType = "html-attr-name";
- else if (this._isAttributeValue())
- this.tokenType = "html-attr-value";
- else if (this._parseCondition === this._parseConditions.DOCTYPE)
- this.tokenType = "html-doctype";
+ this._setExpectingAttribute();
+ var token = this._line.substring(cursorOnEnter, cursor);
+ if (token === "a")
+ this._parseCondition |= this._parseConditions.A_NODE;
+ else if (this._parseCondition & this._parseConditions.A_NODE)
+ this._parseCondition ^= this._parseConditions.A_NODE;
+ } else if (this._isExpectingAttribute()) {
+ var token = this._line.substring(cursorOnEnter, cursor);
+ if (token === "href" || token === "src")
+ this._parseCondition |= this._parseConditions.LINKIFY;
+ else if (this._parseCondition |= this._parseConditions.LINKIFY)
+ this._parseCondition ^= this._parseConditions.LINKIFY;
+ this.tokenType = "html-attribute-name";
+ } else if (this._isExpectingAttributeValue())
+ this.tokenType = this._attrValueTokenType();
else
this.tokenType = null;
return cursor;