@@ -33,25 +33,9 @@ public static String[] getOwnlangArgs() {
3333 public static void main (String [] args ) throws IOException {
3434 if (args .length == 0 ) {
3535 try {
36- final Options options = new Options ();
37- options .showAst = false ;
38- options .showTokens = false ;
39- options .showMeasurements = false ;
40- options .lintMode = false ;
41- options .optimizationLevel = 0 ;
42- run (SourceLoader .readSource ("program.own" ), options );
36+ runDefault ();
4337 } catch (IOException ioe ) {
44- System .out .println ("OwnLang version " + VERSION + "\n \n " +
45- "Usage: ownlang [options]\n " +
46- " options:\n " +
47- " -f, --file [input] Run program file. Required.\n " +
48- " -r, --repl Enter to a REPL mode\n " +
49- " -l, --lint Find bugs in code\n " +
50- " -o N, --optimize N Perform optimization with N passes\n " +
51- " -b, --beautify Beautify source code\n " +
52- " -a, --showast Show AST of program\n " +
53- " -t, --showtokens Show lexical tokens\n " +
54- " -m, --showtime Show elapsed time of parsing and execution" );
38+ printUsage ();
5539 }
5640 return ;
5741 }
@@ -139,6 +123,30 @@ public static void main(String[] args) throws IOException {
139123 run (input , options );
140124 }
141125
126+ private static void runDefault () throws IOException {
127+ final Options options = new Options ();
128+ options .showAst = false ;
129+ options .showTokens = false ;
130+ options .showMeasurements = false ;
131+ options .lintMode = false ;
132+ options .optimizationLevel = 0 ;
133+ run (SourceLoader .readSource ("program.own" ), options );
134+ }
135+
136+ private static void printUsage () {
137+ System .out .println ("OwnLang version " + VERSION + "\n \n " +
138+ "Usage: ownlang [options]\n " +
139+ " options:\n " +
140+ " -f, --file [input] Run program file. Required.\n " +
141+ " -r, --repl Enter to a REPL mode\n " +
142+ " -l, --lint Find bugs in code\n " +
143+ " -o N, --optimize N Perform optimization with N passes\n " +
144+ " -b, --beautify Beautify source code\n " +
145+ " -a, --showast Show AST of program\n " +
146+ " -t, --showtokens Show lexical tokens\n " +
147+ " -m, --showtime Show elapsed time of parsing and execution" );
148+ }
149+
142150 private static void createOwnLangArgs (String [] javaArgs , int index ) {
143151 if (index >= javaArgs .length ) return ;
144152 ownlangArgs = new String [javaArgs .length - index ];
@@ -152,7 +160,8 @@ private static void run(String input, Options options) {
152160 final List <Token > tokens = Lexer .tokenize (input );
153161 measurement .stop ("Tokenize time" );
154162 if (options .showTokens ) {
155- for (int i = 0 ; i < tokens .size (); i ++) {
163+ final int tokensCount = tokens .size ();
164+ for (int i = 0 ; i < tokensCount ; i ++) {
156165 System .out .println (i + " " + tokens .get (i ));
157166 }
158167 }
@@ -205,16 +214,16 @@ private static class Options {
205214 boolean lintMode ;
206215 int optimizationLevel ;
207216
208- public Options () {
217+ Options () {
209218 showTokens = false ;
210219 showAst = false ;
211220 showMeasurements = false ;
212221 lintMode = false ;
213222 optimizationLevel = 0 ;
214223 }
215224
216- public void validate () {
217- if (lintMode == true ) {
225+ void validate () {
226+ if (lintMode ) {
218227 showTokens = false ;
219228 showAst = false ;
220229 showMeasurements = false ;
0 commit comments