當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ITokenizationSupport.tokenize方法代碼示例

本文整理匯總了TypeScript中vs/editor/common/modes.ITokenizationSupport.tokenize方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ITokenizationSupport.tokenize方法的具體用法?TypeScript ITokenizationSupport.tokenize怎麽用?TypeScript ITokenizationSupport.tokenize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vs/editor/common/modes.ITokenizationSupport的用法示例。


在下文中一共展示了ITokenizationSupport.tokenize方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: _actualColorize

function _actualColorize(lines: string[], tabSize: number, tokenizationSupport: ITokenizationSupport): string {
	let html: string[] = [];
	let state = tokenizationSupport.getInitialState();

	for (let i = 0, length = lines.length; i < length; i++) {
		let line = lines[i];

		let tokenizeResult = tokenizationSupport.tokenize(line, state);

		let renderResult = renderLine(new RenderLineInput(
			line,
			tabSize,
			0,
			-1,
			'none',
			false,
			new LineParts(tokenizeResult.tokens.map(t => new ViewLineToken(t.startIndex, t.type)), line.length + 1)
		));

		html = html.concat(renderResult.output);
		html.push('<br/>');

		state = tokenizeResult.endState;
	}

	return html.join('');
}
開發者ID:StateFarmIns,項目名稱:vscode,代碼行數:27,代碼來源:colorizer.ts

示例2: _tokenizeLine

function _tokenizeLine(line: string, tokenizationSupport:ITokenizationSupport, emitToken: IEmitTokenFunc, startState: IState): IState {
	var tokenized = tokenizationSupport.tokenize(line, startState),
		endState = tokenized.endState,
		tokens = tokenized.tokens,
		offset = 0,
		tokenText: string;

	// For each token inject spans with proper class names based on token type
	for (var j = 0; j < tokens.length; j++) {
		var token = tokens[j];

		// Tokens only provide a startIndex from where they are valid from. As such, we need to
		// look ahead the value of the token by advancing until the next tokens start inex or the
		// end of the line.
		if (j < tokens.length - 1) {
			tokenText = line.substring(offset, tokens[j + 1].startIndex);
			offset = tokens[j + 1].startIndex;
		} else {
			tokenText = line.substr(offset);
		}

		var className = 'token';
		var safeType = token.type.replace(/[^a-z0-9\-]/gi, ' ');
		if (safeType.length > 0) {
			className += ' ' + safeType;
		}
		emitToken(className, tokenText);
	}

	return endState;
}
開發者ID:1Hgm,項目名稱:vscode,代碼行數:31,代碼來源:textToHtmlTokenizer.ts


注:本文中的vs/editor/common/modes.ITokenizationSupport.tokenize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。