feat: 支持标准 URL 格式

This commit is contained in:
zhangxun 2025-08-04 15:01:11 +08:00
parent 3a2a1363e6
commit 3e7e5f2dad
5 changed files with 5 additions and 5 deletions

View File

@ -37,7 +37,7 @@ public class LexerEngine {
* @param sourceName 文件名诊断用
*/
public LexerEngine(String source, String sourceName) {
this.absPath = new File(sourceName).getAbsolutePath();
this.absPath = new File(sourceName).getAbsolutePath().replace('\\', '/');
this.context = new LexerContext(source);
this.scanners = List.of(
new WhitespaceTokenScanner(),

View File

@ -50,6 +50,6 @@ public class LexicalError {
*/
@Override
public String toString() {
return file + ":" + line + ":" + column + ": " + message;
return "file:///" + file + ":" + line + ":" + column + ": " + message;
}
}

View File

@ -40,6 +40,6 @@ public class ParseError {
*/
@Override
public String toString() {
return file + ":" + line + ":" + column + ": " + message;
return "file:///" + file + ":" + line + ":" + column + ": " + message;
}
}

View File

@ -39,7 +39,7 @@ public class ParserContext {
*/
public ParserContext(List<Token> tokens, String sourceName) {
this.tokens = new TokenStream(tokens);
this.sourceName = Paths.get(sourceName).toAbsolutePath().toString();
this.sourceName = Paths.get(sourceName).toAbsolutePath().toString().replace('\\', '/');
}

View File

@ -48,7 +48,7 @@ public record SemanticError(Node node, String message) {
}
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder("file:///");
if (file != null && !file.isBlank()) sb.append(file).append(":");
sb.append((line >= 0 && col >= 0) ? line + ":" + col : "未知位置");
sb.append(": ").append(message);