public String[] evaluate( String strScript ) IGosuParser scriptParser = GosuParserFactory.createParser(strScript); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions options = new ParserOptions().withParser( scriptParser ); IParseResult parseResult = programParser.parseExpressionOrProgram( strScript, scriptParser.getSymbolTable(), options );
private static boolean parseJavaFile( ISourceFileHandle src, List<CompilationUnitTree> trees, SourcePositions[] sourcePositions, DiagnosticCollector<JavaFileObject> errorHandler, DocTrees[] docTrees ) { IJavaParser javaParser = GosuParserFactory.getInterface( IJavaParser.class ); return javaParser.parseText( src.getSource().getSource().replace( "\r\n", "\n" ), trees, sp -> sourcePositions[0] = sp, dc -> {if( docTrees != null ) docTrees[0] = dc;}, errorHandler ); }
public static IExpression compileExpression( String script, ISymbolTable table, boolean bThrowOnWarning ) throws ParseResultsException { IGosuParser parser = GosuParserFactory.createParser(script, table, ScriptabilityModifiers.SCRIPTABLE); parser.setThrowParseExceptionForWarnings( bThrowOnWarning ); return parser.parseExpOrProgram( null ); }
private IGosuProgram parseProgram( String expr ) throws ParseResultsException { IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions parserOptions = new ParserOptions(); parserOptions.withTypeUsesMap( _interactiveTypeUsesMap ); IParseResult result = programParser.parseExpressionOrProgram( expr, _interactiveSymbolTable, parserOptions ); return result.getProgram(); }
public static IProgram compileProgram(String script, ISymbolTable table) throws ParseResultsException { IGosuParser parser = GosuParserFactory.createParser(script, table, ScriptabilityModifiers.SCRIPTABLE); parser.setEditorParser(true); return parser.parseProgram(null); }
private IGosuProgram parseProgram( String expr ) throws ParseResultsException { IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions parserOptions = new ParserOptions(); parserOptions.withTypeUsesMap( _interactiveTypeUsesMap ); IParseResult result = programParser.parseExpressionOrProgram( expr, _interactiveSymbolTable, parserOptions ); return result.getProgram(); }
public String[] evaluate( String strScript ) IGosuParser scriptParser = GosuParserFactory.createParser(strScript); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); String qualifiedName = ReloadClassesIndicator.getQualifiedName(); if (qualifiedName == null) {
public static IExpression compileExpression( String script, ISymbolTable table ) throws ParseResultsException { IGosuParser parser = GosuParserFactory.createParser(script, table, ScriptabilityModifiers.SCRIPTABLE); parser.setThrowParseExceptionForWarnings( false ); return parser.parseExpOrProgram( null ); }
IGosuProgramParser parser = GosuParserFactory.createProgramParser(); List<ICapturedSymbol> capturedSymbols = evalExpr instanceof EvalExpression ? ((EvalExpression)evalExpr).getCapturedForBytecode() : Collections.<ICapturedSymbol>emptyList();
private static boolean parseJava( List<CompilationUnitTree> trees, Consumer<SourcePositions> sourcePositions, Consumer<DocTrees> docTrees, String src ) { IJavaParser javaParser = GosuParserFactory.getInterface( IJavaParser.class ); DiagnosticCollector<JavaFileObject> errorHandler = new DiagnosticCollector<>(); if( !javaParser.parseText( src, trees, sourcePositions, docTrees, errorHandler ) ) { return false; } return !errorHandler.getDiagnostics().stream().anyMatch( e -> e.getKind() == Diagnostic.Kind.ERROR ); } }
IGosuParser parserJavadoc = GosuParserFactory.createParser( symTable, ScriptabilityModifiers.SCRIPTABLE ); parserJavadoc.setEditorParser( true ); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions options = new ParserOptions().withParser( parserJavadoc ); IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options );
/** * Parses a type name such as Iterable<Claim>. * @param typeName the name to parse * @return the type */ public static IType parseTypeLiteral(String typeName) { try { IType type = GosuParserFactory.createParser(typeName).parseTypeLiteral(null).getType().getType(); if (type instanceof IErrorType) { throw new RuntimeException("Type not found: " + typeName); } return type; } catch (ParseResultsException e) { throw new RuntimeException("Type not found: " + typeName, e); } }
public static IProgramInstance getProgramInstance( String strProgram, ISymbolTable symTable, IType expectedType ) throws Exception { IGosuProgramParser pcp = GosuParserFactory.createProgramParser(); IParseResult res = pcp.parseProgramOnly( strProgram, symTable, new ParserOptions().withExpectedType(expectedType) ); IGosuProgram gp = res.getProgram(); if( !gp.isValid() ) { throw gp.getParseResultsException(); } Class<?> javaClass = gp.getBackingClass(); return (IProgramInstance)javaClass.newInstance(); } }
@Override public byte[] compile() { IJavaParser javaParser = GosuParserFactory.getInterface( IJavaParser.class ); DiagnosticCollector<JavaFileObject> errorHandler = new DiagnosticCollector<>(); ClassJavaFileObject fileObj = javaParser.compile( getName(), Arrays.asList( "-g", "-Xlint:unchecked", "-parameters" ), errorHandler ); if( fileObj != null ) { return fileObj.getBytes(); } throw new JavaCompileIssuesException( errorHandler ); }
IGosuParser parserJavadoc = GosuParserFactory.createParser( getSymbolTable(), _scriptabilityModifier ); parserJavadoc.setEditorParser( true ); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions options = new ParserOptions().withParser( parserJavadoc ); IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options );
/** * Parses a type name such as Iterable<Claim>. * @param typeName the name to parse * @return the type */ public static IType parseTypeLiteral(String typeName) { try { IType type = GosuParserFactory.createParser(typeName).parseTypeLiteral(null).getType().getType(); if (type instanceof IErrorType) { throw new RuntimeException("Type not found: " + typeName); } return type; } catch (ParseResultsException e) { throw new RuntimeException("Type not found: " + typeName, e); } }
public static IProgramInstance getProgramInstance( String strProgram, ISymbolTable symTable, IType expectedType ) throws Exception { IGosuProgramParser pcp = GosuParserFactory.createProgramParser(); IParseResult res = pcp.parseProgramOnly( strProgram, symTable, new ParserOptions().withExpectedType(expectedType) ); IGosuProgram gp = res.getProgram(); if( !gp.isValid() ) { throw gp.getParseResultsException(); } Class<?> javaClass = gp.getBackingClass(); return (IProgramInstance)javaClass.newInstance(); } }
private boolean compileJavaSources( CommandLineOptions options, ICompilerDriver driver, List<String> javaFiles ) { IJavaParser javaParser = GosuParserFactory.getInterface( IJavaParser.class ); DiagnosticCollector<JavaFileObject> errorHandler = new DiagnosticCollector<>(); List<JavaFileObject> sourceFiles = javaFiles.stream().map( SourceJavaFileObject::new ).collect( Collectors.toList() ); Collection<ClassJavaFileObject> files = javaParser.compile( sourceFiles, makeJavacOptions( options ), errorHandler ); errorHandler.getDiagnostics().forEach( driver::sendCompileIssue ); createJavaOutputFiles( files, driver ); if( driver.getErrors().size() > options.getMaxErrs() ) { System.out.printf( "\nError threshold of %d exceeded; aborting compilation.", options.getMaxErrs() ); return true; } if( !options.isNoWarn() && driver.getWarnings().size() > options.getMaxWarns() ) { System.out.printf( "\nWarning threshold of %d exceeded; aborting compilation.", options.getMaxWarns() ); return true; } return false; }
StringBuffer sb = new StringBuffer( _editor.getText() ); sb.insert( iCaretPos, " +yennikcm ;" ); // Force a parse exception IGosuParser parserJavadoc = GosuParserFactory.createParser( getSymbolTable(), _scriptabilityModifier ); parserJavadoc.setEditorParser( true ); IGosuProgramParser programParser = GosuParserFactory.createProgramParser(); ParserOptions options = new ParserOptions().withParser( parserJavadoc ); IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options );
public static IExpression compileExpression( String script, boolean bThrowOnWarning ) throws ParseResultsException { IGosuParser parser = GosuParserFactory.createParser(script, new StandardSymbolTable(true), ScriptabilityModifiers.SCRIPTABLE); parser.setThrowParseExceptionForWarnings( bThrowOnWarning ); return parser.parseExpOrProgram( null ); }