import { I18nDef } from "../i18n-polyfill" ; license export class ParseLocation { constructor ( public file , public offset , public line , public col ) { } toString ( ) { return this . offset != null ? `${ this . line }:${ this . col }` : "" ; } getContext ( maxChars , maxLines ) { const content = this . file . content ; let startOffset = this . offset ; if ( startOffset != null ) { if ( startOffset > content . length - 1 ) { startOffset = content . length - 1 ; } let endOffset = startOffset ; let ctxChars = 0 ; let ctxLines = 0 ; while ( ctxChars < maxChars && startOffset > 0 ) { startOffset -- ; ctxChars ++ ; if ( content [ startOffset ] === "\n" ) { if ( ++ ctxLines === maxLines ) { break ; } } } ctxChars = 0 ; ctxLines = 0 ; while ( ctxChars < maxChars && endOffset < content . length - 1 ) { endOffset ++ ; ctxChars ++ ; if ( content [ endOffset ] === "\n" ) { if ( ++ ctxLines === maxLines ) { break ; } } } return { before : content . substring ( startOffset , this . offset ) , after : content . substring ( this . offset , endOffset + 1 ) } ; } return null ; } } export class ParseSourceFile { constructor ( public content , public url = "" ) { } } export class ParseSourceSpan { constructor ( public start , public end , public details = null ) { } toString ( ) { return this . start . file . content . substring ( this . start . offset , this . end . offset ) ; } } export enum ParseErrorLevel { WARNING , ERROR } export class ParseError { constructor ( public span , public msg , public level = ParseErrorLevel . ERROR ) { } contextualMessage ( ) { const ctx = this . span . start . getContext ( 100 , 3 ) ; return ctx ? ` ("${ ctx . before }[${ ParseErrorLevel [ this . level ] } ->]${ ctx . after }")` : "" ; } toString ( ) { const details = this . span . details ? `, ${ this . span . details }` : "" ; return `${ this . msg }${ this . contextualMessage ( ) }: ${ this . span . start }${ details }` ; } } /**
 * An i18n error.
 */ export class I18nError extends ParseError { constructor ( span , msg ) { super ( span , msg ) ; } } export function escapeRegExp ( s ) { return s . replace ( /([.*+?^=!:${}()|[\]\/\\])/g , "\\$1" ) ; }