Package java.util.regex

Examples of java.util.regex.MatchResult


        Context contxt = new Context();
        contxt.state = State.initial;
        contxt.key_indent = null;

        while (source.hasMore()) {
            MatchResult m = null;
            if (source.isBeginningOfLine()) {
                contxt.key_indent = null;
            }

            if ((m = source.scan(SPACE)) != null) {
                encoder.textToken(m.group(), TokenType.space);
            }
            else if ((m = source.scan(SPACE_NEWLINE)) != null) {
                encoder.textToken(m.group(), TokenType.space);
                if (m.group().indexOf("\n") != -1) {
                    contxt.state = State.initial;
                }
            }
            else if ((m = source.scan(COMMENT)) != null) {
                encoder.textToken(m.group(), TokenType.comment);
            }
            else if (source.isBeginningOfLine() && head_doctype(source, encoder)) {
                continue;
            }
            else if (contxt.state == State.value && delimiter(source, encoder, contxt)) {
View Full Code Here


            }
        }
    }

    private boolean head_doctype(StringScanner source, Encoder encoder) {
        MatchResult m;
        if ((m = source.scan(HEAD)) != null) {
            encoder.beginGroup(TokenType.head);
            encoder.textToken(m.group(), TokenType.head);
            encoder.endGroup(TokenType.head);
            return true;
        }
        else if ((m = source.scan(DOCTYPE)) != null) {
            encoder.textToken(m.group(), TokenType.doctype);
            return true;
        }
        return false;
    }
View Full Code Here

        }
        return false;
    }

    private boolean delimiter(StringScanner source, Encoder encoder, Context context) {
        MatchResult m;
        int string_indent = 0;
        if (source.check(STRING) == null && (m = source.scan(DOUBLE_QUOTE)) != null) {
            encoder.beginGroup(TokenType.string);
            encoder.textToken(m.group(), TokenType.delimiter);
            if ((m = source.scan(COMMENT_ONELINE)) != null && !"".equals(m.group())) {
                encoder.textToken(m.group(), TokenType.content);
            }
            if ((m = source.scan(DOUBLE_QUOTE)) != null) {
                encoder.textToken(m.group(), TokenType.delimiter);
            }
            encoder.endGroup(TokenType.string);
            return true;
        }
        else if ((m = source.scan(LINE_CONTINUE)) != null) {
            encoder.beginGroup(TokenType.string);
            encoder.textToken(m.group(), TokenType.delimiter);
            string_indent = context.key_indent != null ? context.key_indent : source.column(source.index() - m.group().length()) - 1;
            if ((m = source.scan(Pattern.compile("(?:\\n+ {" + (string_indent + 1) + "}.*)+"))) != null) {
                encoder.textToken(m.group(), TokenType.content);
            }
            encoder.endGroup(TokenType.string);
            return true;
        }
        else if ((m = source.scan(STRING_ENDLINE)) != null) {
            encoder.beginGroup(TokenType.string);
            encoder.textToken(m.group(), TokenType.content);
            string_indent = context.key_indent != null ? context.key_indent : source.column(source.index() - m.group().length()) - 1;
            if ((m = source.scan(Pattern.compile("(?:\\n+ {" + (string_indent + 1) + "}.*)+"))) != null) {
                encoder.textToken(m.group(), TokenType.content);
            }

            encoder.endGroup(TokenType.string);
            return true;
        }
View Full Code Here

        }
        return false;
    }

    private boolean value(StringScanner source, Encoder encoder, Context context) {
        MatchResult m;

        if ((m = source.scan(OPERATOR)) != null) {
            if (context.state == State.colon && (m.group().equals(":") | m.group().equals("-"))) {
                context.state = State.value;
            }
            else if (context.state == State.initial && m.group().equals("-")) {
                context.state = State.value;
            }
            encoder.textToken(m.group(), TokenType.operator);
            return true;
        }
        else if ((m = source.scan(OPERATOR_BRACKETS)) != null) {
            encoder.textToken(m.group(), TokenType.operator);
            return true;
        }
        else if (context.state == State.initial && (m = source.scan(KEY)) != null) {
            encoder.textToken(m.group(), TokenType.key);
            context.key_indent = source.column(source.index() - m.group().length()) - 1;
            context.state = State.colon;
            return true;
        }
        else if ((m = source.scan(KEY_2)) != null) {
            encoder.beginGroup(TokenType.key);
            String match = m.group();
            encoder.textToken(match.substring(0, 1), TokenType.delimiter);
            if (match.length() > 2) {
                encoder.textToken(match.substring(1, match.length() - 1), TokenType.content);
            }
            encoder.textToken(match.substring(match.length() - 1), TokenType.delimiter);
            encoder.endGroup(TokenType.key);
            context.key_indent = source.column(source.index() - match.length()) - 1;
            context.state = State.colon;
            return true;
        }
        else if ((m = source.scan(TYPE_EXP)) != null) {
            encoder.textToken(m.group(1), TokenType.type);
            if (m.group(2) != null) {
                encoder.textToken(":", TokenType.operator);
                encoder.textToken(m.group(3), TokenType.class_);
            }
            return true;
        }
        else if ((m = source.scan(VARIABLE)) != null) {
            encoder.textToken(m.group(), TokenType.variable);
            return true;
        }
        else if ((m = source.scan(GLOBAL_VARIABLE)) != null) {
            encoder.textToken(m.group(), TokenType.global_variable);
            return true;
        }
        else if ((m = source.scan(CLASS_VARIABLE)) != null) {
            encoder.textToken(m.group(), TokenType.class_variable);
            return true;
        }
        else if ((m = source.scan(OCTAL)) != null) {
            encoder.textToken(m.group(), TokenType.octal);
            return true;
        }
        else if ((m = source.scan(OCTAL_2)) != null) {
            encoder.textToken(m.group(), TokenType.octal);
            return true;
        }
        else if ((m = source.scan(SYMBOL)) != null) {
            encoder.textToken(m.group(), TokenType.symbol);
            return true;
        }
        else if ((m = source.scan(ERROR)) != null) {
            encoder.textToken(m.group(), TokenType.error);
            return true;
        }
        else if ((m = source.scan(ERROR_2)) != null) {
            encoder.textToken(m.group(), TokenType.error);
            return true;
        }
        return false;
    }
