!55 feature: 增强错误定位
Merge pull request !55 from zhangxun/feature/enhancement-error-location
This commit is contained in:
commit
5fdb86cd1b
@ -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(),
|
||||
|
||||
@ -50,6 +50,6 @@ public class LexicalError {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return file + ": 行 " + line + ", 列 " + column + ": " + message;
|
||||
return "file:///" + file + ":" + line + ":" + column + ": " + message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +40,6 @@ public class ParseError {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return file + ": 行 " + line + ", 列 " + column + ": " + message;
|
||||
return "file:///" + file + ":" + line + ":" + column + ": " + message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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('\\', '/');
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -48,9 +48,9 @@ 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((line >= 0 && col >= 0) ? line + ":" + col : "未知位置");
|
||||
sb.append(": ").append(message);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user