From 2a74651cf75dbb9db5c1b16a70433aee3ed5c01d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 23 Dec 2024 09:25:22 +0000 Subject: Allow construction of file source with Path --- src/main/java/org/shedlang/compiler/ShedCompiler.java | 2 +- src/main/java/org/shedlang/compiler/sources/Sources.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java index 45c189bf..0efbe1d5 100644 --- a/src/main/java/org/shedlang/compiler/ShedCompiler.java +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -131,7 +131,7 @@ public class ShedCompiler { var namespaceName = new NamespaceName(namespaceNameParts); var sourceContents = Files.readString(sourceFilePath, StandardCharsets.UTF_8); - var source = Sources.file(sourceFilePath.toString(), sourceContents); + var source = Sources.file(sourceFilePath, sourceContents); var tokens = tokenise(source); diff --git a/src/main/java/org/shedlang/compiler/sources/Sources.java b/src/main/java/org/shedlang/compiler/sources/Sources.java index 5fb6a3b0..9a556aff 100644 --- a/src/main/java/org/shedlang/compiler/sources/Sources.java +++ b/src/main/java/org/shedlang/compiler/sources/Sources.java @@ -1,9 +1,15 @@ package org.shedlang.compiler.sources; +import java.nio.file.Path; + public class Sources { public static Source NULL = NullSource.INSTANCE; public static Source RUNTIME = RuntimeSource.INSTANCE; + public static Source file(Path path, String contents) { + return FileFragmentSource.file(path.toString(), contents); + } + public static Source file(String filename, String contents) { return FileFragmentSource.file(filename, contents); } -- cgit v1.2.3