<commit_before>/*
 * Created on 03.des.2005
 *
 * Copyright (c) 2005, <NAME> <<EMAIL>>
 * 
 * Licensed under the GNU Lesser General Public License, v2.1
 */
package org.spoofax.jsglr;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import aterm.ATerm;

public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException, InvalidParseTableException {
        
        if(args.length < 2) {
            usage();
        }

        String parseTable = null;
        String input = null;
        String output = null;
        boolean debugging = false;
        boolean logging = false;
        boolean detectCycles = true;
        boolean filter = true;
        boolean waitForProfiler = false;
        
        int skip = 0;
        for(int i=0;i<args.length;i++) {
            if(skip > 0)
                skip--;
            if(args[i].equals("-p")) {
                parseTable = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-i")) {
                input = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-o")) {
                output = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-d")) {
                debugging = true;
            } else if(args[i].equals("-v")) {
                logging = true;
            } else if(args[i].equals("-f")) {
                filter = false;
            } else if(args[i].equals("-c")) {
                detectCycles = false;
            } else if(args[i].equals("--wait-for-profiler")) {
                waitForProfiler = true;
            }
        }

        if(parseTable == null)
            usage();
        

        ParseTableManager ptm = new ParseTableManager();
        SGLR sglr = new SGLR(ptm.getFactory(), ptm.loadFromFile(parseTable));

        Tools.setDebug(debugging);
        Tools.setLogging(logging);
        sglr.setCycleDetect(detectCycles);
        sglr.setFilter(filter);
        
        InputStream fis = null;
        if(input == null)
            fis = System.in;
        else
            fis = new FileInputStream(input);
        
        OutputStream ous = null;
        if(output != null)
            ous = new FileOutputStream(output);
        else 
            ous = System.out;

        try {
            ATerm t = sglr.parse(fis);
            if(t != null)
                ous.write(t.toString().getBytes());
        } catch(SGLRException e) {
            System.err.println("Parsing failed : " + e);
        }
        
        if(waitForProfiler)
            System.in.read();
    }

    private static void usage() {
        System.out.println("Usage: org.spoofax.jsglr.Main [-f -d -v] -p <parsetable.tbl> -i <inputfile>");
        System.exit(-1);
    }
}<commit_msg>Added --timing switch which measures the table loading and parsing time.<commit_after>/*
 * Created on 03.des.2005
 *
 * Copyright (c) 2005, <NAME> <<EMAIL>>
 * 
 * Licensed under the GNU Lesser General Public License, v2.1
 */
package org.spoofax.jsglr;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import aterm.ATerm;

public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException, InvalidParseTableException {
        
        if(args.length < 2) {
            usage();
        }

        String parseTable = null;
        String input = null;
        String output = null;
        boolean debugging = false;
        boolean logging = false;
        boolean detectCycles = true;
        boolean filter = true;
        boolean waitForProfiler = false;
        boolean timing = false;
        
        int skip = 0;
        for(int i=0;i<args.length;i++) {
            if(skip > 0)
                skip--;
            if(args[i].equals("-p")) {
                parseTable = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-i")) {
                input = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-o")) {
                output = args[i + 1];
                skip = 1;
            } else if(args[i].equals("-d")) {
                debugging = true;
            } else if(args[i].equals("-v")) {
                logging = true;
            } else if(args[i].equals("-f")) {
                filter = false;
            } else if(args[i].equals("-c")) {
                detectCycles = false;
            } else if(args[i].equals("--wait-for-profiler")) {
                waitForProfiler = true;
            } else if(args[i].equals("--timing")) {
            	timing = true;
            }
        }

        if(parseTable == null)
            usage();
        

        ParseTableManager ptm = new ParseTableManager();
        long tableLoadingTime = System.currentTimeMillis(); 
        SGLR sglr = new SGLR(ptm.getFactory(), ptm.loadFromFile(parseTable));
        tableLoadingTime = System.currentTimeMillis() - tableLoadingTime;

        Tools.setDebug(debugging);
        Tools.setLogging(logging);
        sglr.setCycleDetect(detectCycles);
        sglr.setFilter(filter);
        
        InputStream fis = null;
        if(input == null)
            fis = System.in;
        else
            fis = new FileInputStream(input);
        
        OutputStream ous = null;
        if(output != null)
            ous = new FileOutputStream(output);
        else 
            ous = System.out;

        long parsingTime = 0;
        try {
        	parsingTime = System.currentTimeMillis();
            ATerm t = sglr.parse(fis);
            parsingTime = System.currentTimeMillis() - parsingTime;
            if(t != null)
                ous.write(t.toString().getBytes());
        } catch(SGLRException e) {
            System.err.println("Parsing failed : " + e);
        }
        
        if(waitForProfiler)
            System.in.read();
        if(timing) {
        	System.err.println("Parse table loading time : " + tableLoadingTime + "ms");
        	System.err.println("Parsing time             : " + parsingTime + "ms");
        }
    }

    private static void usage() {
        System.out.println("Usage: org.spoofax.jsglr.Main [-f -d -v] -p <parsetable.tbl> -i <inputfile>");
        System.exit(-1);
    }
}
{'fraction_non_alphanumeric': 0.12478816823293791, 'fraction_numerical': 0.007240794946849484, 'mean_word_length': 1.640097600650671, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1454406', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1858, 'n_words': 416}