View Full Code Here

    @Override
    public void scan(StringScanner source, Encoder encoder, Map<String, Object> options) {
        State state = State.initial;

        while (source.hasMore()) {
            MatchResult m = null;

            switch (state) {

                case initial:
                    if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                    }
                    else if ((m = source.scan(DOUBLE_QUOTE)) != null) {
                        state = source.check(KEY) != null ? State.key : State.string;
                        encoder.beginGroup(TokenType.valueOf(state.name()));
                        encoder.textToken(m.group(), TokenType.delimiter);
                    }
                    else if ((m = source.scan(OPERATOR)) != null) {
                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else if ((m = source.scan(BOOLEAN)) != null) {
                        encoder.textToken(m.group(), TokenType.value);
                    }
                    else if ((m = source.scan(NUMBER)) != null) {
                        String match = m.group();
                        if ((m = source.scan(FLOAT)) != null) {
                            match = match + m.group();
                            encoder.textToken(match, TokenType.float_);
                        }
                        else {
                            encoder.textToken(match, TokenType.integer);
                        }
                    }
                    else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;
                case key:
                case string:

                    if ((m = source.scan(CONTENT)) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    }
                    else if ((m = source.scan(DOUBLE_QUOTE)) != null) {
                        encoder.textToken(m.group(), TokenType.delimiter);
                        encoder.endGroup(TokenType.valueOf(state.name()));
                        state = State.initial;
                    }
                    else if ((m = source.scan(CHAR)) != null) {
                        encoder.textToken(m.group(), TokenType.char_);
                    }
                    else if ((m = source.scan(CONTENT_2)) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    }
                    else if ((m = source.scan(END)) != null) {
                        encoder.endGroup(TokenType.valueOf(state.name()));
                        if (!m.group().isEmpty()) {
                            encoder.textToken(m.group(), TokenType.error);
                        }
                        state = State.initial;
                    }
                    else {
                        throw new RuntimeException("else case \" reached " + source.peek(1) + " not handled");
View Full Code Here

        boolean after_def = false;
        boolean value_expected = true;
        TokenType kind = null;

        while (source.hasMore()) {
            MatchResult m = null;

            switch (state) {
                case initial:

                    if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                        if (m.group().indexOf("\n") != -1) {
                            import_clause = after_def = false;
                            if (!value_expected) {
                                value_expected = true;
                            }
                        }
                        continue;
                    }
                    else if ((m = source.scan(COMMENT)) != null) {
                        value_expected = true;
                        after_def = false;
                        encoder.textToken(m.group(), TokenType.comment);
                    }
                    else if ((m = source.scan(DOCTYPE)) != null) {
                        encoder.textToken(m.group(), TokenType.doctype);
                    }
                    else if (import_clause && (m = source.scan(INCLUDE)) != null) {
                        after_def = value_expected = false;
                        encoder.textToken(m.group(), TokenType.include);
                    }
                    else if ((m = source.scan(IDENT)) != null) {
                        kind = IDENT_KIND.lookup(m.group());
                        value_expected = (kind == TokenType.keyword) && KEYWORDS_EXPECTING_VALUE.lookup(m.group());
                        if (".".equals(last_token)) {
                            kind = TokenType.ident;
                        }
                        else if (class_name_follows) {
                            kind = TokenType.class_;
                            class_name_follows = false;
                        }
                        else if (after_def && source.check(AFTER_DEF) != null) {
                            kind = TokenType.method;
                            after_def = false;
                        }
                        else if (kind == TokenType.ident && !"?".equals(last_token) && source.check(":") != null) {
                            kind = TokenType.key;
                        }
                        else {
                            if (m.group().equals("class") || (import_clause && m.group().equals("as"))) {
                                class_name_follows = true;
                            }
                            import_clause = (m.group().equals("import"));
                            if (m.group().equals("def")) {
                                after_def = true;
                            }
                        }
                        encoder.textToken(m.group(), kind);
                    }
                    else if ((m = source.scan(SEMI_COLON)) != null) {
                        import_clause = after_def = false;
                        value_expected = true;
                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else if ((m = source.scan(START_BRACKET)) != null) {
                        class_name_follows = after_def = false;
                        value_expected = true;
                        encoder.textToken(m.group(), TokenType.operator);
                        if (!inlineBlockStack.isEmpty()) {
                            inlineBlockParenDepth += 1;
                        }
                    }
                    else if ((m = source.scan(OPERATOR)) != null) {
                        value_expected = true;
                        //value_expected = :regexp if match == '~';
                        after_def = false;

                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else if ((m = source.scan(END_BRACKET)) != null) {
                        value_expected = after_def = false;
                        if (!inlineBlockStack.isEmpty() && m.group().equals("}")) {
                            inlineBlockParenDepth -= 1;
                            if (inlineBlockParenDepth == 0) // # closing brace of inline block reached
                            {
                                encoder.textToken(m.group(), TokenType.inline_delimiter);
                                encoder.endGroup(TokenType.inline);
                                Object[] inlineBlock = inlineBlockStack.pop();
                                state = (State) inlineBlock[0];
                                stringDelimiter = (String) inlineBlock[1];
                                inlineBlockParenDepth = (int) inlineBlock[2];
                                continue;
                            }
                        }
                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else if (source.check(NUMBER) != null) {
                        after_def = value_expected = false;
                        if ((m = source.scan(HEX)) != null) {
                            encoder.textToken(m.group(), TokenType.hex);
                        }
                        else if ((m = source.scan(OCTAL)) != null) {
                            encoder.textToken(m.group(), TokenType.octal);
                        }
                        else if ((m = source.scan(FLOAT)) != null) {
                            encoder.textToken(m.group(), TokenType.float_);
                        }
                        else if ((m = source.scan(INTEGER)) != null) {
                            encoder.textToken(m.group(), TokenType.integer);
                        }
                    }
                    else if ((m = source.scan(MULTI_LINE_DELIMITER)) != null) {
                        after_def = value_expected = false;
                        state = State.multiline_string;
                        encoder.beginGroup(TokenType.string);
                        stringDelimiter = m.group();
                        encoder.textToken(m.group(), TokenType.delimiter);
                    }
                    else if ((m = source.scan(STRING_DELIMITER)) != null) {
                        after_def = value_expected = false;
                        state = m.group().equals("/") ? State.regexp : State.string;
                        encoder.beginGroup(TokenType.valueOf(state.name()));
                        stringDelimiter = m.group();
                        encoder.textToken(m.group(), TokenType.delimiter);
                    }
                    else if (value_expected && (m = source.scan(START_REGEXP)) != null) {
                        after_def = value_expected = false;
                        encoder.beginGroup(TokenType.regexp);
                        state = State.regexp;
                        stringDelimiter = "/";
                        encoder.textToken(m.group(), TokenType.delimiter);
                    }
                    else if ((m = source.scan(ANNOTATION)) != null) {
                        after_def = value_expected = false;
                        encoder.textToken(m.group(), TokenType.annotation);
                    }
                    else if ((m = source.scan(END_OPERATOR)) != null) {
                        after_def = false;
                        value_expected = true;
                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;

                case string:
                case regexp:
                case multiline_string:

                    if ((m = source.scan(STRING_CONTENT_PATTERN.get(stringDelimiter))) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    }
                    else if ((m = source.scan(state == State.multiline_string ? "'''|\"\"\"" : "[\"'\\/]")) != null) {
                        encoder.textToken(m.group(), TokenType.delimiter);
                        if (state == State.regexp) {
                            MatchResult modifiers = source.scan("[ix]+");
                            if (modifiers != null && !modifiers.group().equals("")) {
                                encoder.textToken(modifiers.group(), TokenType.modifier);
                            }
                        }
                        if (state == State.multiline_string) {
                            state = State.string;
                        }
View Full Code Here

    @Override
    public void scan(StringScanner source, Encoder encoder, Map<String, Object> options) {
        State state = State.initial;

        while (source.hasMore()) {
            MatchResult m = null;
            switch (state) {
                case initial:
                    if ((m = source.scan(COMMENT)) != null) {
                        encoder.textToken(m.group(), TokenType.comment);
                    }
                    else if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                    }
                    else if ((m = source.scan(KEY)) != null) {
                        encoder.textToken(m.group(), TokenType.key);
                    }
                    else if ((m = source.scan(OPERATOR)) != null) {
                        encoder.textToken(m.group(), TokenType.operator);
                        state = State.value;
                    }
                    else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;
                case value:
                    if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                    }
                    else if ((m = source.scan(FLOAT)) != null) {
                        encoder.textToken(m.group(), TokenType.float_);
                        state = State.initial;
                    }
                    else if ((m = source.scan(NUMBER)) != null) {
                        String match = m.group();
                        if ((m = source.scan(FLOAT)) != null) {
                            match = match + m.group();
                            encoder.textToken(match, TokenType.float_);
                        }
                        else {
                            encoder.textToken(match, TokenType.integer);
                        }
                        state = State.initial;
                    }
                    else if ((m = source.scan(BOOLEAN)) != null) {
                        encoder.textToken(m.group(), TokenType.value);
                        state = State.initial;
                    }
                    else if ((m = source.scan(UNICODE_ESCAPE)) != null) {
                        encoder.textToken(m.group(), TokenType.value);
                        state = State.initial;
                    }
                    else if ((m = source.scan(VALUE)) != null) {
                        encoder.textToken(m.group(), TokenType.value);
                        if (!m.group().endsWith("\\")) {
                            state = State.initial;
                        }
                    }
                    else {
                        encoder.textToken(source.next(), TokenType.error);
View Full Code Here

        TokenType package_name_expected = null;
        boolean class_name_follows = false;
        boolean last_token_dot = false;

        while (source.hasMore()) {
            MatchResult m = null;

            switch (state) {
                case initial:
                    if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                        continue;
                    } else if ((m = source.scan(COMMENT)) != null) {
                        encoder.textToken(m.group(), TokenType.comment);
                        continue;
                    } else if (package_name_expected != null && (m = source.scan(PACKAGE)) != null) {
                        encoder.textToken(m.group(), package_name_expected);
                    } else if ((m = source.scan(IDENT_OR_ARRAY_TYPE)) != null) {
                        String match = m.group();
                        TokenType kind = IDENT_KIND.lookup(match);
                        if (last_token_dot) {
                            kind = TokenType.ident;
                        } else if (class_name_follows) {
                            kind = TokenType.class_;
                            class_name_follows = false;
                        } else {
                            if ("import".equals(match)) {
                                package_name_expected = TokenType.include;
                            } else if ("package".equals(match)) {
                                package_name_expected = TokenType.namespace;
                            } else if ("class".equals(match) || "interface".equals(match)) {
                                class_name_follows = true;
                            }
                        }
                        encoder.textToken(match, kind);
                    } else if ((m = source.scan(OPERATORS)) != null) {
                        encoder.textToken(m.group(), TokenType.operator);
                    } else if ((m = source.scan(SEMI_COLON)) != null) {
                        package_name_expected = null;
                        encoder.textToken(m.group(), TokenType.operator);
                    } else if ((m = source.scan(OPEN_BRAKCET)) != null) {
                        class_name_follows = false;
                        encoder.textToken(m.group(), TokenType.operator);
                    } else if ((m = source.check(ANY_WORD)) != null) {
                        if ((m = source.scan(HEX)) != null) {
                            encoder.textToken(m.group(), TokenType.hex);
                        } else if ((m = source.scan(OCTAL)) != null) {
                            encoder.textToken(m.group(), TokenType.octal);
                        } else if ((m = source.scan(FLOAT)) != null) {
                            encoder.textToken(m.group(), TokenType.float_);
                        } else if ((m = source.scan(INTEGER)) != null) {
                            encoder.textToken(m.group(), TokenType.integer);
                        }
                    } else if ((m = source.scan(START_STRING)) != null) {
                        state = State.string;
                        encoder.beginGroup(TokenType.string);
                        string_delimiter = m.group();
                        encoder.textToken(m.group(), TokenType.delimiter);
                    } else if ((m = source.scan(ANNOTATION)) != null) {
                        encoder.textToken(m.group(), TokenType.annotation);
                    } else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;
                case string:
                    if ((m = source.scan(STRING_CONTENT_PATTERN.get(string_delimiter))) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    } else if ((m = source.scan(END_STRING)) != null) {
                        encoder.textToken(m.group(), TokenType.delimiter);
                        encoder.endGroup(TokenType.string);
                        state = State.initial;
                        string_delimiter = null;
                    } else if (state == State.string && (m = source.scan(STRING_CONTENT)) != null) {
                        if ("'".equals(string_delimiter) && !("\\\\".equals(m.group()) || "\\'".equals(m.group()))) {
                            encoder.textToken(m.group(), TokenType.content);
                        } else {
                            encoder.textToken(m.group(), TokenType.char_);
                        }
                    } else if ((m = source.scan(STRING_CONTENT_2)) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    } else if ((m = source.scan(END_GROUP)) != null) {
                        encoder.endGroup(TokenType.string);
                        state = State.initial;
                        if (!m.group().isEmpty()) {
                            encoder.textToken(m.group(), TokenType.error);
                        }
                    } else {
                        throw new RuntimeException("else case \" reached; " + source.peek(1) + " in " + getClass());
                    }
                    break;
                default:
                    throw new RuntimeException("unknown state " + state);
            }
            if (m != null) {
                last_token_dot = (".".equals(m.group()));
            }
        }
        if (state == State.string) {
            encoder.endGroup(TokenType.string);
        }
View Full Code Here

        boolean value_expected = true;
        boolean key_expected = false;
        boolean function_expected = false;

        while (source.hasMore()) {
            MatchResult m = null;

            switch (state) {
                case initial:

                    if ((m = source.scan(SPACE)) != null) {
                        if (!value_expected && m.group().indexOf("\n") != -1) {
                            value_expected = true;
                        }
                        encoder.textToken(m.group(), TokenType.space);
                    } else if ((m = source.scan(COMMENT)) != null) {
                        value_expected = true;
                        encoder.textToken(m.group(), TokenType.comment);
                        if (m.group(1) != null) {
                            state = State.open_multi_line_comment;
                        }
                    } else if ((m = source.check(NUMBER)) != null) {
                        key_expected = value_expected = false;
                        if ((m = source.scan(HEX)) != null) {
                            encoder.textToken(m.group(), TokenType.hex);
                        } else if ((m = source.scan(OCTAL)) != null) {
                            encoder.textToken(m.group(), TokenType.octal);
                        } else if ((m = source.scan(FLOAT)) != null) {
                            encoder.textToken(m.group(), TokenType.float_);
                        } else if ((m = source.scan(INTEGER)) != null) {
                            encoder.textToken(m.group(), TokenType.integer);
                        }
                    } else if (value_expected && (m = source.scan(HTML)) != null) {
                        Syntax.Builder.create()
                                .scannerType(HTMLScanner.TYPE.getName())
                                .encoder(encoder)
                                .execute(m.group());
                        value_expected = true;
                        continue;
                    } else if ((m = source.scan(OPERATOR)) != null) {
                        value_expected = true;
                        String last_operator = m.group().substring(m.group().length() - 1);
                        key_expected = last_operator.equals("{") || last_operator.equals(",");
                        function_expected = false;
                        encoder.textToken(m.group(), TokenType.operator);
                    } else if ((m = source.scan(OPERATOR_END)) != null) {
                        function_expected = key_expected = value_expected = false;
                        encoder.textToken(m.group(), TokenType.operator);
                    } else if ((m = source.scan(IDENT)) != null) {
                        TokenType kind = IDENT_KIND.lookup(m.group());
                        value_expected = (kind == TokenType.keyword) && KEYWORDS_EXPECTING_VALUE.lookup(m.group());
                        if (TokenType.ident == kind) {
                            if (m.group().indexOf("$") != -1) {
                                kind = TokenType.predefined;
                            } else if (function_expected) {
                                kind = TokenType.function;
                            } else if (source.check(FUNCTION) != null) {
                                kind = TokenType.function;
                            } else if (key_expected && source.check(KEY) != null) {
                                kind = TokenType.key;
                            }
                        }
                        function_expected = (kind == TokenType.keyword && m.group().equals("function"));
                        key_expected = false;
                        encoder.textToken(m.group(), kind);
                    } else if ((m = source.scan(ARRAY_KEY)) != null) {
                        if (key_expected && source.check(KEY_CHECK_PATTERN.get(m.group())) != null) {
                            state = State.key;
                        } else {
                            state = State.string;
                        }
                        encoder.beginGroup(TokenType.valueOf(state.name()));
                        string_delimiter = m.group();
                        encoder.textToken(m.group(), TokenType.delimiter);
                    } else if (value_expected && (m = source.scan(REGEXP)) != null) {
                        encoder.beginGroup(TokenType.regexp);
                        state = State.regexp;
                        string_delimiter = "/";
                        encoder.textToken(m.group(), TokenType.delimiter);
                    } else if ((m = source.scan(REGEXP)) != null) {
                        value_expected = true;
                        key_expected = false;
                        encoder.textToken(m.group(), TokenType.operator);
                    } else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;

                case string:
                case regexp:
                case key:

                    if ((m = source.scan(STRING_CONTENT_PATTERN.get(string_delimiter))) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    } else if ((m = source.scan(DELIMITER)) != null) {
                        encoder.textToken(m.group(), TokenType.delimiter);
                        if (State.regexp == state) {
                            MatchResult modifiers;
                            if ((modifiers = source.scan(MODIFIER)) != null) {
                                encoder.textToken(modifiers.group(), TokenType.modifier);
                            }
                        }
                        encoder.endGroup(TokenType.valueOf(state.name()));
                        string_delimiter = null;
                        key_expected = value_expected = false;
View Full Code Here

        State state = State.initial;
        String stringType = null;
        boolean nameExpected = false;

        while (source.hasMore()) {
            MatchResult m = null;

            switch (state) {
                case initial:

                    if ((m = source.scan(SPACE)) != null) {
                        encoder.textToken(m.group(), TokenType.space);
                    }
                    else if ((m = source.scan(COMMENT)) != null) {
                        encoder.textToken(m.group(), TokenType.comment);
                    }
                    else if ((m = source.scan(COMMENT_DIRECTIVE)) != null) {
                        encoder.textToken(m.group(), m.group(1) != null ? TokenType.directive : TokenType.comment);
                    }
                    else if ((m = source.scan(OPERATOR)) != null) {
                        if (m.group().equals(".") && source.check(LETTER) != null) {
                            nameExpected = true;
                        }
                        encoder.textToken(m.group(), TokenType.operator);
                    }
                    else if ((m = source.scan(STRING)) != null) {
                        String prefix = m.group(1);
                        stringType = m.group(2);
                        encoder.beginGroup(TokenType.string);
                        if (prefix != null) {
                            encoder.textToken(prefix, TokenType.modifier);
                        }
                        state = State.string;
                        encoder.textToken(stringType, TokenType.delimiter);
                    }
                    else if ((m = source.scan(IDENT)) != null) {
                        encoder.textToken(m.group(), nameExpected ? TokenType.ident : (m.group().startsWith("@") ? TokenType.variable : IDENT_KIND.lookup(m.group())));
                        nameExpected = false;
                    }
                    else if ((m = source.scan(HEX)) != null) {
                        encoder.textToken(m.group(), TokenType.hex);
                    }
                    else if ((m = source.scan(OCTAL)) != null) {
                        encoder.textToken(m.group(), TokenType.octal);
                    }
                    else if ((m = source.scan(INTEGER)) != null) {
                        encoder.textToken(m.group(), TokenType.integer);
                    }
                    else if ((m = source.scan(FLOAT)) != null) {
                        encoder.textToken(m.group(), TokenType.float_);
                    }
                    else if ((m = source.scan(PREDEFINED_CONSTANT)) != null) {
                        encoder.textToken(m.group(), TokenType.predefined_constant);
                    }
                    else {
                        encoder.textToken(source.next(), TokenType.error);
                    }
                    break;

                case string:
                    if ((m = source.scan(STRING_CONTENT_PATTERN.get(stringType))) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    }
                    else if ((m = source.scan(DELIMITER)) != null) {
                        if (m.group().equals(stringType)) {
                            if (source.peek(1).equals(stringType)) {
                                encoder.textToken(m.group() + source.next(), TokenType.content);
                            }
                            else {
                                encoder.textToken(m.group(), TokenType.delimiter);
                                encoder.endGroup(TokenType.string);
                                state = State.initial;
                                stringType = null;
                            }
                        }
                        else {
                            encoder.textToken(m.group(), TokenType.content);
                        }
                    }
                    else if ((m = source.scan(CHAR)) != null) {
                        encoder.textToken(m.group(), TokenType.char_);
                    }
                    else if ((m = source.scan(CONTENT)) != null) {
                        encoder.textToken(m.group(), TokenType.content);
                    }
                    else if ((m = source.scan(STRING_END)) != null) {
                        if (m.group().length() != 0) {
                            encoder.textToken(m.group(), TokenType.error);
                        }
                        encoder.endGroup(TokenType.string);
                        state = State.initial;
                    }
                    else {
View Full Code Here

TOP

Related Classes of java.util.regex.MatchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.