Skip to content

Commit 19b04b6

Browse files
authored
Merge pull request #77 from MastersOfDesaster/bug/win-utf8
Fix bug Windows UTF8 on consol
2 parents 53dfdab + 30789de commit 19b04b6

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

compiler/src/main/java/vong/piler/her/Main.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
package vong.piler.her;
22

3+
import java.io.BufferedReader;
4+
import java.io.ByteArrayInputStream;
35
import java.io.File;
6+
import java.io.InputStream;
7+
import java.io.InputStreamReader;
48
import java.nio.file.Files;
9+
import java.util.Iterator;
510
import java.util.List;
611

712
import org.apache.commons.cli.CommandLine;
@@ -11,10 +16,10 @@
1116
import org.apache.commons.cli.Option;
1217
import org.apache.commons.cli.Options;
1318
import org.apache.commons.cli.ParseException;
14-
import org.apache.logging.log4j.Logger;
15-
import org.apache.logging.log4j.core.config.Configurator;
1619
import org.apache.logging.log4j.Level;
1720
import org.apache.logging.log4j.LogManager;
21+
import org.apache.logging.log4j.Logger;
22+
import org.apache.logging.log4j.core.config.Configurator;
1823

1924
import vong.piler.her.generator.Generator;
2025
import vong.piler.her.lexer.Lexer;
@@ -41,29 +46,37 @@ public static void main(String[] args) {
4146

4247
CommandLineParser cliParser = new DefaultParser();
4348
try {
44-
CommandLine line = cliParser.parse(createOptions(), args);
49+
CommandLine cmdLine = cliParser.parse(createOptions(), args);
4550
String output = null;
4651

47-
if(line.hasOption("d")) {
52+
if(cmdLine.hasOption("d")) {
4853
Configurator.setLevel("vong.piler.her", Level.DEBUG);
4954
}
50-
if(line.hasOption("o")) {
51-
output = line.getOptionValue("o");
55+
if(cmdLine.hasOption("o")) {
56+
output = cmdLine.getOptionValue("o");
5257
}
53-
if(line.hasOption("h")) {
58+
if(cmdLine.hasOption("h")) {
5459
printHelp(createOptions());
5560
}else {
5661
try {
57-
String filename = line.getArgs()[0];
62+
String filename = cmdLine.getArgs()[0];
63+
64+
InputStream is = new ByteArrayInputStream(Files.readAllBytes(new File(filename).toPath()));
65+
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
66+
StringBuilder sourceBuilder = new StringBuilder();
67+
Iterator<String> sourceIterator = br.lines().iterator();
68+
while(sourceIterator.hasNext()) {
69+
sourceBuilder.append(sourceIterator.next()).append("\n");
70+
}
71+
String source = sourceBuilder.toString();
5872

59-
String source = new String(Files.readAllBytes(new File(filename).toPath()));
6073
List<Token> tokenList = lexer.lex(source);
6174
TreeNode root = parser.parse(tokenList);
6275

6376
if(output == null) {
6477
output = filename.replace(".vsh", ".vch");
6578
}
66-
if(line.hasOption("d")) {
79+
if(cmdLine.hasOption("d")) {
6780
testPrint(root, 2);
6881
}
6982
generator = new Generator(output);

compiler/src/main/java/vong/piler/her/enums/TokenTypeEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public enum TokenTypeEnum {
66
// whitespace
7-
COMMENT("((:X|:zipper_mouth_face:).*?(\n|\r\n)).*"), WHITESPACE("( |\t).*"), NEWLINE("(\n|\r\n).*"),
7+
COMMENT("((:X|:zipper_mouth_face:).*?(\n)).*"), WHITESPACE("( |\t).*"), NEWLINE("(\n).*"),
88

99
// program
1010
START("(was ist das für 1 code\\?).*", "was ist das für 1 code?"), // start

0 commit comments

Comments
 (0)