oracle/graal · error · RuleParseError

Out of tokens

Error message

Out of tokens

What it means

Thrown by RuleParser.peek(null) when the parser needs the next token but the token array is exhausted. It is the generic out-of-input error: the rule string ended in the middle of a construct (unclosed parenthesis, missing node type after '=', trailing operator), and peek() was called without a descriptive name so no 'looking for' context is included.

Source

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

            }
            tokens = list.toArray(new String[0]);

            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 {

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Complete the pattern: balance parentheses and ensure every node type and captured name is present.
  2. Format the rule on one line while editing to avoid truncation by formatters.
  3. If the message lacks context, rebuild the rule incrementally from a minimal working example, adding one input at a time.

Example fix

// before
@MatchRule("Add(")

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

Strategy: try-catch

Try / catch

Compile-time error only. In tooling, surface javac diagnostics containing 'Out of tokens' together with the enclosing @MatchRule annotation for quick fixes.

Prevention

When it happens

Trigger: A truncated @MatchRule such as "Add(" or "Add(x=" — any rule where the tokenizer produces fewer tokens than the grammar requires. peek(null) is also called from the 'Extra tokens following match pattern' path, which is unreachable in practice when tokens are exhausted.

Common situations: Strings chopped by line-length reformatting; incomplete edits; accidentally terminating the annotation string early with a stray quote.

Related errors


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