Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.9 KB
|
Line | |
---|
1 | var TYPE = require('../../tokenizer').TYPE;
|
---|
2 |
|
---|
3 | var IDENT = TYPE.Ident;
|
---|
4 | var NUMBER = TYPE.Number;
|
---|
5 | var DIMENSION = TYPE.Dimension;
|
---|
6 | var LEFTPARENTHESIS = TYPE.LeftParenthesis;
|
---|
7 | var RIGHTPARENTHESIS = TYPE.RightParenthesis;
|
---|
8 | var COLON = TYPE.Colon;
|
---|
9 | var DELIM = TYPE.Delim;
|
---|
10 |
|
---|
11 | module.exports = {
|
---|
12 | name: 'MediaFeature',
|
---|
13 | structure: {
|
---|
14 | name: String,
|
---|
15 | value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
|
---|
16 | },
|
---|
17 | parse: function() {
|
---|
18 | var start = this.scanner.tokenStart;
|
---|
19 | var name;
|
---|
20 | var value = null;
|
---|
21 |
|
---|
22 | this.eat(LEFTPARENTHESIS);
|
---|
23 | this.scanner.skipSC();
|
---|
24 |
|
---|
25 | name = this.consume(IDENT);
|
---|
26 | this.scanner.skipSC();
|
---|
27 |
|
---|
28 | if (this.scanner.tokenType !== RIGHTPARENTHESIS) {
|
---|
29 | this.eat(COLON);
|
---|
30 | this.scanner.skipSC();
|
---|
31 |
|
---|
32 | switch (this.scanner.tokenType) {
|
---|
33 | case NUMBER:
|
---|
34 | if (this.lookupNonWSType(1) === DELIM) {
|
---|
35 | value = this.Ratio();
|
---|
36 | } else {
|
---|
37 | value = this.Number();
|
---|
38 | }
|
---|
39 |
|
---|
40 | break;
|
---|
41 |
|
---|
42 | case DIMENSION:
|
---|
43 | value = this.Dimension();
|
---|
44 | break;
|
---|
45 |
|
---|
46 | case IDENT:
|
---|
47 | value = this.Identifier();
|
---|
48 |
|
---|
49 | break;
|
---|
50 |
|
---|
51 | default:
|
---|
52 | this.error('Number, dimension, ratio or identifier is expected');
|
---|
53 | }
|
---|
54 |
|
---|
55 | this.scanner.skipSC();
|
---|
56 | }
|
---|
57 |
|
---|
58 | this.eat(RIGHTPARENTHESIS);
|
---|
59 |
|
---|
60 | return {
|
---|
61 | type: 'MediaFeature',
|
---|
62 | loc: this.getLocation(start, this.scanner.tokenStart),
|
---|
63 | name: name,
|
---|
64 | value: value
|
---|
65 | };
|
---|
66 | },
|
---|
67 | generate: function(node) {
|
---|
68 | this.chunk('(');
|
---|
69 | this.chunk(node.name);
|
---|
70 | if (node.value !== null) {
|
---|
71 | this.chunk(':');
|
---|
72 | this.node(node.value);
|
---|
73 | }
|
---|
74 | this.chunk(')');
|
---|
75 | }
|
---|
76 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.