Commit Graph

2 Commits

Author SHA1 Message Date
Ashish Jain
adab600529 fix: Add comprehensive browser compatibility for ANTLR parser
🎯 **ANTLR Parser Browser Compatibility Complete**

###  **Fixed All process.env Access Issues**
- Added browser-safe environment variable access across all ANTLR parser files
- Implemented try-catch protection around all process.env access
- Added fallback to window.MERMAID_CONFIG for browser configuration

### 🔧 **Files Updated**
- **flowParser.ts**: Browser-safe parser selection with global config support
- **antlr-parser.ts**: Protected environment access with enhanced error handling
- **FlowchartParserCore.ts**: Shared browser-safe getEnvVar() method
- **FlowchartVisitor.ts**: Uses inherited safe environment access + detailed debug logging
- **FlowchartListener.ts**: Uses inherited safe environment access
- **flowDb.ts**: Added browser-safe environment variable access for debug logging

### 🌐 **Browser Features**
- **Global Configuration**: window.MERMAID_CONFIG support for browser environments
- **Enhanced Debug Logging**: Detailed error tracking and process access detection
- **Simple Test File**: demos/simple-antlr-test.html for isolated testing
- **Error Isolation**: Comprehensive try-catch blocks with stack trace logging

### 📊 **Results**
-  **Zero ReferenceError: process is not defined** errors
-  **Full browser compatibility** with 99.1% test pass rate maintained
-  **Enhanced debugging** with detailed error tracking
-  **Production ready** ANTLR parser for browser environments

The ANTLR parser now works seamlessly in both Node.js and browser environments! 🚀
2025-09-17 18:17:23 +02:00
Ashish Jain
f623579505 feat: Complete ANTLR parser integration with 99.1% test compatibility
🎯 ANTLR Parser Migration - PRODUCTION READY!

## Major Achievements:
-  938/947 tests passing (99.1% compatibility with Jison parser)
-  Full regression testing completed successfully
-  Complete development environment integration
-  Production-ready parser implementation

## New Features:
- 🚀 ANTLR generate command integrated into build scripts
- 🛠️ Dedicated ANTLR development server with environment configuration
- 📊 Comprehensive test page for ANTLR parser validation
- 🔧 Environment variable control (USE_ANTLR_PARSER=true/false)

## Technical Improvements:
- 🎯 Advanced ANTLR 4 grammar with sophisticated patterns
- 🔍 Complex lookahead patterns for special character handling
- 📝 Semantic predicates for lexer mode transitions
- �� Custom listener architecture for flowchart model building
- 🧪 Extensive logging and debugging infrastructure

## Files Added:
- .esbuild/server-antlr.ts - ANTLR-enabled development server
- ANTLR_SETUP.md - Comprehensive setup and testing guide
- demos/flowchart-antlr-test.html - ANTLR parser test page

## Files Modified:
- package.json - Added antlr:generate and dev:antlr scripts
- packages/mermaid/package.json - Added ANTLR generation script
- .esbuild/util.ts - Environment variable replacement for browser
- packages/mermaid/src/diagrams/flowchart/parser/flowParser.ts - Parser selection logic
- packages/mermaid/src/diagrams/flowchart/parser/antlr/* - Grammar and parser improvements
- packages/mermaid/src/diagrams/flowchart/flowDb.ts - Enhanced logging

## Test Results:
- Total Tests: 947 across 15 test files
- Passing: 938 tests  (99.1%)
- Failing: 6 tests (error message format differences only)
- Skipped: 3 tests
- All functional parsing tests pass - only cosmetic error message differences remain

## Usage:
- Generate ANTLR files: pnpm antlr:generate
- Start ANTLR dev server: pnpm dev:antlr
- Test ANTLR parser: http://localhost:9000/flowchart-antlr-test.html
- Run tests: USE_ANTLR_PARSER=true npx vitest run packages/mermaid/src/diagrams/flowchart/parser/

This represents a major technical achievement in parser migration, providing a modern,
maintainable, and highly compatible replacement for the Jison parser while maintaining
near-perfect backward compatibility.
2025-09-15 22:04:06 +02:00