Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 13, 2025

This PR addresses the "code slop from first initial pass" by cleaning up repetitive patterns, removing dead code, and fixing test dependencies in the lexer implementation.

Changes Made

Lexer Improvements

  • Consolidated repetitive patterns: Replaced 8 nearly identical scoped variable handling blocks with a single helper method try_match_scoped_variable()
  • Extracted magic numbers to constants:
    • SILENT_BANG_LENGTH = 7
    • ELLIPSIS_LENGTH = 3
    • FUNCTION_KEYWORD_LENGTH = 8
  • Added reusable helper methods:
    • add_token(type, value) - standardizes token creation
    • advance_position(length) - handles position tracking
  • Removed dead code: Eliminated commented-out string regex pattern
  • Removed redundant keyword matching: The TOKEN_TYPES hash had a keyword regex that conflicted with explicit keyword handling

Test Cleanup

  • Fixed dependency issues: Removed unnecessary pry requirement that was causing test failures
  • Removed unused code: Eliminated the complex print_ast method in spec_helper that had style violations and wasn't being used
  • Fixed unused variable warning in parser_spec.rb

Code Quality

  • Applied RuboCop auto-corrections for consistent style
  • Added frozen string literal comments and proper formatting
  • Improved code organization and readability

Before/After Comparison

Before:

  • 8 repetitive scoped variable blocks (v:, s:, b:, w:, t:, g:, l:, a:)
  • Magic numbers scattered throughout (7, 3, 8)
  • Commented dead code
  • Test dependency issues preventing clean runs

After:

  • Single configurable helper method with pattern mapping
  • Named constants for all magic numbers
  • Clean, focused code with no dead weight
  • All tests passing cleanly

Impact

  • Net reduction: 60 lines of code removed while maintaining full functionality
  • Maintainability: Easier to add new scoped variable types
  • Reliability: All lexer and unit tests continue to pass
  • Style: Consistent formatting and Ruby best practices

The lexer functionality remains exactly the same - this is purely a cleanup refactor that makes the code more maintainable and removes the "late night session" technical debt.

Fixes #1.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits July 13, 2025 21:22
… constants

Co-authored-by: DanBradbury <2555073+DanBradbury@users.noreply.github.com>
Co-authored-by: DanBradbury <2555073+DanBradbury@users.noreply.github.com>
Copilot AI changed the title [WIP] Code slop from first intial pass Clean up sloppy lexer code and test dependencies from initial implementation Jul 13, 2025
Copilot AI requested a review from DanBradbury July 13, 2025 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code slop from first intial pass

2 participants