1 | var cmpChar = require('../../tokenizer').cmpChar;
|
---|
2 | var cmpStr = require('../../tokenizer').cmpStr;
|
---|
3 | var TYPE = require('../../tokenizer').TYPE;
|
---|
4 |
|
---|
5 | var IDENT = TYPE.Ident;
|
---|
6 | var STRING = TYPE.String;
|
---|
7 | var NUMBER = TYPE.Number;
|
---|
8 | var FUNCTION = TYPE.Function;
|
---|
9 | var URL = TYPE.Url;
|
---|
10 | var HASH = TYPE.Hash;
|
---|
11 | var DIMENSION = TYPE.Dimension;
|
---|
12 | var PERCENTAGE = TYPE.Percentage;
|
---|
13 | var LEFTPARENTHESIS = TYPE.LeftParenthesis;
|
---|
14 | var LEFTSQUAREBRACKET = TYPE.LeftSquareBracket;
|
---|
15 | var COMMA = TYPE.Comma;
|
---|
16 | var DELIM = TYPE.Delim;
|
---|
17 | var NUMBERSIGN = 0x0023; // U+0023 NUMBER SIGN (#)
|
---|
18 | var ASTERISK = 0x002A; // U+002A ASTERISK (*)
|
---|
19 | var PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
|
---|
20 | var HYPHENMINUS = 0x002D; // U+002D HYPHEN-MINUS (-)
|
---|
21 | var SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
|
---|
22 | var U = 0x0075; // U+0075 LATIN SMALL LETTER U (u)
|
---|
23 |
|
---|
24 | module.exports = function defaultRecognizer(context) {
|
---|
25 | switch (this.scanner.tokenType) {
|
---|
26 | case HASH:
|
---|
27 | return this.Hash();
|
---|
28 |
|
---|
29 | case COMMA:
|
---|
30 | context.space = null;
|
---|
31 | context.ignoreWSAfter = true;
|
---|
32 | return this.Operator();
|
---|
33 |
|
---|
34 | case LEFTPARENTHESIS:
|
---|
35 | return this.Parentheses(this.readSequence, context.recognizer);
|
---|
36 |
|
---|
37 | case LEFTSQUAREBRACKET:
|
---|
38 | return this.Brackets(this.readSequence, context.recognizer);
|
---|
39 |
|
---|
40 | case STRING:
|
---|
41 | return this.String();
|
---|
42 |
|
---|
43 | case DIMENSION:
|
---|
44 | return this.Dimension();
|
---|
45 |
|
---|
46 | case PERCENTAGE:
|
---|
47 | return this.Percentage();
|
---|
48 |
|
---|
49 | case NUMBER:
|
---|
50 | return this.Number();
|
---|
51 |
|
---|
52 | case FUNCTION:
|
---|
53 | return cmpStr(this.scanner.source, this.scanner.tokenStart, this.scanner.tokenEnd, 'url(')
|
---|
54 | ? this.Url()
|
---|
55 | : this.Function(this.readSequence, context.recognizer);
|
---|
56 |
|
---|
57 | case URL:
|
---|
58 | return this.Url();
|
---|
59 |
|
---|
60 | case IDENT:
|
---|
61 | // check for unicode range, it should start with u+ or U+
|
---|
62 | if (cmpChar(this.scanner.source, this.scanner.tokenStart, U) &&
|
---|
63 | cmpChar(this.scanner.source, this.scanner.tokenStart + 1, PLUSSIGN)) {
|
---|
64 | return this.UnicodeRange();
|
---|
65 | } else {
|
---|
66 | return this.Identifier();
|
---|
67 | }
|
---|
68 |
|
---|
69 | case DELIM:
|
---|
70 | var code = this.scanner.source.charCodeAt(this.scanner.tokenStart);
|
---|
71 |
|
---|
72 | if (code === SOLIDUS ||
|
---|
73 | code === ASTERISK ||
|
---|
74 | code === PLUSSIGN ||
|
---|
75 | code === HYPHENMINUS) {
|
---|
76 | return this.Operator(); // TODO: replace with Delim
|
---|
77 | }
|
---|
78 |
|
---|
79 | // TODO: produce a node with Delim node type
|
---|
80 |
|
---|
81 | if (code === NUMBERSIGN) {
|
---|
82 | this.error('Hex or identifier is expected', this.scanner.tokenStart + 1);
|
---|
83 | }
|
---|
84 |
|
---|
85 | break;
|
---|
86 | }
|
---|
87 | };
|
---|