module author Paolo Masci
 *  date copyright import { execSync } from 'child_process' ; import * as fsUtils from '../../../common/fsUtils' ; import { Diagnostic } from 'vscode-languageserver' ; import * as path from 'path' ; import { ParserDiagnostics } from '../../pvs-parser/javaTarget/pvsParser' ; import * as os from 'os' ; export class DdlParser { param desc async parseFile ( desc , opt ? ) { const ofname = ( opt && opt . output ) ? opt . output : "" ; const ifname = fsUtils . desc2fname ( desc ) ; console . info ( `[ddl-parser] Parsing ${ ifname }` ) ; let diags = null ; const libFolder = path . join ( __dirname , "../../../../out/core/lib" ) ; let cmd = `cd ${ libFolder } && java -jar DdlParser.jar ${ ifname }` ; if ( ofname ) { console . log ( `[ddl-parser] Writing file ${ ofname }` ) ; cmd += ` -out ${ ofname };` ; } try { const ans = execSync ( cmd ) ; if ( ans ) { const res = ans . toLocaleString ( ) ; if ( res ) { diags = JSON . parse ( res ) ; if ( diags && diags . errors && diags . errors . length > 0 ) { let msg = `File ${ desc . fileName }${ desc . fileExtension } parsed with errors` ; if ( diags [ "parse-time" ] ) { msg += ` in ${ diags [ "parse-time" ] . ms }ms` ; } console . log ( `[vscode-pvs-parser] ${ msg }` ) ; } else { let msg = `File ${ desc . fileName }${ desc . fileExtension } parsed successfully` ; if ( diags && diags [ "parse-time" ] ) { msg += ` in ${ diags [ "parse-time" ] . ms }ms` ; } console . log ( `[vscode-pvs-parser] ${ msg }` ) ; } } } } catch ( parserError ) { console . log ( parserError ) ; } finally { return diags ; } } param desc async prettyPrint ( desc ) { if ( desc && desc . expr ) { console . info ( `[ddl-parser] Pretty printing pvs expression ${ desc . expr }` ) ; const ddlFile = path . join ( os . tmpdir ( ) , "ddlFile.tmp" ) ; fsUtils . writeFile ( ddlFile , desc . expr ) ; const libFolder = path . join ( __dirname , "../../../../out/core/lib" ) ; let cmd = `cd ${ libFolder } && java -jar DdlPrettyPrinter.jar ${ ddlFile }` ; let res = "" ; try { const ans = execSync ( cmd ) ; if ( ans ) { res = ans . toLocaleString ( ) ; } } finally { return res ; } } return "" ; } }