The go-plsql-splitter is a Go library designed to accurately split Oracle PL/SQL scripts into individual statements with precise boundary detection. Using ANTLR4 for parsing (with no regex allowed), it aims to provide developers with a reliable tool for extracting SQL statements that can be validated and executed in deployment pipelines.
- Achieve 100% accurate PL/SQL statement boundary detection
- Provide precise source location tracking for each statement
- Deliver high performance for processing large SQL scripts
- Supply detailed error information for syntax issues
- Software developers building Oracle database deployment tools
- DevOps engineers implementing CI/CD pipelines for database changes
- Database administrators automating SQL script validation
- Anyone building tools that require precise PL/SQL statement extraction
- Split PL/SQL scripts into individual statements with 100% boundary accuracy
- Support all Oracle 19c PL/SQL statement types
- Preserve original statement content exactly as it appears in source
- Track line and column numbers for the start and end of each statement
- Maintain context information for error reporting
- Properly handle both single-line (--) and multi-line (/* */) comments
- Preserve comments in output when they're part of a statement
- Process input from file paths
- Process input from string content
- Consider streaming implementation for large files
- Provide detailed syntax error messages
- Include file, line, and column information in error reports
- Offer context about the statement where the error occurred
- All output structures must support JSON marshalling
- Consistent field naming for easy integration with other tools
- Go 1.24 or later required
- ANTLR4 grammar for Oracle PL/SQL (supporting Oracle 19c syntax)
- No regex allowed for statement splitting
- Public GitHub repository under MIT license
- May require creating or updating ANTLR grammar to support latest language features
- Custom grammar implementation if existing packages are outdated
- Performance optimization for the ANTLR4 parsing process
- Optimize for parsing speed while maintaining accuracy
- Should handle multi-megabyte SQL scripts efficiently
- Minimize memory usage, especially for large files
- Consider streaming approach for very large files to avoid loading entire content
- Avoid excessive CPU usage during parsing
- Balance accuracy with performance
- File paths to PL/SQL scripts
- String content containing PL/SQL statements
- File encoding defaults to UTF-8
- Structured data containing individual SQL statements
- Location information (line/column) for each statement
- Statement type classification if available from ANTLR parser
- Format that supports JSON marshalling
Example output structure:
type Statement struct {
Content string `json:"content"`
StartLine int `json:"startLine"`
EndLine int `json:"endLine"`
StartColumn int `json:"startColumn"`
EndColumn int `json:"endColumn"`
Type string `json:"type,omitempty"` // If available from ANTLR parser
}- Detailed error messages for syntax issues
- Include file, line, and column information
- Clear description of the error nature
Example error structure:
type SyntaxError struct {
Message string `json:"message"`
Line int `json:"line"`
Column int `json:"column"`
Statement string `json:"statement,omitempty"`
}- Proper handling of file not found, permission issues, etc.
- Clear error messages for I/O problems
- No error recovery mechanisms required
- Parser should fail with clear error when syntax is invalid
- Design for compatibility with github.com/zodimo/plsql-parser
- Clear interfaces for integration with this package
- Output format suitable for passing to deployment systems
- Consider common deployment tool requirements
// Basic functions for simple use cases
func SplitFile(filePath string) ([]Statement, error)
func SplitString(content string) ([]Statement, error)// More flexible interface with configuration options
type Splitter struct {
// Configuration options
}
func NewSplitter(options ...Option) *Splitter
func (s *Splitter) SplitFile(filePath string) ([]Statement, error)
func (s *Splitter) SplitString(content string) ([]Statement, error)- Comprehensive test suite with high coverage
- Unit tests for parser components
- Integration tests for full splitting functionality
- Tests for all Oracle 19c statement types
- Edge cases (comments, nested statements, etc.)
- Error cases with invalid syntax
- Benchmark tests for performance optimization
- Memory usage monitoring
- Load testing with large SQL scripts
- Standard Go module
- Public GitHub repository under user zodimo
- MIT license
- Comprehensive README with usage examples
- Godoc API documentation
- Examples for common use cases
- Semantic versioning (SemVer)
- Backward compatibility guarantees
- Evaluate existing PL/SQL grammars for ANTLR4
- May need to fork and modify an existing grammar to support Oracle 19c
- Consider performance optimizations in the grammar
- Use ANTLR4's parse tree listeners or visitors
- Track statement boundaries during parsing
- Handle special cases like anonymous blocks, stored procedures, etc.
- Avoid loading entire files into memory for large scripts
- Consider streaming parser implementation for large files
- Efficient string handling
- Set up project structure
- Implement basic file/string parsing
- Handle simple statement types
- Support all Oracle 19c statement types
- Implement detailed error reporting
- Add position tracking
- Benchmark and optimize for speed
- Memory usage optimization
- Handle edge cases
- Comprehensive documentation
- Usage examples
- Integration examples
- PL/SQL grammar is complex and may require significant effort to get 100% correct
- Specific Oracle 19c syntax features might be challenging to parse
- Balancing parsing accuracy with performance
- ANTLR4 parsers can be memory-intensive for complex grammars
- Handling non-standard PL/SQL syntax extensions
- Correctly parsing complex nested constructs
- Required for parsing
- May have its own version constraints
- Need to define clear interfaces with this package
- Ensure compatible design decisions
- Potential support for newer Oracle versions after 19c
- Backward compatibility with older Oracle versions
- Potential support for other SQL dialects
- Statement validation capabilities
- SQL transformation features
- Ongoing optimization for even better performance
- Support for concurrent parsing