private static void writeRules()

in src/main/software/amazon/event/ruler/JsonRuleCompiler.java [285:347]


    private static void writeRules(final List<Map<String, List<Patterns>>> rules,
                                   final String name,
                                   final JsonParser parser,
                                   final boolean withQuotes) throws IOException {

        JsonToken token;
        final List<Patterns> values = new ArrayList<>();

        while ((token = parser.nextToken()) != JsonToken.END_ARRAY) {
            switch (token) {
            case START_OBJECT:
                values.add(processMatchExpression(parser));
                break;

            case VALUE_STRING:
                final String toMatch = parser.getText();

                final Range ipRange = CIDR.ipToRangeIfPossible(toMatch);
                if (ipRange != null) {
                    values.add(ipRange);
                } else if (withQuotes) {
                    values.add(Patterns.exactMatch('"' + toMatch + '"'));
                } else {
                    values.add(Patterns.exactMatch(toMatch));
                }
                break;

            case VALUE_NUMBER_FLOAT:
            case VALUE_NUMBER_INT:
                /*
                 * If the rule specifies a match to a number, we'll insert matchers for both the
                 *  literal expression and the ComparableNumber form. But the number might not
                 *  be representable as a ComparableNumber, for example an AWS account number,
                 *  so make that condition survivable.
                 */
                try {
                    values.add(Patterns.numericEquals(parser.getText()));
                } catch (Exception e) {
                    // no-op
                }
                values.add(Patterns.exactMatch(parser.getText()));
                break;

            case VALUE_NULL:
            case VALUE_TRUE:
            case VALUE_FALSE:
                values.add(Patterns.exactMatch(parser.getText()));
                break;

            default:
                barf(parser, "Match value must be String, number, true, false, or null");
            }
        }
        if (values.isEmpty()) {
            barf(parser, "Empty arrays are not allowed");
        }

        // If the rules list is empty, add the first rule
        if (rules.isEmpty()) {
            rules.add(new HashMap<>());
        }
        rules.forEach(rule -> rule.put(name, values));
    }