⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.java

📁 javascript语言的解释器源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                if (c == '/') {                    return cursor;                }            }        }        return end;    }    private int extract_tag_value(char[] array, int cursor, int end, int id) {        // cursor points after #[^#=]+=        // ALERT: implement support for quoted strings        boolean found = false;        cursor = skip_white_space(array, cursor, end);        if (cursor != end) {            int value_start = cursor;            int value_end = cursor;            while (cursor != end) {                int c = array[cursor];                if (is_white_space(c)) {                    int after_space = skip_white_space(array, cursor + 1, end);                    if (after_space != end && array[after_space] == '#') {                        value_end = cursor;                        cursor = after_space;                        break;                    }                    cursor = after_space + 1;                }                else if (c == '#') {                    value_end = cursor;                    break;                }                else {                    ++cursor;                }            }            if (cursor != end) {                // array[cursor] is '#' here                found = true;                tag_value_start = value_start;                tag_value_end = value_end;                tag_definition_end = cursor + 1;            }        }        return (found) ? id : 0;    }    private int get_tag_id        (char[] array, int begin, int end, boolean at_line_start)    {        if (at_line_start) {            if (equals(SWITCH_TAG_STR, array, begin, end)) {                return SWITCH_TAG;            }            if (equals(GENERATED_TAG_STR, array, begin, end)) {                return GENERATED_TAG;            }        }        if (equals(STRING_TAG_STR, array, begin, end)) {            return STRING_TAG;        }        return 0;    }    private void look_for_id_definitions        (char[] array, int begin, int end, boolean use_tag_value_as_string)    {    // Look for the pattern    // '^[ \t]+Id_([a-zA-Z0-9_]+)[ \t]*=.*$'    // where \1 gives field or method name        int cursor = begin;        // Skip tab and spaces at the beginning        cursor = skip_white_space(array, cursor, end);        int id_start = cursor;        int name_start = skip_matched_prefix("Id_", array, cursor, end);        if (name_start >= 0) {            // Found Id_ prefix            cursor = name_start;            cursor = skip_name_char(array, cursor, end);            int name_end = cursor;            if (name_start != name_end) {                cursor = skip_white_space(array, cursor, end);                if (cursor != end) {                    if (array[cursor] == '=') {                        int id_end = name_end;                        if (use_tag_value_as_string) {                            name_start = tag_value_start;                            name_end = tag_value_end;                        }                        // Got the match                        add_id(array, id_start, id_end, name_start, name_end);                    }                }            }        }    }    private void add_id        (char[] array, int id_start, int id_end, int name_start, int name_end)    {        String name = new String(array, name_start, name_end - name_start);        String value = new String(array, id_start, id_end - id_start);        IdValuePair pair = new IdValuePair(name, value);        pair.setLineNumber(body.getLineNumber());        all_pairs.addElement(pair);    }    private static boolean is_white_space(int c) {        return c == ' ' || c == '\t';    }    private static int skip_white_space(char[] array, int begin, int end) {        int cursor = begin;        for (; cursor != end; ++cursor) {            int c = array[cursor];            if (!is_white_space(c)) { break; }        }        return cursor;    }    private static int skip_matched_prefix        (String prefix, char[] array, int begin, int end)    {        int cursor = -1;        int prefix_length = prefix.length();        if (prefix_length <= end - begin) {            cursor = begin;            for (int i = 0; i != prefix_length; ++i, ++cursor) {                if (prefix.charAt(i) != array[cursor]) {                    cursor = -1; break;                }            }        }        return cursor;    }    private static boolean equals(String str, char[] array, int begin, int end)    {        if (str.length() == end - begin) {            for (int i = begin, j = 0; i != end; ++i, ++j) {                if (array[i] != str.charAt(j)) { return false; }            }            return true;        }        return false;    }    private static int skip_name_char(char[] array, int begin, int end) {        int cursor = begin;        for (; cursor != end; ++cursor) {            int c = array[cursor];            if (!('a' <= c && c <= 'z') && !('A' <= c && c <= 'Z')) {                if (!('0' <= c && c <= '9')) {                    if (c != '_') {                        break;                    }                }            }        }        return cursor;    }    public static void main(String[] args) {        Main self = new Main();        int status = self.exec(args);        System.exit(status);    }    private int exec(String[] args) {        R = new ToolErrorReporter(true, System.err);        int arg_count = process_options(args);        if (arg_count == 0) {            option_error(ToolErrorReporter.getMessage(                             "msg.idswitch.no_file_argument"));            return -1;        }        if (arg_count > 1) {            option_error(ToolErrorReporter.getMessage(                             "msg.idswitch.too_many_arguments"));            return -1;        }        P = new CodePrinter();        P.setIndentStep(4);        P.setIndentTabSize(0);        try {            process_file(args[0]);        }        catch (IOException ex) {            print_error(ToolErrorReporter.getMessage(                            "msg.idswitch.io_error", ex.toString()));            return -1;        }        catch (EvaluatorException ex) {            return -1;        }        return 0;    }    private int process_options(String[] args) {        int status = 1;        boolean show_usage = false;        boolean show_version = false;        int N = args.length;        L: for (int i = 0; i != N; ++i) {            String arg = args[i];            int arg_length = arg.length();            if (arg_length >= 2) {                if (arg.charAt(0) == '-') {                    if (arg.charAt(1) == '-') {                        if (arg_length == 2) {                            args[i] = null; break;                        }                        if (arg.equals("--help")) {                            show_usage = true;                        }                        else if (arg.equals("--version")) {                            show_version = true;                        }                        else {                            option_error(ToolErrorReporter.getMessage(                                             "msg.idswitch.bad_option", arg));                            status = -1; break L;                        }                    }                    else {                        for (int j = 1; j != arg_length; ++j) {                            char c = arg.charAt(j);                            switch (c) {                                case 'h': show_usage = true; break;                                default:                                    option_error(                                        ToolErrorReporter.getMessage(                                            "msg.idswitch.bad_option_char",                                            String.valueOf(c)));                                    status = -1;                                    break L;                            }                        }                    }                    args[i] = null;                }            }        }        if (status == 1) {            if (show_usage) { show_usage(); status = 0; }            if (show_version) { show_version(); status = 0; }        }        if (status != 1) { System.exit(status); }        return remove_nulls(args);    }    private void show_usage() {        System.out.println(            ToolErrorReporter.getMessage("msg.idswitch.usage"));        System.out.println();    }    private void show_version() {        System.out.println(            ToolErrorReporter.getMessage("msg.idswitch.version"));    }    private void option_error(String str) {        print_error(            ToolErrorReporter.getMessage("msg.idswitch.bad_invocation", str));    }    private void print_error(String text) {        System.err.println(text);    }    private int remove_nulls(String[] array) {        int N = array.length;        int cursor = 0;        for (; cursor != N; ++cursor) {            if (array[cursor] == null) { break; }        }        int destination = cursor;        if (cursor != N) {            ++cursor;            for (; cursor != N; ++cursor) {                String elem = array[cursor];                if (elem != null) {                    array[destination] = elem; ++destination;                }            }        }        return destination;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -