Skip to content

[WIP] Update Go AST parser with latest Antlr grammar and test coverage#39

Closed
Copilot wants to merge 1 commit intofeat/go-antlr-grammar-updatefrom
copilot/update-go-ast-parser-antlr
Closed

[WIP] Update Go AST parser with latest Antlr grammar and test coverage#39
Copilot wants to merge 1 commit intofeat/go-antlr-grammar-updatefrom
copilot/update-go-ast-parser-antlr

Conversation

Copy link

Copilot AI commented Jan 14, 2026

  • Explore the repository structure and understand the changes
  • Verify all Go tests pass (41 tests: 40 pass, 1 skip)
  • Confirm GoGenericsTest.kt exists with 7 tests for Go 1.18+ features
  • Confirm GoNumberLiteralsTest.kt exists with 7 tests for number literals
  • Verify grammar files (GoLexer.g4, GoParser.g4) are updated with new flat structure
  • Verify GoParserBase.java has new helper methods (isOperand, isConversion, isMethodExpr)
  • Verify GoFullIdentListener.kt refactoring is complete with new methods
  • Verify all test coverage: generics, type constraints, number literals, underscore separators
  • Run code review tool for quality check
  • Run security checks with CodeQL
  • Finalize and complete the task
Original prompt

feat: modernize Go AST parser with latest Antlr grammar and add Go 1.18+ test coverage

Summary

Updated the Go AST parser to use the latest Antlr grammar and added comprehensive test coverage for modern Go syntax including generics and new number literals.

Changes Made

Core Grammar Updates

  • Updated Antlr Go grammar files (GoLexer.g4, GoParser.g4) to latest version with significant structural changes
  • Enhanced GoParserBase.java with new helper methods for parsing disambiguation (isOperand(), isConversion(), isMethodExpr())

Major Listener Refactoring

  • Completely rewrote GoFullIdentListener.kt to handle new flat primaryExpr grammar structure:
    • handlePrimaryExprCall(): Fixed to handle new non-left-recursive structure and support chained method calls
    • handleForPrimary(): Improved local variable resolution with proper isForLocalVar flag handling
    • getValueFromPrintf(): Fixed to find ArgumentsContext at any position in new grammar
    • Added robust support for receiver type resolution and method chaining

Test Coverage Improvements

  • Fixed all test failures: All 41 tests now pass (40 pass, 1 skip)
  • Added GoGenericsTest.kt with 7 comprehensive tests for Go 1.18+ generics:
    • Generic function declarations and calls
    • Generic type definitions with multiple type parameters
    • Methods on generic types
    • Type constraints and interface with type unions
    • Underlying type constraints with tilde (~type)
  • Added GoNumberLiteralsTest.kt with 7 tests for new number literal syntax:
    • Binary literals (0b1010, 0B1111_0000)
    • Underscore separators in all number types (1_000_000)
    • Hexadecimal float literals (0x1.Fp+0)
    • Modern imaginary literals with all number types

Technical Details

The main challenge was adapting to the new Antlr grammar where primaryExpr changed from:

// Old left-recursive structure
primaryExpr: operand | primaryExpr selector | ...

// New flat structure  
primaryExpr: (operand | conversion | methodExpr) (DOT IDENTIFIER | index | slice_ | typeAssertion | arguments)*

This required completely rewriting the method call parsing logic to iterate through flat children instead of recursive descent.

Testing

  • All existing tests continue to pass
  • Added 14 new tests covering Go 1.18+ features
  • Comprehensive coverage of edge cases and chained method calls
  • Tests validate both parsing success and correct AST extraction

Resolves build failures after Antlr grammar update and provides future-ready support for modern Go syntax.

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Jan 14, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

@phodal phodal marked this pull request as ready for review January 14, 2026 15:20
Copilot AI review requested due to automatic review settings January 14, 2026 15:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@phodal
Copy link
Owner

phodal commented Jan 14, 2026

augment review

@phodal phodal closed this Jan 14, 2026
Copilot AI requested a review from phodal January 14, 2026 15:26
Copilot stopped work on behalf of phodal due to an error January 14, 2026 15:26
@augmentcode
Copy link

augmentcode bot commented Jan 14, 2026

🤖 Augment PR Summary

Summary: Modernizes chapi-ast-go by updating the ANTLR Go grammar and adapting the Go AST listener to the new flat primaryExpr structure.
Changes: Adds/updates parser disambiguation helpers and expands test coverage for Go 1.18+ generics and modern numeric literal formats.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

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.

2 participants