How to use parser method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

sax.js

Source:sax.js Github

copy

Full Screen

1;(function (sax) { // wrapper for non-node envs2 sax.parser = function (strict, opt) { return new SAXParser(strict, opt) }3 sax.SAXParser = SAXParser4 sax.SAXStream = SAXStream5 sax.createStream = createStream6 // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns.7 // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)),8 // since that's the earliest that a buffer overrun could occur. This way, checks are9 // as rare as required, but as often as necessary to ensure never crossing this bound.10 // Furthermore, buffers are only tested at most once per write(), so passing a very11 // large string into write() might have undesirable effects, but this is manageable by12 // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme13 // edge case, result in creating at most one complete copy of the string passed in.14 // Set to Infinity to have unlimited buffers.15 sax.MAX_BUFFER_LENGTH = 64 * 102416 var buffers = [17 'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype',18 'procInstName', 'procInstBody', 'entity', 'attribName',19 'attribValue', 'cdata', 'script'20 ]21 sax.EVENTS = [22 'text',23 'processinginstruction',24 'sgmldeclaration',25 'doctype',26 'comment',27 'opentagstart',28 'attribute',29 'opentag',30 'closetag',31 'opencdata',32 'cdata',33 'closecdata',34 'error',35 'end',36 'ready',37 'script',38 'opennamespace',39 'closenamespace'40 ]41 function SAXParser (strict, opt) {42 if (!(this instanceof SAXParser)) {43 return new SAXParser(strict, opt)44 }45 var parser = this46 clearBuffers(parser)47 parser.q = parser.c = ''48 parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH49 parser.opt = opt || {}50 parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags51 parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase'52 parser.tags = []53 parser.closed = parser.closedRoot = parser.sawRoot = false54 parser.tag = parser.error = null55 parser.strict = !!strict56 parser.noscript = !!(strict || parser.opt.noscript)57 parser.state = S.BEGIN58 parser.strictEntities = parser.opt.strictEntities59 parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES)60 parser.attribList = []61 // namespaces form a prototype chain.62 // it always points at the current tag,63 // which protos to its parent tag.64 if (parser.opt.xmlns) {65 parser.ns = Object.create(rootNS)66 }67 // mostly just for error reporting68 parser.trackPosition = parser.opt.position !== false69 if (parser.trackPosition) {70 parser.position = parser.line = parser.column = 071 }72 emit(parser, 'onready')73 }74 if (!Object.create) {75 Object.create = function (o) {76 function F () {}77 F.prototype = o78 var newf = new F()79 return newf80 }81 }82 if (!Object.keys) {83 Object.keys = function (o) {84 var a = []85 for (var i in o) if (o.hasOwnProperty(i)) a.push(i)86 return a87 }88 }89 function checkBufferLength (parser) {90 var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10)91 var maxActual = 092 for (var i = 0, l = buffers.length; i < l; i++) {93 var len = parser[buffers[i]].length94 if (len > maxAllowed) {95 // Text/cdata nodes can get big, and since they're buffered,96 // we can get here under normal conditions.97 // Avoid issues by emitting the text node now,98 // so at least it won't get any bigger.99 switch (buffers[i]) {100 case 'textNode':101 closeText(parser)102 break103 case 'cdata':104 emitNode(parser, 'oncdata', parser.cdata)105 parser.cdata = ''106 break107 case 'script':108 emitNode(parser, 'onscript', parser.script)109 parser.script = ''110 break111 default:112 error(parser, 'Max buffer length exceeded: ' + buffers[i])113 }114 }115 maxActual = Math.max(maxActual, len)116 }117 // schedule the next check for the earliest possible buffer overrun.118 var m = sax.MAX_BUFFER_LENGTH - maxActual119 parser.bufferCheckPosition = m + parser.position120 }121 function clearBuffers (parser) {122 for (var i = 0, l = buffers.length; i < l; i++) {123 parser[buffers[i]] = ''124 }125 }126 function flushBuffers (parser) {127 closeText(parser)128 if (parser.cdata !== '') {129 emitNode(parser, 'oncdata', parser.cdata)130 parser.cdata = ''131 }132 if (parser.script !== '') {133 emitNode(parser, 'onscript', parser.script)134 parser.script = ''135 }136 }137 SAXParser.prototype = {138 end: function () { end(this) },139 write: write,140 resume: function () { this.error = null; return this },141 close: function () { return this.write(null) },142 flush: function () { flushBuffers(this) }143 }144 var Stream145 try {146 Stream = require('stream').Stream147 } catch (ex) {148 Stream = function () {}149 }150 var streamWraps = sax.EVENTS.filter(function (ev) {151 return ev !== 'error' && ev !== 'end'152 })153 function createStream (strict, opt) {154 return new SAXStream(strict, opt)155 }156 function SAXStream (strict, opt) {157 if (!(this instanceof SAXStream)) {158 return new SAXStream(strict, opt)159 }160 Stream.apply(this)161 this._parser = new SAXParser(strict, opt)162 this.writable = true163 this.readable = true164 var me = this165 this._parser.onend = function () {166 me.emit('end')167 }168 this._parser.onerror = function (er) {169 me.emit('error', er)170 // if didn't throw, then means error was handled.171 // go ahead and clear error, so we can write again.172 me._parser.error = null173 }174 this._decoder = null175 streamWraps.forEach(function (ev) {176 Object.defineProperty(me, 'on' + ev, {177 get: function () {178 return me._parser['on' + ev]179 },180 set: function (h) {181 if (!h) {182 me.removeAllListeners(ev)183 me._parser['on' + ev] = h184 return h185 }186 me.on(ev, h)187 },188 enumerable: true,189 configurable: false190 })191 })192 }193 SAXStream.prototype = Object.create(Stream.prototype, {194 constructor: {195 value: SAXStream196 }197 })198 SAXStream.prototype.write = function (data) {199 if (typeof Buffer === 'function' &&200 typeof Buffer.isBuffer === 'function' &&201 Buffer.isBuffer(data)) {202 if (!this._decoder) {203 var SD = require('string_decoder').StringDecoder204 this._decoder = new SD('utf8')205 }206 data = this._decoder.write(data)207 }208 this._parser.write(data.toString())209 this.emit('data', data)210 return true211 }212 SAXStream.prototype.end = function (chunk) {213 if (chunk && chunk.length) {214 this.write(chunk)215 }216 this._parser.end()217 return true218 }219 SAXStream.prototype.on = function (ev, handler) {220 var me = this221 if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) {222 me._parser['on' + ev] = function () {223 var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments)224 args.splice(0, 0, ev)225 me.emit.apply(me, args)226 }227 }228 return Stream.prototype.on.call(me, ev, handler)229 }230 // this really needs to be replaced with character classes.231 // XML allows all manner of ridiculous numbers and digits.232 var CDATA = '[CDATA['233 var DOCTYPE = 'DOCTYPE'234 var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace'235 var XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/'236 var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE }237 // http://www.w3.org/TR/REC-xml/#NT-NameStartChar238 // This implementation works on strings, a single character at a time239 // as such, it cannot ever support astral-plane characters (10000-EFFFF)240 // without a significant breaking change to either this parser, or the241 // JavaScript language. Implementation of an emoji-capable xml parser242 // is left as an exercise for the reader.243 var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/244 var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/245 var entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/246 var entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/247 function isWhitespace (c) {248 return c === ' ' || c === '\n' || c === '\r' || c === '\t'249 }250 function isQuote (c) {251 return c === '"' || c === '\''252 }253 function isAttribEnd (c) {254 return c === '>' || isWhitespace(c)255 }256 function isMatch (regex, c) {257 return regex.test(c)258 }259 function notMatch (regex, c) {260 return !isMatch(regex, c)261 }262 var S = 0263 sax.STATE = {264 BEGIN: S++, // leading byte order mark or whitespace265 BEGIN_WHITESPACE: S++, // leading whitespace266 TEXT: S++, // general stuff267 TEXT_ENTITY: S++, // &amp and such.268 OPEN_WAKA: S++, // <269 SGML_DECL: S++, // <!BLARG270 SGML_DECL_QUOTED: S++, // <!BLARG foo "bar271 DOCTYPE: S++, // <!DOCTYPE272 DOCTYPE_QUOTED: S++, // <!DOCTYPE "//blah273 DOCTYPE_DTD: S++, // <!DOCTYPE "//blah" [ ...274 DOCTYPE_DTD_QUOTED: S++, // <!DOCTYPE "//blah" [ "foo275 COMMENT_STARTING: S++, // <!-276 COMMENT: S++, // <!--277 COMMENT_ENDING: S++, // <!-- blah -278 COMMENT_ENDED: S++, // <!-- blah --279 CDATA: S++, // <![CDATA[ something280 CDATA_ENDING: S++, // ]281 CDATA_ENDING_2: S++, // ]]282 PROC_INST: S++, // <?hi283 PROC_INST_BODY: S++, // <?hi there284 PROC_INST_ENDING: S++, // <?hi "there" ?285 OPEN_TAG: S++, // <strong286 OPEN_TAG_SLASH: S++, // <strong /287 ATTRIB: S++, // <a288 ATTRIB_NAME: S++, // <a foo289 ATTRIB_NAME_SAW_WHITE: S++, // <a foo _290 ATTRIB_VALUE: S++, // <a foo=291 ATTRIB_VALUE_QUOTED: S++, // <a foo="bar292 ATTRIB_VALUE_CLOSED: S++, // <a foo="bar"293 ATTRIB_VALUE_UNQUOTED: S++, // <a foo=bar294 ATTRIB_VALUE_ENTITY_Q: S++, // <foo bar="&quot;"295 ATTRIB_VALUE_ENTITY_U: S++, // <foo bar=&quot296 CLOSE_TAG: S++, // </a297 CLOSE_TAG_SAW_WHITE: S++, // </a >298 SCRIPT: S++, // <script> ...299 SCRIPT_ENDING: S++ // <script> ... <300 }301 sax.XML_ENTITIES = {302 'amp': '&',303 'gt': '>',304 'lt': '<',305 'quot': '"',306 'apos': "'"307 }308 sax.ENTITIES = {309 'amp': '&',310 'gt': '>',311 'lt': '<',312 'quot': '"',313 'apos': "'",314 'AElig': 198,315 'Aacute': 193,316 'Acirc': 194,317 'Agrave': 192,318 'Aring': 197,319 'Atilde': 195,320 'Auml': 196,321 'Ccedil': 199,322 'ETH': 208,323 'Eacute': 201,324 'Ecirc': 202,325 'Egrave': 200,326 'Euml': 203,327 'Iacute': 205,328 'Icirc': 206,329 'Igrave': 204,330 'Iuml': 207,331 'Ntilde': 209,332 'Oacute': 211,333 'Ocirc': 212,334 'Ograve': 210,335 'Oslash': 216,336 'Otilde': 213,337 'Ouml': 214,338 'THORN': 222,339 'Uacute': 218,340 'Ucirc': 219,341 'Ugrave': 217,342 'Uuml': 220,343 'Yacute': 221,344 'aacute': 225,345 'acirc': 226,346 'aelig': 230,347 'agrave': 224,348 'aring': 229,349 'atilde': 227,350 'auml': 228,351 'ccedil': 231,352 'eacute': 233,353 'ecirc': 234,354 'egrave': 232,355 'eth': 240,356 'euml': 235,357 'iacute': 237,358 'icirc': 238,359 'igrave': 236,360 'iuml': 239,361 'ntilde': 241,362 'oacute': 243,363 'ocirc': 244,364 'ograve': 242,365 'oslash': 248,366 'otilde': 245,367 'ouml': 246,368 'szlig': 223,369 'thorn': 254,370 'uacute': 250,371 'ucirc': 251,372 'ugrave': 249,373 'uuml': 252,374 'yacute': 253,375 'yuml': 255,376 'copy': 169,377 'reg': 174,378 'nbsp': 160,379 'iexcl': 161,380 'cent': 162,381 'pound': 163,382 'curren': 164,383 'yen': 165,384 'brvbar': 166,385 'sect': 167,386 'uml': 168,387 'ordf': 170,388 'laquo': 171,389 'not': 172,390 'shy': 173,391 'macr': 175,392 'deg': 176,393 'plusmn': 177,394 'sup1': 185,395 'sup2': 178,396 'sup3': 179,397 'acute': 180,398 'micro': 181,399 'para': 182,400 'middot': 183,401 'cedil': 184,402 'ordm': 186,403 'raquo': 187,404 'frac14': 188,405 'frac12': 189,406 'frac34': 190,407 'iquest': 191,408 'times': 215,409 'divide': 247,410 'OElig': 338,411 'oelig': 339,412 'Scaron': 352,413 'scaron': 353,414 'Yuml': 376,415 'fnof': 402,416 'circ': 710,417 'tilde': 732,418 'Alpha': 913,419 'Beta': 914,420 'Gamma': 915,421 'Delta': 916,422 'Epsilon': 917,423 'Zeta': 918,424 'Eta': 919,425 'Theta': 920,426 'Iota': 921,427 'Kappa': 922,428 'Lambda': 923,429 'Mu': 924,430 'Nu': 925,431 'Xi': 926,432 'Omicron': 927,433 'Pi': 928,434 'Rho': 929,435 'Sigma': 931,436 'Tau': 932,437 'Upsilon': 933,438 'Phi': 934,439 'Chi': 935,440 'Psi': 936,441 'Omega': 937,442 'alpha': 945,443 'beta': 946,444 'gamma': 947,445 'delta': 948,446 'epsilon': 949,447 'zeta': 950,448 'eta': 951,449 'theta': 952,450 'iota': 953,451 'kappa': 954,452 'lambda': 955,453 'mu': 956,454 'nu': 957,455 'xi': 958,456 'omicron': 959,457 'pi': 960,458 'rho': 961,459 'sigmaf': 962,460 'sigma': 963,461 'tau': 964,462 'upsilon': 965,463 'phi': 966,464 'chi': 967,465 'psi': 968,466 'omega': 969,467 'thetasym': 977,468 'upsih': 978,469 'piv': 982,470 'ensp': 8194,471 'emsp': 8195,472 'thinsp': 8201,473 'zwnj': 8204,474 'zwj': 8205,475 'lrm': 8206,476 'rlm': 8207,477 'ndash': 8211,478 'mdash': 8212,479 'lsquo': 8216,480 'rsquo': 8217,481 'sbquo': 8218,482 'ldquo': 8220,483 'rdquo': 8221,484 'bdquo': 8222,485 'dagger': 8224,486 'Dagger': 8225,487 'bull': 8226,488 'hellip': 8230,489 'permil': 8240,490 'prime': 8242,491 'Prime': 8243,492 'lsaquo': 8249,493 'rsaquo': 8250,494 'oline': 8254,495 'frasl': 8260,496 'euro': 8364,497 'image': 8465,498 'weierp': 8472,499 'real': 8476,500 'trade': 8482,501 'alefsym': 8501,502 'larr': 8592,503 'uarr': 8593,504 'rarr': 8594,505 'darr': 8595,506 'harr': 8596,507 'crarr': 8629,508 'lArr': 8656,509 'uArr': 8657,510 'rArr': 8658,511 'dArr': 8659,512 'hArr': 8660,513 'forall': 8704,514 'part': 8706,515 'exist': 8707,516 'empty': 8709,517 'nabla': 8711,518 'isin': 8712,519 'notin': 8713,520 'ni': 8715,521 'prod': 8719,522 'sum': 8721,523 'minus': 8722,524 'lowast': 8727,525 'radic': 8730,526 'prop': 8733,527 'infin': 8734,528 'ang': 8736,529 'and': 8743,530 'or': 8744,531 'cap': 8745,532 'cup': 8746,533 'int': 8747,534 'there4': 8756,535 'sim': 8764,536 'cong': 8773,537 'asymp': 8776,538 'ne': 8800,539 'equiv': 8801,540 'le': 8804,541 'ge': 8805,542 'sub': 8834,543 'sup': 8835,544 'nsub': 8836,545 'sube': 8838,546 'supe': 8839,547 'oplus': 8853,548 'otimes': 8855,549 'perp': 8869,550 'sdot': 8901,551 'lceil': 8968,552 'rceil': 8969,553 'lfloor': 8970,554 'rfloor': 8971,555 'lang': 9001,556 'rang': 9002,557 'loz': 9674,558 'spades': 9824,559 'clubs': 9827,560 'hearts': 9829,561 'diams': 9830562 }563 Object.keys(sax.ENTITIES).forEach(function (key) {564 var e = sax.ENTITIES[key]565 var s = typeof e === 'number' ? String.fromCharCode(e) : e566 sax.ENTITIES[key] = s567 })568 for (var s in sax.STATE) {569 sax.STATE[sax.STATE[s]] = s570 }571 // shorthand572 S = sax.STATE573 function emit (parser, event, data) {574 parser[event] && parser[event](data)575 }576 function emitNode (parser, nodeType, data) {577 if (parser.textNode) closeText(parser)578 emit(parser, nodeType, data)579 }580 function closeText (parser) {581 parser.textNode = textopts(parser.opt, parser.textNode)582 if (parser.textNode) emit(parser, 'ontext', parser.textNode)583 parser.textNode = ''584 }585 function textopts (opt, text) {586 if (opt.trim) text = text.trim()587 if (opt.normalize) text = text.replace(/\s+/g, ' ')588 return text589 }590 function error (parser, er) {591 closeText(parser)592 if (parser.trackPosition) {593 er += '\nLine: ' + parser.line +594 '\nColumn: ' + parser.column +595 '\nChar: ' + parser.c596 }597 er = new Error(er)598 parser.error = er599 emit(parser, 'onerror', er)600 return parser601 }602 function end (parser) {603 if (parser.sawRoot && !parser.closedRoot) strictFail(parser, 'Unclosed root tag')604 if ((parser.state !== S.BEGIN) &&605 (parser.state !== S.BEGIN_WHITESPACE) &&606 (parser.state !== S.TEXT)) {607 error(parser, 'Unexpected end')608 }609 closeText(parser)610 parser.c = ''611 parser.closed = true612 emit(parser, 'onend')613 SAXParser.call(parser, parser.strict, parser.opt)614 return parser615 }616 function strictFail (parser, message) {617 if (typeof parser !== 'object' || !(parser instanceof SAXParser)) {618 throw new Error('bad call to strictFail')619 }620 if (parser.strict) {621 error(parser, message)622 }623 }624 function newTag (parser) {625 if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]()626 var parent = parser.tags[parser.tags.length - 1] || parser627 var tag = parser.tag = { name: parser.tagName, attributes: {} }628 // will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar"629 if (parser.opt.xmlns) {630 tag.ns = parent.ns631 }632 parser.attribList.length = 0633 emitNode(parser, 'onopentagstart', tag)634 }635 function qname (name, attribute) {636 var i = name.indexOf(':')637 var qualName = i < 0 ? [ '', name ] : name.split(':')638 var prefix = qualName[0]639 var local = qualName[1]640 // <x "xmlns"="http://foo">641 if (attribute && name === 'xmlns') {642 prefix = 'xmlns'643 local = ''644 }645 return { prefix: prefix, local: local }646 }647 function attrib (parser) {648 if (!parser.strict) {649 parser.attribName = parser.attribName[parser.looseCase]()650 }651 if (parser.attribList.indexOf(parser.attribName) !== -1 ||652 parser.tag.attributes.hasOwnProperty(parser.attribName)) {653 parser.attribName = parser.attribValue = ''654 return655 }656 if (parser.opt.xmlns) {657 var qn = qname(parser.attribName, true)658 var prefix = qn.prefix659 var local = qn.local660 if (prefix === 'xmlns') {661 // namespace binding attribute. push the binding into scope662 if (local === 'xml' && parser.attribValue !== XML_NAMESPACE) {663 strictFail(parser,664 'xml: prefix must be bound to ' + XML_NAMESPACE + '\n' +665 'Actual: ' + parser.attribValue)666 } else if (local === 'xmlns' && parser.attribValue !== XMLNS_NAMESPACE) {667 strictFail(parser,668 'xmlns: prefix must be bound to ' + XMLNS_NAMESPACE + '\n' +669 'Actual: ' + parser.attribValue)670 } else {671 var tag = parser.tag672 var parent = parser.tags[parser.tags.length - 1] || parser673 if (tag.ns === parent.ns) {674 tag.ns = Object.create(parent.ns)675 }676 tag.ns[local] = parser.attribValue677 }678 }679 // defer onattribute events until all attributes have been seen680 // so any new bindings can take effect. preserve attribute order681 // so deferred events can be emitted in document order682 parser.attribList.push([parser.attribName, parser.attribValue])683 } else {684 // in non-xmlns mode, we can emit the event right away685 parser.tag.attributes[parser.attribName] = parser.attribValue686 emitNode(parser, 'onattribute', {687 name: parser.attribName,688 value: parser.attribValue689 })690 }691 parser.attribName = parser.attribValue = ''692 }693 function openTag (parser, selfClosing) {694 if (parser.opt.xmlns) {695 // emit namespace binding events696 var tag = parser.tag697 // add namespace info to tag698 var qn = qname(parser.tagName)699 tag.prefix = qn.prefix700 tag.local = qn.local701 tag.uri = tag.ns[qn.prefix] || ''702 if (tag.prefix && !tag.uri) {703 strictFail(parser, 'Unbound namespace prefix: ' +704 JSON.stringify(parser.tagName))705 tag.uri = qn.prefix706 }707 var parent = parser.tags[parser.tags.length - 1] || parser708 if (tag.ns && parent.ns !== tag.ns) {709 Object.keys(tag.ns).forEach(function (p) {710 emitNode(parser, 'onopennamespace', {711 prefix: p,712 uri: tag.ns[p]713 })714 })715 }716 // handle deferred onattribute events717 // Note: do not apply default ns to attributes:718 // http://www.w3.org/TR/REC-xml-names/#defaulting719 for (var i = 0, l = parser.attribList.length; i < l; i++) {720 var nv = parser.attribList[i]721 var name = nv[0]722 var value = nv[1]723 var qualName = qname(name, true)724 var prefix = qualName.prefix725 var local = qualName.local726 var uri = prefix === '' ? '' : (tag.ns[prefix] || '')727 var a = {728 name: name,729 value: value,730 prefix: prefix,731 local: local,732 uri: uri733 }734 // if there's any attributes with an undefined namespace,735 // then fail on them now.736 if (prefix && prefix !== 'xmlns' && !uri) {737 strictFail(parser, 'Unbound namespace prefix: ' +738 JSON.stringify(prefix))739 a.uri = prefix740 }741 parser.tag.attributes[name] = a742 emitNode(parser, 'onattribute', a)743 }744 parser.attribList.length = 0745 }746 parser.tag.isSelfClosing = !!selfClosing747 // process the tag748 parser.sawRoot = true749 parser.tags.push(parser.tag)750 emitNode(parser, 'onopentag', parser.tag)751 if (!selfClosing) {752 // special case for <script> in non-strict mode.753 if (!parser.noscript && parser.tagName.toLowerCase() === 'script') {754 parser.state = S.SCRIPT755 } else {756 parser.state = S.TEXT757 }758 parser.tag = null759 parser.tagName = ''760 }761 parser.attribName = parser.attribValue = ''762 parser.attribList.length = 0763 }764 function closeTag (parser) {765 if (!parser.tagName) {766 strictFail(parser, 'Weird empty close tag.')767 parser.textNode += '</>'768 parser.state = S.TEXT769 return770 }771 if (parser.script) {772 if (parser.tagName !== 'script') {773 parser.script += '</' + parser.tagName + '>'774 parser.tagName = ''775 parser.state = S.SCRIPT776 return777 }778 emitNode(parser, 'onscript', parser.script)779 parser.script = ''780 }781 // first make sure that the closing tag actually exists.782 // <a><b></c></b></a> will close everything, otherwise.783 var t = parser.tags.length784 var tagName = parser.tagName785 if (!parser.strict) {786 tagName = tagName[parser.looseCase]()787 }788 var closeTo = tagName789 while (t--) {790 var close = parser.tags[t]791 if (close.name !== closeTo) {792 // fail the first time in strict mode793 strictFail(parser, 'Unexpected close tag')794 } else {795 break796 }797 }798 // didn't find it. we already failed for strict, so just abort.799 if (t < 0) {800 strictFail(parser, 'Unmatched closing tag: ' + parser.tagName)801 parser.textNode += '</' + parser.tagName + '>'802 parser.state = S.TEXT803 return804 }805 parser.tagName = tagName806 var s = parser.tags.length807 while (s-- > t) {808 var tag = parser.tag = parser.tags.pop()809 parser.tagName = parser.tag.name810 emitNode(parser, 'onclosetag', parser.tagName)811 var x = {}812 for (var i in tag.ns) {813 x[i] = tag.ns[i]814 }815 var parent = parser.tags[parser.tags.length - 1] || parser816 if (parser.opt.xmlns && tag.ns !== parent.ns) {817 // remove namespace bindings introduced by tag818 Object.keys(tag.ns).forEach(function (p) {819 var n = tag.ns[p]820 emitNode(parser, 'onclosenamespace', { prefix: p, uri: n })821 })822 }823 }824 if (t === 0) parser.closedRoot = true825 parser.tagName = parser.attribValue = parser.attribName = ''826 parser.attribList.length = 0827 parser.state = S.TEXT828 }829 function parseEntity (parser) {830 var entity = parser.entity831 var entityLC = entity.toLowerCase()832 var num833 var numStr = ''834 if (parser.ENTITIES[entity]) {835 return parser.ENTITIES[entity]836 }837 if (parser.ENTITIES[entityLC]) {838 return parser.ENTITIES[entityLC]839 }840 entity = entityLC841 if (entity.charAt(0) === '#') {842 if (entity.charAt(1) === 'x') {843 entity = entity.slice(2)844 num = parseInt(entity, 16)845 numStr = num.toString(16)846 } else {847 entity = entity.slice(1)848 num = parseInt(entity, 10)849 numStr = num.toString(10)850 }851 }852 entity = entity.replace(/^0+/, '')853 if (isNaN(num) || numStr.toLowerCase() !== entity) {854 strictFail(parser, 'Invalid character entity')855 return '&' + parser.entity + ';'856 }857 return String.fromCodePoint(num)858 }859 function beginWhiteSpace (parser, c) {860 if (c === '<') {861 parser.state = S.OPEN_WAKA862 parser.startTagPosition = parser.position863 } else if (!isWhitespace(c)) {864 // have to process this as a text node.865 // weird, but happens.866 strictFail(parser, 'Non-whitespace before first tag.')867 parser.textNode = c868 parser.state = S.TEXT869 }870 }871 function charAt (chunk, i) {872 var result = ''873 if (i < chunk.length) {874 result = chunk.charAt(i)875 }876 return result877 }878 function write (chunk) {879 var parser = this880 if (this.error) {881 throw this.error882 }883 if (parser.closed) {884 return error(parser,885 'Cannot write after close. Assign an onready handler.')886 }887 if (chunk === null) {888 return end(parser)889 }890 if (typeof chunk === 'object') {891 chunk = chunk.toString()892 }893 var i = 0894 var c = ''895 while (true) {896 c = charAt(chunk, i++)897 parser.c = c898 if (!c) {899 break900 }901 if (parser.trackPosition) {902 parser.position++903 if (c === '\n') {904 parser.line++905 parser.column = 0906 } else {907 parser.column++908 }909 }910 switch (parser.state) {911 case S.BEGIN:912 parser.state = S.BEGIN_WHITESPACE913 if (c === '\uFEFF') {914 continue915 }916 beginWhiteSpace(parser, c)917 continue918 case S.BEGIN_WHITESPACE:919 beginWhiteSpace(parser, c)920 continue921 case S.TEXT:922 if (parser.sawRoot && !parser.closedRoot) {923 var starti = i - 1924 while (c && c !== '<' && c !== '&') {925 c = charAt(chunk, i++)926 if (c && parser.trackPosition) {927 parser.position++928 if (c === '\n') {929 parser.line++930 parser.column = 0931 } else {932 parser.column++933 }934 }935 }936 parser.textNode += chunk.substring(starti, i - 1)937 }938 if (c === '<' && !(parser.sawRoot && parser.closedRoot && !parser.strict)) {939 parser.state = S.OPEN_WAKA940 parser.startTagPosition = parser.position941 } else {942 if (!isWhitespace(c) && (!parser.sawRoot || parser.closedRoot)) {943 strictFail(parser, 'Text data outside of root node.')944 }945 if (c === '&') {946 parser.state = S.TEXT_ENTITY947 } else {948 parser.textNode += c949 }950 }951 continue952 case S.SCRIPT:953 // only non-strict954 if (c === '<') {955 parser.state = S.SCRIPT_ENDING956 } else {957 parser.script += c958 }959 continue960 case S.SCRIPT_ENDING:961 if (c === '/') {962 parser.state = S.CLOSE_TAG963 } else {964 parser.script += '<' + c965 parser.state = S.SCRIPT966 }967 continue968 case S.OPEN_WAKA:969 // either a /, ?, !, or text is coming next.970 if (c === '!') {971 parser.state = S.SGML_DECL972 parser.sgmlDecl = ''973 } else if (isWhitespace(c)) {974 // wait for it...975 } else if (isMatch(nameStart, c)) {976 parser.state = S.OPEN_TAG977 parser.tagName = c978 } else if (c === '/') {979 parser.state = S.CLOSE_TAG980 parser.tagName = ''981 } else if (c === '?') {982 parser.state = S.PROC_INST983 parser.procInstName = parser.procInstBody = ''984 } else {985 strictFail(parser, 'Unencoded <')986 // if there was some whitespace, then add that in.987 if (parser.startTagPosition + 1 < parser.position) {988 var pad = parser.position - parser.startTagPosition989 c = new Array(pad).join(' ') + c990 }991 parser.textNode += '<' + c992 parser.state = S.TEXT993 }994 continue995 case S.SGML_DECL:996 if ((parser.sgmlDecl + c).toUpperCase() === CDATA) {997 emitNode(parser, 'onopencdata')998 parser.state = S.CDATA999 parser.sgmlDecl = ''1000 parser.cdata = ''1001 } else if (parser.sgmlDecl + c === '--') {1002 parser.state = S.COMMENT1003 parser.comment = ''1004 parser.sgmlDecl = ''1005 } else if ((parser.sgmlDecl + c).toUpperCase() === DOCTYPE) {1006 parser.state = S.DOCTYPE1007 if (parser.doctype || parser.sawRoot) {1008 strictFail(parser,1009 'Inappropriately located doctype declaration')1010 }1011 parser.doctype = ''1012 parser.sgmlDecl = ''1013 } else if (c === '>') {1014 emitNode(parser, 'onsgmldeclaration', parser.sgmlDecl)1015 parser.sgmlDecl = ''1016 parser.state = S.TEXT1017 } else if (isQuote(c)) {1018 parser.state = S.SGML_DECL_QUOTED1019 parser.sgmlDecl += c1020 } else {1021 parser.sgmlDecl += c1022 }1023 continue1024 case S.SGML_DECL_QUOTED:1025 if (c === parser.q) {1026 parser.state = S.SGML_DECL1027 parser.q = ''1028 }1029 parser.sgmlDecl += c1030 continue1031 case S.DOCTYPE:1032 if (c === '>') {1033 parser.state = S.TEXT1034 emitNode(parser, 'ondoctype', parser.doctype)1035 parser.doctype = true // just remember that we saw it.1036 } else {1037 parser.doctype += c1038 if (c === '[') {1039 parser.state = S.DOCTYPE_DTD1040 } else if (isQuote(c)) {1041 parser.state = S.DOCTYPE_QUOTED1042 parser.q = c1043 }1044 }1045 continue1046 case S.DOCTYPE_QUOTED:1047 parser.doctype += c1048 if (c === parser.q) {1049 parser.q = ''1050 parser.state = S.DOCTYPE1051 }1052 continue1053 case S.DOCTYPE_DTD:1054 parser.doctype += c1055 if (c === ']') {1056 parser.state = S.DOCTYPE1057 } else if (isQuote(c)) {1058 parser.state = S.DOCTYPE_DTD_QUOTED1059 parser.q = c1060 }1061 continue1062 case S.DOCTYPE_DTD_QUOTED:1063 parser.doctype += c1064 if (c === parser.q) {1065 parser.state = S.DOCTYPE_DTD1066 parser.q = ''1067 }1068 continue1069 case S.COMMENT:1070 if (c === '-') {1071 parser.state = S.COMMENT_ENDING1072 } else {1073 parser.comment += c1074 }1075 continue1076 case S.COMMENT_ENDING:1077 if (c === '-') {1078 parser.state = S.COMMENT_ENDED1079 parser.comment = textopts(parser.opt, parser.comment)1080 if (parser.comment) {1081 emitNode(parser, 'oncomment', parser.comment)1082 }1083 parser.comment = ''1084 } else {1085 parser.comment += '-' + c1086 parser.state = S.COMMENT1087 }1088 continue1089 case S.COMMENT_ENDED:1090 if (c !== '>') {1091 strictFail(parser, 'Malformed comment')1092 // allow <!-- blah -- bloo --> in non-strict mode,1093 // which is a comment of " blah -- bloo "1094 parser.comment += '--' + c1095 parser.state = S.COMMENT1096 } else {1097 parser.state = S.TEXT1098 }1099 continue1100 case S.CDATA:1101 if (c === ']') {1102 parser.state = S.CDATA_ENDING1103 } else {1104 parser.cdata += c1105 }1106 continue1107 case S.CDATA_ENDING:1108 if (c === ']') {1109 parser.state = S.CDATA_ENDING_21110 } else {1111 parser.cdata += ']' + c1112 parser.state = S.CDATA1113 }1114 continue1115 case S.CDATA_ENDING_2:1116 if (c === '>') {1117 if (parser.cdata) {1118 emitNode(parser, 'oncdata', parser.cdata)1119 }1120 emitNode(parser, 'onclosecdata')1121 parser.cdata = ''1122 parser.state = S.TEXT1123 } else if (c === ']') {1124 parser.cdata += ']'1125 } else {1126 parser.cdata += ']]' + c1127 parser.state = S.CDATA1128 }1129 continue1130 case S.PROC_INST:1131 if (c === '?') {1132 parser.state = S.PROC_INST_ENDING1133 } else if (isWhitespace(c)) {1134 parser.state = S.PROC_INST_BODY1135 } else {1136 parser.procInstName += c1137 }1138 continue1139 case S.PROC_INST_BODY:1140 if (!parser.procInstBody && isWhitespace(c)) {1141 continue1142 } else if (c === '?') {1143 parser.state = S.PROC_INST_ENDING1144 } else {1145 parser.procInstBody += c1146 }1147 continue1148 case S.PROC_INST_ENDING:1149 if (c === '>') {1150 emitNode(parser, 'onprocessinginstruction', {1151 name: parser.procInstName,1152 body: parser.procInstBody1153 })1154 parser.procInstName = parser.procInstBody = ''1155 parser.state = S.TEXT1156 } else {1157 parser.procInstBody += '?' + c1158 parser.state = S.PROC_INST_BODY1159 }1160 continue1161 case S.OPEN_TAG:1162 if (isMatch(nameBody, c)) {1163 parser.tagName += c1164 } else {1165 newTag(parser)1166 if (c === '>') {1167 openTag(parser)1168 } else if (c === '/') {1169 parser.state = S.OPEN_TAG_SLASH1170 } else {1171 if (!isWhitespace(c)) {1172 strictFail(parser, 'Invalid character in tag name')1173 }1174 parser.state = S.ATTRIB1175 }1176 }1177 continue1178 case S.OPEN_TAG_SLASH:1179 if (c === '>') {1180 openTag(parser, true)1181 closeTag(parser)1182 } else {1183 strictFail(parser, 'Forward-slash in opening tag not followed by >')1184 parser.state = S.ATTRIB1185 }1186 continue1187 case S.ATTRIB:1188 // haven't read the attribute name yet.1189 if (isWhitespace(c)) {1190 continue1191 } else if (c === '>') {1192 openTag(parser)1193 } else if (c === '/') {1194 parser.state = S.OPEN_TAG_SLASH1195 } else if (isMatch(nameStart, c)) {1196 parser.attribName = c1197 parser.attribValue = ''1198 parser.state = S.ATTRIB_NAME1199 } else {1200 strictFail(parser, 'Invalid attribute name')1201 }1202 continue1203 case S.ATTRIB_NAME:1204 if (c === '=') {1205 parser.state = S.ATTRIB_VALUE1206 } else if (c === '>') {1207 strictFail(parser, 'Attribute without value')1208 parser.attribValue = parser.attribName1209 attrib(parser)1210 openTag(parser)1211 } else if (isWhitespace(c)) {1212 parser.state = S.ATTRIB_NAME_SAW_WHITE1213 } else if (isMatch(nameBody, c)) {1214 parser.attribName += c1215 } else {1216 strictFail(parser, 'Invalid attribute name')1217 }1218 continue1219 case S.ATTRIB_NAME_SAW_WHITE:1220 if (c === '=') {1221 parser.state = S.ATTRIB_VALUE1222 } else if (isWhitespace(c)) {1223 continue1224 } else {1225 strictFail(parser, 'Attribute without value')1226 parser.tag.attributes[parser.attribName] = ''1227 parser.attribValue = ''1228 emitNode(parser, 'onattribute', {1229 name: parser.attribName,1230 value: ''1231 })1232 parser.attribName = ''1233 if (c === '>') {1234 openTag(parser)1235 } else if (isMatch(nameStart, c)) {1236 parser.attribName = c1237 parser.state = S.ATTRIB_NAME1238 } else {1239 strictFail(parser, 'Invalid attribute name')1240 parser.state = S.ATTRIB1241 }1242 }1243 continue1244 case S.ATTRIB_VALUE:1245 if (isWhitespace(c)) {1246 continue1247 } else if (isQuote(c)) {1248 parser.q = c1249 parser.state = S.ATTRIB_VALUE_QUOTED1250 } else {1251 strictFail(parser, 'Unquoted attribute value')1252 parser.state = S.ATTRIB_VALUE_UNQUOTED1253 parser.attribValue = c1254 }1255 continue1256 case S.ATTRIB_VALUE_QUOTED:1257 if (c !== parser.q) {1258 if (c === '&') {1259 parser.state = S.ATTRIB_VALUE_ENTITY_Q1260 } else {1261 parser.attribValue += c1262 }1263 continue1264 }1265 attrib(parser)1266 parser.q = ''1267 parser.state = S.ATTRIB_VALUE_CLOSED1268 continue1269 case S.ATTRIB_VALUE_CLOSED:1270 if (isWhitespace(c)) {1271 parser.state = S.ATTRIB1272 } else if (c === '>') {1273 openTag(parser)1274 } else if (c === '/') {1275 parser.state = S.OPEN_TAG_SLASH1276 } else if (isMatch(nameStart, c)) {1277 strictFail(parser, 'No whitespace between attributes')1278 parser.attribName = c1279 parser.attribValue = ''1280 parser.state = S.ATTRIB_NAME1281 } else {1282 strictFail(parser, 'Invalid attribute name')1283 }1284 continue1285 case S.ATTRIB_VALUE_UNQUOTED:1286 if (!isAttribEnd(c)) {1287 if (c === '&') {1288 parser.state = S.ATTRIB_VALUE_ENTITY_U1289 } else {1290 parser.attribValue += c1291 }1292 continue1293 }1294 attrib(parser)1295 if (c === '>') {1296 openTag(parser)1297 } else {1298 parser.state = S.ATTRIB1299 }1300 continue1301 case S.CLOSE_TAG:1302 if (!parser.tagName) {1303 if (isWhitespace(c)) {1304 continue1305 } else if (notMatch(nameStart, c)) {1306 if (parser.script) {1307 parser.script += '</' + c1308 parser.state = S.SCRIPT1309 } else {1310 strictFail(parser, 'Invalid tagname in closing tag.')1311 }1312 } else {1313 parser.tagName = c1314 }1315 } else if (c === '>') {1316 closeTag(parser)1317 } else if (isMatch(nameBody, c)) {1318 parser.tagName += c1319 } else if (parser.script) {1320 parser.script += '</' + parser.tagName1321 parser.tagName = ''1322 parser.state = S.SCRIPT1323 } else {1324 if (!isWhitespace(c)) {1325 strictFail(parser, 'Invalid tagname in closing tag')1326 }1327 parser.state = S.CLOSE_TAG_SAW_WHITE1328 }1329 continue1330 case S.CLOSE_TAG_SAW_WHITE:1331 if (isWhitespace(c)) {1332 continue1333 }1334 if (c === '>') {1335 closeTag(parser)1336 } else {1337 strictFail(parser, 'Invalid characters in closing tag')1338 }1339 continue1340 case S.TEXT_ENTITY:1341 case S.ATTRIB_VALUE_ENTITY_Q:1342 case S.ATTRIB_VALUE_ENTITY_U:1343 var returnState1344 var buffer1345 switch (parser.state) {1346 case S.TEXT_ENTITY:1347 returnState = S.TEXT1348 buffer = 'textNode'1349 break1350 case S.ATTRIB_VALUE_ENTITY_Q:1351 returnState = S.ATTRIB_VALUE_QUOTED1352 buffer = 'attribValue'1353 break1354 case S.ATTRIB_VALUE_ENTITY_U:1355 returnState = S.ATTRIB_VALUE_UNQUOTED1356 buffer = 'attribValue'1357 break1358 }1359 if (c === ';') {1360 parser[buffer] += parseEntity(parser)1361 parser.entity = ''1362 parser.state = returnState1363 } else if (isMatch(parser.entity.length ? entityBody : entityStart, c)) {1364 parser.entity += c1365 } else {1366 strictFail(parser, 'Invalid character in entity name')1367 parser[buffer] += '&' + parser.entity + c1368 parser.entity = ''1369 parser.state = returnState1370 }1371 continue1372 default:1373 throw new Error(parser, 'Unknown state: ' + parser.state)1374 }1375 } // while1376 if (parser.position >= parser.bufferCheckPosition) {1377 checkBufferLength(parser)1378 }1379 return parser1380 }1381 /*! http://mths.be/fromcodepoint v0.1.0 by @mathias */1382 /* istanbul ignore next */1383 if (!String.fromCodePoint) {1384 (function () {1385 var stringFromCharCode = String.fromCharCode1386 var floor = Math.floor1387 var fromCodePoint = function () {1388 var MAX_SIZE = 0x40001389 var codeUnits = []1390 var highSurrogate1391 var lowSurrogate1392 var index = -11393 var length = arguments.length1394 if (!length) {1395 return ''1396 }1397 var result = ''1398 while (++index < length) {1399 var codePoint = Number(arguments[index])1400 if (1401 !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity`1402 codePoint < 0 || // not a valid Unicode code point1403 codePoint > 0x10FFFF || // not a valid Unicode code point1404 floor(codePoint) !== codePoint // not an integer1405 ) {1406 throw RangeError('Invalid code point: ' + codePoint)1407 }1408 if (codePoint <= 0xFFFF) { // BMP code point1409 codeUnits.push(codePoint)1410 } else { // Astral code point; split in surrogate halves1411 // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae1412 codePoint -= 0x100001413 highSurrogate = (codePoint >> 10) + 0xD8001414 lowSurrogate = (codePoint % 0x400) + 0xDC001415 codeUnits.push(highSurrogate, lowSurrogate)1416 }1417 if (index + 1 === length || codeUnits.length > MAX_SIZE) {1418 result += stringFromCharCode.apply(null, codeUnits)1419 codeUnits.length = 01420 }1421 }1422 return result1423 }1424 /* istanbul ignore next */1425 if (Object.defineProperty) {1426 Object.defineProperty(String, 'fromCodePoint', {1427 value: fromCodePoint,1428 configurable: true,1429 writable: true1430 })1431 } else {1432 String.fromCodePoint = fromCodePoint1433 }1434 }())1435 }...

Full Screen

Full Screen

WikiParser.js

Source:WikiParser.js Github

copy

Full Screen

1// Copyright 2014 The Chromium Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4/**5 * @constructor6 * @param {string} wikiMarkupText7 */8WebInspector.WikiParser = function(wikiMarkupText)9{10 var text = wikiMarkupText;11 this._tokenizer = new WebInspector.WikiParser.Tokenizer(text);12 this._document = this._parse();13}14/**15 * @constructor16 */17WebInspector.WikiParser.Section = function()18{19 /** @type {string} */20 this.title;21 /** @type {?WebInspector.WikiParser.Values} */22 this.values;23 /** @type {?WebInspector.WikiParser.ArticleElement} */24 this.singleValue;25}26/**27 * @constructor28 */29WebInspector.WikiParser.Field = function()30{31 /** @type {string} */32 this.name;33 /** @type {?WebInspector.WikiParser.FieldValue} */34 this.value;35}36/** @typedef {(?WebInspector.WikiParser.ArticleElement|!Array.<!WebInspector.WikiParser.Section>)} */37WebInspector.WikiParser.FieldValue;38/** @typedef {?Object.<string, !WebInspector.WikiParser.FieldValue>} */39WebInspector.WikiParser.Values;40/** @typedef {(?WebInspector.WikiParser.Value|?WebInspector.WikiParser.ArticleElement)} */41WebInspector.WikiParser.Value;42/**43 * @package44 * @enum {string}45 */46WebInspector.WikiParser.TokenType = {47 Text: "Text",48 OpeningTable: "OpeningTable",49 ClosingTable: "ClosingTable",50 RowSeparator: "RowSeparator",51 CellSeparator: "CellSeparator",52 NameSeparator: "NameSeparator",53 OpeningCurlyBrackets: "OpeningCurlyBrackets",54 ClosingCurlyBrackets: "ClosingCurlyBrackets",55 Exclamation: "Exclamation",56 OpeningSquareBrackets: "OpeningSquareBrackets",57 ClosingBrackets: "ClosingBrackets",58 EqualSign: "EqualSign",59 EqualSignInCurlyBrackets: "EqualSignInCurlyBrackets",60 VerticalLine: "VerticalLine",61 DoubleQuotes: "DoubleQuotes",62 TripleQuotes: "TripleQuotes",63 OpeningCodeTag: "OpeningCodeTag",64 ClosingCodeTag: "ClosingCodeTag",65 Bullet: "Bullet",66 LineEnd: "LineEnd",67 CodeBlock: "CodeBlock",68 Space: "Space"69}70/**71 * @constructor72 * @param {string} result73 * @param {!WebInspector.WikiParser.TokenType} type74 */75WebInspector.WikiParser.Token = function(result, type)76{77 this._value = result;78 this._type = type;79}80WebInspector.WikiParser.Token.prototype = {81 /**82 * @return {string}83 */84 value: function()85 {86 return this._value;87 },88 /**89 * @return {!WebInspector.WikiParser.TokenType}90 */91 type: function()92 {93 return this._type;94 }95}96/**97 * @constructor98 * @param {string} str99 */100WebInspector.WikiParser.Tokenizer = function(str)101{102 this._text = str;103 this._oldText = str;104 this._token = this._internalNextToken();105 this._mode = WebInspector.WikiParser.Tokenizer.Mode.Normal;106}107/**108 * @package109 * @enum {string}110 */111WebInspector.WikiParser.Tokenizer.Mode = {112 Normal: "Normal",113 Link: "Link"114}115WebInspector.WikiParser.Tokenizer.prototype = {116 /**117 * @param {!WebInspector.WikiParser.Tokenizer.Mode} mode118 */119 _setMode: function(mode)120 {121 this._mode = mode;122 this._text = this._oldText;123 this._token = this._internalNextToken();124 },125 /**126 * @return {boolean}127 */128 _isNormalMode: function()129 {130 return this._mode === WebInspector.WikiParser.Tokenizer.Mode.Normal;131 },132 /**133 * @return {!WebInspector.WikiParser.Token}134 */135 peekToken: function()136 {137 return this._token;138 },139 /**140 * @return {!WebInspector.WikiParser.Token}141 */142 nextToken: function()143 {144 var token = this._token;145 this._oldText = this._text;146 this._token = this._internalNextToken();147 return token;148 },149 /**150 * @return {!WebInspector.WikiParser.Token}151 */152 _internalNextToken: function()153 {154 if (WebInspector.WikiParser.newLineWithSpace.test(this._text)) {155 var result = WebInspector.WikiParser.newLineWithSpace.exec(this._text);156 var begin = result.index;157 var end = this._text.length;158 var lineEnd = WebInspector.WikiParser.newLineWithoutSpace.exec(this._text);159 if (lineEnd)160 end = lineEnd.index;161 var token = this._text.substring(begin, end).replace(/\n /g, "\n").replace(/{{=}}/g, "=");162 this._text = this._text.substring(end + 1);163 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.CodeBlock);164 }165 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++i) {166 if (this._isNormalMode() && WebInspector.WikiParser._tokenDescriptors[i].type === WebInspector.WikiParser.TokenType.Space)167 continue;168 var result = WebInspector.WikiParser._tokenDescriptors[i].regex.exec(this._text);169 if (result) {170 this._text = this._text.substring(result.index + result[0].length);171 return new WebInspector.WikiParser.Token(result[0], WebInspector.WikiParser._tokenDescriptors[i].type);172 }173 }174 for (var lastIndex = 0; lastIndex < this._text.length; ++lastIndex) {175 var testString = this._text.substring(lastIndex);176 for (var i = 0; i < WebInspector.WikiParser._tokenDescriptors.length; ++i) {177 if (this._isNormalMode() && WebInspector.WikiParser._tokenDescriptors[i].type === WebInspector.WikiParser.TokenType.Space)178 continue;179 if (WebInspector.WikiParser._tokenDescriptors[i].regex.test(testString)) {180 var token = this._text.substring(0, lastIndex);181 this._text = this._text.substring(lastIndex);182 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.Text);183 }184 }185 }186 var token = this._text;187 this._text = "";188 return new WebInspector.WikiParser.Token(token, WebInspector.WikiParser.TokenType.Text);189 },190 /**191 * @return {!WebInspector.WikiParser.Tokenizer}192 */193 clone: function()194 {195 var tokenizer = new WebInspector.WikiParser.Tokenizer(this._text);196 tokenizer._token = this._token;197 tokenizer._text = this._text;198 tokenizer._oldText = this._oldText;199 tokenizer._mode = this._mode;200 return tokenizer;201 },202 /**203 * @return {boolean}204 */205 hasMoreTokens: function()206 {207 return !!this._text.length;208 }209}210WebInspector.WikiParser.openingTable = /^\n{{{!}}/;211WebInspector.WikiParser.closingTable = /^\n{{!}}}/;212WebInspector.WikiParser.cellSeparator = /^\n{{!}}/;213WebInspector.WikiParser.rowSeparator = /^\n{{!}}-/;214WebInspector.WikiParser.nameSeparator = /^\n!/;215WebInspector.WikiParser.exclamation = /^{{!}}/;216WebInspector.WikiParser.openingCurlyBrackets = /^{{/;217WebInspector.WikiParser.equalSign = /^=/;218WebInspector.WikiParser.equalSignInCurlyBrackets = /^{{=}}/;219WebInspector.WikiParser.closingCurlyBrackets = /^\s*}}/;220WebInspector.WikiParser.oneOpeningSquareBracket = /^\n*\[/;221WebInspector.WikiParser.twoOpeningSquareBrackets = /^\n*\[\[/;222WebInspector.WikiParser.oneClosingBracket = /^\n*\]/;223WebInspector.WikiParser.twoClosingBrackets = /^\n*\]\]/;224WebInspector.WikiParser.tripleQuotes = /^\n*'''/;225WebInspector.WikiParser.doubleQuotes = /^\n*''/;226WebInspector.WikiParser.openingCodeTag = /^<code\s*>/;227WebInspector.WikiParser.closingCodeTag = /^<\/code\s*>/;228WebInspector.WikiParser.closingBullet = /^\*/;229WebInspector.WikiParser.lineEnd = /^\n/;230WebInspector.WikiParser.verticalLine = /^\n*\|/;231WebInspector.WikiParser.newLineWithSpace = /^\n [^ ]/;232WebInspector.WikiParser.newLineWithoutSpace = /\n[^ ]/;233WebInspector.WikiParser.space = /^ /;234/**235 * @constructor236 * @param {!RegExp} regex237 * @param {!WebInspector.WikiParser.TokenType} type238 */239WebInspector.WikiParser.TokenDescriptor = function(regex, type)240{241 this.regex = regex;242 this.type = type;243}244WebInspector.WikiParser._tokenDescriptors = [245 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingTable, WebInspector.WikiParser.TokenType.ClosingTable),246 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingTable, WebInspector.WikiParser.TokenType.OpeningTable),247 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.rowSeparator, WebInspector.WikiParser.TokenType.RowSeparator),248 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.cellSeparator, WebInspector.WikiParser.TokenType.CellSeparator),249 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.nameSeparator, WebInspector.WikiParser.TokenType.NameSeparator),250 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.exclamation, WebInspector.WikiParser.TokenType.Exclamation),251 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSignInCurlyBrackets, WebInspector.WikiParser.TokenType.EqualSignInCurlyBrackets),252 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.equalSign, WebInspector.WikiParser.TokenType.EqualSign),253 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingTable, WebInspector.WikiParser.TokenType.OpeningTable),254 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCurlyBrackets, WebInspector.WikiParser.TokenType.OpeningCurlyBrackets),255 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.verticalLine, WebInspector.WikiParser.TokenType.VerticalLine),256 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCurlyBrackets, WebInspector.WikiParser.TokenType.ClosingCurlyBrackets),257 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoOpeningSquareBrackets, WebInspector.WikiParser.TokenType.OpeningSquareBrackets),258 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.twoClosingBrackets, WebInspector.WikiParser.TokenType.ClosingBrackets),259 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneOpeningSquareBracket, WebInspector.WikiParser.TokenType.OpeningSquareBrackets),260 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.oneClosingBracket, WebInspector.WikiParser.TokenType.ClosingBrackets),261 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.newLineWithSpace, WebInspector.WikiParser.TokenType.CodeBlock),262 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.tripleQuotes, WebInspector.WikiParser.TokenType.TripleQuotes),263 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.doubleQuotes, WebInspector.WikiParser.TokenType.DoubleQuotes),264 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.openingCodeTag, WebInspector.WikiParser.TokenType.OpeningCodeTag),265 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingCodeTag, WebInspector.WikiParser.TokenType.ClosingCodeTag),266 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.closingBullet, WebInspector.WikiParser.TokenType.Bullet),267 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.lineEnd, WebInspector.WikiParser.TokenType.LineEnd),268 new WebInspector.WikiParser.TokenDescriptor(WebInspector.WikiParser.space, WebInspector.WikiParser.TokenType.Space)269]270WebInspector.WikiParser.prototype = {271 /**272 * @return {!Object}273 */274 document: function()275 {276 return this._document;277 },278 /**279 * @return {?WebInspector.WikiParser.TokenType}280 */281 _secondTokenType: function()282 {283 var tokenizer = this._tokenizer.clone();284 if (!tokenizer.hasMoreTokens())285 return null;286 tokenizer.nextToken();287 if (!tokenizer.hasMoreTokens())288 return null;289 return tokenizer.nextToken().type();290 },291 /**292 * @return {!Object.<string, ?WebInspector.WikiParser.Value>}293 */294 _parse: function()295 {296 var obj = {};297 while (this._tokenizer.hasMoreTokens()) {298 var section = this._parseSection();299 if (section.title)300 obj[section.title] = section.singleValue || section.values;301 }302 return obj;303 },304 /**305 * @return {!WebInspector.WikiParser.Section}306 */307 _parseSection: function()308 {309 var section = new WebInspector.WikiParser.Section();310 if (!this._tokenizer.hasMoreTokens() || this._tokenizer.nextToken().type() !== WebInspector.WikiParser.TokenType.OpeningCurlyBrackets)311 return section;312 var title = this._deleteTrailingSpaces(this._parseSectionTitle());313 if (!title.length)314 return section;315 section.title = title;316 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.ClosingCurlyBrackets) {317 this._tokenizer.nextToken();318 return section;319 }320 var secondTokenType = this._secondTokenType();321 if (!secondTokenType || secondTokenType !== WebInspector.WikiParser.TokenType.EqualSign) {322 section.singleValue = this._parseMarkupText();323 } else {324 section.values = {};325 while (this._tokenizer.hasMoreTokens()) {326 var field = this._parseField();327 section.values[field.name] = field.value;328 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.ClosingCurlyBrackets) {329 this._tokenizer.nextToken();330 return section;331 }332 }333 }334 var token = this._tokenizer.nextToken();335 if (token.type() !== WebInspector.WikiParser.TokenType.ClosingCurlyBrackets)336 throw new Error("Two closing curly brackets expected; found " + token.value());337 return section;338 },339 /**340 * @return {!WebInspector.WikiParser.Field}341 */342 _parseField: function()343 {344 var field = new WebInspector.WikiParser.Field();345 field.name = this._parseFieldName();346 var token = this._tokenizer.peekToken();347 switch (token.type()) {348 case WebInspector.WikiParser.TokenType.OpeningCurlyBrackets:349 field.value = this._parseArray();350 break;351 case WebInspector.WikiParser.TokenType.LineEnd:352 this._tokenizer.nextToken();353 break;354 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:355 return field;356 default:357 if (field.name.toUpperCase() === "CODE")358 field.value = this._parseExampleCode();359 else360 field.value = this._parseMarkupText();361 }362 return field;363 },364 /**365 * @return {!Array.<!WebInspector.WikiParser.Section>}366 */367 _parseArray: function()368 {369 var array = [];370 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.OpeningCurlyBrackets)371 array.push(this._parseSection());372 if (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.VerticalLine)373 this._tokenizer.nextToken();374 return array;375 },376 /**377 * @return {string}378 */379 _parseSectionTitle: function()380 {381 var title = "";382 while (this._tokenizer.hasMoreTokens()) {383 var token = this._tokenizer.peekToken();384 switch (token.type()) {385 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:386 return title;387 case WebInspector.WikiParser.TokenType.VerticalLine:388 this._tokenizer.nextToken();389 return title;390 case WebInspector.WikiParser.TokenType.Text:391 title += this._tokenizer.nextToken().value();392 break;393 default:394 throw new Error("Title could not be parsed. Unexpected token " + token.value());395 }396 }397 return title;398 },399 /**400 * @return {string}401 */402 _parseFieldName: function()403 {404 var name = "";405 while (this._tokenizer.hasMoreTokens()) {406 var token = this._tokenizer.peekToken();407 switch (token.type()) {408 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:409 return name;410 case WebInspector.WikiParser.TokenType.EqualSign:411 this._tokenizer.nextToken();412 return name;413 case WebInspector.WikiParser.TokenType.VerticalLine:414 case WebInspector.WikiParser.TokenType.Text:415 name += this._tokenizer.nextToken().value();416 break;417 default:418 throw new Error("Name could not be parsed. Unexpected token " + token.value());419 }420 }421 return name;422 },423 /**424 * @return {!WebInspector.WikiParser.Block}425 */426 _parseExampleCode: function()427 {428 var code = "";429 /**430 * @return {!WebInspector.WikiParser.Block}431 */432 function wrapIntoArticleElement()433 {434 var plainText = new WebInspector.WikiParser.PlainText(code);435 var block = new WebInspector.WikiParser.Block([plainText])436 var articleElement = new WebInspector.WikiParser.Block([block]);437 return articleElement;438 }439 while (this._tokenizer.hasMoreTokens()) {440 var token = this._tokenizer.peekToken();441 switch (token.type()) {442 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:443 return wrapIntoArticleElement();444 case WebInspector.WikiParser.TokenType.VerticalLine:445 this._tokenizer.nextToken();446 return wrapIntoArticleElement();447 case WebInspector.WikiParser.TokenType.Exclamation:448 this._tokenizer.nextToken();449 code += "|";450 break;451 case WebInspector.WikiParser.TokenType.EqualSignInCurlyBrackets:452 this._tokenizer.nextToken();453 code += "=";454 break;455 default:456 this._tokenizer.nextToken();457 code += token.value();458 }459 }460 return wrapIntoArticleElement();461 },462 /**463 * @return {?WebInspector.WikiParser.Block}464 */465 _parseMarkupText: function()466 {467 var children = [];468 var blockChildren = [];469 var text = "";470 /**471 * @this {WebInspector.WikiParser}472 */473 function processSimpleText()474 {475 var currentText = this._deleteTrailingSpaces(text);476 if (!currentText.length)477 return;478 var simpleText = new WebInspector.WikiParser.PlainText(currentText);479 blockChildren.push(simpleText);480 text = "";481 }482 function processBlock()483 {484 if (blockChildren.length) {485 children.push(new WebInspector.WikiParser.Block(blockChildren));486 blockChildren = [];487 }488 }489 while (this._tokenizer.hasMoreTokens()) {490 var token = this._tokenizer.peekToken();491 switch (token.type()) {492 case WebInspector.WikiParser.TokenType.RowSeparator:493 case WebInspector.WikiParser.TokenType.NameSeparator:494 case WebInspector.WikiParser.TokenType.CellSeparator:495 case WebInspector.WikiParser.TokenType.ClosingTable:496 case WebInspector.WikiParser.TokenType.VerticalLine:497 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:498 if (token.type() === WebInspector.WikiParser.TokenType.VerticalLine)499 this._tokenizer.nextToken();500 processSimpleText.call(this);501 processBlock();502 return new WebInspector.WikiParser.Block(children);503 case WebInspector.WikiParser.TokenType.TripleQuotes:504 this._tokenizer.nextToken();505 processSimpleText.call(this);506 blockChildren.push(this._parseHighlight());507 break;508 case WebInspector.WikiParser.TokenType.DoubleQuotes:509 this._tokenizer.nextToken();510 processSimpleText.call(this);511 blockChildren.push(this._parseItalics());512 break;513 case WebInspector.WikiParser.TokenType.OpeningSquareBrackets:514 processSimpleText.call(this);515 blockChildren.push(this._parseLink());516 break;517 case WebInspector.WikiParser.TokenType.OpeningCodeTag:518 this._tokenizer.nextToken();519 processSimpleText.call(this);520 blockChildren.push(this._parseCode());521 break;522 case WebInspector.WikiParser.TokenType.Bullet:523 this._tokenizer.nextToken();524 processSimpleText.call(this);525 processBlock();526 children.push(this._parseBullet());527 break;528 case WebInspector.WikiParser.TokenType.CodeBlock:529 this._tokenizer.nextToken();530 processSimpleText.call(this);531 processBlock();532 var code = new WebInspector.WikiParser.CodeBlock(this._trimLeadingNewLines(token.value()));533 children.push(code);534 break;535 case WebInspector.WikiParser.TokenType.LineEnd:536 this._tokenizer.nextToken();537 processSimpleText.call(this);538 processBlock();539 break;540 case WebInspector.WikiParser.TokenType.EqualSignInCurlyBrackets:541 this._tokenizer.nextToken();542 text += "=";543 break;544 case WebInspector.WikiParser.TokenType.Exclamation:545 this._tokenizer.nextToken();546 text += "|";547 break;548 case WebInspector.WikiParser.TokenType.OpeningTable:549 this._tokenizer.nextToken();550 processSimpleText.call(this);551 processBlock();552 children.push(this._parseTable());553 break;554 case WebInspector.WikiParser.TokenType.ClosingBrackets:555 case WebInspector.WikiParser.TokenType.Text:556 case WebInspector.WikiParser.TokenType.EqualSign:557 this._tokenizer.nextToken();558 text += token.value();559 break;560 default:561 this._tokenizer.nextToken();562 return null;563 }564 }565 processSimpleText.call(this);566 processBlock();567 return new WebInspector.WikiParser.Block(children);568 },569 /**570 * @return {!WebInspector.WikiParser.ArticleElement}571 */572 _parseLink: function()573 {574 var tokenizer = this._tokenizer.clone();575 this._tokenizer.nextToken();576 this._tokenizer._setMode(WebInspector.WikiParser.Tokenizer.Mode.Link);577 var url = "";578 var children = [];579 /**580 * @return {!WebInspector.WikiParser.ArticleElement}581 * @this {WebInspector.WikiParser}582 */583 function finalizeLink()584 {585 this._tokenizer._setMode(WebInspector.WikiParser.Tokenizer.Mode.Normal);586 return new WebInspector.WikiParser.Link(url, children);587 }588 /**589 * @return {!WebInspector.WikiParser.ArticleElement}590 * @this {WebInspector.WikiParser}591 */592 function recoverAsText()593 {594 this._tokenizer = tokenizer;595 return this._parseTextUntilBrackets();596 }597 while (this._tokenizer.hasMoreTokens()) {598 var token = this._tokenizer.nextToken();599 switch (token.type()) {600 case WebInspector.WikiParser.TokenType.ClosingBrackets:601 if (this._isLink(url))602 return finalizeLink.call(this);603 return recoverAsText.call(this);604 case WebInspector.WikiParser.TokenType.VerticalLine:605 case WebInspector.WikiParser.TokenType.Space:606 case WebInspector.WikiParser.TokenType.Exclamation:607 if (this._isLink(url)) {608 children.push(this._parseLinkName());609 return finalizeLink.call(this);610 }611 return recoverAsText.call(this);612 default:613 url += token.value();614 }615 }616 return finalizeLink.call(this);617 },618 /**619 * @return {!WebInspector.WikiParser.Inline}620 */621 _parseLinkName: function()622 {623 var children = [];624 var text = "";625 /**626 * @this {WebInspector.WikiParser}627 */628 function processSimpleText()629 {630 text = this._deleteTrailingSpaces(text);631 if (!text.length)632 return;633 var simpleText = new WebInspector.WikiParser.PlainText(text);634 children.push(simpleText);635 text = "";636 }637 while (this._tokenizer.hasMoreTokens()) {638 var token = this._tokenizer.nextToken();639 switch (token.type()) {640 case WebInspector.WikiParser.TokenType.ClosingBrackets:641 processSimpleText.call(this);642 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Inline, children);643 case WebInspector.WikiParser.TokenType.OpeningCodeTag:644 processSimpleText.call(this);645 children.push(this._parseCode());646 break;647 default:648 text += token.value();649 break;650 }651 }652 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Inline, children);653 },654 /**655 * @return {!WebInspector.WikiParser.Inline}656 */657 _parseCode: function()658 {659 var children = [];660 var text = "";661 /**662 * @this {WebInspector.WikiParser}663 */664 function processSimpleText()665 {666 text = this._deleteTrailingSpaces(text);667 if (!text.length)668 return;669 var simpleText = new WebInspector.WikiParser.PlainText(text);670 children.push(simpleText);671 text = "";672 }673 while (this._tokenizer.hasMoreTokens()) {674 var token = this._tokenizer.peekToken();675 switch (token.type()) {676 case WebInspector.WikiParser.TokenType.ClosingCodeTag:677 this._tokenizer.nextToken();678 processSimpleText.call(this);679 var code = new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Code, children);680 return code;681 case WebInspector.WikiParser.TokenType.OpeningSquareBrackets:682 processSimpleText.call(this);683 children.push(this._parseLink());684 break;685 default:686 this._tokenizer.nextToken();687 text += token.value();688 }689 }690 text = this._deleteTrailingSpaces(text);691 if (text.length)692 children.push(new WebInspector.WikiParser.PlainText(text));693 return new WebInspector.WikiParser.Inline(WebInspector.WikiParser.ArticleElement.Type.Code, children);694 },695 /**696 * @return {!WebInspector.WikiParser.Block}697 */698 _parseBullet: function()699 {700 var children = [];701 while (this._tokenizer.hasMoreTokens()) {702 var token = this._tokenizer.peekToken()703 switch (token.type()) {704 case WebInspector.WikiParser.TokenType.OpeningSquareBrackets:705 children.push(this._parseLink());706 break;707 case WebInspector.WikiParser.TokenType.OpeningCodeTag:708 this._tokenizer.nextToken();709 children.push(this._parseCode());710 break;711 case WebInspector.WikiParser.TokenType.LineEnd:712 this._tokenizer.nextToken();713 return new WebInspector.WikiParser.Block(children, true);714 default:715 this._tokenizer.nextToken();716 var text = this._deleteTrailingSpaces(token.value());717 if (text.length) {718 var simpleText = new WebInspector.WikiParser.PlainText(text);719 children.push(simpleText);720 text = "";721 }722 }723 }724 return new WebInspector.WikiParser.Block(children, true);725 },726 /**727 * @return {!WebInspector.WikiParser.PlainText}728 */729 _parseHighlight: function()730 {731 var text = "";732 while (this._tokenizer.hasMoreTokens()) {733 var token = this._tokenizer.nextToken();734 if (token.type() === WebInspector.WikiParser.TokenType.TripleQuotes) {735 text = this._deleteTrailingSpaces(text);736 return new WebInspector.WikiParser.PlainText(text, true);737 } else {738 text += token.value();739 }740 }741 return new WebInspector.WikiParser.PlainText(text, true);742 },743 /**744 * @return {!WebInspector.WikiParser.PlainText}745 */746 _parseItalics: function()747 {748 var text = "";749 while (this._tokenizer.hasMoreTokens) {750 var token = this._tokenizer.nextToken();751 if (token.type() === WebInspector.WikiParser.TokenType.DoubleQuotes) {752 text = this._deleteTrailingSpaces(text);753 return new WebInspector.WikiParser.PlainText(text, false, true);754 } else {755 text += token.value();756 }757 }758 return new WebInspector.WikiParser.PlainText(text, false, true);759 },760 /**761 * @return {!WebInspector.WikiParser.PlainText}762 */763 _parseTextUntilBrackets: function()764 {765 var text = this._tokenizer.nextToken().value();766 while (this._tokenizer.hasMoreTokens()) {767 var token = this._tokenizer.peekToken();768 switch (token.type()) {769 case WebInspector.WikiParser.TokenType.VerticalLine:770 this._tokenizer.nextToken();771 return new WebInspector.WikiParser.PlainText(text);772 case WebInspector.WikiParser.TokenType.ClosingCurlyBrackets:773 case WebInspector.WikiParser.TokenType.OpeningSquareBrackets:774 return new WebInspector.WikiParser.PlainText(text);775 default:776 this._tokenizer.nextToken();777 text += token.value();778 }779 }780 return new WebInspector.WikiParser.PlainText(text);781 },782 /**783 * @return {!WebInspector.WikiParser.Table}784 */785 _parseTable: function()786 {787 var columnNames = [];788 var rows = [];789 while (this._tokenizer.hasMoreTokens() && this._tokenizer.peekToken().type() !== WebInspector.WikiParser.TokenType.RowSeparator)790 this._tokenizer.nextToken();791 if (!this._tokenizer.hasMoreTokens())792 throw new Error("Table could not be parsed");793 this._tokenizer.nextToken();794 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.NameSeparator) {795 this._tokenizer.nextToken();796 columnNames.push(this._parseMarkupText());797 }798 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.RowSeparator) {799 this._tokenizer.nextToken();800 var row = [];801 while (this._tokenizer.peekToken().type() === WebInspector.WikiParser.TokenType.CellSeparator) {802 this._tokenizer.nextToken();803 row.push(this._parseMarkupText());804 }805 rows.push(row);806 }807 var token = this._tokenizer.nextToken();808 if (token.type() !== WebInspector.WikiParser.TokenType.ClosingTable)809 throw new Error("Table could not be parsed. {{!}}} expected; found " + token.value());810 for (var i = 0; i < rows.length; ++i) {811 if (rows[i].length !== columnNames.length)812 throw new Error(String.sprintf("Table could not be parsed. Row %d has %d cells; expected %d.", i, rows[i].length, columnNames[i].length));813 }814 return new WebInspector.WikiParser.Table(columnNames, rows);815 },816 /**817 * @param {string} str818 * @return {string}819 */820 _deleteTrailingSpaces: function(str)821 {822 return str.replace(/[\n\r]*$/gm, "");823 },824 /**825 * @param {string} str826 * @return {string}827 */828 _trimLeadingNewLines: function(str)829 {830 return str.replace(/^\n*/, "");831 },832 /**833 * @param {string} str834 * @return {boolean}835 */836 _isInternalLink: function(str)837 {838 var len = str.length;839 return /^[a-zA-Z\/-]+$/.test(str);840 },841 /**842 * @param {string} str843 * @return {boolean}844 */845 _isLink: function(str)846 {847 if (this._isInternalLink(str))848 return true;849 var url = new WebInspector.ParsedURL(str);850 return url.isValid;851 }852}853/**854 * @constructor855 * @param {!WebInspector.WikiParser.ArticleElement.Type} type856 */857WebInspector.WikiParser.ArticleElement = function(type)858{859 this._type = type;860}861WebInspector.WikiParser.ArticleElement.prototype = {862 /**863 * @return {!WebInspector.WikiParser.ArticleElement.Type}864 */865 type: function()866 {867 return this._type;868 }869}870/**871 * @enum {string}872 */873WebInspector.WikiParser.ArticleElement.Type = {874 PlainText: "PlainText",875 Link: "Link",876 Code: "Code",877 Block: "Block",878 CodeBlock: "CodeBlock",879 Inline: "Inline",880 Table: "Table"881};882/**883 * @constructor884 * @extends {WebInspector.WikiParser.ArticleElement}885 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} columnNames886 * @param {!Array.<!Array.<!WebInspector.WikiParser.ArticleElement>>} rows887 */888WebInspector.WikiParser.Table = function(columnNames, rows)889{890 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.Table);891 this._columnNames = columnNames;892 this._rows = rows;893}894WebInspector.WikiParser.Table.prototype = {895 /**896 * @return {!Array.<!WebInspector.WikiParser.ArticleElement>}897 */898 columnNames: function()899 {900 return this._columnNames;901 },902 /**903 * @return {!Array.<!Array.<!WebInspector.WikiParser.ArticleElement>>}904 */905 rows: function()906 {907 return this._rows;908 },909 __proto__: WebInspector.WikiParser.ArticleElement.prototype910}911/**912 * @constructor913 * @extends {WebInspector.WikiParser.ArticleElement}914 * @param {string} text915 * @param {boolean=} highlight916 * @param {boolean=} italic917 */918WebInspector.WikiParser.PlainText = function(text, highlight, italic)919{920 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.PlainText);921 this._text = text.unescapeHTML();922 this._isHighlighted = highlight || false;923 this._isItalic = italic || false;924}925WebInspector.WikiParser.PlainText.prototype = {926 /**927 * @return {string}928 */929 text: function()930 {931 return this._text;932 },933 /**934 * @return {boolean}935 */936 isHighlighted: function()937 {938 return this._isHighlighted;939 },940 __proto__: WebInspector.WikiParser.ArticleElement.prototype941}942/**943 * @constructor944 * @extends {WebInspector.WikiParser.ArticleElement}945 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children946 * @param {boolean=} hasBullet947 */948WebInspector.WikiParser.Block = function(children, hasBullet)949{950 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.Block);951 this._children = children;952 this._hasBullet = hasBullet || false;953}954WebInspector.WikiParser.Block.prototype = {955 /**956 * @return {!Array.<!WebInspector.WikiParser.ArticleElement>}957 */958 children: function()959 {960 return this._children;961 },962 /**963 * @return {boolean}964 */965 hasChildren: function()966 {967 return !!this._children && !!this._children.length;968 },969 /**970 * @return {boolean}971 */972 hasBullet: function()973 {974 return this._hasBullet;975 },976 __proto__: WebInspector.WikiParser.ArticleElement.prototype977}978/**979 * @constructor980 * @extends {WebInspector.WikiParser.ArticleElement}981 * @param {string} text982 */983WebInspector.WikiParser.CodeBlock = function(text)984{985 WebInspector.WikiParser.ArticleElement.call(this, WebInspector.WikiParser.ArticleElement.Type.CodeBlock);986 this._code = text.unescapeHTML();987}988WebInspector.WikiParser.CodeBlock.prototype = {989 /**990 * @return {string}991 */992 code: function()993 {994 return this._code;995 },996 __proto__: WebInspector.WikiParser.ArticleElement.prototype997}998/**999 * @constructor1000 * @extends {WebInspector.WikiParser.ArticleElement}1001 * @param {!WebInspector.WikiParser.ArticleElement.Type} type1002 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children1003 */1004WebInspector.WikiParser.Inline = function(type, children)1005{1006 WebInspector.WikiParser.ArticleElement.call(this, type)1007 this._children = children;1008}1009WebInspector.WikiParser.Inline.prototype = {1010 /**1011 * @return {!Array.<!WebInspector.WikiParser.ArticleElement>}1012 */1013 children: function()1014 {1015 return this._children;1016 },1017 __proto__: WebInspector.WikiParser.ArticleElement.prototype1018}1019/**1020 * @constructor1021 * @extends {WebInspector.WikiParser.Inline}1022 * @param {string} url1023 * @param {!Array.<!WebInspector.WikiParser.ArticleElement>} children1024 */1025WebInspector.WikiParser.Link = function(url, children)1026{1027 WebInspector.WikiParser.Inline.call(this, WebInspector.WikiParser.ArticleElement.Type.Link, children);1028 this._url = url;1029}1030WebInspector.WikiParser.Link.prototype = {1031 /**1032 * @return {string}1033 */1034 url : function()1035 {1036 return this._url;1037 },1038 __proto__: WebInspector.WikiParser.Inline.prototype...

Full Screen

Full Screen

SolidityListener.py

Source:SolidityListener.py Github

copy

Full Screen

1# Generated from solidity-antlr4/Solidity.g4 by ANTLR 4.7.22from antlr4 import *3if __name__ is not None and "." in __name__:4 from .SolidityParser import SolidityParser5else:6 from SolidityParser import SolidityParser7# This class defines a complete listener for a parse tree produced by SolidityParser.8class SolidityListener(ParseTreeListener):9 # Enter a parse tree produced by SolidityParser#sourceUnit.10 def enterSourceUnit(self, ctx:SolidityParser.SourceUnitContext):11 pass12 # Exit a parse tree produced by SolidityParser#sourceUnit.13 def exitSourceUnit(self, ctx:SolidityParser.SourceUnitContext):14 pass15 # Enter a parse tree produced by SolidityParser#pragmaDirective.16 def enterPragmaDirective(self, ctx:SolidityParser.PragmaDirectiveContext):17 pass18 # Exit a parse tree produced by SolidityParser#pragmaDirective.19 def exitPragmaDirective(self, ctx:SolidityParser.PragmaDirectiveContext):20 pass21 # Enter a parse tree produced by SolidityParser#pragmaName.22 def enterPragmaName(self, ctx:SolidityParser.PragmaNameContext):23 pass24 # Exit a parse tree produced by SolidityParser#pragmaName.25 def exitPragmaName(self, ctx:SolidityParser.PragmaNameContext):26 pass27 # Enter a parse tree produced by SolidityParser#pragmaValue.28 def enterPragmaValue(self, ctx:SolidityParser.PragmaValueContext):29 pass30 # Exit a parse tree produced by SolidityParser#pragmaValue.31 def exitPragmaValue(self, ctx:SolidityParser.PragmaValueContext):32 pass33 # Enter a parse tree produced by SolidityParser#version.34 def enterVersion(self, ctx:SolidityParser.VersionContext):35 pass36 # Exit a parse tree produced by SolidityParser#version.37 def exitVersion(self, ctx:SolidityParser.VersionContext):38 pass39 # Enter a parse tree produced by SolidityParser#versionOperator.40 def enterVersionOperator(self, ctx:SolidityParser.VersionOperatorContext):41 pass42 # Exit a parse tree produced by SolidityParser#versionOperator.43 def exitVersionOperator(self, ctx:SolidityParser.VersionOperatorContext):44 pass45 # Enter a parse tree produced by SolidityParser#versionConstraint.46 def enterVersionConstraint(self, ctx:SolidityParser.VersionConstraintContext):47 pass48 # Exit a parse tree produced by SolidityParser#versionConstraint.49 def exitVersionConstraint(self, ctx:SolidityParser.VersionConstraintContext):50 pass51 # Enter a parse tree produced by SolidityParser#importDeclaration.52 def enterImportDeclaration(self, ctx:SolidityParser.ImportDeclarationContext):53 pass54 # Exit a parse tree produced by SolidityParser#importDeclaration.55 def exitImportDeclaration(self, ctx:SolidityParser.ImportDeclarationContext):56 pass57 # Enter a parse tree produced by SolidityParser#importDirective.58 def enterImportDirective(self, ctx:SolidityParser.ImportDirectiveContext):59 pass60 # Exit a parse tree produced by SolidityParser#importDirective.61 def exitImportDirective(self, ctx:SolidityParser.ImportDirectiveContext):62 pass63 # Enter a parse tree produced by SolidityParser#contractDefinition.64 def enterContractDefinition(self, ctx:SolidityParser.ContractDefinitionContext):65 pass66 # Exit a parse tree produced by SolidityParser#contractDefinition.67 def exitContractDefinition(self, ctx:SolidityParser.ContractDefinitionContext):68 pass69 # Enter a parse tree produced by SolidityParser#inheritanceSpecifier.70 def enterInheritanceSpecifier(self, ctx:SolidityParser.InheritanceSpecifierContext):71 pass72 # Exit a parse tree produced by SolidityParser#inheritanceSpecifier.73 def exitInheritanceSpecifier(self, ctx:SolidityParser.InheritanceSpecifierContext):74 pass75 # Enter a parse tree produced by SolidityParser#contractPart.76 def enterContractPart(self, ctx:SolidityParser.ContractPartContext):77 pass78 # Exit a parse tree produced by SolidityParser#contractPart.79 def exitContractPart(self, ctx:SolidityParser.ContractPartContext):80 pass81 # Enter a parse tree produced by SolidityParser#stateVariableDeclaration.82 def enterStateVariableDeclaration(self, ctx:SolidityParser.StateVariableDeclarationContext):83 pass84 # Exit a parse tree produced by SolidityParser#stateVariableDeclaration.85 def exitStateVariableDeclaration(self, ctx:SolidityParser.StateVariableDeclarationContext):86 pass87 # Enter a parse tree produced by SolidityParser#usingForDeclaration.88 def enterUsingForDeclaration(self, ctx:SolidityParser.UsingForDeclarationContext):89 pass90 # Exit a parse tree produced by SolidityParser#usingForDeclaration.91 def exitUsingForDeclaration(self, ctx:SolidityParser.UsingForDeclarationContext):92 pass93 # Enter a parse tree produced by SolidityParser#structDefinition.94 def enterStructDefinition(self, ctx:SolidityParser.StructDefinitionContext):95 pass96 # Exit a parse tree produced by SolidityParser#structDefinition.97 def exitStructDefinition(self, ctx:SolidityParser.StructDefinitionContext):98 pass99 # Enter a parse tree produced by SolidityParser#constructorDefinition.100 def enterConstructorDefinition(self, ctx:SolidityParser.ConstructorDefinitionContext):101 pass102 # Exit a parse tree produced by SolidityParser#constructorDefinition.103 def exitConstructorDefinition(self, ctx:SolidityParser.ConstructorDefinitionContext):104 pass105 # Enter a parse tree produced by SolidityParser#modifierDefinition.106 def enterModifierDefinition(self, ctx:SolidityParser.ModifierDefinitionContext):107 pass108 # Exit a parse tree produced by SolidityParser#modifierDefinition.109 def exitModifierDefinition(self, ctx:SolidityParser.ModifierDefinitionContext):110 pass111 # Enter a parse tree produced by SolidityParser#modifierInvocation.112 def enterModifierInvocation(self, ctx:SolidityParser.ModifierInvocationContext):113 pass114 # Exit a parse tree produced by SolidityParser#modifierInvocation.115 def exitModifierInvocation(self, ctx:SolidityParser.ModifierInvocationContext):116 pass117 # Enter a parse tree produced by SolidityParser#functionDefinition.118 def enterFunctionDefinition(self, ctx:SolidityParser.FunctionDefinitionContext):119 pass120 # Exit a parse tree produced by SolidityParser#functionDefinition.121 def exitFunctionDefinition(self, ctx:SolidityParser.FunctionDefinitionContext):122 pass123 # Enter a parse tree produced by SolidityParser#returnParameters.124 def enterReturnParameters(self, ctx:SolidityParser.ReturnParametersContext):125 pass126 # Exit a parse tree produced by SolidityParser#returnParameters.127 def exitReturnParameters(self, ctx:SolidityParser.ReturnParametersContext):128 pass129 # Enter a parse tree produced by SolidityParser#modifierList.130 def enterModifierList(self, ctx:SolidityParser.ModifierListContext):131 pass132 # Exit a parse tree produced by SolidityParser#modifierList.133 def exitModifierList(self, ctx:SolidityParser.ModifierListContext):134 pass135 # Enter a parse tree produced by SolidityParser#eventDefinition.136 def enterEventDefinition(self, ctx:SolidityParser.EventDefinitionContext):137 pass138 # Exit a parse tree produced by SolidityParser#eventDefinition.139 def exitEventDefinition(self, ctx:SolidityParser.EventDefinitionContext):140 pass141 # Enter a parse tree produced by SolidityParser#enumValue.142 def enterEnumValue(self, ctx:SolidityParser.EnumValueContext):143 pass144 # Exit a parse tree produced by SolidityParser#enumValue.145 def exitEnumValue(self, ctx:SolidityParser.EnumValueContext):146 pass147 # Enter a parse tree produced by SolidityParser#enumDefinition.148 def enterEnumDefinition(self, ctx:SolidityParser.EnumDefinitionContext):149 pass150 # Exit a parse tree produced by SolidityParser#enumDefinition.151 def exitEnumDefinition(self, ctx:SolidityParser.EnumDefinitionContext):152 pass153 # Enter a parse tree produced by SolidityParser#parameterList.154 def enterParameterList(self, ctx:SolidityParser.ParameterListContext):155 pass156 # Exit a parse tree produced by SolidityParser#parameterList.157 def exitParameterList(self, ctx:SolidityParser.ParameterListContext):158 pass159 # Enter a parse tree produced by SolidityParser#parameter.160 def enterParameter(self, ctx:SolidityParser.ParameterContext):161 pass162 # Exit a parse tree produced by SolidityParser#parameter.163 def exitParameter(self, ctx:SolidityParser.ParameterContext):164 pass165 # Enter a parse tree produced by SolidityParser#eventParameterList.166 def enterEventParameterList(self, ctx:SolidityParser.EventParameterListContext):167 pass168 # Exit a parse tree produced by SolidityParser#eventParameterList.169 def exitEventParameterList(self, ctx:SolidityParser.EventParameterListContext):170 pass171 # Enter a parse tree produced by SolidityParser#eventParameter.172 def enterEventParameter(self, ctx:SolidityParser.EventParameterContext):173 pass174 # Exit a parse tree produced by SolidityParser#eventParameter.175 def exitEventParameter(self, ctx:SolidityParser.EventParameterContext):176 pass177 # Enter a parse tree produced by SolidityParser#functionTypeParameterList.178 def enterFunctionTypeParameterList(self, ctx:SolidityParser.FunctionTypeParameterListContext):179 pass180 # Exit a parse tree produced by SolidityParser#functionTypeParameterList.181 def exitFunctionTypeParameterList(self, ctx:SolidityParser.FunctionTypeParameterListContext):182 pass183 # Enter a parse tree produced by SolidityParser#functionTypeParameter.184 def enterFunctionTypeParameter(self, ctx:SolidityParser.FunctionTypeParameterContext):185 pass186 # Exit a parse tree produced by SolidityParser#functionTypeParameter.187 def exitFunctionTypeParameter(self, ctx:SolidityParser.FunctionTypeParameterContext):188 pass189 # Enter a parse tree produced by SolidityParser#variableDeclaration.190 def enterVariableDeclaration(self, ctx:SolidityParser.VariableDeclarationContext):191 pass192 # Exit a parse tree produced by SolidityParser#variableDeclaration.193 def exitVariableDeclaration(self, ctx:SolidityParser.VariableDeclarationContext):194 pass195 # Enter a parse tree produced by SolidityParser#typeName.196 def enterTypeName(self, ctx:SolidityParser.TypeNameContext):197 pass198 # Exit a parse tree produced by SolidityParser#typeName.199 def exitTypeName(self, ctx:SolidityParser.TypeNameContext):200 pass201 # Enter a parse tree produced by SolidityParser#userDefinedTypeName.202 def enterUserDefinedTypeName(self, ctx:SolidityParser.UserDefinedTypeNameContext):203 pass204 # Exit a parse tree produced by SolidityParser#userDefinedTypeName.205 def exitUserDefinedTypeName(self, ctx:SolidityParser.UserDefinedTypeNameContext):206 pass207 # Enter a parse tree produced by SolidityParser#mapping.208 def enterMapping(self, ctx:SolidityParser.MappingContext):209 pass210 # Exit a parse tree produced by SolidityParser#mapping.211 def exitMapping(self, ctx:SolidityParser.MappingContext):212 pass213 # Enter a parse tree produced by SolidityParser#functionTypeName.214 def enterFunctionTypeName(self, ctx:SolidityParser.FunctionTypeNameContext):215 pass216 # Exit a parse tree produced by SolidityParser#functionTypeName.217 def exitFunctionTypeName(self, ctx:SolidityParser.FunctionTypeNameContext):218 pass219 # Enter a parse tree produced by SolidityParser#storageLocation.220 def enterStorageLocation(self, ctx:SolidityParser.StorageLocationContext):221 pass222 # Exit a parse tree produced by SolidityParser#storageLocation.223 def exitStorageLocation(self, ctx:SolidityParser.StorageLocationContext):224 pass225 # Enter a parse tree produced by SolidityParser#stateMutability.226 def enterStateMutability(self, ctx:SolidityParser.StateMutabilityContext):227 pass228 # Exit a parse tree produced by SolidityParser#stateMutability.229 def exitStateMutability(self, ctx:SolidityParser.StateMutabilityContext):230 pass231 # Enter a parse tree produced by SolidityParser#block.232 def enterBlock(self, ctx:SolidityParser.BlockContext):233 pass234 # Exit a parse tree produced by SolidityParser#block.235 def exitBlock(self, ctx:SolidityParser.BlockContext):236 pass237 # Enter a parse tree produced by SolidityParser#statement.238 def enterStatement(self, ctx:SolidityParser.StatementContext):239 pass240 # Exit a parse tree produced by SolidityParser#statement.241 def exitStatement(self, ctx:SolidityParser.StatementContext):242 pass243 # Enter a parse tree produced by SolidityParser#expressionStatement.244 def enterExpressionStatement(self, ctx:SolidityParser.ExpressionStatementContext):245 pass246 # Exit a parse tree produced by SolidityParser#expressionStatement.247 def exitExpressionStatement(self, ctx:SolidityParser.ExpressionStatementContext):248 pass249 # Enter a parse tree produced by SolidityParser#ifStatement.250 def enterIfStatement(self, ctx:SolidityParser.IfStatementContext):251 pass252 # Exit a parse tree produced by SolidityParser#ifStatement.253 def exitIfStatement(self, ctx:SolidityParser.IfStatementContext):254 pass255 # Enter a parse tree produced by SolidityParser#whileStatement.256 def enterWhileStatement(self, ctx:SolidityParser.WhileStatementContext):257 pass258 # Exit a parse tree produced by SolidityParser#whileStatement.259 def exitWhileStatement(self, ctx:SolidityParser.WhileStatementContext):260 pass261 # Enter a parse tree produced by SolidityParser#simpleStatement.262 def enterSimpleStatement(self, ctx:SolidityParser.SimpleStatementContext):263 pass264 # Exit a parse tree produced by SolidityParser#simpleStatement.265 def exitSimpleStatement(self, ctx:SolidityParser.SimpleStatementContext):266 pass267 # Enter a parse tree produced by SolidityParser#forStatement.268 def enterForStatement(self, ctx:SolidityParser.ForStatementContext):269 pass270 # Exit a parse tree produced by SolidityParser#forStatement.271 def exitForStatement(self, ctx:SolidityParser.ForStatementContext):272 pass273 # Enter a parse tree produced by SolidityParser#inlineAssemblyStatement.274 def enterInlineAssemblyStatement(self, ctx:SolidityParser.InlineAssemblyStatementContext):275 pass276 # Exit a parse tree produced by SolidityParser#inlineAssemblyStatement.277 def exitInlineAssemblyStatement(self, ctx:SolidityParser.InlineAssemblyStatementContext):278 pass279 # Enter a parse tree produced by SolidityParser#doWhileStatement.280 def enterDoWhileStatement(self, ctx:SolidityParser.DoWhileStatementContext):281 pass282 # Exit a parse tree produced by SolidityParser#doWhileStatement.283 def exitDoWhileStatement(self, ctx:SolidityParser.DoWhileStatementContext):284 pass285 # Enter a parse tree produced by SolidityParser#continueStatement.286 def enterContinueStatement(self, ctx:SolidityParser.ContinueStatementContext):287 pass288 # Exit a parse tree produced by SolidityParser#continueStatement.289 def exitContinueStatement(self, ctx:SolidityParser.ContinueStatementContext):290 pass291 # Enter a parse tree produced by SolidityParser#breakStatement.292 def enterBreakStatement(self, ctx:SolidityParser.BreakStatementContext):293 pass294 # Exit a parse tree produced by SolidityParser#breakStatement.295 def exitBreakStatement(self, ctx:SolidityParser.BreakStatementContext):296 pass297 # Enter a parse tree produced by SolidityParser#returnStatement.298 def enterReturnStatement(self, ctx:SolidityParser.ReturnStatementContext):299 pass300 # Exit a parse tree produced by SolidityParser#returnStatement.301 def exitReturnStatement(self, ctx:SolidityParser.ReturnStatementContext):302 pass303 # Enter a parse tree produced by SolidityParser#throwStatement.304 def enterThrowStatement(self, ctx:SolidityParser.ThrowStatementContext):305 pass306 # Exit a parse tree produced by SolidityParser#throwStatement.307 def exitThrowStatement(self, ctx:SolidityParser.ThrowStatementContext):308 pass309 # Enter a parse tree produced by SolidityParser#emitStatement.310 def enterEmitStatement(self, ctx:SolidityParser.EmitStatementContext):311 pass312 # Exit a parse tree produced by SolidityParser#emitStatement.313 def exitEmitStatement(self, ctx:SolidityParser.EmitStatementContext):314 pass315 # Enter a parse tree produced by SolidityParser#variableDeclarationStatement.316 def enterVariableDeclarationStatement(self, ctx:SolidityParser.VariableDeclarationStatementContext):317 pass318 # Exit a parse tree produced by SolidityParser#variableDeclarationStatement.319 def exitVariableDeclarationStatement(self, ctx:SolidityParser.VariableDeclarationStatementContext):320 pass321 # Enter a parse tree produced by SolidityParser#variableDeclarationList.322 def enterVariableDeclarationList(self, ctx:SolidityParser.VariableDeclarationListContext):323 pass324 # Exit a parse tree produced by SolidityParser#variableDeclarationList.325 def exitVariableDeclarationList(self, ctx:SolidityParser.VariableDeclarationListContext):326 pass327 # Enter a parse tree produced by SolidityParser#identifierList.328 def enterIdentifierList(self, ctx:SolidityParser.IdentifierListContext):329 pass330 # Exit a parse tree produced by SolidityParser#identifierList.331 def exitIdentifierList(self, ctx:SolidityParser.IdentifierListContext):332 pass333 # Enter a parse tree produced by SolidityParser#elementaryTypeName.334 def enterElementaryTypeName(self, ctx:SolidityParser.ElementaryTypeNameContext):335 pass336 # Exit a parse tree produced by SolidityParser#elementaryTypeName.337 def exitElementaryTypeName(self, ctx:SolidityParser.ElementaryTypeNameContext):338 pass339 # Enter a parse tree produced by SolidityParser#expression.340 def enterExpression(self, ctx:SolidityParser.ExpressionContext):341 pass342 # Exit a parse tree produced by SolidityParser#expression.343 def exitExpression(self, ctx:SolidityParser.ExpressionContext):344 pass345 # Enter a parse tree produced by SolidityParser#primaryExpression.346 def enterPrimaryExpression(self, ctx:SolidityParser.PrimaryExpressionContext):347 pass348 # Exit a parse tree produced by SolidityParser#primaryExpression.349 def exitPrimaryExpression(self, ctx:SolidityParser.PrimaryExpressionContext):350 pass351 # Enter a parse tree produced by SolidityParser#expressionList.352 def enterExpressionList(self, ctx:SolidityParser.ExpressionListContext):353 pass354 # Exit a parse tree produced by SolidityParser#expressionList.355 def exitExpressionList(self, ctx:SolidityParser.ExpressionListContext):356 pass357 # Enter a parse tree produced by SolidityParser#nameValueList.358 def enterNameValueList(self, ctx:SolidityParser.NameValueListContext):359 pass360 # Exit a parse tree produced by SolidityParser#nameValueList.361 def exitNameValueList(self, ctx:SolidityParser.NameValueListContext):362 pass363 # Enter a parse tree produced by SolidityParser#nameValue.364 def enterNameValue(self, ctx:SolidityParser.NameValueContext):365 pass366 # Exit a parse tree produced by SolidityParser#nameValue.367 def exitNameValue(self, ctx:SolidityParser.NameValueContext):368 pass369 # Enter a parse tree produced by SolidityParser#functionCallArguments.370 def enterFunctionCallArguments(self, ctx:SolidityParser.FunctionCallArgumentsContext):371 pass372 # Exit a parse tree produced by SolidityParser#functionCallArguments.373 def exitFunctionCallArguments(self, ctx:SolidityParser.FunctionCallArgumentsContext):374 pass375 # Enter a parse tree produced by SolidityParser#functionCall.376 def enterFunctionCall(self, ctx:SolidityParser.FunctionCallContext):377 pass378 # Exit a parse tree produced by SolidityParser#functionCall.379 def exitFunctionCall(self, ctx:SolidityParser.FunctionCallContext):380 pass381 # Enter a parse tree produced by SolidityParser#assemblyBlock.382 def enterAssemblyBlock(self, ctx:SolidityParser.AssemblyBlockContext):383 pass384 # Exit a parse tree produced by SolidityParser#assemblyBlock.385 def exitAssemblyBlock(self, ctx:SolidityParser.AssemblyBlockContext):386 pass387 # Enter a parse tree produced by SolidityParser#assemblyItem.388 def enterAssemblyItem(self, ctx:SolidityParser.AssemblyItemContext):389 pass390 # Exit a parse tree produced by SolidityParser#assemblyItem.391 def exitAssemblyItem(self, ctx:SolidityParser.AssemblyItemContext):392 pass393 # Enter a parse tree produced by SolidityParser#assemblyExpression.394 def enterAssemblyExpression(self, ctx:SolidityParser.AssemblyExpressionContext):395 pass396 # Exit a parse tree produced by SolidityParser#assemblyExpression.397 def exitAssemblyExpression(self, ctx:SolidityParser.AssemblyExpressionContext):398 pass399 # Enter a parse tree produced by SolidityParser#assemblyCall.400 def enterAssemblyCall(self, ctx:SolidityParser.AssemblyCallContext):401 pass402 # Exit a parse tree produced by SolidityParser#assemblyCall.403 def exitAssemblyCall(self, ctx:SolidityParser.AssemblyCallContext):404 pass405 # Enter a parse tree produced by SolidityParser#assemblyLocalDefinition.406 def enterAssemblyLocalDefinition(self, ctx:SolidityParser.AssemblyLocalDefinitionContext):407 pass408 # Exit a parse tree produced by SolidityParser#assemblyLocalDefinition.409 def exitAssemblyLocalDefinition(self, ctx:SolidityParser.AssemblyLocalDefinitionContext):410 pass411 # Enter a parse tree produced by SolidityParser#assemblyAssignment.412 def enterAssemblyAssignment(self, ctx:SolidityParser.AssemblyAssignmentContext):413 pass414 # Exit a parse tree produced by SolidityParser#assemblyAssignment.415 def exitAssemblyAssignment(self, ctx:SolidityParser.AssemblyAssignmentContext):416 pass417 # Enter a parse tree produced by SolidityParser#assemblyIdentifierOrList.418 def enterAssemblyIdentifierOrList(self, ctx:SolidityParser.AssemblyIdentifierOrListContext):419 pass420 # Exit a parse tree produced by SolidityParser#assemblyIdentifierOrList.421 def exitAssemblyIdentifierOrList(self, ctx:SolidityParser.AssemblyIdentifierOrListContext):422 pass423 # Enter a parse tree produced by SolidityParser#assemblyIdentifierList.424 def enterAssemblyIdentifierList(self, ctx:SolidityParser.AssemblyIdentifierListContext):425 pass426 # Exit a parse tree produced by SolidityParser#assemblyIdentifierList.427 def exitAssemblyIdentifierList(self, ctx:SolidityParser.AssemblyIdentifierListContext):428 pass429 # Enter a parse tree produced by SolidityParser#assemblyStackAssignment.430 def enterAssemblyStackAssignment(self, ctx:SolidityParser.AssemblyStackAssignmentContext):431 pass432 # Exit a parse tree produced by SolidityParser#assemblyStackAssignment.433 def exitAssemblyStackAssignment(self, ctx:SolidityParser.AssemblyStackAssignmentContext):434 pass435 # Enter a parse tree produced by SolidityParser#labelDefinition.436 def enterLabelDefinition(self, ctx:SolidityParser.LabelDefinitionContext):437 pass438 # Exit a parse tree produced by SolidityParser#labelDefinition.439 def exitLabelDefinition(self, ctx:SolidityParser.LabelDefinitionContext):440 pass441 # Enter a parse tree produced by SolidityParser#assemblySwitch.442 def enterAssemblySwitch(self, ctx:SolidityParser.AssemblySwitchContext):443 pass444 # Exit a parse tree produced by SolidityParser#assemblySwitch.445 def exitAssemblySwitch(self, ctx:SolidityParser.AssemblySwitchContext):446 pass447 # Enter a parse tree produced by SolidityParser#assemblyCase.448 def enterAssemblyCase(self, ctx:SolidityParser.AssemblyCaseContext):449 pass450 # Exit a parse tree produced by SolidityParser#assemblyCase.451 def exitAssemblyCase(self, ctx:SolidityParser.AssemblyCaseContext):452 pass453 # Enter a parse tree produced by SolidityParser#assemblyFunctionDefinition.454 def enterAssemblyFunctionDefinition(self, ctx:SolidityParser.AssemblyFunctionDefinitionContext):455 pass456 # Exit a parse tree produced by SolidityParser#assemblyFunctionDefinition.457 def exitAssemblyFunctionDefinition(self, ctx:SolidityParser.AssemblyFunctionDefinitionContext):458 pass459 # Enter a parse tree produced by SolidityParser#assemblyFunctionReturns.460 def enterAssemblyFunctionReturns(self, ctx:SolidityParser.AssemblyFunctionReturnsContext):461 pass462 # Exit a parse tree produced by SolidityParser#assemblyFunctionReturns.463 def exitAssemblyFunctionReturns(self, ctx:SolidityParser.AssemblyFunctionReturnsContext):464 pass465 # Enter a parse tree produced by SolidityParser#assemblyFor.466 def enterAssemblyFor(self, ctx:SolidityParser.AssemblyForContext):467 pass468 # Exit a parse tree produced by SolidityParser#assemblyFor.469 def exitAssemblyFor(self, ctx:SolidityParser.AssemblyForContext):470 pass471 # Enter a parse tree produced by SolidityParser#assemblyIf.472 def enterAssemblyIf(self, ctx:SolidityParser.AssemblyIfContext):473 pass474 # Exit a parse tree produced by SolidityParser#assemblyIf.475 def exitAssemblyIf(self, ctx:SolidityParser.AssemblyIfContext):476 pass477 # Enter a parse tree produced by SolidityParser#assemblyLiteral.478 def enterAssemblyLiteral(self, ctx:SolidityParser.AssemblyLiteralContext):479 pass480 # Exit a parse tree produced by SolidityParser#assemblyLiteral.481 def exitAssemblyLiteral(self, ctx:SolidityParser.AssemblyLiteralContext):482 pass483 # Enter a parse tree produced by SolidityParser#subAssembly.484 def enterSubAssembly(self, ctx:SolidityParser.SubAssemblyContext):485 pass486 # Exit a parse tree produced by SolidityParser#subAssembly.487 def exitSubAssembly(self, ctx:SolidityParser.SubAssemblyContext):488 pass489 # Enter a parse tree produced by SolidityParser#tupleExpression.490 def enterTupleExpression(self, ctx:SolidityParser.TupleExpressionContext):491 pass492 # Exit a parse tree produced by SolidityParser#tupleExpression.493 def exitTupleExpression(self, ctx:SolidityParser.TupleExpressionContext):494 pass495 # Enter a parse tree produced by SolidityParser#elementaryTypeNameExpression.496 def enterElementaryTypeNameExpression(self, ctx:SolidityParser.ElementaryTypeNameExpressionContext):497 pass498 # Exit a parse tree produced by SolidityParser#elementaryTypeNameExpression.499 def exitElementaryTypeNameExpression(self, ctx:SolidityParser.ElementaryTypeNameExpressionContext):500 pass501 # Enter a parse tree produced by SolidityParser#numberLiteral.502 def enterNumberLiteral(self, ctx:SolidityParser.NumberLiteralContext):503 pass504 # Exit a parse tree produced by SolidityParser#numberLiteral.505 def exitNumberLiteral(self, ctx:SolidityParser.NumberLiteralContext):506 pass507 # Enter a parse tree produced by SolidityParser#identifier.508 def enterIdentifier(self, ctx:SolidityParser.IdentifierContext):509 pass510 # Exit a parse tree produced by SolidityParser#identifier.511 def exitIdentifier(self, ctx:SolidityParser.IdentifierContext):...

Full Screen

Full Screen

test_dictionary.py

Source:test_dictionary.py Github

copy

Full Screen

1def WebIDLTest(parser, harness):2 parser.parse("""3 dictionary Dict2 : Dict1 {4 long child = 5;5 Dict1 aaandAnother;6 };7 dictionary Dict1 {8 long parent;9 double otherParent;10 };11 """)12 results = parser.finish()13 dict1 = results[1];14 dict2 = results[0];15 harness.check(len(dict1.members), 2, "Dict1 has two members")16 harness.check(len(dict2.members), 2, "Dict2 has four members")17 harness.check(dict1.members[0].identifier.name, "otherParent",18 "'o' comes before 'p'")19 harness.check(dict1.members[1].identifier.name, "parent",20 "'o' really comes before 'p'")21 harness.check(dict2.members[0].identifier.name, "aaandAnother",22 "'a' comes before 'c'")23 harness.check(dict2.members[1].identifier.name, "child",24 "'a' really comes before 'c'")25 # Now reset our parser26 parser = parser.reset()27 threw = False28 try:29 parser.parse("""30 dictionary Dict {31 long prop = 5;32 long prop;33 };34 """)35 results = parser.finish()36 except:37 threw = True38 harness.ok(threw, "Should not allow name duplication in a dictionary")39 # Now reset our parser again40 parser = parser.reset()41 threw = False42 try:43 parser.parse("""44 dictionary Dict1 : Dict2 {45 long prop = 5;46 };47 dictionary Dict2 : Dict3 {48 long prop2;49 };50 dictionary Dict3 {51 double prop;52 };53 """)54 results = parser.finish()55 except:56 threw = True57 harness.ok(threw, "Should not allow name duplication in a dictionary and "58 "its ancestor")59 # More reset60 parser = parser.reset()61 threw = False62 try:63 parser.parse("""64 interface Iface {};65 dictionary Dict : Iface {66 long prop;67 };68 """)69 results = parser.finish()70 except:71 threw = True72 harness.ok(threw, "Should not allow non-dictionary parents for dictionaries")73 # Even more reset74 parser = parser.reset()75 threw = False76 try:77 parser.parse("""78 dictionary A : B {};79 dictionary B : A {};80 """)81 results = parser.finish()82 except:83 threw = True84 harness.ok(threw, "Should not allow cycles in dictionary inheritance chains")85 parser = parser.reset()86 threw = False87 try:88 parser.parse("""89 dictionary A {90 [TreatNullAs=EmptyString] DOMString foo;91 };92 """)93 results = parser.finish()94 except:95 threw = True96 harness.ok(threw, "Should not allow [TreatNullAs] on dictionary members");97 parser = parser.reset()98 threw = False99 try:100 parser.parse("""101 dictionary A {102 };103 interface X {104 void doFoo(A arg);105 };106 """)107 results = parser.finish()108 except:109 threw = True110 harness.ok(threw, "Trailing dictionary arg must be optional")111 parser = parser.reset()112 threw = False113 try:114 parser.parse("""115 dictionary A {116 };117 interface X {118 void doFoo((A or DOMString) arg);119 };120 """)121 results = parser.finish()122 except:123 threw = True124 harness.ok(threw,125 "Trailing union arg containing a dictionary must be optional")126 parser = parser.reset()127 threw = False128 try:129 parser.parse("""130 dictionary A {131 };132 interface X {133 void doFoo(A arg1, optional long arg2);134 };135 """)136 results = parser.finish()137 except:138 threw = True139 harness.ok(threw, "Dictionary arg followed by optional arg must be optional")140 parser = parser.reset()141 threw = False142 try:143 parser.parse("""144 dictionary A {145 };146 interface X {147 void doFoo(A arg1, optional long arg2, long arg3);148 };149 """)150 results = parser.finish()151 except:152 threw = True153 harness.ok(not threw,154 "Dictionary arg followed by non-optional arg doesn't have to be optional")155 parser = parser.reset()156 threw = False157 try:158 parser.parse("""159 dictionary A {160 };161 interface X {162 void doFoo((A or DOMString) arg1, optional long arg2);163 };164 """)165 results = parser.finish()166 except:167 threw = True168 harness.ok(threw,169 "Union arg containing dictionary followed by optional arg must "170 "be optional")171 parser = parser.reset()172 parser.parse("""173 dictionary A {174 };175 interface X {176 void doFoo(A arg1, long arg2);177 };178 """)179 results = parser.finish()180 harness.ok(True, "Dictionary arg followed by required arg can be required")181 parser = parser.reset()182 threw = False183 try:184 parser.parse("""185 dictionary A {186 };187 interface X {188 void doFoo(optional A? arg1);189 };190 """)191 results = parser.finish()192 except:193 threw = True194 harness.ok(threw, "Dictionary arg must not be nullable")195 parser = parser.reset()196 threw = False197 try:198 parser.parse("""199 dictionary A {200 };201 interface X {202 void doFoo(optional (A or long)? arg1);203 };204 """)205 results = parser.finish()206 except:207 threw = True208 harness.ok(threw, "Dictionary arg must not be in a nullable union")209 parser = parser.reset()210 threw = False211 try:212 parser.parse("""213 dictionary A {214 };215 interface X {216 void doFoo(optional (A or long?) arg1);217 };218 """)219 results = parser.finish()220 except:221 threw = True222 harness.ok(threw,223 "Dictionary must not be in a union with a nullable type")224 parser = parser.reset()225 threw = False226 try:227 parser.parse("""228 dictionary A {229 };230 interface X {231 void doFoo(optional (long? or A) arg1);232 };233 """)234 results = parser.finish()235 except:236 threw = True237 harness.ok(threw,238 "A nullable type must not be in a union with a dictionary")239 parser = parser.reset()240 parser.parse("""241 dictionary A {242 };243 interface X {244 A? doFoo();245 };246 """)247 results = parser.finish()248 harness.ok(True, "Dictionary return value can be nullable")249 parser = parser.reset()250 parser.parse("""251 dictionary A {252 };253 interface X {254 void doFoo(optional A arg);255 };256 """)257 results = parser.finish()258 harness.ok(True, "Dictionary arg should actually parse")259 parser = parser.reset()260 parser.parse("""261 dictionary A {262 };263 interface X {264 void doFoo(optional (A or DOMString) arg);265 };266 """)267 results = parser.finish()268 harness.ok(True, "Union arg containing a dictionary should actually parse")269 parser = parser.reset()270 threw = False271 try:272 parser.parse("""273 dictionary Foo {274 Foo foo;275 };276 """)277 results = parser.finish()278 except:279 threw = True280 harness.ok(threw, "Member type must not be its Dictionary.")281 parser = parser.reset()282 threw = False283 try:284 parser.parse("""285 dictionary Foo3 : Foo {286 short d;287 };288 dictionary Foo2 : Foo3 {289 boolean c;290 };291 dictionary Foo1 : Foo2 {292 long a;293 };294 dictionary Foo {295 Foo1 b;296 };297 """)298 results = parser.finish()299 except:300 threw = True301 harness.ok(threw, "Member type must not be a Dictionary that "302 "inherits from its Dictionary.")303 parser = parser.reset()304 threw = False305 try:306 parser.parse("""307 dictionary Foo {308 (Foo or DOMString)[]? b;309 };310 """)311 results = parser.finish()312 except:313 threw = True314 harness.ok(threw, "Member type must not be a Nullable type "315 "whose inner type includes its Dictionary.")316 parser = parser.reset()317 threw = False318 try:319 parser.parse("""320 dictionary Foo {321 (DOMString or Foo) b;322 };323 """)324 results = parser.finish()325 except:326 threw = True327 harness.ok(threw, "Member type must not be a Union type, one of "328 "whose member types includes its Dictionary.")329 parser = parser.reset()330 threw = False331 try:332 parser.parse("""333 dictionary Foo {334 sequence<sequence<sequence<Foo>>> c;335 };336 """)337 results = parser.finish()338 except:339 threw = True340 harness.ok(threw, "Member type must not be a Sequence type "341 "whose element type includes its Dictionary.")342 parser = parser.reset()343 threw = False344 try:345 parser.parse("""346 dictionary Foo {347 (DOMString or Foo)[] d;348 };349 """)350 results = parser.finish()351 except:352 threw = True353 harness.ok(threw, "Member type must not be an Array type "354 "whose element type includes its Dictionary.")355 parser = parser.reset()356 threw = False357 try:358 parser.parse("""359 dictionary Foo {360 Foo1 b;361 };362 dictionary Foo3 {363 Foo d;364 };365 dictionary Foo2 : Foo3 {366 short c;367 };368 dictionary Foo1 : Foo2 {369 long a;370 };371 """)372 results = parser.finish()373 except:374 threw = True375 harness.ok(threw, "Member type must not be a Dictionary, one of whose "376 "members or inherited members has a type that includes "377 "its Dictionary.")378 parser = parser.reset();379 threw = False380 try:381 parser.parse("""382 dictionary Foo {383 };384 dictionary Bar {385 Foo? d;386 };387 """)388 results = parser.finish()389 except:390 threw = True391 harness.ok(threw, "Member type must not be a nullable dictionary")392 parser = parser.reset();393 parser.parse("""394 dictionary Foo {395 unrestricted float urFloat = 0;396 unrestricted float urFloat2 = 1.1;397 unrestricted float urFloat3 = -1.1;398 unrestricted float? urFloat4 = null;399 unrestricted float infUrFloat = Infinity;400 unrestricted float negativeInfUrFloat = -Infinity;401 unrestricted float nanUrFloat = NaN;402 unrestricted double urDouble = 0;403 unrestricted double urDouble2 = 1.1;404 unrestricted double urDouble3 = -1.1;405 unrestricted double? urDouble4 = null;406 unrestricted double infUrDouble = Infinity;407 unrestricted double negativeInfUrDouble = -Infinity;408 unrestricted double nanUrDouble = NaN;409 };410 """)411 results = parser.finish()412 harness.ok(True, "Parsing default values for unrestricted types succeeded.")413 parser = parser.reset();414 threw = False415 try:416 parser.parse("""417 dictionary Foo {418 double f = Infinity;419 };420 """)421 results = parser.finish()422 except:423 threw = True424 harness.ok(threw, "Only unrestricted values can be initialized to Infinity")425 parser = parser.reset();426 threw = False427 try:428 parser.parse("""429 dictionary Foo {430 double f = -Infinity;431 };432 """)433 results = parser.finish()434 except:435 threw = True436 harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")437 parser = parser.reset();438 threw = False439 try:440 parser.parse("""441 dictionary Foo {442 double f = NaN;443 };444 """)445 results = parser.finish()446 except:447 threw = True448 harness.ok(threw, "Only unrestricted values can be initialized to NaN")449 parser = parser.reset();450 threw = False451 try:452 parser.parse("""453 dictionary Foo {454 float f = Infinity;455 };456 """)457 results = parser.finish()458 except:459 threw = True460 harness.ok(threw, "Only unrestricted values can be initialized to Infinity")461 parser = parser.reset();462 threw = False463 try:464 parser.parse("""465 dictionary Foo {466 float f = -Infinity;467 };468 """)469 results = parser.finish()470 except:471 threw = True472 harness.ok(threw, "Only unrestricted values can be initialized to -Infinity")473 parser = parser.reset();474 threw = False475 try:476 parser.parse("""477 dictionary Foo {478 float f = NaN;479 };480 """)481 results = parser.finish()482 except:483 threw = True...

Full Screen

Full Screen

dslListener.py

Source:dslListener.py Github

copy

Full Screen

1# Generated from dsl.g4 by ANTLR 4.82from antlr4 import *3if __name__ is not None and "." in __name__:4 from .dslParser import dslParser5else:6 from dslParser import dslParser7# This class defines a complete listener for a parse tree produced by dslParser.8class dslListener(ParseTreeListener):9 # Enter a parse tree produced by dslParser#twitbot.10 def enterTwitbot(self, ctx:dslParser.TwitbotContext):11 pass12 # Exit a parse tree produced by dslParser#twitbot.13 def exitTwitbot(self, ctx:dslParser.TwitbotContext):14 pass15 # Enter a parse tree produced by dslParser#stat.16 def enterStat(self, ctx:dslParser.StatContext):17 pass18 # Exit a parse tree produced by dslParser#stat.19 def exitStat(self, ctx:dslParser.StatContext):20 pass21 # Enter a parse tree produced by dslParser#action.22 def enterAction(self, ctx:dslParser.ActionContext):23 pass24 # Exit a parse tree produced by dslParser#action.25 def exitAction(self, ctx:dslParser.ActionContext):26 pass27 # Enter a parse tree produced by dslParser#tweet.28 def enterTweet(self, ctx:dslParser.TweetContext):29 pass30 # Exit a parse tree produced by dslParser#tweet.31 def exitTweet(self, ctx:dslParser.TweetContext):32 pass33 # Enter a parse tree produced by dslParser#tweet_required_parameter.34 def enterTweet_required_parameter(self, ctx:dslParser.Tweet_required_parameterContext):35 pass36 # Exit a parse tree produced by dslParser#tweet_required_parameter.37 def exitTweet_required_parameter(self, ctx:dslParser.Tweet_required_parameterContext):38 pass39 # Enter a parse tree produced by dslParser#tweet_optional_parameters.40 def enterTweet_optional_parameters(self, ctx:dslParser.Tweet_optional_parametersContext):41 pass42 # Exit a parse tree produced by dslParser#tweet_optional_parameters.43 def exitTweet_optional_parameters(self, ctx:dslParser.Tweet_optional_parametersContext):44 pass45 # Enter a parse tree produced by dslParser#tweetImage.46 def enterTweetImage(self, ctx:dslParser.TweetImageContext):47 pass48 # Exit a parse tree produced by dslParser#tweetImage.49 def exitTweetImage(self, ctx:dslParser.TweetImageContext):50 pass51 # Enter a parse tree produced by dslParser#tweet_image_required_parameter.52 def enterTweet_image_required_parameter(self, ctx:dslParser.Tweet_image_required_parameterContext):53 pass54 # Exit a parse tree produced by dslParser#tweet_image_required_parameter.55 def exitTweet_image_required_parameter(self, ctx:dslParser.Tweet_image_required_parameterContext):56 pass57 # Enter a parse tree produced by dslParser#reply.58 def enterReply(self, ctx:dslParser.ReplyContext):59 pass60 # Exit a parse tree produced by dslParser#reply.61 def exitReply(self, ctx:dslParser.ReplyContext):62 pass63 # Enter a parse tree produced by dslParser#reply_required_parameters.64 def enterReply_required_parameters(self, ctx:dslParser.Reply_required_parametersContext):65 pass66 # Exit a parse tree produced by dslParser#reply_required_parameters.67 def exitReply_required_parameters(self, ctx:dslParser.Reply_required_parametersContext):68 pass69 # Enter a parse tree produced by dslParser#retweet.70 def enterRetweet(self, ctx:dslParser.RetweetContext):71 pass72 # Exit a parse tree produced by dslParser#retweet.73 def exitRetweet(self, ctx:dslParser.RetweetContext):74 pass75 # Enter a parse tree produced by dslParser#retweet_required_parameter.76 def enterRetweet_required_parameter(self, ctx:dslParser.Retweet_required_parameterContext):77 pass78 # Exit a parse tree produced by dslParser#retweet_required_parameter.79 def exitRetweet_required_parameter(self, ctx:dslParser.Retweet_required_parameterContext):80 pass81 # Enter a parse tree produced by dslParser#favourite.82 def enterFavourite(self, ctx:dslParser.FavouriteContext):83 pass84 # Exit a parse tree produced by dslParser#favourite.85 def exitFavourite(self, ctx:dslParser.FavouriteContext):86 pass87 # Enter a parse tree produced by dslParser#favourite_required_parameter.88 def enterFavourite_required_parameter(self, ctx:dslParser.Favourite_required_parameterContext):89 pass90 # Exit a parse tree produced by dslParser#favourite_required_parameter.91 def exitFavourite_required_parameter(self, ctx:dslParser.Favourite_required_parameterContext):92 pass93 # Enter a parse tree produced by dslParser#scheduleTweet.94 def enterScheduleTweet(self, ctx:dslParser.ScheduleTweetContext):95 pass96 # Exit a parse tree produced by dslParser#scheduleTweet.97 def exitScheduleTweet(self, ctx:dslParser.ScheduleTweetContext):98 pass99 # Enter a parse tree produced by dslParser#schedule_tweet_required_parameter.100 def enterSchedule_tweet_required_parameter(self, ctx:dslParser.Schedule_tweet_required_parameterContext):101 pass102 # Exit a parse tree produced by dslParser#schedule_tweet_required_parameter.103 def exitSchedule_tweet_required_parameter(self, ctx:dslParser.Schedule_tweet_required_parameterContext):104 pass105 # Enter a parse tree produced by dslParser#date_time_parameter.106 def enterDate_time_parameter(self, ctx:dslParser.Date_time_parameterContext):107 pass108 # Exit a parse tree produced by dslParser#date_time_parameter.109 def exitDate_time_parameter(self, ctx:dslParser.Date_time_parameterContext):110 pass111 # Enter a parse tree produced by dslParser#minute.112 def enterMinute(self, ctx:dslParser.MinuteContext):113 pass114 # Exit a parse tree produced by dslParser#minute.115 def exitMinute(self, ctx:dslParser.MinuteContext):116 pass117 # Enter a parse tree produced by dslParser#hour.118 def enterHour(self, ctx:dslParser.HourContext):119 pass120 # Exit a parse tree produced by dslParser#hour.121 def exitHour(self, ctx:dslParser.HourContext):122 pass123 # Enter a parse tree produced by dslParser#day_of_month.124 def enterDay_of_month(self, ctx:dslParser.Day_of_monthContext):125 pass126 # Exit a parse tree produced by dslParser#day_of_month.127 def exitDay_of_month(self, ctx:dslParser.Day_of_monthContext):128 pass129 # Enter a parse tree produced by dslParser#month.130 def enterMonth(self, ctx:dslParser.MonthContext):131 pass132 # Exit a parse tree produced by dslParser#month.133 def exitMonth(self, ctx:dslParser.MonthContext):134 pass135 # Enter a parse tree produced by dslParser#numeric_month.136 def enterNumeric_month(self, ctx:dslParser.Numeric_monthContext):137 pass138 # Exit a parse tree produced by dslParser#numeric_month.139 def exitNumeric_month(self, ctx:dslParser.Numeric_monthContext):140 pass141 # Enter a parse tree produced by dslParser#numeric_day.142 def enterNumeric_day(self, ctx:dslParser.Numeric_dayContext):143 pass144 # Exit a parse tree produced by dslParser#numeric_day.145 def exitNumeric_day(self, ctx:dslParser.Numeric_dayContext):146 pass147 # Enter a parse tree produced by dslParser#numeric_hour.148 def enterNumeric_hour(self, ctx:dslParser.Numeric_hourContext):149 pass150 # Exit a parse tree produced by dslParser#numeric_hour.151 def exitNumeric_hour(self, ctx:dslParser.Numeric_hourContext):152 pass153 # Enter a parse tree produced by dslParser#numeric_minute.154 def enterNumeric_minute(self, ctx:dslParser.Numeric_minuteContext):155 pass156 # Exit a parse tree produced by dslParser#numeric_minute.157 def exitNumeric_minute(self, ctx:dslParser.Numeric_minuteContext):158 pass159 # Enter a parse tree produced by dslParser#directMessage.160 def enterDirectMessage(self, ctx:dslParser.DirectMessageContext):161 pass162 # Exit a parse tree produced by dslParser#directMessage.163 def exitDirectMessage(self, ctx:dslParser.DirectMessageContext):164 pass165 # Enter a parse tree produced by dslParser#direct_message_required_parameters.166 def enterDirect_message_required_parameters(self, ctx:dslParser.Direct_message_required_parametersContext):167 pass168 # Exit a parse tree produced by dslParser#direct_message_required_parameters.169 def exitDirect_message_required_parameters(self, ctx:dslParser.Direct_message_required_parametersContext):170 pass171 # Enter a parse tree produced by dslParser#autoFavouriteRetweet.172 def enterAutoFavouriteRetweet(self, ctx:dslParser.AutoFavouriteRetweetContext):173 pass174 # Exit a parse tree produced by dslParser#autoFavouriteRetweet.175 def exitAutoFavouriteRetweet(self, ctx:dslParser.AutoFavouriteRetweetContext):176 pass177 # Enter a parse tree produced by dslParser#autoFollowFollowers.178 def enterAutoFollowFollowers(self, ctx:dslParser.AutoFollowFollowersContext):179 pass180 # Exit a parse tree produced by dslParser#autoFollowFollowers.181 def exitAutoFollowFollowers(self, ctx:dslParser.AutoFollowFollowersContext):182 pass183 # Enter a parse tree produced by dslParser#autoReplyMentions.184 def enterAutoReplyMentions(self, ctx:dslParser.AutoReplyMentionsContext):185 pass186 # Exit a parse tree produced by dslParser#autoReplyMentions.187 def exitAutoReplyMentions(self, ctx:dslParser.AutoReplyMentionsContext):188 pass189 # Enter a parse tree produced by dslParser#automateReplyParameter.190 def enterAutomateReplyParameter(self, ctx:dslParser.AutomateReplyParameterContext):191 pass192 # Exit a parse tree produced by dslParser#automateReplyParameter.193 def exitAutomateReplyParameter(self, ctx:dslParser.AutomateReplyParameterContext):194 pass195 # Enter a parse tree produced by dslParser#keyword.196 def enterKeyword(self, ctx:dslParser.KeywordContext):197 pass198 # Exit a parse tree produced by dslParser#keyword.199 def exitKeyword(self, ctx:dslParser.KeywordContext):200 pass201 # Enter a parse tree produced by dslParser#stringValue.202 def enterStringValue(self, ctx:dslParser.StringValueContext):203 pass204 # Exit a parse tree produced by dslParser#stringValue.205 def exitStringValue(self, ctx:dslParser.StringValueContext):206 pass207 # Enter a parse tree produced by dslParser#number.208 def enterNumber(self, ctx:dslParser.NumberContext):209 pass210 # Exit a parse tree produced by dslParser#number.211 def exitNumber(self, ctx:dslParser.NumberContext):212 pass213 # Enter a parse tree produced by dslParser#unary_operator.214 def enterUnary_operator(self, ctx:dslParser.Unary_operatorContext):215 pass216 # Exit a parse tree produced by dslParser#unary_operator.217 def exitUnary_operator(self, ctx:dslParser.Unary_operatorContext):218 pass219 # Enter a parse tree produced by dslParser#unsigned_number.220 def enterUnsigned_number(self, ctx:dslParser.Unsigned_numberContext):221 pass222 # Exit a parse tree produced by dslParser#unsigned_number.223 def exitUnsigned_number(self, ctx:dslParser.Unsigned_numberContext):224 pass225 # Enter a parse tree produced by dslParser#boolean.226 def enterBoolean(self, ctx:dslParser.BooleanContext):227 pass228 # Exit a parse tree produced by dslParser#boolean.229 def exitBoolean(self, ctx:dslParser.BooleanContext):230 pass...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation/pact');2var path = require('path');3var fs = require('fs');4var parser = require('pact-foundation/pact/parser');5var pactFile = path.resolve(__dirname, 'pacts', 'pact.json');6var pactObj = parser.parse(fs.readFileSync(pactFile, 'utf8'));7console.log(pactObj);8var pact = require('pact-foundation/pact');9var path = require('path');10var fs = require('fs');11var parser = require('pact-foundation/pact/parser');12var pactFile = path.resolve(__dirname, 'pacts', 'pact.json');13var pactObj = parser.parse(fs.readFileSync(pactFile, 'utf8'));14console.log(pactObj);15var parser = require('pact-foundation/pact/parser');

Full Screen

Using AI Code Generation

copy

Full Screen

1const pact = require('@pact-foundation/pact');2const fs = require('fs');3const path = require('path');4const chai = require('chai');5const expect = chai.expect;6const pactFile = path.resolve(__dirname, '../pacts/testconsumer-testprovider.json');7describe('Pact', () => {8 it('should validate the pact file against the schema', () => {9 const pactFile = path.resolve(__dirname, '../pacts/testconsumer-testprovider.json');10 const pactFileContents = fs.readFileSync(pactFile, 'utf-8');11 const parsedPactFile = pact.parsePact(pactFileContents);12 expect(parsedPactFile).to.be.an('object');13 });14});15{16 "scripts": {17 },18 "dependencies": {19 }20}21{22 "dependencies": {23 "@pact-foundation/pact": {

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pact-foundation-pact automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful