<commit_before>import { Node } from "../Node"
import { Source } from "../Source"
import { Block } from "./Block"
import { Inline } from "../Inline/Inline"
import { Template } from "../Template"
import { Renderer } from "../Renderer"
import { Error, Uri } from "@cogneco/mend"

import * as fs from "fs"

export class Assignment extends Block {
	constructor(private name: string, private value: string, region: Error.Region) {
		super(region)
	}
	getName(): string { return this.name }
	getValue(): string { return this.value }
	async render(renderer: Renderer): Promise<string> {
		renderer.setVariable(this.name, this.value)
		if (this.name == "template") {
			const templatePath = Uri.Locator.parse(this.value + ".json")
			renderer.setVariable("template-path", templatePath ? templatePath.folder.toString() : "")
			const documentPath = this.getRegion().resource
			const location = templatePath ? templatePath.resolve(documentPath) : documentPath || new Uri.Locator()
			const nativePath = (location.isRelative ? "" : "/") + location.path.join("/")
			let content: string
			try {
				content = fs.readFileSync(nativePath, "utf-8")
				try {
					renderer.setTemplate(JSON.parse(content) as Template)
				} catch (error) {
					console.error(`Failed to parse template: ${nativePath}`)
				}
			} catch (error) {
				console.error(`Failed to open template: ${nativePath}`)
			}
		}
		return ""
	}
	toObject(): any {
		return { type: "Assignment", name: this.name, value: this.value }
	}<commit_msg>Added support for windows paths.<commit_after>import { Node } from "../Node"
import { Source } from "../Source"
import { Block } from "./Block"
import { Inline } from "../Inline/Inline"
import { Template } from "../Template"
import { Renderer } from "../Renderer"
import { Error, Uri } from "@cogneco/mend"

import * as fs from "fs"
import * as path from "path"

export class Assignment extends Block {
	constructor(private name: string, private value: string, region: Error.Region) {
		super(region)
	}
	getName(): string { return this.name }
	getValue(): string { return this.value }
	async render(renderer: Renderer): Promise<string> {
		renderer.setVariable(this.name, this.value)
		if (this.name == "template") {
			const templatePath = Uri.Locator.parse(this.value + ".json")
			renderer.setVariable("template-path", templatePath ? templatePath.folder.toString() : "")
			const documentPath = this.getRegion().resource
			const location = templatePath ? templatePath.resolve(documentPath) : documentPath || new Uri.Locator()
			const nativePath = (location.isRelative ? "" : path.sep) + location.path.join(path.sep)
			let content: string
			try {
				content = fs.readFileSync(nativePath, "utf-8")
				try {
					renderer.setTemplate(JSON.parse(content) as Template)
				} catch (error) {
					console.error(`Failed to parse template: ${nativePath}`)
				}
			} catch (error) {
				console.error(`Failed to open template: ${nativePath}`)
			}
		}
		return ""
	}
	toObject(): any {
		return { type: "Assignment", name: this.name, value: this.value }
	}
{'fraction_non_alphanumeric': 0.14780902550686723, 'fraction_numerical': 0.0006540222367560497, 'mean_word_length': 3.8865814696485623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '502433', 'n_tokens_mistral': 1005, 'n_tokens_neox': 917, 'n_words': 252}