# All files / parser/common parserErrorListener.ts

68.75% Statements 11/16
30% Branches 3/10
75% Functions 3/4
68.75% Lines 11/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    8x

    8x

    10x
    10x

    4x
    4x
    4x

    4x

    8x

    4x
    4x

     import { Token, Recognizer } from 'antlr4';
    import { ErrorListener } from 'antlr4/error';

    export interface ParserError {
       startLine: number;
       endLine: number;
       startCol: number;
       endCol: number;
       message: string;
    }

    export interface SyntaxError {
       recognizer: Recognizer;
       offendingSymbol: Token;
       line: number;
       charPositionInLine: number;
       msg: string;
       e: any;
    }

    export type ErrorHandler = (err: ParserError, errOption: SyntaxError) => void;

    export class ParserErrorCollector extends ErrorListener {
       private _errors: ParserError[];

       constructor(error: ParserError[]) {
          super();
          this._errors = error;
       }

       syntaxError(
          recognizer: Recognizer,
          offendingSymbol: Token,
          line: number,
          charPositionInLine: number,
          msg: string,
          e: any,
       ) {
          let endCol = charPositionInLine + 1;
          Eif (offendingSymbol && offendingSymbol.text !== null) {
             endCol = charPositionInLine + offendingSymbol.text.length;
          }
          this._errors.push({
             startLine: line,
             endLine: line,
             startCol: charPositionInLine,
             endCol: endCol,
             message: msg,
          });
       }
    }

    export default class ParserErrorListener extends ErrorListener {
       private _errorHandler;

       constructor(errorListener: ErrorHandler) {
          super();
          this._errorHandler = errorListener;
       }

       syntaxError(
          recognizer: Recognizer,
          offendingSymbol: Token,
          line: number,
          charPositionInLine: number,
          msg: string,
          e: any,
       ) {
          let endCol = charPositionInLine + 1;
          if (offendingSymbol && offendingSymbol.text !== null) {
             endCol = charPositionInLine + offendingSymbol.text.length;
          }
          if (this._errorHandler) {
             this._errorHandler(
                {
                   startLine: line,
                   endLine: line,
                   startCol: charPositionInLine,
                   endCol: endCol,
                   message: msg,
                },
                {
                   e,
                   line,
                   msg,
                   recognizer,
                   offendingSymbol,
                   charPositionInLine,
                },
             );
          }
       }
    }