-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Add clear command to clear the canvas #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add clear command to clear the canvas #73
Conversation
- Created ClearStatement.java AST node - Added CLEAR token type to TokenType enum - Updated Lexer to recognize 'clear' keyword - Added parseClearStatement method to Parser - Implemented ClearStatement evaluation in Evaluator to emit ClearEvent - Users can now use 'clear' command to reset the canvas during execution
WalkthroughThe pull request adds support for a new "clear" command throughout the kidcode-core system. The "clear" keyword is recognized by the lexer as TokenType.CLEAR, parsed by the parser into a ClearStatement AST node, and evaluated by the evaluator to emit a ClearEvent for canvas clearing. Changes
Sequence DiagramsequenceDiagram
participant Input as Input: "clear"
participant Lexer
participant Parser
participant Evaluator
participant Event as ClearEvent
Input->>Lexer: Scan "clear"
Lexer->>Lexer: Match CLEAR keyword
Lexer-->>Parser: TokenType.CLEAR token
Parser->>Parser: parseClearStatement()
Parser-->>Evaluator: ClearStatement node
Evaluator->>Evaluator: Handle ClearStatement
Evaluator->>Event: Emit ClearEvent
Event-->>Event: Canvas cleared
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
kidcode-core/src/main/java/com/kidcode/core/evaluator/Evaluator.java (1)
141-144: Emit a MoveEvent after ClearEvent to re-seed turtle stateAfter clearing, also send a zero-distance MoveEvent so the UI redraws the turtle at its current position/direction even if no move follows.
- } else if (stmt instanceof ClearStatement) { - // Emit a clear event to clear the canvas - events.add(new ExecutionEvent.ClearEvent()); + } else if (stmt instanceof ClearStatement) { + events.add(new ExecutionEvent.ClearEvent()); + // Re-emit current state so the renderer redraws the turtle post-clear. + events.add(new ExecutionEvent.MoveEvent( + env.getX(), env.getY(), env.getX(), env.getY(), + env.getDirection(), env.isPenDown(), env.getPenColor() + )); }kidcode-core/src/main/java/com/kidcode/core/parser/Parser.java (1)
148-152: No-arg parse is fine; optionally guard against trailing tokensImplementation mirrors HOME. For better UX, consider detecting unexpected tokens after “clear” on the same line and adding a specific error (“'clear' takes no arguments”).
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
kidcode-core/src/main/java/com/kidcode/core/ast/ClearStatement.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/evaluator/Evaluator.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/lexer/Lexer.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/lexer/TokenType.java(1 hunks)kidcode-core/src/main/java/com/kidcode/core/parser/Parser.java(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
kidcode-core/src/main/java/com/kidcode/core/evaluator/Evaluator.java (1)
kidcode-web/src/main/resources/static/app.js (1)
events(273-273)
🔇 Additional comments (4)
kidcode-core/src/main/java/com/kidcode/core/ast/ClearStatement.java (1)
3-6: LGTM; tiny polishRecord-based AST node is consistent. Optionally add a brief Javadoc for grammar (“clear” takes no args). Also confirm the module’s target JDK supports records.
kidcode-core/src/main/java/com/kidcode/core/lexer/TokenType.java (1)
5-5: Enum addition looks goodCLEAR fits under commands; no conflicts spotted.
kidcode-core/src/main/java/com/kidcode/core/lexer/Lexer.java (1)
35-36: Keyword mapping is correct"clear" → TokenType.CLEAR aligns with TokenType and parser changes.
kidcode-core/src/main/java/com/kidcode/core/parser/Parser.java (1)
77-79: Routing for CLEAR added correctlyDispatch to parseClearStatement keeps statement table consistent.
Summary by CodeRabbit