'use strict' ; import { Range } from 'vscode' ; import { Validator } from './validator' ; export class ProblemPattern { regEx : RegExp ; indexMap : number [ ] ; param patternWithMatchGroupOrder param fileNames constructor ( patternWithMatchGroupOrder , fileNames ) { const fileNamesJoint = fileNames . join ( '|' ) . split ( '\\' ) . join ( "\\\\" ) . split ( '.' ) . join ( "\\." ) ; const [ patternOrig , flags , order ] = patternWithMatchGroupOrder . split ( '/' ) . slice ( 1 ) ; const pattern = patternOrig . replace ( '$(filePaths)' , fileNamesJoint ) ; this . regEx = new RegExp ( pattern , flags ) ; this . indexMap = order . split ( ',' ) . map ( str => parseInt ( str ) ) ; } getFilePath ( match ) { return match [ this . mapIndex ( 0 ) ] ; } getSeverity ( match ) { return match [ this . mapIndex ( 1 ) ] ; } getLine ( match ) { return parseInt ( match [ this . mapIndex ( 2 ) ] ) - 1 ; } getCharacter ( match ) { const index = this . mapIndex ( 3 ) ; return index ? parseInt ( match [ index ] ) - 1 : undefined ; } getMessage ( match ) { return match [ this . mapIndex ( 4 ) ] ; } getRange ( match ) { const line = this . getLine ( match ) ; const character = this . getCharacter ( match ) ; return character !== undefined ? Validator . createRange ( line , character ) : Validator . createLineRange ( line ) ; } private mapIndex ( i ) { return this . indexMap [ i ] ; } }