11package vong .piler .her ;
22
3+ import java .io .BufferedReader ;
4+ import java .io .ByteArrayInputStream ;
35import java .io .File ;
6+ import java .io .InputStream ;
7+ import java .io .InputStreamReader ;
48import java .nio .file .Files ;
9+ import java .util .Iterator ;
510import java .util .List ;
611
712import org .apache .commons .cli .CommandLine ;
1116import org .apache .commons .cli .Option ;
1217import org .apache .commons .cli .Options ;
1318import org .apache .commons .cli .ParseException ;
14- import org .apache .logging .log4j .Logger ;
15- import org .apache .logging .log4j .core .config .Configurator ;
1619import org .apache .logging .log4j .Level ;
1720import org .apache .logging .log4j .LogManager ;
21+ import org .apache .logging .log4j .Logger ;
22+ import org .apache .logging .log4j .core .config .Configurator ;
1823
1924import vong .piler .her .generator .Generator ;
2025import 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 );
0 commit comments