Chromium Code Reviews| Index: Source/devtools/front_end/documentation/WikiParser.js |
| diff --git a/Source/devtools/front_end/documentation/WikiParser.js b/Source/devtools/front_end/documentation/WikiParser.js |
| index 63ffd0b26dfe091fdf601d30f81f95fc583100c0..b220c7aa9fd2958dbcf1f36e23b65adc5a0b1b22 100644 |
| --- a/Source/devtools/front_end/documentation/WikiParser.js |
| +++ b/Source/devtools/front_end/documentation/WikiParser.js |
| @@ -8,57 +8,15 @@ |
| */ |
| WebInspector.WikiParser = function(wikiMarkupText) |
| { |
| - this._position = 0; |
| - this._wikiMarkupText = wikiMarkupText; |
| + var text = wikiMarkupText.replace(/</g, "<") |
| + .replace(/>/g, ">") |
| + .replace(/:/g, ":") |
| + .replace(/"/g, "\"") |
| + .replace(/</g, "<") |
| + .replace(/>/g, ">") |
| + .replace(/&/g, "&"); |
| + this._tokenizer = new WebInspector.WikiParser.Tokenizer(text); |
| this._document = this._parse(); |
| - /** @type {?WebInspector.WikiParser.Tokenizer} */ |
| - this._tokenizer; |
| -} |
| - |
| -/** |
| - * @package |
| - * @enum {string} |
| - */ |
| -WebInspector.WikiParser.State = { |
| - Error: "Error", |
| - FirstOpen: "FirstOpen", |
| - SecondOpen: "SecondOpen", |
| - Title: "Title", |
| - PropertyName: "PropertyName", |
| - PropertyValue: "PropertyValue", |
| - FirstClose: "FirstClose", |
| - SecondClose: "SecondClose" |
| -} |
| - |
| -/** |
| - * @package |
| - * @enum {string} |
| - */ |
| -WebInspector.WikiParser.LinkStates = { |
| - Error: "Error", |
| - LinkUrl: "LinkUrl", |
| - LinkName: "LinkName" |
| -} |
| - |
| -/** |
| - * @package |
| - * @enum {string} |
| - */ |
| -WebInspector.WikiParser.HtmlStates = { |
| - Error: "Error", |
| - Entry: "Entry", |
| - InsideTag: "InsideTag", |
| - Exit: "Exit" |
| -} |
| - |
| -/** |
| - * @package |
| - * @enum {string} |
| - */ |
| -WebInspector.WikiParser.ValueState = { |
| - Error: "Error", |
| - Outside: "Outside", |
| - InsideSquare: "InsideSquare" |
| } |
| /** |
| @@ -66,16 +24,23 @@ WebInspector.WikiParser.ValueState = { |
| * @enum {string} |
| */ |
| WebInspector.WikiParser.TokenType = { |
| - TripleQuotes: "TripleQuotes", |
| + Text: "Text", |
| + Table: "Table", |
| + OpeningBraces: "OpeningBraces", |
| + ClosingBraces: "ClosingBraces", |
| + Exclamation: "Exclamation", |
| OpeningBrackets: "OpeningBrackets", |
| - OpeningCodeTag: "OpeningCodeTag", |
| ClosingBrackets: "ClosingBrackets", |
| + EqualSign: "EqualSign", |
| + EqualSignInBraces: "EqualSignInBraces", |
| + VerticalLine: "VerticalLine", |
| + TripleQuotes: "TripleQuotes", |
| + OpeningCodeTag: "OpeningCodeTag", |
| ClosingCodeTag: "ClosingCodeTag", |
| Bullet: "Bullet", |
| - Text: "Text", |
| - VerticalLine: "VerticalLine", |
| LineEnd: "LineEnd", |
| - CodeBlock: "CodeBlock" |
| + CodeBlock: "CodeBlock", |
| + Space: "Space" |
| } |
| /** |
| @@ -106,7 +71,6 @@ WebInspector.WikiParser.Token.prototype = { |
| return this._type; |
| } |
| } |
| - |
|
loislo
2014/09/09 08:05:05
please return back this empty line
iliia
2014/09/09 08:19:29
Done.
|
| /** |
| * @constructor |
| * @param {string} str |
| @@ -114,22 +78,41 @@ WebInspector.WikiParser.Token.prototype = { |
| WebInspector.WikiParser.Tokenizer = function(str) |
| { |
| this._text = str; |
| + this._token = this._internalNextToken(); |
| } |
| WebInspector.WikiParser.Tokenizer.prototype = { |
| /** |
| * @return {!WebInspector.WikiParser.Token} |
| */ |
| - _nextToken: function() |
| + peekToken: function() |
| + { |
| + return this._token; |
| + }, |
| + |
| + /** |
| + * @return {!WebInspector.WikiParser.Token} |
| + */ |
| + nextToken: function() |
| + { |
| + var token = this._token; |
| + this._token = this._internalNextToken(); |
| + return token; |
| + }, |
| + |
| + /** |
| + * @return {!WebInspector.WikiParser.Token} |
| + */ |
| + _internalNextToken: function() |
| { |
| if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) { |
| var result = WebInspector.WikiParser.newLineWithSpace.exec(this._text); |
| - var begin = result.index + result[0].length; |
| + var begin = result.index + result[0].length - 1; |
| var end = this._text.length; |
| var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this._text); |
| if (lineEnd) |
| end = lineEnd.index; |
| - var token = this._text.substring(begin, end).replace(/\n */g, "\n"); |
| + var token = this._text.substring(begin, end).replace(/\n /g, "\n").replace(/{{=}}/g, "="); |
| this._text = this._text.substring(end + 1); |
| return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.CodeBlock); |
| } |
| @@ -159,14 +142,77 @@ WebInspector.WikiParser.Tokenizer.prototype = { |
| }, |
| /** |
| + * @return {?WebInspector.WikiParser.TokenType} |
| + */ |
| + secondToken: function() |
| + { |
| + var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text); |
| + if (tokenizer.hasMoreTokens()) |
| + return tokenizer.nextToken().type(); |
| + return null; |
| + }, |
| + |
| + /** |
| * @return {boolean} |
| */ |
| - _hasMoreTokens: function() |
| + hasMoreTokens: function() |
| { |
| return !!this._text.length; |
| } |
| } |
| +WebInspector.WikiParser.table = /^{{{!}}/; |
| +WebInspector.WikiParser.exclamation = /^{{!}}/; |
| +WebInspector.WikiParser.openingBraces = /^{{/; |
| +WebInspector.WikiParser.equalSign = /^=/; |
| +WebInspector.WikiParser.equalSignInBraces = /^{{=}}/; |
| +WebInspector.WikiParser.closingBraces = /^\s*}}/; |
| +WebInspector.WikiParser.oneOpeningBracketWithSpace = /^\n* \[/; |
| +WebInspector.WikiParser.twoOpeningBracketsWithSpace = /^\n* \[\[/; |
| +WebInspector.WikiParser.oneClosingBracket = /^\n*\]/; |
| +WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/; |
| +WebInspector.WikiParser.tripleQuotes = /^\n*'''/; |
| +WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/; |
| +WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/; |
| +WebInspector.WikiParser.closingBullet = /^\*/; |
| +WebInspector.WikiParser.lineEnd = /^\n/; |
| +WebInspector.WikiParser.verticalLine = /^\n*\|/; |
| +WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/; |
| +WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/; |
| +WebInspector.WikiParser.space = /^ /; |
| + |
| +/** |
| + * @constructor |
| + * @param {!RegExp} regex |
| + * @param {!WebInspector.WikiParser.TokenType} type |
| + */ |
| +WebInspector.WikiParser.TokenDescriptor = function(regex, type) |
| +{ |
| + this.regex = regex; |
| + this.type = type; |
| +} |
| + |
| +WebInspector.WikiParser._tokenDescriptors = [ |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamation, WebInspector.WikiParser.TokenType.Exclamation), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSignInBraces, WebInspector.WikiParser.TokenType.EqualSignInBraces), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSign, WebInspector.WikiParser.TokenType.EqualSign), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.table, WebInspector.WikiParser.TokenType.Table), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingBraces, WebInspector.WikiParser.TokenType.OpeningBraces), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.verticalLine, WebInspector.WikiParser.TokenType.VerticalLine), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBraces, WebInspector.WikiParser.TokenType.ClosingBraces), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeningBracketsWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosingBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeningBracketWithSpace, WebInspector.WikiParser.TokenType.OpeningBrackets), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosingBracket, WebInspector.WikiParser.TokenType.ClosingBrackets), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineWithSpace, WebInspector.WikiParser.TokenType.CodeBlock), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQuotes, WebInspector.WikiParser.TokenType.TripleQuotes), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCodeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCodeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBullet, WebInspector.WikiParser.TokenType.Bullet), |
| + new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd)//, |
| + //new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.space, WebInspector.WikiParser.TokenType.Space) |
| +] |
| + |
| WebInspector.WikiParser.prototype = { |
| /** |
| * @return {!Object} |
| @@ -182,16 +228,7 @@ WebInspector.WikiParser.prototype = { |
| _parse: function() |
| { |
| var obj = {}; |
| - this._wikiMarkupText = this._wikiMarkupText.replace(/</g, "<") |
| - .replace(/>/g, ">") |
| - .replace(/:/g, ":") |
| - .replace(/"/g, "\"") |
| - .replace(/</g, "<") |
| - .replace(/>/g, ">") |
| - .replace(/{{=}}/g, "=") |
| - .replace(/{{!}}/g, "|") |
| - .replace(/&/g, "&"); |
| - while (this._position < this._wikiMarkupText.length) { |
| + while (this._tokenizer.hasMoreTokens()) { |
| var field = this._parseField(); |
| for (var key in field) { |
| console.assert(typeof obj[key] === "undefined", "Duplicate key: " + key); |
| @@ -202,174 +239,154 @@ WebInspector.WikiParser.prototype = { |
| }, |
| /** |
| - * @return {string} |
| + * @return {?Object} |
| */ |
| - _parseValue: function() { |
| - var states = WebInspector.WikiParser.ValueState; |
| - var state = states.Outside; |
| - var value = ""; |
| - while (this._position < this._wikiMarkupText.length) { |
| - switch (state) { |
| - case states.Outside: |
| - if (this._wikiMarkupText[this._position] === "|" || (this._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] === "}")) |
| - return value; |
| - switch (this._wikiMarkupText[this._position]) { |
| - case "<": |
| - var indexClose = this._wikiMarkupText.indexOf(">", this._position); |
| - if (indexClose !== -1) { |
| - value += this._wikiMarkupText.substring(this._position, indexClose + 1); |
| - this._position = indexClose; |
| - } |
| + _parseField: function() |
| + { |
| + var field = {}; |
| + if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type() !== WebInspector.WikiParser.TokenType.OpeningBraces) |
| + return field; |
| + |
| + var title = this._deleteTrailingSpaces(this._parseTitle()); |
| + if (!title.length) |
| + return field; |
| + field[title] = {}; |
| + if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.ClosingBraces) { |
| + this._tokenizer.nextToken(); |
| + return field; |
| + } |
| + if (!this._tokenizer.secondToken() || this._tokenizer.secondToken() !== WebInspector.WikiParser.TokenType.EqualSign) { |
| + var propertyValue = this._parseString(); |
| + field[title] = propertyValue; |
| + } else { |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var propertyName = this._parseName(); |
| + var token = this._tokenizer.peekToken(); |
| + switch (token.type()) { |
| + case WebInspector.WikiParser.TokenType.OpeningBraces: |
| + field[title][propertyName] = this._parseArray(); |
| + break; |
| + case WebInspector.WikiParser.TokenType.LineEnd: |
| + this._tokenizer.nextToken(); |
| break; |
| - case "[": |
| - state = states.InsideSquare; |
| - value += this._wikiMarkupText[this._position]; |
| + case WebInspector.WikiParser.TokenType.ClosingBraces: |
| + this._tokenizer.nextToken(); |
| + return field; |
| break; |
| default: |
| - value += this._wikiMarkupText[this._position]; |
| + if (propertyName === "Code") |
| + field[title][propertyName] = this._parseExampleCode(); |
| + else |
| + field[title][propertyName] = this._parseString(); |
| } |
| - break; |
| - case states.InsideSquare: |
| - if (this._wikiMarkupText[this._position] === "[") { |
| - var indexClose = this._wikiMarkupText.indexOf("]]", this._position); |
| - if (indexClose !== -1) { |
| - value += this._wikiMarkupText.substring(this._position, indexClose + 2); |
| - this._position = indexClose + 1; |
| - } |
| - } else { |
| - var indexClose = this._wikiMarkupText.indexOf("]", this._position); |
| - if (indexClose !== -1) { |
| - value += this._wikiMarkupText.substring(this._position, indexClose + 1); |
| - this._position = indexClose; |
| - } |
| - } |
| - state = states.Outside; |
| - break; |
| } |
| - this._position++; |
| } |
| - return value; |
| + var token = this._tokenizer.nextToken(); |
| + if (token.type() !== WebInspector.WikiParser.TokenType.ClosingBraces) |
| + throw new Error("Two closing braces expected; found " + token.value()); |
| + |
| + return field; |
| }, |
| /** |
| - * @return {!Object} |
| + * @return {!Array.<?Object>} |
| */ |
| - _parseField: function() |
| + _parseArray: function() |
| + { |
| + var array = []; |
| + while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.OpeningBraces) |
| + array.push(this._parseField()); |
| + if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.VerticalLine) |
| + this._tokenizer.nextToken(); |
| + return array; |
| + }, |
| + |
| + /** |
| + * @return {string} |
| + */ |
| + _parseTitle: function() |
| { |
| - var obj = {}; |
| var title = ""; |
| - var propertyName = ""; |
| - var propertyValue = ""; |
| - var states = WebInspector.WikiParser.State; |
| - var state = states.FirstOpen; |
| - while (this._position < this._wikiMarkupText.length) { |
| - var skipIncrement = false; |
| - switch (state) { |
| - case states.FirstOpen: |
| - if (this._wikiMarkupText[this._position] === "{") |
| - state = states.SecondOpen; |
| - else |
| - state = states.Error; |
| - break; |
| - case states.SecondOpen: |
| - if (this._wikiMarkupText[this._position] === "{") |
| - state = states.Title; |
| - else |
| - state = states.Error; |
| - break; |
| - case states.Title: |
| - if (this._wikiMarkupText[this._position] === "|") { |
| - title = this._deleteTrailingSpaces(title); |
| - if (title !== "") |
| - obj[title] = {}; |
| - state = states.PropertyName; |
| - } else if (this._wikiMarkupText[this._position] === "}") { |
| - title = this._deleteTrailingSpaces(title); |
| - if (title !== "") |
| - obj[title] = {}; |
| - state = states.FirstClose; |
| - } else { |
| - title += (this._wikiMarkupText[this._position] === "\n" ? "" : this._wikiMarkupText[this._position]); |
| - } |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.peekToken(); |
| + switch (token.type()) { |
| + case WebInspector.WikiParser.TokenType.ClosingBraces: |
| + return title; |
| + case WebInspector.WikiParser.TokenType.VerticalLine: |
| + this._tokenizer.nextToken(); |
| + return title; |
| + case WebInspector.WikiParser.TokenType.Text: |
| + case WebInspector.WikiParser.TokenType.Space: |
| + title += this._tokenizer.nextToken().value(); |
| break; |
| - case states.PropertyName: |
| - if (this._wikiMarkupText[this._position] === "=") { |
| - state = states.PropertyValue; |
| - this._deleteTrailingSpaces(propertyName); |
| - if (propertyName !== "") |
| - obj[title][propertyName] = []; |
| - } else { |
| - if (this._wikiMarkupText[this._position] === "}") { |
| - propertyName = this._deleteTrailingSpaces(propertyName); |
| - obj[title] = propertyName; |
| - state = states.FirstClose; |
| - } else { |
| - propertyName += this._wikiMarkupText[this._position]; |
| - } |
| - } |
| + default: |
| + throw new Error("Can't parse Title, unexpected token " + token.value()); |
| + } |
| + } |
| + return title; |
| + }, |
| + |
| + /** |
| + * @return {string} |
| + */ |
| + _parseName: function() |
| + { |
| + var name = ""; |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.peekToken(); |
| + switch (token.type()) { |
| + case WebInspector.WikiParser.TokenType.ClosingBraces: |
| + return name; |
| + case WebInspector.WikiParser.TokenType.EqualSign: |
| + this._tokenizer.nextToken(); |
| + return name; |
| + case WebInspector.WikiParser.TokenType.VerticalLine: |
| + case WebInspector.WikiParser.TokenType.Space: |
| + case WebInspector.WikiParser.TokenType.Text: |
| + name += this._tokenizer.nextToken().value(); |
| break; |
| - case states.PropertyValue: |
| - if (this._wikiMarkupText[this._position] === "{" && this._wikiMarkupText[this._position + 1] === "{") { |
| - propertyValue = this._parseField(); |
| - obj[title][propertyName].push(propertyValue); |
| - propertyValue = ""; |
| - skipIncrement = true; |
| - } else if (this._wikiMarkupText[this._position] === "|") { |
| - propertyValue = this._deleteTrailingSpaces(propertyValue); |
| - if (propertyValue !== "") |
| - obj[title][propertyName] = propertyValue; |
| - |
| - state = states.PropertyName; |
| - if (Array.isArray(obj[title][propertyName]) && obj[title][propertyName].length === 1) { |
| - var newObj = obj[title][propertyName][0]; |
| - obj[title][propertyName] = newObj; |
| - } |
| - |
| - propertyName = ""; |
| - propertyValue = ""; |
| - } else if (this._position + 1 < this._wikiMarkupText.length && this._wikiMarkupText[this._position] === "}" && this._wikiMarkupText[this._position + 1] === "}") { |
| - propertyValue = this._deleteTrailingSpaces(propertyValue); |
| - if (propertyValue !== "") |
| - obj[title][propertyName].push(propertyValue); |
| - if (Array.isArray(obj[title][propertyName]) && obj[title][propertyName].length === 1) { |
| - var newObj = obj[title][propertyName][0]; |
| - obj[title][propertyName] = newObj; |
| - } |
| - |
| - propertyValue = ""; |
| - state = states.FirstClose; |
| - } else { |
| - propertyValue = this._parseValue(); |
| - skipIncrement = true; |
| - } |
| + default: |
| + throw new Error("Can't parse name, unexpected token " + token.value()); |
| + } |
| + } |
| + return name; |
| + }, |
| + |
| + /** |
| + * @return {string} |
| + */ |
| + _parseExampleCode: function() |
| + { |
| + var code = ""; |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.peekToken(); |
| + switch (token.type()) { |
| + case WebInspector.WikiParser.TokenType.ClosingBraces: |
| + return code; |
| + case WebInspector.WikiParser.TokenType.VerticalLine: |
| + this._tokenizer.nextToken(); |
| + return code; |
| + case WebInspector.WikiParser.TokenType.Exclamation: |
| + this._tokenizer.nextToken(); |
| + code += '|'; |
| break; |
| - case states.FirstClose: |
| - if (this._wikiMarkupText[this._position] === "}") |
| - state = states.SecondClose; |
| - else |
| - state = states.Error; |
| + case WebInspector.WikiParser.TokenType.EqualSignInBraces: |
| + this._tokenizer.nextToken(); |
| + code += "="; |
| break; |
| - case states.SecondClose: |
| - while (this._position < this._wikiMarkupText.length && this._wikiMarkupText[this._position] === "\n") |
| - this._position++; |
| - return obj; |
| - case states.Error: |
| - this._position = this._wikiMarkupText.length; |
| - return {}; |
| + default: |
| + this._tokenizer.nextToken(); |
| + code += token.value(); |
| } |
| - if (!skipIncrement) |
| - this._position++; |
| } |
| - return obj; |
| + return code; |
| }, |
| /** |
| - * @param {string} str |
| * @return {?WebInspector.WikiParser.Block} |
| */ |
| - parseString: function(str) |
| + _parseString: function() |
| { |
| - this._tokenizer = new WebInspector.WikiParser.Tokenizer(str); |
| var children = []; |
| var blockChildren = []; |
| var text = ""; |
| @@ -392,45 +409,70 @@ WebInspector.WikiParser.prototype = { |
| blockChildren = []; |
| } |
| } |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken(); |
| + |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.peekToken(); |
| switch (token.type()) { |
| + case WebInspector.WikiParser.TokenType.VerticalLine: |
| + this._tokenizer.nextToken(); |
| + case WebInspector.WikiParser.TokenType.ClosingBraces: |
| + processSimpleText(); |
| + processBlock(); |
| + return new WebInspector.WikiParser.Block(children, false); |
| case WebInspector.WikiParser.TokenType.TripleQuotes: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| var highlightText = this._parseHighlight(); |
| blockChildren.push(highlightText) |
| break; |
| case WebInspector.WikiParser.TokenType.OpeningBrackets: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| var link = this._parseLink(); |
| blockChildren.push(link); |
| break; |
| case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| var code = this._parseCode(); |
| blockChildren.push(code); |
| break; |
| case WebInspector.WikiParser.TokenType.Bullet: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| processBlock(); |
| var bulletText = this._parseBullet(); |
| children.push(bulletText); |
| break; |
| case WebInspector.WikiParser.TokenType.CodeBlock: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| processBlock(); |
| var code = new WebInspector.WikiParser.CodeBlock(token.value()); |
| children.push(code); |
| break; |
| case WebInspector.WikiParser.TokenType.LineEnd: |
| + this._tokenizer.nextToken(); |
| processSimpleText(); |
| processBlock(); |
| break; |
| - case WebInspector.WikiParser.TokenType.VerticalLine: |
| + case WebInspector.WikiParser.TokenType.EqualSignInBraces: |
| + this._tokenizer.nextToken(); |
| + text += "="; |
| + break; |
| + case WebInspector.WikiParser.TokenType.Exclamation: |
| + this._tokenizer.nextToken(); |
| + text += "|"; |
| + break; |
| + case WebInspector.WikiParser.TokenType.ClosingBrackets: |
| case WebInspector.WikiParser.TokenType.Text: |
| + case WebInspector.WikiParser.TokenType.Space: |
| + case WebInspector.WikiParser.TokenType.EqualSign: |
| + this._tokenizer.nextToken(); |
| text += token.value(); |
| break; |
| default: |
| + this._tokenizer.nextToken(); |
| return null; |
| } |
| } |
| @@ -448,12 +490,13 @@ WebInspector.WikiParser.prototype = { |
| { |
| var url = ""; |
| var children = []; |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken(); |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.nextToken(); |
| switch (token.type()) { |
| case WebInspector.WikiParser.TokenType.ClosingBrackets: |
| return new WebInspector.WikiParser.Link(url, children); |
| case WebInspector.WikiParser.TokenType.VerticalLine: |
| + case WebInspector.WikiParser.TokenType.Exclamation: |
| children.push(this._parseLinkName()); |
| return new WebInspector.WikiParser.Link(url, children); |
| default: |
| @@ -470,16 +513,30 @@ WebInspector.WikiParser.prototype = { |
| _parseLinkName: function() |
| { |
| var children = []; |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken(); |
| + var text = ""; |
| + var self = this; |
| + function processSimpleText() |
| + { |
| + text = self._deleteTrailingSpaces(text); |
| + if (!text.length) |
| + return; |
| + var simpleText = new WebInspector.WikiParser.PlainText(text, false); |
| + children.push(simpleText); |
| + text = ""; |
| + } |
| + |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.nextToken(); |
| switch (token.type()) { |
| case WebInspector.WikiParser.TokenType.ClosingBrackets: |
| + processSimpleText(); |
| return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Inline, children); |
| case WebInspector.WikiParser.TokenType.OpeningCodeTag: |
| + processSimpleText(); |
| children.push(this._parseCode()); |
| break; |
| default: |
| - children.push(new WebInspector.WikiParser.PlainText(token.value(), false)); |
| + text += token.value(); |
| break; |
| } |
| } |
| @@ -494,8 +551,8 @@ WebInspector.WikiParser.prototype = { |
| { |
| var children = []; |
| var text = ""; |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken(); |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.nextToken(); |
| switch (token.type()) { |
| case WebInspector.WikiParser.TokenType.ClosingCodeTag: |
| text = this._deleteTrailingSpaces(text); |
| @@ -528,8 +585,8 @@ WebInspector.WikiParser.prototype = { |
| _parseBullet: function() |
| { |
| var children = []; |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken() |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.nextToken() |
| switch (token.type()) { |
| case WebInspector.WikiParser.TokenType.OpeningBrackets: |
| children.push(this._parseLink()); |
| @@ -558,8 +615,8 @@ WebInspector.WikiParser.prototype = { |
| _parseHighlight: function() |
| { |
| var text = ""; |
| - while (this._tokenizer._hasMoreTokens()) { |
| - var token = this._tokenizer._nextToken() |
| + while (this._tokenizer.hasMoreTokens()) { |
| + var token = this._tokenizer.nextToken() |
| switch (token.type()) { |
| case WebInspector.WikiParser.TokenType.TripleQuotes: |
| text = this._deleteTrailingSpaces(text); |
| @@ -581,44 +638,6 @@ WebInspector.WikiParser.prototype = { |
| } |
| } |
| -WebInspector.WikiParser.oneOpeningBracket = /^\n* \[[^\[]/; |
| -WebInspector.WikiParser.twoOpeningBrackets = /^\n* \[\[/; |
| -WebInspector.WikiParser.oneClosingBracket = /^\n*\][^\]] /; |
| -WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/; |
| -WebInspector.WikiParser.tripleQuotes = /^\n*'''/; |
| -WebInspector.WikiParser.openingCodeTag = /^<\s*code\s*>/; |
| -WebInspector.WikiParser.closingCodeTag = /^<\s*\/\s*code\s*>/; |
| -WebInspector.WikiParser.closingBullet = /^\*/; |
| -WebInspector.WikiParser.lineEnd = /^\n/; |
| -WebInspector.WikiParser.verticalLine = /^\|/; |
| -WebInspector.WikiParser.newLineWithSpace = /^\n /; |
| -WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/; |
| - |
| -/** |
| - * @constructor |
| - * @param {!RegExp} regex |
| - * @param {!WebInspector.WikiParser.TokenType} type |
| - */ |
| -WebInspector.WikiParser.TokenDescriptor = function(regex, type) |
| -{ |
| - this.regex = regex; |
| - this.type = type; |
| -} |
| - |
| -WebInspector.WikiParser._tokenDescriptors = [ |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineWithSpace, WebInspector.WikiParser.TokenType.CodeBlock), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQuotes, WebInspector.WikiParser.TokenType.TripleQuotes), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeningBracket, WebInspector.WikiParser.TokenType.OpeningBrackets), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeningBrackets, WebInspector.WikiParser.TokenType.OpeningBrackets), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosingBracket, WebInspector.WikiParser.TokenType.ClosingBrackets), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosingBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCodeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCodeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBullet, WebInspector.WikiParser.TokenType.Bullet), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.verticalLine, WebInspector.WikiParser.TokenType.VerticalLine), |
| - new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd) |
| -]; |
| - |
| /** |
| * @constructor |
| * @param {!WebInspector.WikiParser.ArticleElement.Type} type |