• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Generated by re2c 0.13.5 on Tue Feb  2 00:44:38 2010 */
2/*
3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 *     * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *     * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 *     * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32// Generate js file as follows:
33//
34// re2c -isc WebCore/inspector/front-end/SourceHTMLTokenizer.re2js \
35// | sed 's|^yy\([^:]*\)*\:|case \1:|' \
36// | sed 's|[*]cursor[+][+]|this._charAt(cursor++)|' \
37// | sed 's|[[*][+][+]cursor|this._charAt(++cursor)|' \
38// | sed 's|[*]cursor|this._charAt(cursor)|' \
39// | sed 's|yych = \*\([^;]*\)|yych = this._charAt\1|' \
40// | sed 's|{ gotoCase = \([^; continue; };]*\)|{ gotoCase = \1; continue; }|' \
41// | sed 's|unsigned\ int|var|' \
42// | sed 's|var\ yych|case 1: case 1: var yych|'
43
44WebInspector.SourceHTMLTokenizer = function()
45{
46    WebInspector.SourceTokenizer.call(this);
47
48    // The order is determined by the generated code.
49    this._lexConditions = {
50        INITIAL: 0,
51        COMMENT: 1,
52        DOCTYPE: 2,
53        TAG: 3,
54        DSTRING: 4,
55        SSTRING: 5
56    };
57    this.case_INITIAL = 1000;
58    this.case_COMMENT = 1001;
59    this.case_DOCTYPE = 1002;
60    this.case_TAG = 1003;
61    this.case_DSTRING = 1004;
62    this.case_SSTRING = 1005;
63
64    this._parseConditions = {
65        INITIAL: 0,
66        ATTRIBUTE: 1,
67        ATTRIBUTE_VALUE: 2,
68        LINKIFY: 4,
69        A_NODE: 8,
70        SCRIPT: 16
71    };
72
73    this.initialCondition = { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
74}
75
76WebInspector.SourceHTMLTokenizer.prototype = {
77    _isExpectingAttribute: function()
78    {
79        return this._parseCondition & this._parseConditions.ATTRIBUTE;
80    },
81
82    _isExpectingAttributeValue: function()
83    {
84        return this._parseCondition & this._parseConditions.ATTRIBUTE_VALUE;
85    },
86
87    _setExpectingAttribute: function()
88    {
89        if (this._isExpectingAttributeValue())
90            this._parseCondition ^= this._parseConditions.ATTRIBUTE_VALUE;
91        this._parseCondition |= this._parseConditions.ATTRIBUTE;
92    },
93
94    _setExpectingAttributeValue: function()
95    {
96        if (this._isExpectingAttribute())
97            this._parseCondition ^= this._parseConditions.ATTRIBUTE;
98        this._parseCondition |= this._parseConditions.ATTRIBUTE_VALUE;
99    },
100
101    _stringToken: function(cursor, stringEnds)
102    {
103        if (!this._isExpectingAttributeValue()) {
104            this.tokenType = null;
105            return cursor;
106        }
107        this.tokenType = this._attrValueTokenType();
108        if (stringEnds)
109            this._setExpectingAttribute();
110        return cursor;
111    },
112
113    _attrValueTokenType: function()
114    {
115        if (this._parseCondition & this._parseConditions.LINKIFY) {
116            if (this._parseCondition & this._parseConditions.A_NODE)
117                return "html-external-link";
118            return "html-resource-link";
119        }
120        return "html-attribute-value";
121    },
122
123    nextToken: function(cursor)
124    {
125        var cursorOnEnter = cursor;
126        var gotoCase = 1;
127        while (1) {
128            switch (gotoCase)
129            // Following comment is replaced with generated state machine.
130
131        {
132            case 1: var yych;
133            var yyaccept = 0;
134            if (this.getLexCondition() < 3) {
135                if (this.getLexCondition() < 1) {
136                    { gotoCase = this.case_INITIAL; continue; };
137                } else {
138                    if (this.getLexCondition() < 2) {
139                        { gotoCase = this.case_COMMENT; continue; };
140                    } else {
141                        { gotoCase = this.case_DOCTYPE; continue; };
142                    }
143                }
144            } else {
145                if (this.getLexCondition() < 4) {
146                    { gotoCase = this.case_TAG; continue; };
147                } else {
148                    if (this.getLexCondition() < 5) {
149                        { gotoCase = this.case_DSTRING; continue; };
150                    } else {
151                        { gotoCase = this.case_SSTRING; continue; };
152                    }
153                }
154            }
155/* *********************************** */
156case this.case_COMMENT:
157
158            yych = this._charAt(cursor);
159            if (yych <= '\f') {
160                if (yych == '\n') { gotoCase = 4; continue; };
161                { gotoCase = 3; continue; };
162            } else {
163                if (yych <= '\r') { gotoCase = 4; continue; };
164                if (yych == '-') { gotoCase = 6; continue; };
165                { gotoCase = 3; continue; };
166            }
167case 2:
168            { this.tokenType = "html-comment"; return cursor; }
169case 3:
170            yyaccept = 0;
171            yych = this._charAt(YYMARKER = ++cursor);
172            { gotoCase = 9; continue; };
173case 4:
174            ++cursor;
175case 5:
176            { this.tokenType = null; return cursor; }
177case 6:
178            yyaccept = 1;
179            yych = this._charAt(YYMARKER = ++cursor);
180            if (yych != '-') { gotoCase = 5; continue; };
181case 7:
182            ++cursor;
183            yych = this._charAt(cursor);
184            if (yych == '>') { gotoCase = 10; continue; };
185case 8:
186            yyaccept = 0;
187            YYMARKER = ++cursor;
188            yych = this._charAt(cursor);
189case 9:
190            if (yych <= '\f') {
191                if (yych == '\n') { gotoCase = 2; continue; };
192                { gotoCase = 8; continue; };
193            } else {
194                if (yych <= '\r') { gotoCase = 2; continue; };
195                if (yych == '-') { gotoCase = 12; continue; };
196                { gotoCase = 8; continue; };
197            }
198case 10:
199            ++cursor;
200            this.setLexCondition(this._lexConditions.INITIAL);
201            { this.tokenType = "html-comment"; return cursor; }
202case 12:
203            ++cursor;
204            yych = this._charAt(cursor);
205            if (yych == '-') { gotoCase = 7; continue; };
206            cursor = YYMARKER;
207            if (yyaccept <= 0) {
208                { gotoCase = 2; continue; };
209            } else {
210                { gotoCase = 5; continue; };
211            }
212/* *********************************** */
213case this.case_DOCTYPE:
214            yych = this._charAt(cursor);
215            if (yych <= '\f') {
216                if (yych == '\n') { gotoCase = 18; continue; };
217                { gotoCase = 17; continue; };
218            } else {
219                if (yych <= '\r') { gotoCase = 18; continue; };
220                if (yych == '>') { gotoCase = 20; continue; };
221                { gotoCase = 17; continue; };
222            }
223case 16:
224            { this.tokenType = "html-doctype"; return cursor; }
225case 17:
226            yych = this._charAt(++cursor);
227            { gotoCase = 23; continue; };
228case 18:
229            ++cursor;
230            { this.tokenType = null; return cursor; }
231case 20:
232            ++cursor;
233            this.setLexCondition(this._lexConditions.INITIAL);
234            { this.tokenType = "html-doctype"; return cursor; }
235case 22:
236            ++cursor;
237            yych = this._charAt(cursor);
238case 23:
239            if (yych <= '\f') {
240                if (yych == '\n') { gotoCase = 16; continue; };
241                { gotoCase = 22; continue; };
242            } else {
243                if (yych <= '\r') { gotoCase = 16; continue; };
244                if (yych == '>') { gotoCase = 16; continue; };
245                { gotoCase = 22; continue; };
246            }
247/* *********************************** */
248case this.case_DSTRING:
249            yych = this._charAt(cursor);
250            if (yych <= '\f') {
251                if (yych == '\n') { gotoCase = 28; continue; };
252                { gotoCase = 27; continue; };
253            } else {
254                if (yych <= '\r') { gotoCase = 28; continue; };
255                if (yych == '"') { gotoCase = 30; continue; };
256                { gotoCase = 27; continue; };
257            }
258case 26:
259            { return this._stringToken(cursor); }
260case 27:
261            yych = this._charAt(++cursor);
262            { gotoCase = 34; continue; };
263case 28:
264            ++cursor;
265            { this.tokenType = null; return cursor; }
266case 30:
267            ++cursor;
268case 31:
269            this.setLexCondition(this._lexConditions.TAG);
270            { return this._stringToken(cursor, true); }
271case 32:
272            yych = this._charAt(++cursor);
273            { gotoCase = 31; continue; };
274case 33:
275            ++cursor;
276            yych = this._charAt(cursor);
277case 34:
278            if (yych <= '\f') {
279                if (yych == '\n') { gotoCase = 26; continue; };
280                { gotoCase = 33; continue; };
281            } else {
282                if (yych <= '\r') { gotoCase = 26; continue; };
283                if (yych == '"') { gotoCase = 32; continue; };
284                { gotoCase = 33; continue; };
285            }
286/* *********************************** */
287case this.case_INITIAL:
288            yych = this._charAt(cursor);
289            if (yych == '<') { gotoCase = 39; continue; };
290            ++cursor;
291            { this.tokenType = null; return cursor; }
292case 39:
293            yyaccept = 0;
294            yych = this._charAt(YYMARKER = ++cursor);
295            if (yych <= '/') {
296                if (yych == '!') { gotoCase = 44; continue; };
297                if (yych >= '/') { gotoCase = 41; continue; };
298            } else {
299                if (yych <= 'S') {
300                    if (yych >= 'S') { gotoCase = 42; continue; };
301                } else {
302                    if (yych == 's') { gotoCase = 42; continue; };
303                }
304            }
305case 40:
306            this.setLexCondition(this._lexConditions.TAG);
307            {
308                    if (this._parseCondition & this._parseConditions.SCRIPT) {
309                        // Do not tokenize script tag contents, keep lexer state although processing "<".
310                        this.setLexCondition(this._lexConditions.INITIAL);
311                        this.tokenType = null;
312                        return cursor;
313                    }
314
315                    this._parseCondition = this._parseConditions.INITIAL;
316                    this.tokenType = "html-tag";
317                    return cursor;
318                }
319case 41:
320            yyaccept = 0;
321            yych = this._charAt(YYMARKER = ++cursor);
322            if (yych == 'S') { gotoCase = 68; continue; };
323            if (yych == 's') { gotoCase = 68; continue; };
324            { gotoCase = 40; continue; };
325case 42:
326            yych = this._charAt(++cursor);
327            if (yych == 'C') { gotoCase = 62; continue; };
328            if (yych == 'c') { gotoCase = 62; continue; };
329case 43:
330            cursor = YYMARKER;
331            { gotoCase = 40; continue; };
332case 44:
333            yych = this._charAt(++cursor);
334            if (yych <= 'C') {
335                if (yych != '-') { gotoCase = 43; continue; };
336            } else {
337                if (yych <= 'D') { gotoCase = 46; continue; };
338                if (yych == 'd') { gotoCase = 46; continue; };
339                { gotoCase = 43; continue; };
340            }
341            yych = this._charAt(++cursor);
342            if (yych == '-') { gotoCase = 54; continue; };
343            { gotoCase = 43; continue; };
344case 46:
345            yych = this._charAt(++cursor);
346            if (yych == 'O') { gotoCase = 47; continue; };
347            if (yych != 'o') { gotoCase = 43; continue; };
348case 47:
349            yych = this._charAt(++cursor);
350            if (yych == 'C') { gotoCase = 48; continue; };
351            if (yych != 'c') { gotoCase = 43; continue; };
352case 48:
353            yych = this._charAt(++cursor);
354            if (yych == 'T') { gotoCase = 49; continue; };
355            if (yych != 't') { gotoCase = 43; continue; };
356case 49:
357            yych = this._charAt(++cursor);
358            if (yych == 'Y') { gotoCase = 50; continue; };
359            if (yych != 'y') { gotoCase = 43; continue; };
360case 50:
361            yych = this._charAt(++cursor);
362            if (yych == 'P') { gotoCase = 51; continue; };
363            if (yych != 'p') { gotoCase = 43; continue; };
364case 51:
365            yych = this._charAt(++cursor);
366            if (yych == 'E') { gotoCase = 52; continue; };
367            if (yych != 'e') { gotoCase = 43; continue; };
368case 52:
369            ++cursor;
370            this.setLexCondition(this._lexConditions.DOCTYPE);
371            { this.tokenType = "html-doctype"; return cursor; }
372case 54:
373            ++cursor;
374            yych = this._charAt(cursor);
375            if (yych <= '\f') {
376                if (yych == '\n') { gotoCase = 57; continue; };
377                { gotoCase = 54; continue; };
378            } else {
379                if (yych <= '\r') { gotoCase = 57; continue; };
380                if (yych != '-') { gotoCase = 54; continue; };
381            }
382            ++cursor;
383            yych = this._charAt(cursor);
384            if (yych == '-') { gotoCase = 59; continue; };
385            { gotoCase = 43; continue; };
386case 57:
387            ++cursor;
388            this.setLexCondition(this._lexConditions.COMMENT);
389            { this.tokenType = "html-comment"; return cursor; }
390case 59:
391            ++cursor;
392            yych = this._charAt(cursor);
393            if (yych != '>') { gotoCase = 54; continue; };
394            ++cursor;
395            { this.tokenType = "html-comment"; return cursor; }
396case 62:
397            yych = this._charAt(++cursor);
398            if (yych == 'R') { gotoCase = 63; continue; };
399            if (yych != 'r') { gotoCase = 43; continue; };
400case 63:
401            yych = this._charAt(++cursor);
402            if (yych == 'I') { gotoCase = 64; continue; };
403            if (yych != 'i') { gotoCase = 43; continue; };
404case 64:
405            yych = this._charAt(++cursor);
406            if (yych == 'P') { gotoCase = 65; continue; };
407            if (yych != 'p') { gotoCase = 43; continue; };
408case 65:
409            yych = this._charAt(++cursor);
410            if (yych == 'T') { gotoCase = 66; continue; };
411            if (yych != 't') { gotoCase = 43; continue; };
412case 66:
413            ++cursor;
414            this.setLexCondition(this._lexConditions.TAG);
415            {
416                    this.tokenType = "html-tag";
417                    this._parseCondition = this._parseConditions.SCRIPT;
418                    this._setExpectingAttribute();
419                    return cursor;
420                }
421case 68:
422            yych = this._charAt(++cursor);
423            if (yych == 'C') { gotoCase = 69; continue; };
424            if (yych != 'c') { gotoCase = 43; continue; };
425case 69:
426            yych = this._charAt(++cursor);
427            if (yych == 'R') { gotoCase = 70; continue; };
428            if (yych != 'r') { gotoCase = 43; continue; };
429case 70:
430            yych = this._charAt(++cursor);
431            if (yych == 'I') { gotoCase = 71; continue; };
432            if (yych != 'i') { gotoCase = 43; continue; };
433case 71:
434            yych = this._charAt(++cursor);
435            if (yych == 'P') { gotoCase = 72; continue; };
436            if (yych != 'p') { gotoCase = 43; continue; };
437case 72:
438            yych = this._charAt(++cursor);
439            if (yych == 'T') { gotoCase = 73; continue; };
440            if (yych != 't') { gotoCase = 43; continue; };
441case 73:
442            ++cursor;
443            this.setLexCondition(this._lexConditions.TAG);
444            {
445                    this.tokenType = "html-tag";
446                    this._parseCondition = this._parseConditions.INITIAL;
447                    return cursor;
448                }
449/* *********************************** */
450case this.case_SSTRING:
451            yych = this._charAt(cursor);
452            if (yych <= '\f') {
453                if (yych == '\n') { gotoCase = 79; continue; };
454                { gotoCase = 78; continue; };
455            } else {
456                if (yych <= '\r') { gotoCase = 79; continue; };
457                if (yych == '\'') { gotoCase = 81; continue; };
458                { gotoCase = 78; continue; };
459            }
460case 77:
461            { return this._stringToken(cursor); }
462case 78:
463            yych = this._charAt(++cursor);
464            { gotoCase = 85; continue; };
465case 79:
466            ++cursor;
467            { this.tokenType = null; return cursor; }
468case 81:
469            ++cursor;
470case 82:
471            this.setLexCondition(this._lexConditions.TAG);
472            { return this._stringToken(cursor, true); }
473case 83:
474            yych = this._charAt(++cursor);
475            { gotoCase = 82; continue; };
476case 84:
477            ++cursor;
478            yych = this._charAt(cursor);
479case 85:
480            if (yych <= '\f') {
481                if (yych == '\n') { gotoCase = 77; continue; };
482                { gotoCase = 84; continue; };
483            } else {
484                if (yych <= '\r') { gotoCase = 77; continue; };
485                if (yych == '\'') { gotoCase = 83; continue; };
486                { gotoCase = 84; continue; };
487            }
488/* *********************************** */
489case this.case_TAG:
490            yych = this._charAt(cursor);
491            if (yych <= '&') {
492                if (yych <= '\r') {
493                    if (yych == '\n') { gotoCase = 90; continue; };
494                    if (yych >= '\r') { gotoCase = 90; continue; };
495                } else {
496                    if (yych <= ' ') {
497                        if (yych >= ' ') { gotoCase = 90; continue; };
498                    } else {
499                        if (yych == '"') { gotoCase = 92; continue; };
500                    }
501                }
502            } else {
503                if (yych <= '>') {
504                    if (yych <= ';') {
505                        if (yych <= '\'') { gotoCase = 93; continue; };
506                    } else {
507                        if (yych <= '<') { gotoCase = 90; continue; };
508                        if (yych <= '=') { gotoCase = 94; continue; };
509                        { gotoCase = 96; continue; };
510                    }
511                } else {
512                    if (yych <= '[') {
513                        if (yych >= '[') { gotoCase = 90; continue; };
514                    } else {
515                        if (yych == ']') { gotoCase = 90; continue; };
516                    }
517                }
518            }
519            ++cursor;
520            yych = this._charAt(cursor);
521            { gotoCase = 109; continue; };
522case 89:
523            {
524                    if (this._parseCondition === this._parseConditions.SCRIPT) {
525                        // Fall through if expecting attributes.
526                        this.tokenType = null;
527                        return cursor;
528                    }
529
530                    if (this._parseCondition === this._parseConditions.INITIAL) {
531                        this.tokenType = "html-tag";
532                        this._setExpectingAttribute();
533                        var token = this._line.substring(cursorOnEnter, cursor);
534                        if (token === "a")
535                            this._parseCondition |= this._parseConditions.A_NODE;
536                        else if (this._parseCondition & this._parseConditions.A_NODE)
537                            this._parseCondition ^= this._parseConditions.A_NODE;
538                    } else if (this._isExpectingAttribute()) {
539                        var token = this._line.substring(cursorOnEnter, cursor);
540                        if (token === "href" || token === "src")
541                            this._parseCondition |= this._parseConditions.LINKIFY;
542                        else if (this._parseCondition |= this._parseConditions.LINKIFY)
543                            this._parseCondition ^= this._parseConditions.LINKIFY;
544                        this.tokenType = "html-attribute-name";
545                    } else if (this._isExpectingAttributeValue())
546                        this.tokenType = this._attrValueTokenType();
547                    else
548                        this.tokenType = null;
549                    return cursor;
550                }
551case 90:
552            ++cursor;
553            { this.tokenType = null; return cursor; }
554case 92:
555            yyaccept = 0;
556            yych = this._charAt(YYMARKER = ++cursor);
557            { gotoCase = 105; continue; };
558case 93:
559            yyaccept = 0;
560            yych = this._charAt(YYMARKER = ++cursor);
561            { gotoCase = 99; continue; };
562case 94:
563            ++cursor;
564            {
565                    if (this._isExpectingAttribute())
566                        this._setExpectingAttributeValue();
567                    this.tokenType = null;
568                    return cursor;
569                }
570case 96:
571            ++cursor;
572            this.setLexCondition(this._lexConditions.INITIAL);
573            {
574                    if (this._parseCondition & this._parseConditions.SCRIPT) {
575                        // Do not tokenize script tag contents.
576                        this.tokenType = null;
577                        return cursor;
578                    }
579
580                    this._parseCondition = this._parseConditions.INITIAL;
581                    this.tokenType = "html-tag";
582                    return cursor;
583                }
584case 98:
585            ++cursor;
586            yych = this._charAt(cursor);
587case 99:
588            if (yych <= '\f') {
589                if (yych != '\n') { gotoCase = 98; continue; };
590            } else {
591                if (yych <= '\r') { gotoCase = 100; continue; };
592                if (yych == '\'') { gotoCase = 102; continue; };
593                { gotoCase = 98; continue; };
594            }
595case 100:
596            ++cursor;
597            this.setLexCondition(this._lexConditions.SSTRING);
598            { return this._stringToken(cursor); }
599case 102:
600            ++cursor;
601            { return this._stringToken(cursor, true); }
602case 104:
603            ++cursor;
604            yych = this._charAt(cursor);
605case 105:
606            if (yych <= '\f') {
607                if (yych != '\n') { gotoCase = 104; continue; };
608            } else {
609                if (yych <= '\r') { gotoCase = 106; continue; };
610                if (yych == '"') { gotoCase = 102; continue; };
611                { gotoCase = 104; continue; };
612            }
613case 106:
614            ++cursor;
615            this.setLexCondition(this._lexConditions.DSTRING);
616            { return this._stringToken(cursor); }
617case 108:
618            ++cursor;
619            yych = this._charAt(cursor);
620case 109:
621            if (yych <= '"') {
622                if (yych <= '\r') {
623                    if (yych == '\n') { gotoCase = 89; continue; };
624                    if (yych <= '\f') { gotoCase = 108; continue; };
625                    { gotoCase = 89; continue; };
626                } else {
627                    if (yych == ' ') { gotoCase = 89; continue; };
628                    if (yych <= '!') { gotoCase = 108; continue; };
629                    { gotoCase = 89; continue; };
630                }
631            } else {
632                if (yych <= '>') {
633                    if (yych == '\'') { gotoCase = 89; continue; };
634                    if (yych <= ';') { gotoCase = 108; continue; };
635                    { gotoCase = 89; continue; };
636                } else {
637                    if (yych <= '[') {
638                        if (yych <= 'Z') { gotoCase = 108; continue; };
639                        { gotoCase = 89; continue; };
640                    } else {
641                        if (yych == ']') { gotoCase = 89; continue; };
642                        { gotoCase = 108; continue; };
643                    }
644                }
645            }
646        }
647
648        }
649    }
650}
651
652WebInspector.SourceHTMLTokenizer.prototype.__proto__ = WebInspector.SourceTokenizer.prototype;
653