|
import { |
|
Ident, |
|
String as StringToken, |
|
Number as NumberToken, |
|
Function as FunctionToken, |
|
Url, |
|
Hash, |
|
Dimension, |
|
Percentage, |
|
LeftParenthesis, |
|
LeftSquareBracket, |
|
Comma, |
|
Delim |
|
} from '../../tokenizer/index.js'; |
|
|
|
const NUMBERSIGN = 0x0023; |
|
const ASTERISK = 0x002A; |
|
const PLUSSIGN = 0x002B; |
|
const HYPHENMINUS = 0x002D; |
|
const SOLIDUS = 0x002F; |
|
const U = 0x0075; |
|
|
|
export default function defaultRecognizer(context) { |
|
switch (this.tokenType) { |
|
case Hash: |
|
return this.Hash(); |
|
|
|
case Comma: |
|
return this.Operator(); |
|
|
|
case LeftParenthesis: |
|
return this.Parentheses(this.readSequence, context.recognizer); |
|
|
|
case LeftSquareBracket: |
|
return this.Brackets(this.readSequence, context.recognizer); |
|
|
|
case StringToken: |
|
return this.String(); |
|
|
|
case Dimension: |
|
return this.Dimension(); |
|
|
|
case Percentage: |
|
return this.Percentage(); |
|
|
|
case NumberToken: |
|
return this.Number(); |
|
|
|
case FunctionToken: |
|
return this.cmpStr(this.tokenStart, this.tokenEnd, 'url(') |
|
? this.Url() |
|
: this.Function(this.readSequence, context.recognizer); |
|
|
|
case Url: |
|
return this.Url(); |
|
|
|
case Ident: |
|
|
|
if (this.cmpChar(this.tokenStart, U) && |
|
this.cmpChar(this.tokenStart + 1, PLUSSIGN)) { |
|
return this.UnicodeRange(); |
|
} else { |
|
return this.Identifier(); |
|
} |
|
|
|
case Delim: { |
|
const code = this.charCodeAt(this.tokenStart); |
|
|
|
if (code === SOLIDUS || |
|
code === ASTERISK || |
|
code === PLUSSIGN || |
|
code === HYPHENMINUS) { |
|
return this.Operator(); |
|
} |
|
|
|
|
|
|
|
if (code === NUMBERSIGN) { |
|
this.error('Hex or identifier is expected', this.tokenStart + 1); |
|
} |
|
|
|
break; |
|
} |
|
} |
|
}; |
|
|