{"record":{"id":"29e28d0f9cac118f","repo":"oracle/graal","slug":"unexpected-token-s-when-looking-for-name-or-nod","errorCode":null,"errorMessage":"Unexpected token \"%s\" when looking for name or node type","messagePattern":"Unexpected token \"(.+?)\" when looking for name or node type","errorType":"validation","errorClass":"RuleParseError","httpStatus":null,"severity":"error","filePath":"compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/core/match/processor/MatchProcessor.java","lineNumber":199,"sourceCode":"        private MatchDescriptor parseType(boolean forExpression) {\n            TypeDescriptor type = null;\n            String name = null;\n            if (Character.isUpperCase(peek(\"node type or name\").charAt(0))) {\n                String token = next();\n                type = knownTypes.get(token);\n                if (type == null) {\n                    throw new RuleParseError(\"Unknown node type: \" + token);\n                }\n                if (peek(\"=\").equals(\"=\")) {\n                    next();\n                    name = next();\n                }\n                originatingElements.addAll(type.originatingElements);\n            } else if (Character.isLowerCase(peek(\"name\").charAt(0))) {\n                name = next();\n                type = valueType;\n            } else {\n                throw new RuleParseError(\"Unexpected token \\\"%s\\\" when looking for name or node type\", peek(null));\n            }\n            requiredPackages.add(type.nodePackage);\n            if (name != null) {\n                if (!capturedNames.contains(name)) {\n                    capturedNames.add(name);\n                    capturedTypes.add(type);\n                } else {\n                    int index = capturedNames.indexOf(name);\n                    if (capturedTypes.get(index) != type) {\n                        throw new RuleParseError(\"Captured node \\\"%s\\\" has differing types\", name);\n                    }\n                }\n            }\n            return new MatchDescriptor(type, name, forExpression);\n        }\n\n        List<String> generateVariants() {\n            return matchDescriptor.generateVariants();","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/compiler/src/jdk.graal.compiler.processor/src/jdk/graal/compiler/core/match/processor/MatchProcessor.java#L181-L217","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Replace the quoted token with a valid identifier: uppercase-first for a node type, lowercase-first for a capture name.","Remove doubled commas/stray operators at that position in the rule string.","Re-check the rule against the grammar: '(' Type ('=' name)? inputs ')'."],"exampleFix":"// before\n@MatchRule(\"Add(=x, y)\")\n\n// after\n@MatchRule(\"Add(x = a, y = b)\")","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Compile-time only; surface the quoted unexpected token from the diagnostic in developer tooling.","preventionTips":["Use only identifiers in patterns: uppercase-first for types, lowercase-first for captures.","Remove doubled commas and stray '=' or ')' tokens when editing.","Validate rule shape mentally as '(' Type ('=' name)? inputs ')' before building."],"tags":["graalvm","match-rules","annotation-processing","syntax","compile-time"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}