main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
2.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | var TYPE = require('../../tokenizer').TYPE;
|
---|
| 2 |
|
---|
| 3 | var WHITESPACE = TYPE.WhiteSpace;
|
---|
| 4 | var COMMENT = TYPE.Comment;
|
---|
| 5 | var ATKEYWORD = TYPE.AtKeyword;
|
---|
| 6 | var CDO = TYPE.CDO;
|
---|
| 7 | var CDC = TYPE.CDC;
|
---|
| 8 | var EXCLAMATIONMARK = 0x0021; // U+0021 EXCLAMATION MARK (!)
|
---|
| 9 |
|
---|
| 10 | function consumeRaw(startToken) {
|
---|
| 11 | return this.Raw(startToken, null, false);
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | module.exports = {
|
---|
| 15 | name: 'StyleSheet',
|
---|
| 16 | structure: {
|
---|
| 17 | children: [[
|
---|
| 18 | 'Comment',
|
---|
| 19 | 'CDO',
|
---|
| 20 | 'CDC',
|
---|
| 21 | 'Atrule',
|
---|
| 22 | 'Rule',
|
---|
| 23 | 'Raw'
|
---|
| 24 | ]]
|
---|
| 25 | },
|
---|
| 26 | parse: function() {
|
---|
| 27 | var start = this.scanner.tokenStart;
|
---|
| 28 | var children = this.createList();
|
---|
| 29 | var child;
|
---|
| 30 |
|
---|
| 31 | scan:
|
---|
| 32 | while (!this.scanner.eof) {
|
---|
| 33 | switch (this.scanner.tokenType) {
|
---|
| 34 | case WHITESPACE:
|
---|
| 35 | this.scanner.next();
|
---|
| 36 | continue;
|
---|
| 37 |
|
---|
| 38 | case COMMENT:
|
---|
| 39 | // ignore comments except exclamation comments (i.e. /*! .. */) on top level
|
---|
| 40 | if (this.scanner.source.charCodeAt(this.scanner.tokenStart + 2) !== EXCLAMATIONMARK) {
|
---|
| 41 | this.scanner.next();
|
---|
| 42 | continue;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | child = this.Comment();
|
---|
| 46 | break;
|
---|
| 47 |
|
---|
| 48 | case CDO: // <!--
|
---|
| 49 | child = this.CDO();
|
---|
| 50 | break;
|
---|
| 51 |
|
---|
| 52 | case CDC: // -->
|
---|
| 53 | child = this.CDC();
|
---|
| 54 | break;
|
---|
| 55 |
|
---|
| 56 | // CSS Syntax Module Level 3
|
---|
| 57 | // §2.2 Error handling
|
---|
| 58 | // At the "top level" of a stylesheet, an <at-keyword-token> starts an at-rule.
|
---|
| 59 | case ATKEYWORD:
|
---|
| 60 | child = this.parseWithFallback(this.Atrule, consumeRaw);
|
---|
| 61 | break;
|
---|
| 62 |
|
---|
| 63 | // Anything else starts a qualified rule ...
|
---|
| 64 | default:
|
---|
| 65 | child = this.parseWithFallback(this.Rule, consumeRaw);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | children.push(child);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | return {
|
---|
| 72 | type: 'StyleSheet',
|
---|
| 73 | loc: this.getLocation(start, this.scanner.tokenStart),
|
---|
| 74 | children: children
|
---|
| 75 | };
|
---|
| 76 | },
|
---|
| 77 | generate: function(node) {
|
---|
| 78 | this.children(node);
|
---|
| 79 | },
|
---|
| 80 | walkContext: 'stylesheet'
|
---|
| 81 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.