Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
44million committed Dec 3, 2023
1 parent ff5362a commit 63ff99b
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 122 deletions.
64 changes: 34 additions & 30 deletions src/main/java/qlang/core/lang/NativeFunctionLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public NativeFunctionLoader() {

}

public NativeFunctionLoader registerNatives() {
public void registerNatives() {
// register libraries, the text is the name of the library, and then boolean is whether or not it's formatted
// unformatted livraries look like `.q.std` as opposed to formatted, which is just `std` or `q.std`.
Util.register("std", true);
Expand Down Expand Up @@ -931,38 +931,43 @@ public String parent() {
public void exec(List<Value> list) {
String method = list.get(0).toString();

if (method.equals("parseString")) {
String str = list.get(1).toString();
Parser.execBlock(str);
} else if (method.equals("parseFile")) {
String file = list.get(1).toString();

try {
String fcontents = CharStreams.fromFileName(file).toString();
Parser parser = new Parser().fromText(fcontents);
parser.parse(false);
} catch (IOException e) {
throw new Problem(e.getMessage());
switch (method) {
case "parseString" -> {
String str = list.get(1).toString();
Parser.execBlock(str);
}
} else if (method.equals("parseStringWith")) {
String str = list.get(1).toString();
Parser.execBlock(str);

String with = list.get(2).toString();
Parser.execBlock(with);
} else if (method.equals("parseFileWith")) {
String file = list.get(1).toString();
case "parseFile" -> {
String file = list.get(1).toString();

try {
String fcontents = CharStreams.fromFileName(file).toString();
Parser parser = new Parser().fromText(fcontents);
parser.parse(false);
} catch (IOException e) {
throw new Problem(e.getMessage());
}
}
case "parseStringWith" -> {
String str = list.get(1).toString();
Parser.execBlock(str);

try {
String fcontents = CharStreams.fromFileName(file).toString();
Parser parser = new Parser().fromText(fcontents);
parser.parse(false);
} catch (IOException e) {
throw new Problem(e.getMessage());
String with = list.get(2).toString();
Parser.execBlock(with);
}
case "parseFileWith" -> {
String file = list.get(1).toString();

try {
String fcontents = CharStreams.fromFileName(file).toString();
Parser parser = new Parser().fromText(fcontents);
parser.parse(false);
} catch (IOException e) {
throw new Problem(e.getMessage());
}

String with = list.get(2).toString();
Parser.execBlock(with);
String with = list.get(2).toString();
Parser.execBlock(with);
}
}
}

Expand Down Expand Up @@ -1217,6 +1222,5 @@ public boolean args() {
return true;
}
});
return this;
}
}
7 changes: 6 additions & 1 deletion src/main/java/qlang/core/lang/Q/QFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ public QFile execute() {

System.err.println(err);
if (Environment.global.verbose) {
e.printStackTrace();
StackTraceElement[] s = e.getStackTrace();

for (StackTraceElement s1 : s) {
System.err.println(s1.toString());
}

}

if (err.contains("FATAL")) {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/qlang/core/lang/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.nio.file.Paths;
import java.util.*;

import static java.nio.file.Files.walk;

/*
Misc file, full of stuff I may or may not even need anymore
*/
Expand Down Expand Up @@ -111,9 +113,8 @@ public static void execute(String cmd) {
String result = null;
try (InputStream inputStream = Runtime.getRuntime().exec(cmd).getInputStream();
Scanner s = new Scanner(inputStream).useDelimiter("\\A")) {
result = s.hasNext() ? s.next() : null;
result = s.hasNext() ? s.next() : null;
} catch (IOException e) {
//e.printStackTrace();
throw new Problem(e);
}
}
Expand Down Expand Up @@ -148,9 +149,8 @@ public static String getTextFromLink(String link) {
} catch (MalformedURLException e1) {
throw new Problem(e1.getMessage());
}
HttpURLConnection http = null;
HttpURLConnection http;
try {
assert url != null;
http = (HttpURLConnection) url.openConnection();
} catch (IOException e1) {
throw new Problem(e1);
Expand Down Expand Up @@ -322,14 +322,13 @@ public static String execCmd(String cmd) {

public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation)
throws IOException {
Files.walk(Paths.get(sourceDirectoryLocation))
walk(Paths.get(sourceDirectoryLocation))
.forEach(source -> {
Path destination = Paths.get(destinationDirectoryLocation, source.toString()
.substring(sourceDirectoryLocation.length()));
try {
Files.copy(source, destination);
} catch (IOException e) {
//e.printStackTrace();
throw new Problem(e.getMessage());
}
});
Expand Down
Loading

0 comments on commit 63ff99b

Please sign in to comment.