Skip to content

Commit 14cf9d4

Browse files
committed
Clean up
1 parent f8710a3 commit 14cf9d4

27 files changed

Lines changed: 84 additions & 4119 deletions

.idea/workspace.xml

Lines changed: 23 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ko.carbonel.compiler.runner;
2+
3+
import ko.carbonel.Logger;
4+
import ko.carbonel.compiler.AttributeParser;
5+
import ko.carbonel.compiler.ParserAssistant;
6+
import ko.carbonel.compiler.config.ArgumentName;
7+
import ko.carbonel.compiler.config.Config;
8+
import ko.carbonel.compiler.intermediate.SymbolTable;
9+
import ko.carbonel.compiler.stream.lexer.Lexer;
10+
import ko.carbonel.compiler.stream.lexer.LexerToken;
11+
import ko.carbonel.compiler.stream.reader.FileSourceReader;
12+
13+
import java.util.function.Function;
14+
15+
import static ko.carbonel.json.SerializeClass.Value.AST;
16+
import static ko.carbonel.json.SerializeClass.Value.TS;
17+
18+
public class ASTParserRunner<P extends ParserAssistant<T, TT> & AttributeParser<S>, T extends LexerToken<TT>, TT extends Enum<TT>, S extends SymbolTable> extends STParserRunner<P, T, TT, S> {
19+
public ASTParserRunner(Function<FileSourceReader, Lexer<T, TT>> lexerSupplier, Function<Lexer<T, TT>, P> parserSupplier, boolean doAlphabetCheck) {
20+
super(lexerSupplier, parserSupplier, doAlphabetCheck);
21+
}
22+
23+
@Override
24+
protected void afterParse(P parser) {
25+
parser.getSymbolTable().consolidate();
26+
parser.getSymbolTable().checkExpressions();
27+
Logger.output(Config.lang().semanticASTOK() + "\n");
28+
outputIntermediateRepr(parser, ArgumentName.OUTPUT_TS_FILE, ".ts.json", TS);
29+
outputIntermediateRepr(parser, ArgumentName.OUTPUT_AST_FILE, ".ast.json", AST);
30+
logCompactRender(parser);
31+
}
32+
}

src/main/java/ko/carbonel/compiler/runner/Runner.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ko.carbonel.compiler.exception.semantic.SemanticError;
1111
import ko.carbonel.compiler.runner.language.Language;
1212

13+
import java.io.File;
1314
import java.io.IOException;
1415
import java.io.OutputStream;
1516
import java.nio.charset.StandardCharsets;
@@ -58,4 +59,15 @@ protected void output(String s) {
5859
System.exit(-1);
5960
}
6061
}
62+
63+
protected void outputParallelFile(String defaultExtension, String content) {
64+
File file = new File(inputFileName);
65+
String name = file.getName();
66+
int i = name.lastIndexOf('.');
67+
if (i > 0) name = name.substring(0, i);
68+
name += defaultExtension;
69+
File parentFile = file.getParentFile();
70+
String newFileName = parentFile.getAbsolutePath() + "/" + name;
71+
Utils.writeFile(newFileName, content);
72+
}
6173
}

src/main/java/ko/carbonel/compiler/runner/Runners.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
package ko.carbonel.compiler.runner;
22

3-
import ko.carbonel.Logger;
4-
import ko.carbonel.compiler.AttributeParser;
5-
import ko.carbonel.compiler.codegen.DeCompiler;
6-
import ko.carbonel.compiler.config.ArgumentName;
73
import ko.carbonel.compiler.generated.AttrBNFParser;
84
import ko.carbonel.compiler.generated.AttrTinyRustParser;
95
import ko.carbonel.compiler.generated.BNFParser;
106
import ko.carbonel.compiler.generated.TinyRustParser;
117
import ko.carbonel.compiler.intermediate.tinyRust.TSSerializer;
12-
import ko.carbonel.compiler.intermediate.tinyRust.TinyRustSymbolTable;
138
import ko.carbonel.compiler.stream.lexer.bnf.BNFLexer;
149
import ko.carbonel.compiler.stream.lexer.tinyRust.TinyRustLexer;
1510

16-
import static ko.carbonel.json.SerializeClass.Value.AST;
17-
1811
public class Runners {
1912
// if (!inputFileName.endsWith(".rs")) Logger.inputRSWarning();
2013
public static final Runner TINY_RUST_PARSER = new GenericParserRunner<>(TinyRustLexer::new, TinyRustParser::new, true);
@@ -23,36 +16,7 @@ public class Runners {
2316
public static final Runner ATTR_BNF_PARSER = new STParserRunner<>(BNFLexer::new, AttrBNFParser::new, false);
2417
public static final Runner TINY_RUST_LEXER = new GenericLexerRunner<>(TinyRustLexer::new, true);
2518
public static final Runner BNF_LEXER = new GenericLexerRunner<>(BNFLexer::new, false);
26-
27-
public static final Runner TINY_RUST_AST_PARSER = new STParserRunner<>(TinyRustLexer::new, AttrTinyRustParser::new, true){
28-
protected void afterParse(AttrTinyRustParser parser) {
29-
super.afterParse(parser);
30-
String input = "";
31-
TinyRustSymbolTable st = ((AttributeParser<TinyRustSymbolTable>)parser).getSymbolTable();
32-
st.checkExpressions();
33-
String serialize = TSSerializer.serialize(st);
34-
Logger.output(serialize);
35-
36-
outputIntermediateRepr(parser, ArgumentName.OUTPUT_AST_FILE, ".ast.json", AST);
37-
// outputParallelFile("rsC", DeCompiler.decompile(st));
38-
Logger.output(DeCompiler.decompile(st));
39-
40-
// while (!input.equals("exit")){
41-
// try {
42-
// Logger.outputNoNewline("> ");
43-
// input = new BufferedReader(new InputStreamReader(System.in)).readLine();
44-
// TinyRustLexer tinyRustLexer = new TinyRustLexer(new StringSourceReader(input, true));
45-
// List<TinyRustLexerToken> tokens = tinyRustLexer.stream().toList();
46-
// Object o = ChainResolver.resolveChaining(st, tokens.stream().filter(it -> !it.type().equals(TinyRustTokenType.DOT)).toList());
47-
// Logger.output(o != null ? o.toString() : null);
48-
// } catch (IOException e) {
49-
// throw new RuntimeException(e);
50-
// } catch (CompilerError e){
51-
// Logger.error(e.getMessage(), e);
52-
// }
53-
// }
54-
}
55-
};
19+
public static final Runner TINY_RUST_AST_PARSER = new ASTParserRunner<>(TinyRustLexer::new, AttrTinyRustParser::new, true);
5620

5721
private Runners() {
5822
}

0 commit comments

Comments
 (0)