constructor()

in src/rule.ts [136:189]


	constructor(regExpSource: string, ruleId: number, handleAnchors: boolean = true) {
		if (handleAnchors) {
			if (regExpSource) {
				const len = regExpSource.length;
				let lastPushedPos = 0;
				let output: string[] = [];

				let hasAnchor = false;
				for (let pos = 0; pos < len; pos++) {
					const ch = regExpSource.charAt(pos);

					if (ch === '\\') {
						if (pos + 1 < len) {
							const nextCh = regExpSource.charAt(pos + 1);
							if (nextCh === 'z') {
								output.push(regExpSource.substring(lastPushedPos, pos));
								output.push('$(?!\\n)(?<!\\n)');
								lastPushedPos = pos + 2;
							} else if (nextCh === 'A' || nextCh === 'G') {
								hasAnchor = true;
							}
							pos++;
						}
					}
				}

				this.hasAnchor = hasAnchor;
				if (lastPushedPos === 0) {
					// No \z hit
					this.source = regExpSource;
				} else {
					output.push(regExpSource.substring(lastPushedPos, len));
					this.source = output.join('');
				}
			} else {
				this.hasAnchor = false;
				this.source = regExpSource;
			}
		} else {
			this.hasAnchor = false;
			this.source = regExpSource;
		}

		if (this.hasAnchor) {
			this._anchorCache = this._buildAnchorCache();
		} else {
			this._anchorCache = null;
		}

		this.ruleId = ruleId;
		this.hasBackReferences = HAS_BACK_REFERENCES.test(this.source);

		// console.log('input: ' + regExpSource + ' => ' + this.source + ', ' + this.hasAnchor);
	}