/** * Delegate to the actual EBJ scanner. * * @param clazz the class. * @return the runtime annotation handler. */ @Override public RuntimeAnnotationHandler scan(Class<?> clazz) { if (delegate != null) { return delegate.scan(clazz); } return null; }
private void scanConfig(String graniteConfigProperties) { // if config overriding exists Scanner scanner = ScannerFactory.createScanner( this, graniteConfigProperties != null ? graniteConfigProperties : GRANITE_CONFIG_PROPERTIES); try { scanner.scan(); } catch (Exception e) { log.error(e, "Could not scan classpath for configuration"); } }
/** * verify that current token in input matches expected token and advance to next token * * @param expectedToken * @throws SyntaxError if match fails */ private String accept(TokenKind expectedTokenKind) throws SyntaxError { if (token.kind == expectedTokenKind) { if (trace) pTrace(); String tokenSpelling = token.spelling; // previousTokenPosition = token.posn; token = scanner.scan(); return tokenSpelling; } else { parseError("expecting '" + expectedTokenKind + "' but found '" + token.kind + "'"); return null; } }
@Test(expected = LexicalError.class) public void testWeirdChar() throws LexicalError { ITokenList list = null; try { list = scanner.scan(bufferFromString("\u2602")); } catch (IOException e) { fail(e.getMessage()); } if (list == null) { fail("list is null"); } }
public void generateTasks(SModel model, Generator.Modes m, SModel[] allModels) { try { Scanner scanner = new Scanner(Generator.ANT_PATH, getPath(m)); List<ClassInfo> toImport = scanner.scan(); Importer.IClassInfoProvider provider = scanner.createClassInfoProvider(); NamesMap namesMap = scanner.getNamesMap(); Importer<SNode> importer = new Importer<SNode>(toImport, this.getExistingDeclarations(allModels), provider); Generator.Builder builder = new Generator.Builder(model, namesMap); for (ClassInfo cl : scanner.getRoots()) { importer.createDeclaration(builder, cl); } importer.importAll(builder); } catch (IOException e) { Generator.LOG.error(e); } catch (ClassNotFoundException e) { Generator.LOG.error(e); } }
public static void main(String[] argv) throws IOException, SAXException { Scanner s = new PYXScanner(); Reader r = new InputStreamReader(System.in, "UTF-8"); Writer w = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8")); s.scan(r, new PYXWriter(w)); }
/** start parse */ public AST parse() { token = scanner.scan(); AST p = parseProgram(); return p; }
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { Scanner scanner = new Scanner((BeanDefinitionRegistry) beanFactory); scanner.setResourceLoader(this.applicationContext); scanner.scan("org.wcong.test.spring.scan"); }
@Test public void testScanDivide() throws LexicalError { ITokenList list = null; try { list = scanner.scan(getCode("divide.iml")); } catch (IOException e) { fail(e.getMessage()); } if (list == null) { fail("list is null"); } /** Create expected list. */ // program intDiv addToken(new Keyword.Program(), 1); addToken(new Ident("intDiv"), 1); // global addToken(new Keyword.Global(), 2); // proc divide(in copy m:int32, in copy n:int32, out ref q:int32, out ref r:int32) addToken(new Keyword.Proc(), 3); addToken(new Ident("divide"), 3); addToken(new Symbol.LParen(), 3); addToken(new Mode.FlowMode(ModeAttribute.IN), 3); addToken(new Mode.MechMode(ModeAttribute.COPY), 3); addToken(new Ident("m"), 3); addToken(new Symbol.Colon(), 3); addToken(new Type(TypeAttribute.INT32), 3); addToken(new Symbol.Comma(), 3); addToken(new Mode.FlowMode(ModeAttribute.IN), 3); addToken(new Mode.MechMode(ModeAttribute.COPY), 3); addToken(new Ident("n"), 3); addToken(new Symbol.Colon(), 3); addToken(new Type(TypeAttribute.INT32), 3); addToken(new Symbol.Comma(), 3); addToken(new Mode.FlowMode(ModeAttribute.OUT), 3); addToken(new Mode.MechMode(ModeAttribute.REF), 3); addToken(new Ident("q"), 3); addToken(new Symbol.Colon(), 3); addToken(new Type(TypeAttribute.INT32), 3); addToken(new Symbol.Comma(), 3); addToken(new Mode.FlowMode(ModeAttribute.OUT), 3); addToken(new Mode.MechMode(ModeAttribute.REF), 3); addToken(new Ident("r"), 3); addToken(new Symbol.Colon(), 3); addToken(new Type(TypeAttribute.INT32), 3); addToken(new Symbol.RParen(), 3); // { addToken(new Symbol.LBrace(), 4); // q init := 0; addToken(new Ident("q"), 5); addToken(new Keyword.Init(), 5); addToken(new Symbol.Becomes(), 5); addToken(new Literal(0), 5); addToken(new Symbol.Semicolon(), 5); // r init := m; addToken(new Ident("r"), 6); addToken(new Keyword.Init(), 6); addToken(new Symbol.Becomes(), 6); addToken(new Ident("m"), 6); addToken(new Symbol.Semicolon(), 6); // while (r >= n) { addToken(new Keyword.While(), 7); addToken(new Symbol.LParen(), 7); addToken(new Ident("r"), 7); addToken(new Operator.RelOpr(OperatorAttribute.GE), 7); addToken(new Ident("n"), 7); addToken(new Symbol.RParen(), 7); addToken(new Symbol.LBrace(), 7); // q := q + 1; addToken(new Ident("q"), 8); addToken(new Symbol.Becomes(), 8); addToken(new Ident("q"), 8); addToken(new Operator.AddOpr(OperatorAttribute.PLUS), 8); addToken(new Literal(1), 8); addToken(new Symbol.Semicolon(), 8); // r := r - n addToken(new Ident("r"), 9); addToken(new Symbol.Becomes(), 9); addToken(new Ident("r"), 9); addToken(new Operator.AddOpr(OperatorAttribute.MINUS), 9); addToken(new Ident("n"), 9); // } addToken(new Symbol.RBrace(), 10); // }; addToken(new Symbol.RBrace(), 11); addToken(new Symbol.Semicolon(), 11); // var m:int32; addToken(new Mode.ChangeMode(ModeAttribute.VAR), 13); addToken(new Ident("m"), 13); addToken(new Symbol.Colon(), 13); addToken(new Type(TypeAttribute.INT32), 13); addToken(new Symbol.Semicolon(), 13); // var n:int32; addToken(new Mode.ChangeMode(ModeAttribute.VAR), 14); addToken(new Ident("n"), 14); addToken(new Symbol.Colon(), 14); addToken(new Type(TypeAttribute.INT32), 14); addToken(new Symbol.Semicolon(), 14); // var q:int32; addToken(new Mode.ChangeMode(ModeAttribute.VAR), 15); addToken(new Ident("q"), 15); addToken(new Symbol.Colon(), 15); addToken(new Type(TypeAttribute.INT32), 15); addToken(new Symbol.Semicolon(), 15); // var r:int32 addToken(new Mode.ChangeMode(ModeAttribute.VAR), 16); addToken(new Ident("r"), 16); addToken(new Symbol.Colon(), 16); addToken(new Type(TypeAttribute.INT32), 16); // { addToken(new Symbol.LBrace(), 17); // ? m init; addToken(new Symbol.QuestMark(), 18); addToken(new Ident("m"), 18); addToken(new Keyword.Init(), 18); addToken(new Symbol.Semicolon(), 18); // ? n init; addToken(new Symbol.QuestMark(), 19); addToken(new Ident("n"), 19); addToken(new Keyword.Init(), 19); addToken(new Symbol.Semicolon(), 19); // call divide(m, n, q init, r init); addToken(new Keyword.Call(), 20); addToken(new Ident("divide"), 20); addToken(new Symbol.LParen(), 20); addToken(new Ident("m"), 20); addToken(new Symbol.Comma(), 20); addToken(new Ident("n"), 20); addToken(new Symbol.Comma(), 20); addToken(new Ident("q"), 20); addToken(new Keyword.Init(), 20); addToken(new Symbol.Comma(), 20); addToken(new Ident("r"), 20); addToken(new Keyword.Init(), 20); addToken(new Symbol.RParen(), 20); addToken(new Symbol.Semicolon(), 20); // ! q; addToken(new Symbol.ExclaMark(), 21); addToken(new Ident("q"), 21); addToken(new Symbol.Semicolon(), 21); // ! r addToken(new Symbol.ExclaMark(), 22); addToken(new Ident("r"), 22); // } addToken(new Symbol.RBrace(), 23); addToken(new Keyword.Sentinel(), 23); assertEquals(expectedList, list); }