/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "@vscode/l10n", "../htmlLanguageTypes"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createScanner = void 0; const l10n = require("@vscode/l10n"); const htmlLanguageTypes_1 = require("../htmlLanguageTypes"); class MultiLineStream { constructor(source, position) { this.source = source; this.len = source.length; this.position = position; } eos() { return this.len <= this.position; } getSource() { return this.source; } pos() { return this.position; } goBackTo(pos) { this.position = pos; } goBack(n) { this.position -= n; } advance(n) { this.position += n; } goToEnd() { this.position = this.source.length; } nextChar() { return this.source.charCodeAt(this.position++) || 0; } peekChar(n = 0) { return this.source.charCodeAt(this.position + n) || 0; } advanceIfChar(ch) { if (ch === this.source.charCodeAt(this.position)) { this.position++; return true; } return false; } advanceIfChars(ch) { let i; if (this.position + ch.length > this.source.length) { return false; } for (i = 0; i < ch.length; i++) { if (this.source.charCodeAt(this.position + i) !== ch[i]) { return false; } } this.advance(i); return true; } advanceIfRegExp(regex) { const str = this.source.substr(this.position); const match = str.match(regex); if (match) { this.position = this.position + match.index + match[0].length; return match[0]; } return ''; } advanceUntilRegExp(regex) { const str = this.source.substr(this.position); const match = str.match(regex); if (match) { this.position = this.position + match.index; return match[0]; } else { this.goToEnd(); } return ''; } advanceUntilChar(ch) { while (this.position < this.source.length) { if (this.source.charCodeAt(this.position) === ch) { return true; } this.advance(1); } return false; } advanceUntilChars(ch) { while (this.position + ch.length <= this.source.length) { let i = 0; for (; i < ch.length && this.source.charCodeAt(this.position + i) === ch[i]; i++) { } if (i === ch.length) { return true; } this.advance(1); } this.goToEnd(); return false; } skipWhitespace() { const n = this.advanceWhileChar(ch => { return ch === _WSP || ch === _TAB || ch === _NWL || ch === _LFD || ch === _CAR; }); return n > 0; } advanceWhileChar(condition) { const posNow = this.position; while (this.position < this.len && condition(this.source.charCodeAt(this.position))) { this.position++; } return this.position - posNow; } } const _BNG = '!'.charCodeAt(0); const _MIN = '-'.charCodeAt(0); const _LAN = '<'.charCodeAt(0); const _RAN = '>'.charCodeAt(0); const _FSL = '/'.charCodeAt(0); const _EQS = '='.charCodeAt(0); const _DQO = '"'.charCodeAt(0); const _SQO = '\''.charCodeAt(0); const _NWL = '\n'.charCodeAt(0); const _CAR = '\r'.charCodeAt(0); const _LFD = '\f'.charCodeAt(0); const _WSP = ' '.charCodeAt(0); const _TAB = '\t'.charCodeAt(0); const htmlScriptContents = { 'text/x-handlebars-template': true, // Fix for https://github.com/microsoft/vscode/issues/77977 'text/html': true, }; function createScanner(input, initialOffset = 0, initialState = htmlLanguageTypes_1.ScannerState.WithinContent, emitPseudoCloseTags = false) { const stream = new MultiLineStream(input, initialOffset); let state = initialState; let tokenOffset = 0; let tokenType = htmlLanguageTypes_1.TokenType.Unknown; let tokenError; let hasSpaceAfterTag; let lastTag; let lastAttributeName; let lastTypeValue; function nextElementName() { return stream.advanceIfRegExp(/^[_:\w][_:\w-.\d]*/).toLowerCase(); } function nextAttributeName() { return stream.advanceIfRegExp(/^[^\s"'> state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndCommentTag); } stream.advanceUntilChars([_MIN, _MIN, _RAN]); // --> return finishToken(offset, htmlLanguageTypes_1.TokenType.Comment); case htmlLanguageTypes_1.ScannerState.WithinDoctype: if (stream.advanceIfChar(_RAN)) { state = htmlLanguageTypes_1.ScannerState.WithinContent; return finishToken(offset, htmlLanguageTypes_1.TokenType.EndDoctypeTag); } stream.advanceUntilChar(_RAN); // > return finishToken(offset, htmlLanguageTypes_1.TokenType.Doctype); case htmlLanguageTypes_1.ScannerState.WithinContent: if (stream.advanceIfChar(_LAN)) { // < if (!stream.eos() && stream.peekChar() === _BNG) { // ! if (stream.advanceIfChars([_BNG, _MIN, _MIN])) { // |<\/?script\s*\/?>?/i); if (match.length === 0) { stream.goToEnd(); return finishToken(offset, htmlLanguageTypes_1.TokenType.Script); } else if (match === '') { sciptState = 1; } else if (match[1] !== '/') { //