public void setParserOptions( IGosuParser parser ) { parser.setTypeUsesMap( _typeUsesMap ); if( _ti != null ) { parser.setTokenizerInstructor( _ti ); } parser.setGenerateRootExpressionAccessForProgram( _bGenRootExprAccess ); if( _additionalDFSDecls != null ) { parser.putDfsDeclsInTable( _additionalDFSDecls ); } parser.setCaptureSymbolsForEval( _captureSymbolsForEval ); if( _declSymbols != null ) { parser.setDfsDeclInSetByName( _declSymbols ); } parser.setIgnoreWarnings(_ignoreWarnings); }
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 ); }
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); }
IParseTree getDeepestLocationSpanning( int start, int end ) { if( _parser == null ) { return null; } else { List<IParseTree> locations = _parser.getLocations(); return IParseTree.Search.getDeepestLocationSpanning( locations, start - _parser.getOffsetShift(), end - _parser.getOffsetShift(), true ); } }
_parser.setThrowParseExceptionForWarnings( true ); _parser.setDontOptimizeStatementLists( true ); _parser.setValidator( _validator ); _parser.setWarnOnCaseIssue( true ); _parser.setEditorParser( true ); if( _typeUsesMap != null ) _parser.setTypeUsesMap( _typeUsesMap ); if( _parser.getSymbolTable() != getSymbolTable() ) _parser.setSymbolTable( getSymbolTable() ); _parser.setScript( strText ); if( getClassType() == ClassType.Template ) _parser.setTokenizerInstructor( GosuShop.createTemplateInstructor( _parser.getTokenizer() ) ); if( _parser.getSymbolTable() != null ) _parser.putDfsDeclsInTable( _parser.getSymbolTable() ); _parser.putDfsDeclInSetByName( specialFunction ); _parsedGosuClass = _parser.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), strText, _bTestResource, classType ), true, true ); _parser.parseStatements( getScriptPart() ); IParseResult result = programParser.parseExpressionOrProgram( strText, _parser.getSymbolTable(), options );
private IProgram verify( IGosuParser parser, Map<String, List<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, boolean bDoNotThrowParseResultsException ) throws ParseResultsException ISymbolTable symTable = parser.getSymbolTable(); symTable.pushScope(); try parser.setScript( _scriptStr ); if (parser instanceof GosuParser) { parser.setTokenizerInstructor( new TemplateTokenizerInstructor(((GosuParser)parser).getTokenizer()) ); parser.setDfsDeclInSetByName(dfsDeclByName); typeUsesMap = parser.getTypeUsesMap(); } else { parser.setTypeUsesMap(typeUsesMap); parser.setTypeUsesMap(typeUsesMap); IScriptPartId scriptPart = parser.getScriptPart() == null ? new TypelessScriptPartId( GS_TEMPLATE ) : new ScriptPartId( parser.getScriptPart().getContainingType(), GS_TEMPLATE ); return parser.parseProgram( scriptPart, true, false, null, null, false, bDoNotThrowParseResultsException ); for (IParseTree parseTree : parser.getLocations()) { parseTree.setLength(Math.min(parseTree.getLength(), _scriptStr.length() - parseTree.getOffset()));
sb.insert( offset, "; +yennikcm ;" ); // Force a parse exception IGosuParser parserJavadoc = GosuParserFactory.createParser( getSymbolTable(), _scriptabilityModifier ); parserJavadoc.setEditorParser( true ); parserJavadoc.setScript( sb.toString() ); try IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options ); IGosuClass parsedGosuClass = result.getProgram(); ParseResultsException parseResultsException = parsedGosuClass.getParseResultsException(); parserJavadoc.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), sb, _bTestResource, ClassType.Class ), true, true ); parserJavadoc.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), sb, _bTestResource, ClassType.Enhancement ), true, true ); parserJavadoc.parseStatements( getScriptPart() ); parserJavadoc.parseExpOrProgram( getScriptPart() );
((GosuParser)parser).pushScriptPart( id ); parser.setScript( strCompiledSource ); if(parser instanceof GosuParser) { parser.setDfsDeclInSetByName(dfsDeclByName); if (ctxInferenceMgr != null) { ((GosuParser) parser).setContextInferenceManager(ctxInferenceMgr); typeUsesMap = parser.getTypeUsesMap(); } else { parser.setTypeUsesMap(typeUsesMap); for (Entry<String, Set<IFunctionSymbol>> dfsDecls : parser.getDfsDecls().entrySet()) { for (Iterator<IFunctionSymbol> it = dfsDecls.getValue().iterator(); it.hasNext(); ) { IFunctionSymbol fs = it.next(); Program program = (Program)parser.parseProgram( scriptPart, null, null, true ); program.clearParseTreeInformation(); return program;
sb.insert( offset, "; +yennikcm ;" ); // Force a parse exception IGosuParser parserJavadoc = GosuParserFactory.createParser( symTable, ScriptabilityModifiers.SCRIPTABLE ); parserJavadoc.setEditorParser( true ); parserJavadoc.setScript( sb.toString() ); try IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options ); IGosuClass parsedGosuClass = result.getProgram(); ParseResultsException parseResultsException = parsedGosuClass.getParseResultsException(); parserJavadoc.parseClass( gsClass.getName(), new StringSourceFileHandle( gsClass.getName(), sb, false, ClassType.Enhancement ), true, true ); parserJavadoc.parseClass( gsClass.getName(), new StringSourceFileHandle( gsClass.getName(), sb, false, ClassType.Class ), true, true );
public int complete( String buffer, int cursor, List candidates ) parser.setTypeUsesMap( _typeUsesMap ); IParsedElement pe; try pe = parser.parseExpOrProgram( null );
private IGosuFragment parseImpl( String script, ISymbolTable table, ParserOptions options, String name, HashMap<String, ISymbol> externalSymbols, boolean parseExpression ) throws ParseResultsException { IGosuParser parser = GosuParserFactory.createParser( script ); parser.putDfsDeclsInTable( table ); options.setParserOptions( parser ); TypeSystem.pushSymTableCtx(table); try{ parser.setSymbolTable( TypeSystem.getCompiledGosuClassSymbolTable() ); // Set up the symbol table try { if (parseExpression) { result = parser.parseExp( new ScriptPartId(fragment, null), options.getExpectedType(), options.getFileContext(), false ); } else { result = parser.parseProgram( new ScriptPartId(fragment, null), true, true, options.getExpectedType(), options.getFileContext(), false );
private IProgram verify( IGosuParser parser, boolean bDoNotThrowParseResultException ) throws ParseResultsException { HashMap<String, List<IFunctionSymbol>> dfsMap = new HashMap<>(); dfsMap.put( PRINT_METHOD, Collections.<IFunctionSymbol>singletonList(new DynamicFunctionSymbol(parser.getSymbolTable(), PRINT_METHOD, new FunctionType(PRINT_METHOD, GosuParserTypes.NULL_TYPE(), new IType[]{GosuParserTypes.STRING_TYPE(), JavaTypes.pBOOLEAN()}), Arrays.<ISymbol>asList(new Symbol("content", GosuParserTypes.STRING_TYPE(), null), new Symbol("escape", JavaTypes.pBOOLEAN(), null)), (IExpression)null))); dfsMap.put(PRINT_RANGE_METHOD, Collections.<IFunctionSymbol>singletonList(new DynamicFunctionSymbol(parser.getSymbolTable(), PRINT_RANGE_METHOD, new FunctionType(PRINT_RANGE_METHOD, GosuParserTypes.NULL_TYPE(), new IType[]{GosuParserTypes.STRING_TYPE(), JavaTypes.pINT(), JavaTypes.pINT()}), Arrays.<ISymbol>asList(new Symbol("start", JavaTypes.pINT(), null), new Symbol("end", JavaTypes.pINT(), null)), (IExpression) null))); return verify( parser, dfsMap, null, bDoNotThrowParseResultException ); }
private IParseTree returnStatementOrExpression( IParseTree statement ) { if( statement != null ) { return statement; } if( _parser.getLocations().size() == 1 && _parser.getLocations().get( 0 ).getParsedElement() instanceof IExpression ) { return _parser.getLocations().get( 0 ); } return null; }
/** * Creates an IGosuParser appropriate for parsing and executing Gosu. * * @param strSource The text of the the rule source * @param symTable The symbol table the parser uses to parse and execute the rule * @param scriptabilityConstraint Specifies the types of methods/properties that are visible * * @return A parser appropriate for parsing Gosu source. */ public IGosuParser createParser( String strSource, ISymbolTable symTable, IScriptabilityModifier scriptabilityConstraint ) { IGosuParser parser = new GosuParser( symTable, scriptabilityConstraint ); parser.setScript( strSource ); return parser; }
@Override public IParseTree getStatementAtLine( int iLineNum ) { if( _parser != null ) { List<IParseTree> locations = _parser.getLocations(); return IParseTree.Search.getStatementAtLine( locations, iLineNum - _parser.getLineNumShift(), IStatementList.class ); } return null; }
program.setCreateEditorParser( options.getParser().isEditorParser() ); program.setTokenizerInstructor( new TemplateTokenizerInstructor( options.getParser().getTokenizer() ) );
Map<String, List<IFunctionSymbol>> dfsDecls = _editor.getParser().getDfsDecls(); List<IFunctionSymbol> dynamicFunctionSymbols = dfsDecls.get( funcType.getName() ); if( dynamicFunctionSymbols != null )
_parser.setThrowParseExceptionForWarnings( true ); _parser.setDontOptimizeStatementLists( true ); _parser.setValidator( _validator ); _parser.setWarnOnCaseIssue( true ); _parser.setEditorParser( true ); if( _typeUsesMap != null ) _parser.setTypeUsesMap( _typeUsesMap ); if( _parser.getSymbolTable() != getSymbolTable() ) _parser.setSymbolTable( getSymbolTable() ); _parser.setScript( strText ); if( getClassType() == ClassType.Template ) _parser.setTokenizerInstructor( GosuShop.createTemplateInstructor( _parser.getTokenizer() ) ); if( _parser.getSymbolTable() != null ) _parser.putDfsDeclsInTable( _parser.getSymbolTable() ); _parsedGosuClass = _parser.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), strText, _bTestResource, classType ), true, true ); _parser.parseStatements( getScriptPart() ); IParseResult result = programParser.parseExpressionOrProgram( strText, _parser.getSymbolTable(), options ); _parsedGosuClass = result.getProgram(); ParseResultsException parseRes = _parsedGosuClass.getParseResultsException();
private IProgram verify( IGosuParser parser, Map<String, Set<IFunctionSymbol>> dfsDeclByName, ITypeUsesMap typeUsesMap, boolean bDoNotThrowParseResultsException ) throws ParseResultsException ISymbolTable symTable = parser.getSymbolTable(); symTable.pushScope(); try parser.setScript( _scriptStr ); if (parser instanceof GosuParser) { parser.setTokenizerInstructor( new TemplateTokenizerInstructor(((GosuParser)parser).getTokenizer()) ); parser.setDfsDeclInSetByName(dfsDeclByName); typeUsesMap = parser.getTypeUsesMap(); } else { parser.setTypeUsesMap(typeUsesMap); parser.setTypeUsesMap(typeUsesMap); IScriptPartId scriptPart = parser.getScriptPart() == null ? new TypelessScriptPartId( GS_TEMPLATE ) : new ScriptPartId( parser.getScriptPart().getContainingType(), GS_TEMPLATE ); return parser.parseProgram( scriptPart, true, false, null, null, false, bDoNotThrowParseResultsException ); for (IParseTree parseTree : parser.getLocations()) { parseTree.setLength(Math.min(parseTree.getLength(), _scriptStr.length() - parseTree.getOffset()));
sb.insert( iCaretPos, " +yennikcm ;" ); // Force a parse exception IGosuParser parserJavadoc = GosuParserFactory.createParser( getSymbolTable(), _scriptabilityModifier ); parserJavadoc.setEditorParser( true ); parserJavadoc.setScript( sb.toString() ); try IParseResult result = programParser.parseExpressionOrProgram( sb.toString(), parserJavadoc.getSymbolTable(), options ); IGosuClass parsedGosuClass = result.getProgram(); ParseResultsException parseResultsException = parsedGosuClass.getParseResultsException(); parserJavadoc.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), sb, _bTestResource, ClassType.Class ), true, true ); parserJavadoc.parseClass( getScriptPart().getContainingTypeName(), new StringSourceFileHandle( getScriptPart().getContainingTypeName(), sb, _bTestResource, ClassType.Enhancement ), true, true ); parserJavadoc.parseStatements( getScriptPart() ); parserJavadoc.parseExpOrProgram( getScriptPart() );