diff options
Diffstat (limited to 'src/main/java/org/shedlang/compiler/ShedCompiler.java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ShedCompiler.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/ShedCompiler.java b/src/main/java/org/shedlang/compiler/ShedCompiler.java new file mode 100644 index 00000000..a7949d53 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/ShedCompiler.java @@ -0,0 +1,63 @@ +package org.shedlang.compiler; + +import org.shedlang.compiler.parser.Parser; +import org.shedlang.compiler.sources.Sources; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + +import static org.shedlang.compiler.parser.Tokeniser.tokenise; + +public class ShedCompiler { + public void compile(Path projectRoot) throws IOException { + var sourceRoot = projectRoot.resolve("src"); + + var sourceFilePaths = collectSourceFilePaths(sourceRoot); + + for (var sourceFilePath : sourceFilePaths) { + System.out.println(sourceFilePath); + + var sourceContents = Files.readString(sourceFilePath, StandardCharsets.UTF_8); + var source = Sources.file(sourceFilePath.toString(), sourceContents); + var tokens = tokenise(source); + var node = Parser.parseNamespace(tokens); + System.out.println(node); + + System.out.println(); + } + } + + private List<Path> collectSourceFilePaths(Path sourceRoot) throws IOException { + var paths = new ArrayList<Path>(); + Files.walkFileTree(sourceRoot, new SimpleFileVisitor<Path>() { + @Override + public FileVisitResult visitFile( + Path file, + BasicFileAttributes attrs + ) { + if (file.getFileName().toString().endsWith(".shed")) { + paths.add(file); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory( + Path dir, + IOException exc + ) { + return FileVisitResult.CONTINUE; + } + }); + paths.sort(Comparator.naturalOrder()); + return paths; + } +} |
