oracle/graal · error · RuleParseError

Unexpected token "%s" when looking for name or node type

Error message

Unexpected token "%s" when looking for name or node type

What it means

Thrown by RuleParser.parseType when the next token starts neither with an uppercase letter (node type) nor a lowercase letter (captured name) — for example a digit, punctuation like ')' or '=', appearing where a name or node type is required. The message quotes the offending token.

Source

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

        private MatchDescriptor parseType(boolean forExpression) {
            TypeDescriptor type = null;
            String name = null;
            if (Character.isUpperCase(peek("node type or name").charAt(0))) {
                String token = next();
                type = knownTypes.get(token);
                if (type == null) {
                    throw new RuleParseError("Unknown node type: " + token);
                }
                if (peek("=").equals("=")) {
                    next();
                    name = next();
                }
                originatingElements.addAll(type.originatingElements);
            } else if (Character.isLowerCase(peek("name").charAt(0))) {
                name = next();
                type = valueType;
            } else {
                throw new RuleParseError("Unexpected token \"%s\" when looking for name or node type", peek(null));
            }
            requiredPackages.add(type.nodePackage);
            if (name != null) {
                if (!capturedNames.contains(name)) {
                    capturedNames.add(name);
                    capturedTypes.add(type);
                } else {
                    int index = capturedNames.indexOf(name);
                    if (capturedTypes.get(index) != type) {
                        throw new RuleParseError("Captured node \"%s\" has differing types", name);
                    }
                }
            }
            return new MatchDescriptor(type, name, forExpression);
        }

        List<String> generateVariants() {
            return matchDescriptor.generateVariants();

View on GitHub (pinned to a66e9ccd1d)

Solutions

  1. Replace the quoted token with a valid identifier: uppercase-first for a node type, lowercase-first for a capture name.
  2. Remove doubled commas/stray operators at that position in the rule string.
  3. Re-check the rule against the grammar: '(' Type ('=' name)? inputs ')'.

Example fix

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

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

Strategy: try-catch

Try / catch

Compile-time only; surface the quoted unexpected token from the diagnostic in developer tooling.

Prevention

When it happens

Trigger: Patterns like "Add(=x, y)" (stray '='), "Add(,x)" (leading comma), or numbers where names are expected. peek("node type or name").charAt(0) fails both Character.isUpperCase and isLowerCase tests, falling to the final throw.

Common situations: Hand-editing rules and leaving doubled separators; attempting Java-like syntax (commas between positional elements handled elsewhere, '==' comparisons) inside the pattern; stray tokens after refactoring.

Understand the failure class

Related errors


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