public static final int optionsFromScheme(Value value, Value type) { if (value instanceof Symbol) { if (value == CASE_INSENSITIVE) { if (type == REGEX_PERL5) return Perl5Compiler.CASE_INSENSITIVE_MASK; else if (type == REGEX_GLOB) return GlobCompiler.CASE_INSENSITIVE_MASK; else if (type == REGEX_AWK) return AwkCompiler.CASE_INSENSITIVE_MASK; else throw new RuntimeException("Unknown compiler " + type); } else if (value == EXTENDED) { if (type == REGEX_PERL5) return Perl5Compiler.EXTENDED_MASK; else throw new RuntimeException("The extended mask is supported only by Perl5 regexps"); } else if (value == SINGLELINE) { if (type == REGEX_PERL5) return Perl5Compiler.SINGLELINE_MASK; else throw new RuntimeException("The singleline mask is supported only by Perl5 regexps"); } else if (value == MULTILINE) { if (type == REGEX_PERL5) return Perl5Compiler.MULTILINE_MASK; else if (type == REGEX_GLOB) throw new RuntimeException("Glob compiler doesn't support this option: " + value); else if (type == REGEX_AWK) return AwkCompiler.MULTILINE_MASK; } else throw new RuntimeException("Unsupported regexp option " + value); } else if (value instanceof Pair) { int options = 0; Pair pv = (Pair) value; while (pv != EMPTYLIST) { options |= optionsFromScheme(pv.car(), type); pv = (Pair) pv.cdr(); } return options; } else throw new RuntimeException("Invalid format for options " + value); // Not reached, but keeps the Java compiler happy return 0; }