/** * This will load up a DSL from the reader specified. * This will make the expander available to any parser * regardless of name. * * The DSL expander will be the default expander. * * This is the constructor most people should use. */ public DefaultExpanderResolver(final Reader reader) throws IOException { final DSLTokenizedMappingFile file = new DSLTokenizedMappingFile(); if ( file.parseAndLoad( reader ) ) { final Expander expander = new DefaultExpander(); expander.addDSLMapping( file.getMapping() ); this.expanders.put( "*", expander ); } else { throw new RuntimeDroolsException( "Error parsing and loading DSL file." + file.getErrors() ); } }
@Override public boolean parseAndLoad(Reader dsl) throws IOException { List<ParserError> errors = new ArrayList<ParserError>(); String text = readFile( dsl ); dsl = new StringReader( text ); DSLMapping mapping = buildFileMapping(errors, dsl); mapping.setOptions( optionSet ); setMapping( mapping ); List<ParserError> moderr = new ArrayList<ParserError>(); for( ParserError err: errors ){ errors.add( parserError ); setErrors( errors );
private DSLMapping buildFileMapping(final List<ParserError> errors, final Reader dsl) throws IOException, RecognitionException{ ANTLRReaderStream reader = new ANTLRReaderStream(dsl); DSLMapWalker walker = buildFileMappingWalker(errors, reader); DSLMapping mapping = walker.mapping_file(); return mapping; }
public void addDsl( Resource resource ) throws IOException { this.resource = resource; DSLTokenizedMappingFile file = new DSLTokenizedMappingFile(); Reader reader = null; try { reader = resource.getReader(); if (!file.parseAndLoad( reader )) { this.results.addAll( file.getErrors() ); } if (this.dslFiles == null) { this.dslFiles = new ArrayList<DSLTokenizedMappingFile>(); } this.dslFiles.add( file ); } finally { if (reader != null) { reader.close(); } this.resource = null; } }
@Test public void testTestAnyEnum() throws Exception { SuggestionCompletionLoader suggestionCompletionLoader = new SuggestionCompletionLoader(); ArrayList<DSLTokenizedMappingFile> dsls = new ArrayList<DSLTokenizedMappingFile>(); DSLTokenizedMappingFile dslTokenizedMappingFile = new DSLTokenizedMappingFile(); DSLMappingEntry dslMappingEntry = mock( DSLMappingEntry.class ); when( dslMappingEntry.getSection() ).thenReturn( DSLMappingEntry.ANY ); dslTokenizedMappingFile.getMapping().addEntry( dslMappingEntry ); dsls.add( dslTokenizedMappingFile ); SuggestionCompletionEngine suggestionEngine = suggestionCompletionLoader.getSuggestionEngine( "", Collections.<JarInputStream> emptyList(), dsls ); assertEquals( 1, suggestionEngine.actionDSLSentences.length ); assertEquals( 1, suggestionEngine.conditionDSLSentences.length ); assertEquals( 0, suggestionEngine.keywordDSLItems.length ); }
private void populateDSLSentences(final List<DSLTokenizedMappingFile> dsls) { for ( DSLTokenizedMappingFile file : dsls ) { for ( DSLMappingEntry entry : file.getMapping().getEntries() ) { if ( entry.getSection() == DSLMappingEntry.CONDITION ) { builder.addDSLConditionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) { builder.addDSLActionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) { builder.addDSLMapping( entry ); } else if ( entry.getSection() == DSLMappingEntry.ANY ) { builder.addDSLConditionSentence( entry.getMappingKey() ); builder.addDSLActionSentence( entry.getMappingKey() ); } } } }
@Test public void testGetExpander() { BRMSPackageBuilder builder = new BRMSPackageBuilder(); List<DSLTokenizedMappingFile> files = new ArrayList<DSLTokenizedMappingFile>(); files.add(new DSLTokenizedMappingFile()); builder.setDSLFiles(files); assertTrue(builder.hasDSL()); assertNotNull(builder.getDSLExpander()); }
private void populateDSLSentences(final List<DSLTokenizedMappingFile> dsls) { for ( DSLTokenizedMappingFile file : dsls ) { for ( DSLMappingEntry entry : file.getMapping().getEntries() ) { if ( entry.getSection() == DSLMappingEntry.CONDITION ) { builder.addDSLConditionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.CONSEQUENCE ) { builder.addDSLActionSentence( entry.getMappingKey() ); } else if ( entry.getSection() == DSLMappingEntry.KEYWORD ) { builder.addDSLMapping( entry ); } else if ( entry.getSection() == DSLMappingEntry.ANY ) { builder.addDSLConditionSentence( entry.getMappingKey() ); builder.addDSLActionSentence( entry.getMappingKey() ); } } } }