Skip to content

Commit

Permalink
added DbmlParser as single point of entry
Browse files Browse the repository at this point in the history
  • Loading branch information
nilswende committed Feb 23, 2024
1 parent 0d4fde3 commit 4560a81
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Using Java 17.

Example usage:
```java
import com.wn.dbml.compiler.lexer.LexerImpl;
import com.wn.dbml.compiler.parser.ParserImpl;
import com.wn.dbml.compiler.DbmlParser;
import com.wn.dbml.model.Database;

class Example {
Expand All @@ -18,7 +17,7 @@ class Example {
id integer
}""";
// parse the dbml
Database database = new ParserImpl().parse(new LexerImpl(dbml));
Database database = DbmlParser.parse(dbml);
// process the database structure
database.getSchemas().stream()
.flatMap(schema -> schema.getTables().stream())
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/wn/dbml/compiler/DbmlParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.wn.dbml.compiler;

import com.wn.dbml.compiler.lexer.LexerImpl;
import com.wn.dbml.compiler.parser.ParserImpl;
import com.wn.dbml.model.Database;

import java.io.Reader;

/**
* Creates a database representation using DBML.
*/
public final class DbmlParser {
/**
* Creates a database representation using a DBML string.
*
* @param dbml a DBML string
*/
public static Database parse(final String dbml) {
return new ParserImpl().parse(new LexerImpl(dbml));
}

/**
* Creates a database representation using a DBML reader.
*
* @param dbml a DBML reader
*/
public static Database parse(final Reader dbml) {
return new ParserImpl().parse(new LexerImpl(dbml));
}
}

0 comments on commit 4560a81

Please sign in to comment.