private static void runWithFile( File script, List<String> args ) throws IOException, ParseResultsException { _script = script; // set remaining arguments as arguments to the Gosu program _rawArgs = args; byte[] bytes = StreamUtil.getContent( new BufferedInputStream( new FileInputStream( script ) ) ); String content = StreamUtil.toString( bytes ); IFileContext ctx = new ProgramFileContext( script, makeFqn( script ) ); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions options = new ParserOptions().withFileContext( ctx ); IParseResult result = programParser.parseExpressionOrProgram( content, new StandardSymbolTable( true ), options ); IGosuProgram program = result.getProgram(); Object ret = program.getProgramInstance().evaluate( null ); // evaluate it IType expressionType = result.getType(); if( expressionType != null && !JavaTypes.pVOID().equals( expressionType ) ) { GosuShop.print( ret ); } }
private static void runWithInlineScript( String script, List<String> args ) throws IOException, ParseResultsException { _script = null; // set remaining arguments as arguments to the Gosu program _rawArgs = args; IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); IParseResult result = programParser.parseExpressionOrProgram( script, new StandardSymbolTable( true ), new ParserOptions() ); IGosuProgram program = result.getProgram(); Object ret = program.getProgramInstance().evaluate( null ); // evaluate it IType expressionType = result.getType(); if( expressionType != null && !JavaTypes.pVOID().equals( expressionType ) ) { GosuShop.print( ret ); } }
IGosuProgram program = result.getProgram(); IType expressionType = result.getType(); if( expressionType != null && !JavaTypes.pVOID().equals(expressionType) )