Skip to content

Commit aad47f0

Browse files
committed
fix: arrumada logica de verificação da extensão do aquivo target
1 parent 9dd1766 commit aad47f0

18 files changed

Lines changed: 192 additions & 176 deletions

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ============================================================
2-
# Klang Project — .gitignore (Temporary Distribution Mode)
2+
# Klar Project — .gitignore (Temporary Distribution Mode)
33
# ============================================================
44

55
# ---------------------------
@@ -138,7 +138,7 @@ config/local.yml
138138
!*.k
139139

140140
# ---------------------------
141-
# KLANG-SPECIFIC
141+
# Klar-SPECIFIC
142142
# ---------------------------
143143
#*.kc
144144
#*.ko

cli/src/main/java/org/klar/cli/BuildCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ public void run() {
3232
String _fileName = path.getFileName().toString();
3333
String fileName = _fileName.substring(0, _fileName.length() - 2);
3434

35-
if (!_fileName.endsWith(".kl") || !_fileName.endsWith(".klar")) {
35+
System.err.println(_fileName);
36+
if (!_fileName.endsWith(".kl") && !_fileName.endsWith(".klar")) {
3637
throw new KcInvalidFileType(
3738
KcDiagnosticCode.KC002,
3839
"build",

cli/src/main/java/org/klar/cli/HelpCommand.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ private void printHelpBody() {
3838
str.append(" ").append(KcDiagnosticColors.structure("parse")).append(" ").append(KcDiagnosticColors.neutral("Parse file.k"))
3939
.append("\n");
4040

41-
str.append(" ").append(KcDiagnosticColors.structure("build")).append(" ").append(KcDiagnosticColors.neutral("Build Klang source to Java (for now)"))
41+
str.append(" ").append(KcDiagnosticColors.structure("build")).append(" ").append(KcDiagnosticColors.neutral("Build Klar source to Java (for now)"))
4242
.append("\n");
4343

44-
str.append(" ").append(KcDiagnosticColors.structure("run")).append(" ").append(KcDiagnosticColors.neutral("Transpile, compile and run a Klang program"))
44+
str.append(" ").append(KcDiagnosticColors.structure("run")).append(" ").append(KcDiagnosticColors.neutral("Transpile, compile and run a Klar program"))
4545
.append("\n");
4646

4747
str.append(" ").append(KcDiagnosticColors.structure("gen-completion")).append(" ").append(KcDiagnosticColors.neutral("Generate autocomplete script"))
@@ -52,7 +52,7 @@ private void printHelpBody() {
5252

5353
str.append(" ").append(KcDiagnosticColors.structure("-h")).append(KcDiagnosticColors.separator(", ")).append(KcDiagnosticColors.structure("--help")).append(" ").append(KcDiagnosticColors.neutral("Show this help catalog"))
5454
.append("\n");
55-
str.append(" ").append(KcDiagnosticColors.structure("-V")).append(KcDiagnosticColors.separator(", ")).append(KcDiagnosticColors.structure("--version")).append(" ").append(KcDiagnosticColors.neutral("Show Klang version"))
55+
str.append(" ").append(KcDiagnosticColors.structure("-V")).append(KcDiagnosticColors.separator(", ")).append(KcDiagnosticColors.structure("--version")).append(" ").append(KcDiagnosticColors.neutral("Show Klar version"))
5656
.append(NEW_LINE);
5757

5858
str.append(" ").append(KcDiagnosticColors.structure("Examples"))

cli/src/main/java/org/klar/cli/KMain.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.klar.cli;
22

3-
import org.klar.cli.error.KlangExceptionHandler;
4-
import org.klar.cli.error.KlangParameterExceptionHandler;
3+
import org.klar.cli.error.KlarExceptionHandler;
4+
import org.klar.cli.error.KlarParameterExceptionHandler;
55
import org.klar.core.errors.KException;
66

77
import picocli.CommandLine;
@@ -56,8 +56,8 @@ public static void main(String[] args) {
5656
try {
5757
CommandLine cmd = new CommandLine(new KMain());
5858

59-
cmd.setExecutionExceptionHandler(new KlangExceptionHandler());
60-
cmd.setParameterExceptionHandler(new KlangParameterExceptionHandler());
59+
cmd.setExecutionExceptionHandler(new KlarExceptionHandler());
60+
cmd.setParameterExceptionHandler(new KlarParameterExceptionHandler());
6161

6262
int exitCode = cmd.execute(args);
6363
System.exit(exitCode);

cli/src/main/java/org/klar/cli/KVersionProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import picocli.CommandLine.IVersionProvider;
66

77
public class KVersionProvider implements IVersionProvider {
8-
private static final String VERSION = "0.13.0";
8+
private static final String VERSION = "0.13.1";
99
private static final StringBuilder str = new StringBuilder();
1010

1111
@Override

cli/src/main/java/org/klar/cli/LexCommand.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,24 @@
1616
import org.klar.core.lexer.Lexer;
1717
import org.klar.core.lexer.Token;
1818

19-
@Command(
20-
name = "lex",
21-
description = "Show file tokens"
22-
)
19+
@Command(name = "lex", description = "Show file tokens")
2320
public class LexCommand implements Runnable {
2421

2522
@Parameters(paramLabel = "FILE")
2623
private File file;
2724

28-
@Option(names = {"--show-tokens", "-st"}, description = "Explicitly show tokens")
25+
@Option(names = { "--show-tokens", "-st" }, description = "Explicitly show tokens")
2926
private boolean showTokens = false;
3027

31-
@Option(names = {"--show-error", "-se"}, description = "Explicitly show tokens")
28+
@Option(names = { "--show-error", "-se" }, description = "Explicitly show tokens")
3229
private boolean showError = false;
3330

3431
@Override
3532
public void run() {
3633
Path path = file.toPath();
3734
String fileName = path.getFileName().toString();
3835

39-
if (!fileName.endsWith(".kl") || !fileName.endsWith(".klar")) {
36+
if (!fileName.endsWith(".kl") && !fileName.endsWith(".klar")) {
4037

4138
throw new KcInvalidFileType(KcDiagnosticCode.KC002, "lex", null, path.getFileName().toString());
4239
}
@@ -48,23 +45,24 @@ public void run() {
4845
Lexer lexer = new Lexer(source, file.getPath(), sourceManager);
4946
List<Token> a = lexer.tokenizeSourceCode();
5047

51-
if (showTokens){
48+
if (showTokens) {
5249
for (Token var : a) {
5350
System.out.println(var);
54-
};
51+
}
52+
;
5553
} else {
5654
System.out.println("Lexing successful! (Use --show-tokens to see the output)");
5755
}
58-
5956

6057
} catch (KException e) {
6158
System.out.println(e.format());
6259

6360
} catch (Exception e) {
64-
if (showError){
61+
if (showError) {
6562
e.printStackTrace();
66-
}{
67-
System.out.println("Use --show-error or -se to show stack trace");
63+
}
64+
{
65+
System.out.println("Use --show-error or -se to show stack trace");
6866
}
6967
throw new RuntimeException("Internal compiler error", e);
7068
}

cli/src/main/java/org/klar/cli/ParseCommand.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import org.klar.core.parser.Parser;
1717
import org.klar.core.parser.ast.ProgramNode;
1818

19-
@Command(
20-
name = "parse",
21-
description = "Parse file.kl | file.klar"
22-
)
19+
@Command(name = "parse", description = "Parse file.kl | file.klar")
2320
public class ParseCommand implements Runnable {
2421

2522
@Parameters(paramLabel = "FILE")
@@ -30,12 +27,12 @@ public void run() {
3027
Path path = file.toPath();
3128
String fileName = path.getFileName().toString();
3229

33-
if (!fileName.endsWith(".kl") || !fileName.endsWith(".klar")) {
30+
if (!fileName.endsWith(".kl") && !fileName.endsWith(".klar")) {
3431
throw new KcInvalidFileType(
35-
KcDiagnosticCode.KC002,
36-
"parse",
37-
null,
38-
path.getFileName().toString());
32+
KcDiagnosticCode.KC002,
33+
"parse",
34+
null,
35+
path.getFileName().toString());
3936
}
4037

4138
try {

cli/src/main/java/org/klar/cli/RunCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public void run() {
6161
boolean needsRebuild = BuildCache.needsRebuild(path, cacheFile) || !Files.exists(classFile);
6262

6363
if (needsRebuild) {
64-
// System.out.println("Building " + fileName + ".k...");
6564

6665
// 1. Read
6766
String source = Files.readString(path);

cli/src/main/java/org/klar/cli/error/KcInvalidFileType.java

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,49 @@
33
import org.klar.cli.error.diagnostic.KcDiagnosticCode;
44
import org.klar.cli.error.diagnostic.KcDiagnosticColors;
55

6-
public class KcInvalidFileType extends KcCliException{
7-
private final String fileName;
8-
9-
public KcInvalidFileType(KcDiagnosticCode code, String command, String fix, String fileName){
10-
super(code, command, fix);
11-
12-
this.fileName = fileName;
13-
}
14-
15-
@Override
16-
public String format() {
17-
StringBuilder sb = new StringBuilder();
18-
sb.append(KcDiagnosticColors.structure("[K:"))
19-
.append(KcDiagnosticColors.cliErrorCode(code.name()))
20-
.append(KcDiagnosticColors.structure("] "))
21-
.append(KcDiagnosticColors.neutral(code.name))
22-
.append("\n");
23-
24-
// ERROR (Lexical) discreto, só informativo
25-
sb.append(KcDiagnosticColors.structure("ERROR (" + code.phase.name() + ")"))
26-
.append("\n");
27-
28-
sb.append(KcDiagnosticColors.structure("at input file"))
29-
.append("\n\n");
30-
31-
sb.append(KcDiagnosticColors.structure("The file '")).append(KcDiagnosticColors.neutral(fileName)).append(KcDiagnosticColors.structure("' is not a Klang source file."))
32-
.append("\n\n");
33-
34-
sb.append(KcDiagnosticColors.structure("Cause:"))
35-
.append("\n ")
36-
.append(KcDiagnosticColors.neutral("Klar only processes files with the extensions '.kl' and '.klar'."))
37-
.append("\n\n");
38-
39-
sb.append(KcDiagnosticColors.structure("Fix:"))
40-
.append("\n ")
41-
.append(KcDiagnosticColors.neutral("Rename the file or select a valid '.kl' or '.klar' source."))
42-
.append("\n\n");
43-
44-
sb.append(KcDiagnosticColors.structure("Example:"))
45-
.append("\n ")
46-
.append(KcDiagnosticColors.neutral("kc " + this.command +" program.kl"));
47-
48-
return sb.toString();
49-
}
6+
public class KcInvalidFileType extends KcCliException {
7+
private final String fileName;
8+
9+
public KcInvalidFileType(KcDiagnosticCode code, String command, String fix, String fileName) {
10+
super(code, command, fix);
11+
12+
this.fileName = fileName;
13+
}
14+
15+
@Override
16+
public String format() {
17+
StringBuilder sb = new StringBuilder();
18+
sb.append(KcDiagnosticColors.structure("[K:"))
19+
.append(KcDiagnosticColors.cliErrorCode(code.name()))
20+
.append(KcDiagnosticColors.structure("] "))
21+
.append(KcDiagnosticColors.neutral(code.name))
22+
.append("\n");
23+
24+
// ERROR (Lexical) discreto, só informativo
25+
sb.append(KcDiagnosticColors.structure("ERROR (" + code.phase.name() + ")"))
26+
.append("\n");
27+
28+
sb.append(KcDiagnosticColors.structure("at input file"))
29+
.append("\n\n");
30+
31+
sb.append(KcDiagnosticColors.structure("The file '")).append(KcDiagnosticColors.neutral(fileName))
32+
.append(KcDiagnosticColors.structure("' is not a Klar source file."))
33+
.append("\n\n");
34+
35+
sb.append(KcDiagnosticColors.structure("Cause:"))
36+
.append("\n ")
37+
.append(KcDiagnosticColors.neutral("Klar only processes files with the extensions '.kl' and '.klar'."))
38+
.append("\n\n");
39+
40+
sb.append(KcDiagnosticColors.structure("Fix:"))
41+
.append("\n ")
42+
.append(KcDiagnosticColors.neutral("Rename the file or select a valid '.kl' or '.klar' source."))
43+
.append("\n\n");
44+
45+
sb.append(KcDiagnosticColors.structure("Example:"))
46+
.append("\n ")
47+
.append(KcDiagnosticColors.neutral("kc " + this.command + " program.kl"));
48+
49+
return sb.toString();
50+
}
5051
}

cli/src/main/java/org/klar/cli/error/KlangExceptionHandler.java renamed to cli/src/main/java/org/klar/cli/error/KlarExceptionHandler.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@
44

55
import picocli.CommandLine;
66

7-
public class KlangExceptionHandler implements CommandLine.IExecutionExceptionHandler {
7+
public class KlarExceptionHandler implements CommandLine.IExecutionExceptionHandler {
88

99
@Override
1010
public int handleExecutionException(
11-
Exception ex,
12-
CommandLine commandLine,
11+
Exception ex,
12+
CommandLine commandLine,
1313
CommandLine.ParseResult parseResult) {
14-
15-
// ===== CASO 1: Exceções customizadas do Klang (LexicalException, etc) =====
14+
15+
// ===== CASO 1: Exceções customizadas do Klar (LexicalException, etc) =====
1616
if (ex instanceof KException) {
1717
KException kex = (KException) ex;
1818
System.err.println(kex.format());
1919
return 1;
2020
}
21-
21+
2222
// ===== CASO 2: Exceções de CLI customizadas =====
2323
if (ex instanceof KcCliException) {
2424
KcCliException cliEx = (KcCliException) ex;
2525
System.err.println(cliEx.format());
2626
return 1;
2727
}
28-
28+
2929
// ===== CASO 3: RuntimeException genéricas =====
3030
if (ex instanceof RuntimeException) {
3131
System.err.println("Runtime error: " + ex.getMessage());
@@ -34,7 +34,7 @@ public int handleExecutionException(
3434
}
3535
return 1;
3636
}
37-
37+
3838
// ===== CASO 4: Outras exceções =====
3939
System.err.println("Unexpected error: " + ex.getMessage());
4040
ex.printStackTrace(System.err);

0 commit comments

Comments
 (0)