<commit_before>import {Token} from "../def/token";
import {SyntaxDB} from "./syntaxdb";

export class ClosureItem {
	// インスタンス生成後に内部状態が変化することはないものとする
	private _lr0_hash: string;
	private _lr1_hash: string;
	constructor(private syntax: SyntaxDB, private _syntax_id: number, private _dot_index: number, private _lookaheads: Array<Token>) {
		this.sortLA();
		this.updateHash();
	}
	get syntax_id(): number {
		return this._syntax_id;
	}
	get dot_index(): number {
		return this._dot_index;
	}
	get lookaheads(): Array<Token> {
		return this._lookaheads;
	}
	private sortLA() {
		this.lookaheads.sort((t1: Token, t2: Token) => {
			return this.syntax.getTokenId(t1) - this.syntax.getTokenId(t2);
		});
	}
	// ハッシュ文字列を生成する
	private updateHash() {<commit_msg>ClosureItem throws error on invalid constructor args<commit_after>import {Token} from "../def/token";
import {SyntaxDB} from "./syntaxdb";

export class ClosureItem {
	// インスタンス生成後に内部状態が変化することはないものとする
	private _lr0_hash: string;
	private _lr1_hash: string;
	constructor(private syntax: SyntaxDB, private _syntax_id: number, private _dot_index: number, private _lookaheads: Array<Token>) {
		// 有効な値かどうか調べる
		if (!this.syntax.hasDefinitionId(this._syntax_id)) {
			throw new Error("invalid syntax id");
		}
		if (this._dot_index < 0 || this._dot_index > this.syntax.getDefinitionById(this._syntax_id).pattern.length) {
			throw new Error("dot index out of range");
		}
		if (this._lookaheads.length == 0) {
			// 必要か？
			throw new Error("one or more lookahead symbols needed");
		}
		this.sortLA();
		this.updateHash();
	}
	get syntax_id(): number {
		return this._syntax_id;
	}
	get dot_index(): number {
		return this._dot_index;
	}
	get lookaheads(): Array<Token> {
		return this._lookaheads;
	}
	private sortLA() {
		this.lookaheads.sort((t1: Token, t2: Token) => {
			return this.syntax.getTokenId(t1) - this.syntax.getTokenId(t2);
		});
	}
	// ハッシュ文字列を生成する
	private updateHash() {
{'fraction_non_alphanumeric': 0.13460546673543064, 'fraction_numerical': 0.007220216606498195, 'mean_word_length': 4.464788732394366, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4421413', 'n_tokens_mistral': 795, 'n_tokens_neox': 734, 'n_words': 156}