oracle/graal · error · RuleParseError

Out of tokens looking for

Error message

Out of tokens looking for %s

What it means

Thrown by RuleParser.peek(name) when tokens run out while the parser was specifically expecting something (a node type, a name, ')', etc.). Unlike the plain 'Out of tokens' variant, it names what was being looked for, which pinpoints the missing element of the match pattern.

Solutions

  1. Supply the token named in the message — usually a closing ')' or the node type/name it says it was looking for.
  2. Re-balance parentheses by counting opens/closes in the rule string.
  3. Use the message's 'looking for %s' field literally: it tells you the exact grammar element to append.

Example fix

// before
@MatchRule("Add(x = ")

// after
@MatchRule("Add(x = value, y)")
Defensive patterns

Strategy: try-catch

Try / catch

Compile-time error only. Parse the 'looking for %s' field from the javac diagnostic in developer tooling to auto-suggest the missing token.

Prevention

When it happens

Trigger: Rules such as "Add(x, " (looking for ')' or a node type/name), "Add(x = " (looking for a captured name after '='), or any construct left half-finished. Every peek(String) call site passes its expectation, e.g. peek("node type or name"), peek(")"), peek("=").

Common situations: Interrupted edits to @MatchRule strings; renaming nodes and dropping a token; copy-paste that loses the tail of a long pattern.

Related errors


AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14). Data as JSON: /api/errors/7285ccd02e3d7494. Report an issue: GitHub.

Appendix: source

Thrown at compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/core/match/processor/MatchProcessor.java:147

            matchDescriptor = parseExpression();
            if (!done()) {
                throw new RuleParseError("didn't consume all tokens");
            }
            capturedNames.add(0, "root");
            capturedTypes.add(0, matchDescriptor.nodeType);
        }

        String next() {
            return tokens[current++];
        }

        String peek(String name) {
            if (current >= tokens.length) {
                if (name == null) {
                    throw new RuleParseError("Out of tokens");
                }
                throw new RuleParseError("Out of tokens looking for %s", name);
            }
            return tokens[current];
        }

        boolean done() {
            return current == tokens.length;
        }

        private MatchDescriptor parseExpression() {
            if (peek("(").equals("(")) {
                next();
                MatchDescriptor descriptor = parseType(true);
                for (int n = 0; n < descriptor.nodeType.inputs.size(); n++) {
                    if (peek("(").equals("(")) {
                        descriptor.inputs[n] = parseExpression();
                    } else {
                        descriptor.inputs[n] = parseType(false);
                    }

View on GitHub (pinned to a66e9ccd1d)