@Test public void testEntityParser() throws SyntaxError { String dsl = "ENTITY User {" + " TEXT code *" + " NUMBER value" + " }" + " " + " ENTITY Test {" + " }"; StringReader reader = new StringReader(dsl); RawSchema rawSchema = SchemaParser.parse(reader); Set<RawEntity> rawEntities = rawSchema.getRawEntities(); assertEquals(2, rawEntities.size()); Map<String, RawEntity> rawModelsByName = rawSchema.getRawEntitiesByName(); RawEntity user = rawModelsByName.get("USER"); Optional<RawEntity.Entry> code = user.getEntries().stream().filter(RawEntity.Entry::isLogicalKey).findAny(); assertTrue(code.isPresent()); RawEntity.Entry entry = code.get(); assertEquals("code", entry.getName()); }
private RawSchema parse() throws SyntaxError { RawSchemaBuilder rawSchemaBuilder = new RawSchemaBuilder(); nextToken(); while (currentToken != TokenType.EOF) { switch (currentToken) { case INTERFACE: rawSchemaBuilder.addInterface(parseEntity()); break; case ENTITY: rawSchemaBuilder.addEntity(parseEntity()); break; } } return rawSchemaBuilder.build(); }
SchemaParser { private RawSchema parse() throws SyntaxError { RawSchemaBuilder rawSchemaBuilder = new RawSchemaBuilder(); nextToken(); while (currentToken != TokenType.EOF) { switch (currentToken) { case INTERFACE: rawSchemaBuilder.addInterface(parseEntity()); break; case ENTITY: rawSchemaBuilder.addEntity(parseEntity()); break; } } return rawSchemaBuilder.build(); } }
SchemaParser { private RawSchema parse() throws SyntaxError { RawSchemaBuilder rawSchemaBuilder = new RawSchemaBuilder(); nextToken(); while (currentToken != TokenType.EOF) { switch (currentToken) { case INTERFACE: rawSchemaBuilder.addInterface(parseEntity()); break; case ENTITY: rawSchemaBuilder.addEntity(parseEntity()); break; } } return rawSchemaBuilder.build(); } private  SchemaParser(Reader r); }
SchemaParser { private RawSchema parse() throws SyntaxError { RawSchemaBuilder rawSchemaBuilder = new RawSchemaBuilder(); nextToken(); while (currentToken != TokenType.EOF) { switch (currentToken) { case INTERFACE: rawSchemaBuilder.addInterface(parseEntity()); break; case ENTITY: rawSchemaBuilder.addEntity(parseEntity()); break; } } return rawSchemaBuilder.build(); } private  SchemaParser(Reader r); static RawSchema parse(Reader r); }
SchemaParser { private RawSchema parse() throws SyntaxError { RawSchemaBuilder rawSchemaBuilder = new RawSchemaBuilder(); nextToken(); while (currentToken != TokenType.EOF) { switch (currentToken) { case INTERFACE: rawSchemaBuilder.addInterface(parseEntity()); break; case ENTITY: rawSchemaBuilder.addEntity(parseEntity()); break; } } return rawSchemaBuilder.build(); } private  SchemaParser(Reader r); static RawSchema parse(Reader r);  }