protected scanNext()

in src/parser/cssScanner.ts [270:386]


	protected scanNext(offset: number): IToken {

		// CDO <!--
		if (this.stream.advanceIfChars([_LAN, _BNG, _MIN, _MIN])) {
			return this.finishToken(offset, TokenType.CDO);
		}

		// CDC -->
		if (this.stream.advanceIfChars([_MIN, _MIN, _RAN])) {
			return this.finishToken(offset, TokenType.CDC);
		}

		let content: string[] = [];
		if (this.ident(content)) {
			return this.finishToken(offset, TokenType.Ident, content.join(''));
		}

		// at-keyword
		if (this.stream.advanceIfChar(_ATS)) {
			content = ['@'];
			if (this._name(content)) {
				const keywordText = content.join('');
				if (keywordText === '@charset') {
					return this.finishToken(offset, TokenType.Charset, keywordText);
				}
				return this.finishToken(offset, TokenType.AtKeyword, keywordText);
			} else {
				return this.finishToken(offset, TokenType.Delim);
			}
		}

		// hash
		if (this.stream.advanceIfChar(_HSH)) {
			content = ['#'];
			if (this._name(content)) {
				return this.finishToken(offset, TokenType.Hash, content.join(''));
			} else {
				return this.finishToken(offset, TokenType.Delim);
			}
		}

		// Important
		if (this.stream.advanceIfChar(_BNG)) {
			return this.finishToken(offset, TokenType.Exclamation);
		}

		// Numbers
		if (this._number()) {

			const pos = this.stream.pos();
			content = [this.stream.substring(offset, pos)];
			if (this.stream.advanceIfChar(_PRC)) {
				// Percentage 43%
				return this.finishToken(offset, TokenType.Percentage);
			} else if (this.ident(content)) {
				const dim = this.stream.substring(pos).toLowerCase();
				const tokenType = <TokenType>staticUnitTable[dim];
				if (typeof tokenType !== 'undefined') {
					// Known dimension 43px
					return this.finishToken(offset, tokenType, content.join(''));
				} else {
					// Unknown dimension 43ft
					return this.finishToken(offset, TokenType.Dimension, content.join(''));
				}
			}

			return this.finishToken(offset, TokenType.Num);
		}

		// String, BadString
		content = [];
		let tokenType = this._string(content);
		if (tokenType !== null) {
			return this.finishToken(offset, tokenType, content.join(''));
		}

		// single character tokens
		tokenType = <TokenType>staticTokenTable[this.stream.peekChar()];
		if (typeof tokenType !== 'undefined') {
			this.stream.advance(1);
			return this.finishToken(offset, tokenType);
		}

		// includes ~=
		if (this.stream.peekChar(0) === _TLD && this.stream.peekChar(1) === _EQS) {
			this.stream.advance(2);
			return this.finishToken(offset, TokenType.Includes);
		}

		// DashMatch |=
		if (this.stream.peekChar(0) === _PIP && this.stream.peekChar(1) === _EQS) {
			this.stream.advance(2);
			return this.finishToken(offset, TokenType.Dashmatch);
		}

		// Substring operator *=
		if (this.stream.peekChar(0) === _MUL && this.stream.peekChar(1) === _EQS) {
			this.stream.advance(2);
			return this.finishToken(offset, TokenType.SubstringOperator);
		}

		// Substring operator ^=
		if (this.stream.peekChar(0) === _HAT && this.stream.peekChar(1) === _EQS) {
			this.stream.advance(2);
			return this.finishToken(offset, TokenType.PrefixOperator);
		}

		// Substring operator $=
		if (this.stream.peekChar(0) === _DLR && this.stream.peekChar(1) === _EQS) {
			this.stream.advance(2);
			return this.finishToken(offset, TokenType.SuffixOperator);
		}

		// Delim
		this.stream.nextChar();
		return this.finishToken(offset, TokenType.Delim);
	}