'use strict' ; import { Diagnostic } from 'vscode' ; import { Validator } from './validator' ; import { ParserOptions , ParserRunContext , ProblemPattern } from 'ai-planning-val' ; import { ProblemInfo , DomainInfo } from 'pddl-workspace' ; import { Parser } from 'ai-planning-val' ; import { toDiagnostics } from './validatorUtils' ; export class ValidatorExecutable extends Validator { private parser : ConfiguredParser ; constructor ( path , public readonly syntax , public readonly customPattern ) { super ( path ) ; this . parser = new ConfiguredParser ( { executablePath : this . path , customPattern , syntax } ) ; } async validate ( domainInfo , problemFiles , onSuccess , onError ) { if ( ! problemFiles . length ) { try { const parsingErrors = await this . parser . validate ( domainInfo ) ; onSuccess . apply ( this , [ toDiagnostics ( parsingErrors , [ domainInfo ] ) ] ) ; } catch ( err ) { onError . apply ( this , [ "" + err ] ) ; } } else { problemFiles . forEach ( async ( problemFile ) => { try { const parsingErrors = await this . parser . validate ( domainInfo , problemFile ) ; onSuccess . apply ( this , [ toDiagnostics ( parsingErrors , [ domainInfo , problemFile ] ) ] ) ; } catch ( err ) { onError . apply ( this , [ "" + err ] ) ; } } ) ; } } } class ConfiguredParser extends Parser { customPattern : string ; args : string [ ] ; constructor ( options ) { super ( options ) ; this . customPattern = options . customPattern ; this . args = options . syntax . split ( ' ' ) ; } protected getSyntax ( ) { return this . args ; } protected createPatternMatchers ( context ) { const filePaths = context . fileNameMap . getFilePaths ( ) ; const patterns = [ new ProblemPattern ( `/^($(filePaths))\\s*:\\s*line\\s*:\\s*(\\d*)\\s*:\\s*(Error|Warning)\\s*:\\s*(.*)$/gmi/1,3,2,0,4` , filePaths ) , new ProblemPattern ( `/(error|warning) at line (\\d+), column (\\d+), file \\(($(filePaths))\\)\\s*:\\s*(.+)/ig/4,1,2,3,5` , filePaths ) , ] ; if ( this . customPattern ) { patterns . push ( new ProblemPattern ( this . customPattern , filePaths ) ) ; } return patterns ; } } interface ConfiguredParserOptions extends ParserOptions { customPattern : string ; syntax : string ; }