44import com .annimon .ownlang .exceptions .LexerException ;
55import com .annimon .ownlang .parser .Beautifier ;
66import com .annimon .ownlang .parser .Lexer ;
7+ import com .annimon .ownlang .parser .Linter ;
78import com .annimon .ownlang .parser .Parser ;
89import com .annimon .ownlang .parser .SourceLoader ;
910import com .annimon .ownlang .parser .Token ;
@@ -34,13 +35,15 @@ public static void main(String[] args) throws IOException {
3435 options .showAst = true ;
3536 options .showTokens = true ;
3637 options .showMeasurements = true ;
38+ options .lintMode = true ;
3739 run (SourceLoader .readSource ("program.own" ), options );
3840 } catch (IOException ioe ) {
3941 System .out .println ("OwnLang version " + VERSION + "\n \n " +
4042 "Usage: ownlang [options]\n " +
4143 " options:\n " +
4244 " -f, --file [input] Run program file. Required.\n " +
4345 " -r, --repl Enter to a REPL mode\n " +
46+ " -l, --lint Find bugs in code\n " +
4447 " -b, --beautify Beautify source code\n " +
4548 " -a, --showast Show AST of program\n " +
4649 " -t, --showtokens Show lexical tokens\n " +
@@ -78,6 +81,11 @@ public static void main(String[] args) throws IOException {
7881 case "--repl" :
7982 repl ();
8083 return ;
84+
85+ case "-l" :
86+ case "--lint" :
87+ options .lintMode = true ;
88+ return ;
8189
8290 case "-f" :
8391 case "--file" :
@@ -113,6 +121,7 @@ private static void createOwnLangArgs(String[] javaArgs, int index) {
113121 }
114122
115123 private static void run (String input , Options options ) {
124+ options .validate ();
116125 final TimeMeasurement measurement = new TimeMeasurement ();
117126 measurement .start ("Tokenize time" );
118127 final List <Token > tokens = Lexer .tokenize (input );
@@ -134,6 +143,10 @@ private static void run(String input, Options options) {
134143 System .out .println (parser .getParseErrors ());
135144 return ;
136145 }
146+ if (options .lintMode ) {
147+ Linter .lint (program );
148+ return ;
149+ }
137150 program .accept (new FunctionAdder ());
138151 try {
139152 measurement .start ("Execution time" );
@@ -189,11 +202,21 @@ private static void repl() {
189202
190203 private static class Options {
191204 boolean showTokens , showAst , showMeasurements ;
205+ boolean lintMode ;
192206
193207 public Options () {
194208 showTokens = false ;
195209 showAst = false ;
196210 showMeasurements = false ;
211+ lintMode = false ;
212+ }
213+
214+ public void validate () {
215+ if (lintMode == true ) {
216+ showTokens = false ;
217+ showAst = false ;
218+ showMeasurements = false ;
219+ }
197220 }
198221 }
199222}
0 commit comments