test-parser-jdk
Test the Java parser by parsing JDK source files and fixing parse errors. Use when asked to find/fix parse errors, test the parser, or improve JDK compatibility.
When & Why to Use This Skill
The test-parser-jdk skill is a specialized developer tool designed to validate and enhance Java parser accuracy by testing it against official JDK source files. It streamlines the process of identifying syntax incompatibilities, debugging parse errors, and ensuring comprehensive support for modern Java features such as switch expressions, record patterns, and sealed classes.
Use Cases
- Scenario 1: Improving JDK Compatibility - Run the parser against the entire JDK source tree to identify and fix gaps in language feature support for specific Java versions.
- Scenario 2: Debugging Syntax Errors - Quickly locate the exact line and column of parsing failures in complex Java files to accelerate the refinement of grammar rules in parser.go.
- Scenario 3: Regression Testing - Use the automated JDK parse test suite to ensure that new updates to the parser or lexer do not introduce regressions in existing syntax handling.
- Scenario 4: Modern Java Feature Implementation - Systematically test and verify the parser's ability to handle advanced syntax like pattern matching and array type method references.
| name | test-parser-jdk |
|---|---|
| description | Test the Java parser by parsing JDK source files and fixing parse errors. Use when asked to find/fix parse errors, test the parser, or improve JDK compatibility. |
Test Parser with JDK Sources
Overview
This skill helps identify and fix parse errors in the Java parser by running it against JDK source files in testcases/jdk/.
Commands
Run the JDK parse test
go test -v -run TestParseJDKSourceFiles ./java/parser/ 2>&1 | grep -c "parse error"
This shows the total count of files with parse errors.
List files with parse errors
go test -v -run TestParseJDKSourceFiles ./java/parser/ 2>&1 | grep "parse error" | head -20
Parse a specific file and show errors
go run ./cmd/javalyzer parse <file> 2>&1 | grep -i "error"
Example:
go run ./cmd/javalyzer parse testcases/jdk/java.base/java/io/ObjectStreamClass.java 2>&1 | grep -i "error"
Workflow for Fixing Parse Errors
- Identify a failing file: Run the test and pick the first file with errors
- Find the error location: Parse the file and grep for "ERROR:" to see line numbers
- Read the problematic code: Use Read tool to examine the Java syntax at that location
- Understand the syntax: Identify which Java language feature isn't being parsed
- Fix the parser: Edit
java/parser/parser.goto handle the syntax - Verify the fix: Re-parse the file to confirm errors are gone
- Run full test: Check the total error count decreased
- Commit: Use
git commit --no-verify -m "parser: <description of fix>"
Common Parse Error Patterns
- Switch expressions:
case null, default ->(Java 21) - Array type method references:
String[]::new,Class<?>[]::new - Pattern matching:
case String s -> - Record patterns:
case Point(int x, int y) -> - Sealed classes:
sealed class,permits
Key Parser Files
java/parser/parser.go- Main parser implementationjava/parser/grammar.ebnf- Grammar referencejava/parser/lexer.go- Token definitions
Example Error Output
Error [314:24-314:31] ERROR: expected expression
This means at line 314, columns 24-31, the parser expected an expression but found something unexpected.