-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.issy; | ||
|
||
import com.issy.compiler.FileMatcher; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class Walker { | ||
|
||
public List<String> walk(String startPath, FileMatcher fileMatcher) { | ||
try (Stream<Path> pathStream = Files.walk(Path.of(startPath))) { | ||
return pathStream.map(Path::toString).filter(fileMatcher::matches).toList(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Error reading file: " + e.getMessage()); | ||
} catch (SecurityException e) { | ||
throw new RuntimeException("Not permitted to read file: " + e.getMessage()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
package com.issy.compiler; | ||
|
||
// TODO: Include line:col position data for better error messages | ||
public record TokenContext(Token token, String value) { | ||
public record TokenContext(Token token, String value, Integer line, Integer column) { | ||
|
||
public static TokenContext withPosition(Token token, String value, Lexer.Position position) { | ||
return new TokenContext(token, value, position.line(), position.column()); | ||
} | ||
|
||
public String getFormattedPosition() { | ||
return String.format("%d:%d", line + 1, column); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters