1<?php 2 3declare(strict_types=1); 4 5namespace Antlr\Antlr4\Runtime\Error\Listeners; 6 7use Antlr\Antlr4\Runtime\Atn\ATNConfigSet; 8use Antlr\Antlr4\Runtime\Dfa\DFA; 9use Antlr\Antlr4\Runtime\Error\Exceptions\RecognitionException; 10use Antlr\Antlr4\Runtime\Parser; 11use Antlr\Antlr4\Runtime\Recognizer; 12use Antlr\Antlr4\Runtime\Utils\BitSet; 13 14/** 15 * This implementation of {@see ANTLRErrorListener} dispatches all calls to a 16 * collection of delegate listeners. This reduces the effort required to support 17 * multiple listeners. 18 * 19 * @author Sam Harwell 20 */ 21class ProxyErrorListener implements ANTLRErrorListener 22{ 23 /** @var array<ANTLRErrorListener> */ 24 private $delegates; 25 26 /** 27 * @param array<ANTLRErrorListener> $delegates 28 */ 29 public function __construct(array $delegates) 30 { 31 $this->delegates = $delegates; 32 } 33 34 public function syntaxError( 35 Recognizer $recognizer, 36 ?object $offendingSymbol, 37 int $line, 38 int $charPositionInLine, 39 string $msg, 40 ?RecognitionException $e 41 ) : void { 42 foreach ($this->delegates as $listener) { 43 $listener->syntaxError($recognizer, $offendingSymbol, $line, $charPositionInLine, $msg, $e); 44 } 45 } 46 47 public function reportAmbiguity( 48 Parser $recognizer, 49 DFA $dfa, 50 int $startIndex, 51 int $stopIndex, 52 bool $exact, 53 ?BitSet $ambigAlts, 54 ATNConfigSet $configs 55 ) : void { 56 foreach ($this->delegates as $listener) { 57 $listener->reportAmbiguity($recognizer, $dfa, $startIndex, $stopIndex, $exact, $ambigAlts, $configs); 58 } 59 } 60 61 public function reportAttemptingFullContext( 62 Parser $recognizer, 63 DFA $dfa, 64 int $startIndex, 65 int $stopIndex, 66 ?BitSet $conflictingAlts, 67 ATNConfigSet $configs 68 ) : void { 69 foreach ($this->delegates as $listener) { 70 $listener->reportAttemptingFullContext( 71 $recognizer, 72 $dfa, 73 $startIndex, 74 $stopIndex, 75 $conflictingAlts, 76 $configs 77 ); 78 } 79 } 80 81 public function reportContextSensitivity( 82 Parser $recognizer, 83 DFA $dfa, 84 int $startIndex, 85 int $stopIndex, 86 int $prediction, 87 ATNConfigSet $configs 88 ) : void { 89 foreach ($this->delegates as $listener) { 90 $listener->reportContextSensitivity($recognizer, $dfa, $startIndex, $stopIndex, $prediction, $configs); 91 } 92 } 93} 94