@@ -33,25 +33,9 @@ public static String[] getOwnlangArgs() {
33
33
public static void main (String [] args ) throws IOException {
34
34
if (args .length == 0 ) {
35
35
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 ();
43
37
} 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 ();
55
39
}
56
40
return ;
57
41
}
@@ -139,6 +123,30 @@ public static void main(String[] args) throws IOException {
139
123
run (input , options );
140
124
}
141
125
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
+
142
150
private static void createOwnLangArgs (String [] javaArgs , int index ) {
143
151
if (index >= javaArgs .length ) return ;
144
152
ownlangArgs = new String [javaArgs .length - index ];
@@ -152,7 +160,8 @@ private static void run(String input, Options options) {
152
160
final List <Token > tokens = Lexer .tokenize (input );
153
161
measurement .stop ("Tokenize time" );
154
162
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 ++) {
156
165
System .out .println (i + " " + tokens .get (i ));
157
166
}
158
167
}
@@ -205,16 +214,16 @@ private static class Options {
205
214
boolean lintMode ;
206
215
int optimizationLevel ;
207
216
208
- public Options () {
217
+ Options () {
209
218
showTokens = false ;
210
219
showAst = false ;
211
220
showMeasurements = false ;
212
221
lintMode = false ;
213
222
optimizationLevel = 0 ;
214
223
}
215
224
216
- public void validate () {
217
- if (lintMode == true ) {
225
+ void validate () {
226
+ if (lintMode ) {
218
227
showTokens = false ;
219
228
showAst = false ;
220
229
showMeasurements = false ;
0 commit comments