forked from croc-code/sql-boot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create branch croc-code#104 * add md visitor * add md visitor * save register for headers element
- Loading branch information
Showing
9 changed files
with
210 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../java/com/github/mgramin/sqlboot/model/resource_type/impl/composite/md/CustomVisitor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Maksim Gramin | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mgramin.sqlboot.model.resource_type.impl.composite.md; | ||
|
||
import org.commonmark.node.AbstractVisitor; | ||
import org.commonmark.node.FencedCodeBlock; | ||
import org.commonmark.node.Heading; | ||
import org.commonmark.node.Text; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class CustomVisitor extends AbstractVisitor { | ||
|
||
private String currentTag; | ||
private Map<String, String> map = new LinkedHashMap<>(); | ||
|
||
@Override | ||
public void visit(Text text) { | ||
if (text.getParent() instanceof Heading && ((Heading)text.getParent()).getLevel()>=3) { | ||
currentTag = text.getLiteral(); | ||
} | ||
} | ||
|
||
@Override | ||
public void visit(FencedCodeBlock fencedCodeBlock) { | ||
if (fencedCodeBlock.getFenceLength() == 4) { | ||
map.put(currentTag, fencedCodeBlock.getLiteral()); | ||
} | ||
} | ||
|
||
public Map<String, String> getMap() { | ||
return map; | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...n/java/com/github/mgramin/sqlboot/model/resource_type/impl/composite/md/MarkdownFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Maksim Gramin | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mgramin.sqlboot.model.resource_type.impl.composite.md; | ||
|
||
import org.commonmark.node.Node; | ||
import org.commonmark.parser.Parser; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author Maksim Gramin (mgramin@gmail.com) | ||
* @version $Id$ | ||
* @since 0.1 | ||
*/ | ||
// TODO implement com.github.mgramin.sqlboot.tools.files.file.File ? | ||
public class MarkdownFile { | ||
|
||
private final String text; | ||
|
||
public MarkdownFile(final String text) { | ||
this.text = text; | ||
} | ||
|
||
public Map<String, String> parse() { | ||
Parser parser = Parser.builder().build(); | ||
Node document = parser.parse(text); | ||
CustomVisitor visitor = new CustomVisitor(); | ||
document.accept(visitor); | ||
return visitor.getMap(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...va/com/github/mgramin/sqlboot/model/resource_type/impl/composite/md/MarkdownFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2016-2017 Maksim Gramin | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package com.github.mgramin.sqlboot.model.resource_type.impl.composite.md; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public class MarkdownFileTest { | ||
|
||
private Map<String, String> map; | ||
|
||
@Test | ||
public void parse() throws IOException { | ||
String text = FileUtils.readFileToString(new File("test.md")); | ||
|
||
MarkdownFile markdownFile = new MarkdownFile(text); | ||
Map<String, String> parse = markdownFile.parse(); | ||
System.out.println(parse); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Schema | ||
|
||
### get_all_tables | ||
````sql | ||
select u.username as "@schema" | ||
, u.user_id as "user_id" | ||
, u.created as "created" | ||
from all_users u | ||
order by u.username | ||
```` | ||
```sql | ||
select DBMS_DDL.get_metadata(...) | ||
from dual | ||
``` | ||
|
||
### row_count | ||
|
||
````sql | ||
select count(1) | ||
from all_users u | ||
order by u.username | ||
```` |