mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Немного рефакторинга и исправлений
This commit is contained in:
parent
795d7660f9
commit
eb7430f507
@ -8,6 +8,8 @@ import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class Console {
|
||||
|
||||
private Console() { }
|
||||
|
||||
private static final String FILE_PREFIX = "tmp/";
|
||||
private static boolean filePrefixEnabled;
|
||||
|
||||
|
@ -40,8 +40,7 @@ public final class Main {
|
||||
return;
|
||||
}
|
||||
|
||||
final Options options = new Options();
|
||||
boolean beautifyMode = false;
|
||||
final RunOptions options = new RunOptions();
|
||||
String input = null;
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
switch (args[i]) {
|
||||
@ -52,19 +51,19 @@ public final class Main {
|
||||
|
||||
case "-b":
|
||||
case "--beautify":
|
||||
beautifyMode = true;
|
||||
options.beautifyMode = true;
|
||||
break;
|
||||
|
||||
|
||||
case "-t":
|
||||
case "--showtokens":
|
||||
options.showTokens = true;
|
||||
break;
|
||||
|
||||
|
||||
case "-m":
|
||||
case "--showtime":
|
||||
options.showMeasurements = true;
|
||||
break;
|
||||
|
||||
|
||||
case "-o":
|
||||
case "--optimize":
|
||||
if (i + 1 < args.length) {
|
||||
@ -88,7 +87,7 @@ public final class Main {
|
||||
case "--lint":
|
||||
options.lintMode = true;
|
||||
return;
|
||||
|
||||
|
||||
case "-f":
|
||||
case "--file":
|
||||
if (i + 1 < args.length) {
|
||||
@ -104,7 +103,7 @@ public final class Main {
|
||||
System.arraycopy(ownlangArgs, 0, newArgs, 0, ownlangArgs.length);
|
||||
Sandbox.main(newArgs);
|
||||
return;
|
||||
|
||||
|
||||
default:
|
||||
if (input == null) {
|
||||
input = args[i];
|
||||
@ -116,7 +115,7 @@ public final class Main {
|
||||
if (input == null) {
|
||||
throw new IllegalArgumentException("Empty input");
|
||||
}
|
||||
if (beautifyMode) {
|
||||
if (options.beautifyMode) {
|
||||
System.out.println(Beautifier.beautify(input));
|
||||
return;
|
||||
}
|
||||
@ -124,12 +123,7 @@ public final class Main {
|
||||
}
|
||||
|
||||
private static void runDefault() throws IOException {
|
||||
final Options options = new Options();
|
||||
options.showAst = false;
|
||||
options.showTokens = false;
|
||||
options.showMeasurements = false;
|
||||
options.lintMode = false;
|
||||
options.optimizationLevel = 0;
|
||||
final RunOptions options = new RunOptions();
|
||||
run(SourceLoader.readSource("program.own"), options);
|
||||
}
|
||||
|
||||
@ -153,7 +147,7 @@ public final class Main {
|
||||
System.arraycopy(javaArgs, index, ownlangArgs, 0, ownlangArgs.length);
|
||||
}
|
||||
|
||||
private static void run(String input, Options options) {
|
||||
private static void run(String input, RunOptions options) {
|
||||
options.validate();
|
||||
final TimeMeasurement measurement = new TimeMeasurement();
|
||||
measurement.start("Tokenize time");
|
||||
@ -209,16 +203,18 @@ public final class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Options {
|
||||
private static class RunOptions {
|
||||
boolean showTokens, showAst, showMeasurements;
|
||||
boolean lintMode;
|
||||
boolean beautifyMode;
|
||||
int optimizationLevel;
|
||||
|
||||
Options() {
|
||||
RunOptions() {
|
||||
showTokens = false;
|
||||
showAst = false;
|
||||
showMeasurements = false;
|
||||
lintMode = false;
|
||||
beautifyMode = false;
|
||||
optimizationLevel = 0;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,8 @@ public class ParserTest {
|
||||
}
|
||||
|
||||
private static void assertStatements(BlockStatement expected, BlockStatement actual) {
|
||||
for (int i = 0; i < expected.statements.size(); i++) {
|
||||
final int size = expected.statements.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
assertEquals(expected.statements.get(i).getClass(), actual.statements.get(i).getClass());
|
||||
}
|
||||
}
|
||||
|
@ -36,12 +36,16 @@ public class ProgramsTest {
|
||||
public static Collection<String> data() {
|
||||
final File resDir = new File(RES_DIR);
|
||||
return scanDirectory(resDir)
|
||||
.map(f -> f.getPath())
|
||||
.map(File::getPath)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static Stream<File> scanDirectory(File dir) {
|
||||
return Arrays.stream(dir.listFiles())
|
||||
final File[] files = dir.listFiles();
|
||||
if (files == null || files.length == 0) {
|
||||
return Stream.empty();
|
||||
}
|
||||
return Arrays.stream(files)
|
||||
.flatMap(file -> {
|
||||
if (file.isDirectory()) {
|
||||
return scanDirectory(file);
|
||||
|
Loading…
Reference in New Issue
Block a user