From 9b683d223e06fc5ec9e2561c659de5a79d3a8194 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 10 Sep 2020 21:15:00 +0300 Subject: [PATCH 1/5] Separate multiline code block language from remaining parameters Parse document property Parse separators --- .../sixth/core/document/Document.java | 2 +- .../svjatoslav/sixth/core/document/Utils.java | 4 + .../content/DocumentPropertyCollection.java | 40 ++++++++ .../core/document/content/ListElement.java | 91 ++++++++++++++++--- .../core/document/content/MultilineCode.java | 16 +++- .../document/content/PropertyCollection.java | 14 --- .../core/document/content/Separator.java | 20 ++++ .../core/document/content/TextBlock.java | 17 +++- 8 files changed, 168 insertions(+), 36 deletions(-) create mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/PropertyCollection.java create mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java index e4c45bd..c61d613 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java @@ -62,7 +62,7 @@ public class Document { // DocumentProperty: // "#+OPTIONS: H:20 num:20" - tokenizer.addTerminator(PRESERVE, "#\\+[^\\s]+:.*\\r?\\n", TG_DOCUMENT_PROPERTY); + tokenizer.addTerminator(PRESERVE, "#\\+([^\\s]+):(.*)\\r?\\n", TG_DOCUMENT_PROPERTY); // Drawer property: // " :ID: 533734b9-0456-4448-9830-a43646345615" diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java index 406e7ef..00166ef 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java @@ -20,4 +20,8 @@ public class Utils { return sb.toString(); } + public static boolean isBlank(String s){ + return s.trim().length() == 0; + } + } diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java new file mode 100644 index 0000000..adb3c12 --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java @@ -0,0 +1,40 @@ +package eu.svjatoslav.sixth.core.document.content; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Things like: + * #+RESULTS: + * #+LATEX_HEADER: \\usepackage{parskip} + * #+OPTIONS: H:20 num:20 + * #+attr_latex: :width 300px + */ + +public class DocumentPropertyCollection implements Content { + private Map> keyToValue = new HashMap<>(); + + @Override + public void toMD(StringBuilder sb, int indent) { + } + + public void addProperty(String key, String value){ + getOrCreateValueList(key).add(value); + } + + private List getOrCreateValueList(String key){ + String actualKey = key.toLowerCase(); + if (keyToValue.containsKey(actualKey)) + return keyToValue.get(actualKey); + + List valueList = new ArrayList(); + keyToValue.put(actualKey, valueList); + return valueList; + } + + public boolean hasProperty(String key){ + return keyToValue.containsKey(key.toLowerCase()); + } +} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java index e1cf33d..0db636f 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.List; import static eu.svjatoslav.sixth.core.document.Helper.*; +import static eu.svjatoslav.sixth.core.document.Utils.isBlank; public class ListElement implements Content { public final FormattedText name; @@ -15,7 +16,6 @@ public class ListElement implements Content { public final ListElement parent; private final String type; private final List content = new ArrayList<>(); - StringBuilder normalTextAccumulator = new StringBuilder(); public ListElement(FormattedText name, int indent, ListElement parent, String type) { this.indent = indent; @@ -24,25 +24,26 @@ public class ListElement implements Content { this.parent = parent; } - public void addContent(Content content) { - applyTextAccumulator(); - this.content.add(content); + private Content findCurrentContentElement(){ + if (content.isEmpty()) return null; + return content.get(content.size()-1); } - private void applyTextAccumulator(){ - if (normalTextAccumulator.length() == 0) - return; + private boolean isLastContentElement(Class aClass){ + Content contentElement = findCurrentContentElement(); + if (contentElement == null) return false; - content.add(new TextBlock(normalTextAccumulator.toString())); + return contentElement.getClass().isInstance(aClass); + } - normalTextAccumulator.setLength(0); + public void addContent(Content contentElement){ + content.add(contentElement); } public void parse(TokenizerMatch tm) { if (tm.isGroup(TG_DOCUMENT_PROPERTY)) { - // TODO - // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token); + parseDocumentProperty(tm); return; } @@ -53,14 +54,19 @@ public class ListElement implements Content { } if (tm.isGroup(TG_NORMAL_TEXT)) { - normalTextAccumulator.append(tm.token); + if (isBlank(tm.token)){ + parseSeparator(); + return; + } + + parseTextBlock(tm); return; } if (tm.isGroup(TG_MULTILINE_CODE)){ // System.out.println(tm.toString()); String[] groups = tm.getRegExpGroups(); - addContent(new MultilineCode( + content.add(new MultilineCode( groups[3], // language groups[5] // code )); @@ -69,16 +75,51 @@ public class ListElement implements Content { if (tm.isGroup(TG_VERSE)){ String[] groups = tm.getRegExpGroups(); - addContent(new Verse(groups[5])); + content.add(new Verse(groups[5])); return; } System.out.println("ERROR!!!! Unable to handle: " + tm); } + private void parseTextBlock(TokenizerMatch tm) { + TextBlock textBlock; + if (isLastContentElement(TextBlock.class)) { + textBlock = ((TextBlock) findCurrentContentElement()); + } else { + textBlock = new TextBlock(); + content.add(textBlock); + } + + textBlock.addContent(tm.token + "\n"); + } + + private void parseDocumentProperty(TokenizerMatch tm) { + DocumentPropertyCollection documentPropertyCollection; + + if (isLastContentElement(DocumentPropertyCollection.class)){ + documentPropertyCollection = (DocumentPropertyCollection)findCurrentContentElement(); + } else { + documentPropertyCollection = new DocumentPropertyCollection(); + content.add(documentPropertyCollection); + } + + documentPropertyCollection.addProperty( + tm.getRegExpGroups()[0], + tm.getRegExpGroups()[1]); + } + + private void parseSeparator() { + if (isLastContentElement(Separator.class)){ + ((Separator)findCurrentContentElement()).addLine(); + } else { + content.add(new Separator()); + } + } + public void toMD(StringBuilder sb, int indent) { - applyTextAccumulator(); + disablePlantUmlExport(); if (this.indent >= 0) { String2 s = new String2(); @@ -90,4 +131,24 @@ public class ListElement implements Content { c.toMD(sb, this.indent + 2); } } + + private void disablePlantUmlExport() { + + for (int i = 0; i< (content.size()-2); i++){ + if (!(content.get(i) instanceof MultilineCode)) continue; + + MultilineCode code = (MultilineCode) content.get(i); + if (!"plantuml".equalsIgnoreCase(code.language)) continue;; + + if (!(content.get(i+1) instanceof DocumentPropertyCollection)) continue; + DocumentPropertyCollection property = (DocumentPropertyCollection) content.get(i+1); + + if (!property.hasProperty("results")) continue;; + + if (!(content.get(i+2) instanceof TextBlock)) continue; + TextBlock textBlock = (TextBlock) content.get(i+2); + + textBlock.disableForExport(); + } + } } diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java index db64e3e..212d412 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java @@ -1,13 +1,24 @@ package eu.svjatoslav.sixth.core.document.content; import eu.svjatoslav.commons.string.String2; +import eu.svjatoslav.commons.string.tokenizer.Tokenizer; + +import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP; public class MultilineCode implements Content { public final String language; public final String code; - public MultilineCode(String language, String code) { - this.language = language; + public MultilineCode(String languageAndParams, String code) { + + final Tokenizer tokenizer = new Tokenizer(languageAndParams); + tokenizer.addTerminator(DROP, "[ \\t]+", "whitespace"); + if (tokenizer.hasMoreContent()){ + language = tokenizer.getNextToken().token; + } else { + language = null; + } + this.code = code; } @@ -22,7 +33,6 @@ public class MultilineCode implements Content { } public String getMDlanguage(){ - // TODO: do not append ORG parameters to language, like: file: .... if (language == null) return ""; return language; } diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/PropertyCollection.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/PropertyCollection.java deleted file mode 100644 index 4034670..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/PropertyCollection.java +++ /dev/null @@ -1,14 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import java.util.HashMap; -import java.util.Map; - -public class PropertyCollection implements Content { - - private Map propertyToValue = new HashMap<>(); - - @Override - public void toMD(StringBuilder sb, int indent) { - // TODO - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java new file mode 100644 index 0000000..44097e9 --- /dev/null +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java @@ -0,0 +1,20 @@ +package eu.svjatoslav.sixth.core.document.content; + +public class Separator implements Content { + + private int numLines = 1; + + public Separator(){ + } + + @Override + public void toMD(StringBuilder sb, int indent) { + for (int i = 0; i < numLines; i++) { + sb.append("\n"); + } + } + + public void addLine(){ + numLines++; + } +} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java index a3a4611..56177b6 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java @@ -3,14 +3,25 @@ package eu.svjatoslav.sixth.core.document.content; import eu.svjatoslav.sixth.core.document.text.FormattedText; public class TextBlock implements Content { - private final FormattedText text; + private StringBuilder orgAccumulator = new StringBuilder(); + private boolean enabledForExport = true; - public TextBlock (String contentInOrgMarkup){ - text = FormattedText.fromOrg(contentInOrgMarkup); + public TextBlock (){ + } + + public void addContent(String content){ + orgAccumulator.append(content); } @Override public void toMD(StringBuilder sb, int indent) { + if (!enabledForExport) return; + + FormattedText text = FormattedText.fromOrg(orgAccumulator.toString()); sb.append(text.toMD(indent) + "\n"); } + + public void disableForExport(){ + enabledForExport = false; + } } -- 2.20.1 From 168cf05300cec2bb4c0607711b752609976b2901 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 2 Oct 2020 17:45:00 +0300 Subject: [PATCH 2/5] Misc fixes: Fixed last content element and list title continuation detections. Properly handle list depth decrease. Better parsing of multiline list title. --- .../sixth/core/document/Heading.java | 55 ++++++------------- .../svjatoslav/sixth/core/document/Utils.java | 31 ++++++++++- .../core/document/content/ListElement.java | 25 ++++++--- 3 files changed, 63 insertions(+), 48 deletions(-) diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java index ca72321..8a80d9c 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java @@ -1,7 +1,6 @@ package eu.svjatoslav.sixth.core.document; import eu.svjatoslav.commons.string.String2; -import eu.svjatoslav.commons.string.tokenizer.Tokenizer; import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; import eu.svjatoslav.sixth.core.document.content.ListElement; import eu.svjatoslav.sixth.core.document.text.FormattedText; @@ -58,6 +57,9 @@ public class Heading { public void parse(TokenizerMatch tm){ + int indent = Utils.getLineIndent(tm.token); + if (indent > -1 && indent <= currentListElement.indent) handleListDepthDecrease(indent); + if (tm.isGroup(TG_LIST)){ parseList(tm); return; @@ -66,11 +68,22 @@ public class Heading { currentListElement.parse(tm); } + private void handleListDepthDecrease(int indent) { + while (true){ + if (currentListElement.parent.indent <= indent){ + currentListElement = currentListElement.parent; + return; + } + currentListElement = currentListElement.parent; + } + } + private void parseList(TokenizerMatch tm) { String[] listSections = tm.getRegExpGroups(); int indent = listSections[0].length(); String type = listSections[1]; - FormattedText title = FormattedText.fromOrg(parseFullListTitle(getPartialTitle(listSections), tm.getTokenizer(), indent)); + + String title = getPartialTitle(listSections); if (indent > currentListElement.indent){ // list dept increases @@ -88,47 +101,11 @@ public class Heading { return; } - // list dept decreases - while (true){ - if (currentListElement.parent.indent <= indent){ - ListElement newElement = new ListElement(title, indent, currentListElement.parent.parent, type); - currentListElement.parent.parent.addContent(newElement); - currentListElement = newElement; - return; - } - currentListElement = currentListElement.parent; - } - + throw new RuntimeException("Impossible condition reached. Must be a bug!"); } private String getPartialTitle(String[] listSections) { return listSections.length > 2 ? listSections[2] : ""; } - private String parseFullListTitle(String partialTitle, Tokenizer tokenizer, int listIndent){ - StringBuilder sb = new StringBuilder(); - sb.append(partialTitle); - - while (tokenizer.hasMoreContent()){ - final TokenizerMatch tm = tokenizer.getNextToken(); - - if (isContentContinuation(tm, listIndent, Helper.TG_NORMAL_TEXT)){ - String titleContinuation = tm.token.substring(listIndent).trim(); - sb.append("\n").append(titleContinuation); - continue; - } - - tokenizer.unreadToken(); - break; - } - - return sb.toString(); - } - - public static boolean isContentContinuation(TokenizerMatch tm, int requiredIndent, String requiredGroup) { - if (tm.token.length() <= requiredIndent) return false; - - return tm.isGroup(requiredGroup) && tm.token.substring(0, requiredIndent +1).trim().length() == 0; - } - } diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java index 00166ef..4883d1d 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java @@ -4,6 +4,8 @@ import eu.svjatoslav.commons.string.String2; public class Utils { + public static final char[] whitespace = new char[]{'\n', '\r', ' ', '\t'}; + public static String addIndentExceptFirstLine(String input, int indent) { String[] lines = input.split("\\r?\\n"); @@ -21,7 +23,34 @@ public class Utils { } public static boolean isBlank(String s){ - return s.trim().length() == 0; + for (char c : s.toCharArray()) + if (!isWhitespaceChar(c)) return false; + + return true; + } + + /** + * @return line indent in characters or -1 if line is blank or empty + */ + public static int getLineIndent(String line){ + for (int i = 0; i < line.length(); i++) { + if (!isWhitespaceChar(line.charAt(i))) + return i; + } + return -1; + } + + public static boolean isWhitespaceChar(char c){ + for (char whitespaceChar : whitespace) + if (whitespaceChar == c) return true; + + return false; + } + + public static String removePrefix(String string, int charsToRemove){ + String2 s = new String2(string); + s.trimPrefix(charsToRemove); + return s.toString(); } } diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java index 0db636f..5cfc791 100644 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java +++ b/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java @@ -9,17 +9,18 @@ import java.util.List; import static eu.svjatoslav.sixth.core.document.Helper.*; import static eu.svjatoslav.sixth.core.document.Utils.isBlank; +import static eu.svjatoslav.sixth.core.document.Utils.removePrefix; public class ListElement implements Content { - public final FormattedText name; + StringBuilder nameInOrg = new StringBuilder(); public final int indent; public final ListElement parent; private final String type; private final List content = new ArrayList<>(); - public ListElement(FormattedText name, int indent, ListElement parent, String type) { + public ListElement(String nameInOrg, int indent, ListElement parent, String type) { this.indent = indent; - this.name = name; + this.nameInOrg.append(nameInOrg); this.type = type; this.parent = parent; } @@ -33,7 +34,7 @@ public class ListElement implements Content { Content contentElement = findCurrentContentElement(); if (contentElement == null) return false; - return contentElement.getClass().isInstance(aClass); + return aClass.isInstance(contentElement); } public void addContent(Content contentElement){ @@ -86,12 +87,16 @@ public class ListElement implements Content { TextBlock textBlock; if (isLastContentElement(TextBlock.class)) { textBlock = ((TextBlock) findCurrentContentElement()); + } if (content.isEmpty()){ + // list title continuation + nameInOrg.append("\n").append(removePrefix(tm.token, indent + 2)); + return; } else { textBlock = new TextBlock(); content.add(textBlock); } - textBlock.addContent(tm.token + "\n"); + textBlock.addContent(tm.token); } private void parseDocumentProperty(TokenizerMatch tm) { @@ -123,7 +128,7 @@ public class ListElement implements Content { if (this.indent >= 0) { String2 s = new String2(); - s.append(" ", indent).append(type).append(" ").append(name.toMD(indent + 2)).append("\n"); + s.append(" ", indent).append(type).append(" ").append(getName().toMD(indent + 2)).append("\n"); sb.append(s.toString()); } @@ -132,18 +137,22 @@ public class ListElement implements Content { } } + private FormattedText getName(){ + return FormattedText.fromOrg(nameInOrg.toString()); + } + private void disablePlantUmlExport() { for (int i = 0; i< (content.size()-2); i++){ if (!(content.get(i) instanceof MultilineCode)) continue; MultilineCode code = (MultilineCode) content.get(i); - if (!"plantuml".equalsIgnoreCase(code.language)) continue;; + if (!"plantuml".equalsIgnoreCase(code.language)) continue; if (!(content.get(i+1) instanceof DocumentPropertyCollection)) continue; DocumentPropertyCollection property = (DocumentPropertyCollection) content.get(i+1); - if (!property.hasProperty("results")) continue;; + if (!property.hasProperty("results")) continue; if (!(content.get(i+2) instanceof TextBlock)) continue; TextBlock textBlock = (TextBlock) content.get(i+2); -- 2.20.1 From c91e7d20d9ebd423eae87eb89cc6b69caf1cb8de Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Fri, 20 Nov 2020 17:54:26 +0200 Subject: [PATCH 3/5] Moved Org Mode support to dedicated repository and project. --- .../sixth/core/document/Document.java | 110 ------------ .../sixth/core/document/Heading.java | 111 ------------ .../sixth/core/document/Helper.java | 15 -- .../sixth/core/document/MdGenerator.java | 21 --- .../sixth/core/document/OrgParser.java | 24 --- .../svjatoslav/sixth/core/document/Utils.java | 56 ------ .../sixth/core/document/content/Content.java | 5 - .../content/DocumentPropertyCollection.java | 40 ----- .../core/document/content/ListElement.java | 163 ------------------ .../core/document/content/MultilineCode.java | 39 ----- .../core/document/content/Separator.java | 20 --- .../core/document/content/TextBlock.java | 27 --- .../sixth/core/document/content/Verse.java | 21 --- .../core/document/text/FormattedText.java | 58 ------- .../document/text/FormattedTextElement.java | 6 - .../sixth/core/document/text/Hyperlink.java | 44 ----- .../sixth/core/document/text/PlainText.java | 17 -- 17 files changed, 777 deletions(-) delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/Document.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/Heading.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/Helper.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/Utils.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/Content.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/content/Verse.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedText.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedTextElement.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java delete mode 100644 src/main/java/eu/svjatoslav/sixth/core/document/text/PlainText.java diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java b/src/main/java/eu/svjatoslav/sixth/core/document/Document.java deleted file mode 100644 index c61d613..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Document.java +++ /dev/null @@ -1,110 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; -import eu.svjatoslav.commons.string.tokenizer.Tokenizer; -import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; -import eu.svjatoslav.sixth.core.document.text.FormattedText; - -import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.PRESERVE; -import static eu.svjatoslav.sixth.core.document.Helper.*; -import static eu.svjatoslav.sixth.core.document.text.FormattedText.fromOrg; - -public class Document { - public final Heading rootHeading = new Heading( null , 0, null); - private Heading currentHeading = rootHeading; - - public Heading createHeading(FormattedText name, int targetLevel){ - if (currentHeading.level == (targetLevel - 1)){ - Heading newHeading = new Heading(name, targetLevel, currentHeading); - currentHeading.addChild(newHeading); - currentHeading = newHeading; - return newHeading; - } - - if (currentHeading.level > (targetLevel - 1)){ - currentHeading = currentHeading.parent; - return createHeading(name, targetLevel); - } - - Heading missingIntermediate = new Heading(fromOrg(""), currentHeading.level + 1, currentHeading); - currentHeading.addChild(missingIntermediate); - currentHeading = missingIntermediate; - return createHeading(name, targetLevel); - } - - public Heading getCurrentHeading(){ - return currentHeading; - } - - private void parseHeading(TokenizerMatch token) throws InvalidSyntaxException { - String[] headingSections = token.getRegExpGroups(); - int level = headingSections[0].length(); - String title = headingSections[1]; - createHeading(fromOrg(title), level); - } - - public void parse(String fileContentsAsString) throws InvalidSyntaxException { - final Tokenizer tokenizer = new Tokenizer(fileContentsAsString); - - // Org heading: - // "*** Example Heading 1234" - tokenizer.addTerminator(PRESERVE, "(\\*+)[ \\t](.*)\\r?\\n", TG_HEADING); - - // Org list. Examples: - // " + my list title" - // " - my list title" - tokenizer.addTerminator(PRESERVE, "([ \\t]*)(\\+|-)[ \\t]+(.*)?\\r?\\n", TG_LIST); - - // " * my list title" - tokenizer.addTerminator(PRESERVE, "([ \\t]+)(\\*)[ \\t]+(.*)?\\r?\\n", TG_LIST); - - // TODO: add numbered list - - // DocumentProperty: - // "#+OPTIONS: H:20 num:20" - tokenizer.addTerminator(PRESERVE, "#\\+([^\\s]+):(.*)\\r?\\n", TG_DOCUMENT_PROPERTY); - - // Drawer property: - // " :ID: 533734b9-0456-4448-9830-a43646345615" - tokenizer.addTerminator(PRESERVE, "([ \\t]*):([^\\s]+):(.*)\\r?\\n", TG_DRAWER_PROPERTY); - - - // multiline code block - tokenizer.addTerminator(PRESERVE, - "([ \\t]*)#\\+BEGIN_SRC" + // source begin identifier - "(([ \\t]+)(.*))?(\\r?\\n)" + // source block parameters - "((?:.|\\n|\\r)*?)" + // source content - "(\\r?\\n)([ \\t]*)#\\+END_SRC(.*)\\r?\\n" // source end identifier - , TG_MULTILINE_CODE); - - // verse - tokenizer.addTerminator(PRESERVE, - "([ \\t]*)#\\+BEGIN_VERSE" + // verse begin identifier - "(([ \\t]+)(.*))?(\\r?\\n)" + // verse block parameters - "((?:.|\\n|\\r)*?)" + // verse - "(\\r?\\n)([ \\t]*)#\\+END_VERSE(.*)\\r?\\n" // verse end identifier - , TG_VERSE); - - - // TODO: add support for export blocks: - // #+begin_export latex - // \clearpage - //#+end_export - - - // normal text - tokenizer.addTerminator(PRESERVE,".*\\r?\\n", TG_NORMAL_TEXT); - - while (tokenizer.hasMoreContent()) { - final TokenizerMatch tm = tokenizer.getNextToken(); - - if (tm.isGroup(TG_HEADING)){ - parseHeading(tm); - continue; - } - - currentHeading.parse(tm); - } - - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java b/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java deleted file mode 100644 index 8a80d9c..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Heading.java +++ /dev/null @@ -1,111 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -import eu.svjatoslav.commons.string.String2; -import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; -import eu.svjatoslav.sixth.core.document.content.ListElement; -import eu.svjatoslav.sixth.core.document.text.FormattedText; - -import java.util.ArrayList; -import java.util.List; - -import static eu.svjatoslav.sixth.core.document.Helper.TG_LIST; - -public class Heading { - public final FormattedText name; - public final int level; - public final Heading parent; - private final List children = new ArrayList<>(); - - public final ListElement rootListElement = new ListElement(null, -2, null, ""); - private ListElement currentListElement = rootListElement; - - public Heading(FormattedText name, int level, Heading parent){ - this.level = level; - this.name = name; - this.parent = parent; - } - - public void addChild(Heading heading){ - children.add(heading); - } - - public List getChildren(){ - return children; - } - - public String toMD () { - StringBuilder sb = new StringBuilder(); - - if (level > 0) sb.append(enlistTitleInMD()); - - rootListElement.toMD(sb, -2); - - children.stream().map(Heading::toMD).forEach(sb::append); - - return sb.toString(); - } - - private String enlistTitleInMD() { - String2 s = new String2(); - s.append("#", level).append(" ").append(name.toMD(0)).append("\n"); - return s.toString(); - } - - public ListElement getCurrentHeading(){ - return currentListElement; - } - - public void parse(TokenizerMatch tm){ - - int indent = Utils.getLineIndent(tm.token); - if (indent > -1 && indent <= currentListElement.indent) handleListDepthDecrease(indent); - - if (tm.isGroup(TG_LIST)){ - parseList(tm); - return; - } - - currentListElement.parse(tm); - } - - private void handleListDepthDecrease(int indent) { - while (true){ - if (currentListElement.parent.indent <= indent){ - currentListElement = currentListElement.parent; - return; - } - currentListElement = currentListElement.parent; - } - } - - private void parseList(TokenizerMatch tm) { - String[] listSections = tm.getRegExpGroups(); - int indent = listSections[0].length(); - String type = listSections[1]; - - String title = getPartialTitle(listSections); - - if (indent > currentListElement.indent){ - // list dept increases - ListElement newElement = new ListElement(title, indent, currentListElement, type); - currentListElement.addContent(newElement); - currentListElement = newElement; - return; - } - - if (indent > currentListElement.parent.indent){ - // list depth is the same - ListElement newElement = new ListElement(title, indent, currentListElement.parent, type); - currentListElement.parent.addContent(newElement); - currentListElement = newElement; - return; - } - - throw new RuntimeException("Impossible condition reached. Must be a bug!"); - } - - private String getPartialTitle(String[] listSections) { - return listSections.length > 2 ? listSections[2] : ""; - } - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Helper.java b/src/main/java/eu/svjatoslav/sixth/core/document/Helper.java deleted file mode 100644 index 7ae3274..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Helper.java +++ /dev/null @@ -1,15 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -public class Helper { - - public static final String TG_NORMAL_TEXT = "normaltext"; - public static final String TG_MULTILINE_CODE = "multiline code"; - public static final String TG_VERSE = "verse"; - public static final String TG_HYPERLINK = "hyperlink"; - public static final String TG_HEADING = "heading"; - public static final String TG_LIST = "list"; - - public static final String TG_DOCUMENT_PROPERTY = "document property"; - public static final String TG_DRAWER_PROPERTY = "drawer property"; - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java b/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java deleted file mode 100644 index fbc8320..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/MdGenerator.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -import java.io.File; -import java.io.IOException; - -import static eu.svjatoslav.commons.file.IOHelper.saveToFile; - -public class MdGenerator { - - private StringBuilder sb; - - public void generate(Document document, File file) throws IOException { - sb = new StringBuilder(); - - sb.append(document.rootHeading.toMD()); - - saveToFile(file, sb.toString()); - } - - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java b/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java deleted file mode 100644 index 8822d21..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/OrgParser.java +++ /dev/null @@ -1,24 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -import eu.svjatoslav.commons.string.tokenizer.InvalidSyntaxException; - -import java.io.File; -import java.io.IOException; - -import static eu.svjatoslav.commons.file.IOHelper.getFileContentsAsString; - -public class OrgParser { - - private Document document; - - public Document parse(File file) throws IOException, InvalidSyntaxException { - document = new Document(); - - String fileContentsAsString = getFileContentsAsString(file); - - document.parse(fileContentsAsString); - - return document; - } - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java b/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java deleted file mode 100644 index 4883d1d..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/Utils.java +++ /dev/null @@ -1,56 +0,0 @@ -package eu.svjatoslav.sixth.core.document; - -import eu.svjatoslav.commons.string.String2; - -public class Utils { - - public static final char[] whitespace = new char[]{'\n', '\r', ' ', '\t'}; - - public static String addIndentExceptFirstLine(String input, int indent) { - String[] lines = input.split("\\r?\\n"); - - StringBuilder sb = new StringBuilder(); - - if (lines.length >0 ) sb.append(lines[0]); - - for (int i = 1; i< lines.length; i++) { - sb.append("\n"); - sb.append(new String2(" ").repeat(indent).toString()); - sb.append(lines[i]); - } - - return sb.toString(); - } - - public static boolean isBlank(String s){ - for (char c : s.toCharArray()) - if (!isWhitespaceChar(c)) return false; - - return true; - } - - /** - * @return line indent in characters or -1 if line is blank or empty - */ - public static int getLineIndent(String line){ - for (int i = 0; i < line.length(); i++) { - if (!isWhitespaceChar(line.charAt(i))) - return i; - } - return -1; - } - - public static boolean isWhitespaceChar(char c){ - for (char whitespaceChar : whitespace) - if (whitespaceChar == c) return true; - - return false; - } - - public static String removePrefix(String string, int charsToRemove){ - String2 s = new String2(string); - s.trimPrefix(charsToRemove); - return s.toString(); - } - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/Content.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/Content.java deleted file mode 100644 index 1dad36c..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/Content.java +++ /dev/null @@ -1,5 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -public interface Content { - void toMD(StringBuilder sb, int indent); -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java deleted file mode 100644 index adb3c12..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/DocumentPropertyCollection.java +++ /dev/null @@ -1,40 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Things like: - * #+RESULTS: - * #+LATEX_HEADER: \\usepackage{parskip} - * #+OPTIONS: H:20 num:20 - * #+attr_latex: :width 300px - */ - -public class DocumentPropertyCollection implements Content { - private Map> keyToValue = new HashMap<>(); - - @Override - public void toMD(StringBuilder sb, int indent) { - } - - public void addProperty(String key, String value){ - getOrCreateValueList(key).add(value); - } - - private List getOrCreateValueList(String key){ - String actualKey = key.toLowerCase(); - if (keyToValue.containsKey(actualKey)) - return keyToValue.get(actualKey); - - List valueList = new ArrayList(); - keyToValue.put(actualKey, valueList); - return valueList; - } - - public boolean hasProperty(String key){ - return keyToValue.containsKey(key.toLowerCase()); - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java deleted file mode 100644 index 5cfc791..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/ListElement.java +++ /dev/null @@ -1,163 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import eu.svjatoslav.commons.string.String2; -import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; -import eu.svjatoslav.sixth.core.document.text.FormattedText; - -import java.util.ArrayList; -import java.util.List; - -import static eu.svjatoslav.sixth.core.document.Helper.*; -import static eu.svjatoslav.sixth.core.document.Utils.isBlank; -import static eu.svjatoslav.sixth.core.document.Utils.removePrefix; - -public class ListElement implements Content { - StringBuilder nameInOrg = new StringBuilder(); - public final int indent; - public final ListElement parent; - private final String type; - private final List content = new ArrayList<>(); - - public ListElement(String nameInOrg, int indent, ListElement parent, String type) { - this.indent = indent; - this.nameInOrg.append(nameInOrg); - this.type = type; - this.parent = parent; - } - - private Content findCurrentContentElement(){ - if (content.isEmpty()) return null; - return content.get(content.size()-1); - } - - private boolean isLastContentElement(Class aClass){ - Content contentElement = findCurrentContentElement(); - if (contentElement == null) return false; - - return aClass.isInstance(contentElement); - } - - public void addContent(Content contentElement){ - content.add(contentElement); - } - - public void parse(TokenizerMatch tm) { - - if (tm.isGroup(TG_DOCUMENT_PROPERTY)) { - parseDocumentProperty(tm); - return; - } - - if (tm.isGroup(TG_DRAWER_PROPERTY)) { - // TODO - // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token); - return; - } - - if (tm.isGroup(TG_NORMAL_TEXT)) { - if (isBlank(tm.token)){ - parseSeparator(); - return; - } - - parseTextBlock(tm); - return; - } - - if (tm.isGroup(TG_MULTILINE_CODE)){ - // System.out.println(tm.toString()); - String[] groups = tm.getRegExpGroups(); - content.add(new MultilineCode( - groups[3], // language - groups[5] // code - )); - return; - } - - if (tm.isGroup(TG_VERSE)){ - String[] groups = tm.getRegExpGroups(); - content.add(new Verse(groups[5])); - return; - } - - System.out.println("ERROR!!!! Unable to handle: " + tm); - } - - private void parseTextBlock(TokenizerMatch tm) { - TextBlock textBlock; - if (isLastContentElement(TextBlock.class)) { - textBlock = ((TextBlock) findCurrentContentElement()); - } if (content.isEmpty()){ - // list title continuation - nameInOrg.append("\n").append(removePrefix(tm.token, indent + 2)); - return; - } else { - textBlock = new TextBlock(); - content.add(textBlock); - } - - textBlock.addContent(tm.token); - } - - private void parseDocumentProperty(TokenizerMatch tm) { - DocumentPropertyCollection documentPropertyCollection; - - if (isLastContentElement(DocumentPropertyCollection.class)){ - documentPropertyCollection = (DocumentPropertyCollection)findCurrentContentElement(); - } else { - documentPropertyCollection = new DocumentPropertyCollection(); - content.add(documentPropertyCollection); - } - - documentPropertyCollection.addProperty( - tm.getRegExpGroups()[0], - tm.getRegExpGroups()[1]); - } - - private void parseSeparator() { - if (isLastContentElement(Separator.class)){ - ((Separator)findCurrentContentElement()).addLine(); - } else { - content.add(new Separator()); - } - } - - - public void toMD(StringBuilder sb, int indent) { - disablePlantUmlExport(); - - if (this.indent >= 0) { - String2 s = new String2(); - s.append(" ", indent).append(type).append(" ").append(getName().toMD(indent + 2)).append("\n"); - sb.append(s.toString()); - } - - for (Content c : content) { - c.toMD(sb, this.indent + 2); - } - } - - private FormattedText getName(){ - return FormattedText.fromOrg(nameInOrg.toString()); - } - - private void disablePlantUmlExport() { - - for (int i = 0; i< (content.size()-2); i++){ - if (!(content.get(i) instanceof MultilineCode)) continue; - - MultilineCode code = (MultilineCode) content.get(i); - if (!"plantuml".equalsIgnoreCase(code.language)) continue; - - if (!(content.get(i+1) instanceof DocumentPropertyCollection)) continue; - DocumentPropertyCollection property = (DocumentPropertyCollection) content.get(i+1); - - if (!property.hasProperty("results")) continue; - - if (!(content.get(i+2) instanceof TextBlock)) continue; - TextBlock textBlock = (TextBlock) content.get(i+2); - - textBlock.disableForExport(); - } - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java deleted file mode 100644 index 212d412..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/MultilineCode.java +++ /dev/null @@ -1,39 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import eu.svjatoslav.commons.string.String2; -import eu.svjatoslav.commons.string.tokenizer.Tokenizer; - -import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP; - -public class MultilineCode implements Content { - public final String language; - public final String code; - - public MultilineCode(String languageAndParams, String code) { - - final Tokenizer tokenizer = new Tokenizer(languageAndParams); - tokenizer.addTerminator(DROP, "[ \\t]+", "whitespace"); - if (tokenizer.hasMoreContent()){ - language = tokenizer.getNextToken().token; - } else { - language = null; - } - - this.code = code; - } - - @Override - public void toMD(StringBuilder sb, int indent) { - String2 s = new String2(); - s.append(" ", indent).append("```" + getMDlanguage() + "\n"); - // TODO: ensure that required indent is present - s.append(code + "\n"); - s.append(" ", indent).append("```\n"); - sb.append(s.toString()); - } - - public String getMDlanguage(){ - if (language == null) return ""; - return language; - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java deleted file mode 100644 index 44097e9..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/Separator.java +++ /dev/null @@ -1,20 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -public class Separator implements Content { - - private int numLines = 1; - - public Separator(){ - } - - @Override - public void toMD(StringBuilder sb, int indent) { - for (int i = 0; i < numLines; i++) { - sb.append("\n"); - } - } - - public void addLine(){ - numLines++; - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java deleted file mode 100644 index 56177b6..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/TextBlock.java +++ /dev/null @@ -1,27 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import eu.svjatoslav.sixth.core.document.text.FormattedText; - -public class TextBlock implements Content { - private StringBuilder orgAccumulator = new StringBuilder(); - private boolean enabledForExport = true; - - public TextBlock (){ - } - - public void addContent(String content){ - orgAccumulator.append(content); - } - - @Override - public void toMD(StringBuilder sb, int indent) { - if (!enabledForExport) return; - - FormattedText text = FormattedText.fromOrg(orgAccumulator.toString()); - sb.append(text.toMD(indent) + "\n"); - } - - public void disableForExport(){ - enabledForExport = false; - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/content/Verse.java b/src/main/java/eu/svjatoslav/sixth/core/document/content/Verse.java deleted file mode 100644 index 9c62af7..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/content/Verse.java +++ /dev/null @@ -1,21 +0,0 @@ -package eu.svjatoslav.sixth.core.document.content; - -import eu.svjatoslav.commons.string.String2; - -public class Verse implements Content { - public final String verse; - - public Verse(String verse) { - this.verse = verse; - } - - @Override - public void toMD(StringBuilder sb, int indent) { - String2 s = new String2(); - s.append(" ", indent).append("```\n"); - // TODO: ensure that required indent is present - s.append(verse + "\n"); - s.append(" ", indent).append("```\n"); - sb.append(s.toString()); - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedText.java b/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedText.java deleted file mode 100644 index 350abf3..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedText.java +++ /dev/null @@ -1,58 +0,0 @@ -package eu.svjatoslav.sixth.core.document.text; - -import eu.svjatoslav.commons.string.tokenizer.Tokenizer; -import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; - -import java.util.ArrayList; -import java.util.List; - -import static eu.svjatoslav.sixth.core.document.Helper.TG_HYPERLINK; -import static eu.svjatoslav.sixth.core.document.Utils.addIndentExceptFirstLine; - -public class FormattedText { - List elements = new ArrayList<>(); - - public void parseOrgSyntax(String orgText) { - - Tokenizer tokenizer = getTokenizer(orgText); - while (tokenizer.hasMoreContent()) { - final TokenizerMatch token = tokenizer.getNextToken(); - - if (token.isGroup(TG_HYPERLINK)){ - elements.add(Hyperlink.fromOrg(token)); - continue; - } - - PlainText plainText = new PlainText(token.token); - elements.add(plainText); - } - - } - - public static FormattedText fromOrg(String orgText){ - FormattedText formattedText = new FormattedText(); - formattedText.parseOrgSyntax(orgText); - return formattedText; - } - - public String toMD(int indent){ - StringBuilder sb = new StringBuilder(); - - for (FormattedTextElement element : elements) - sb.append(element.toMD()); - - return addIndentExceptFirstLine(sb.toString(), indent); - } - - private Tokenizer getTokenizer(String contents) { - final Tokenizer tokenizer = new Tokenizer(contents); - tokenizer.addTerminator(Hyperlink.orgTerminator); - tokenizer.addTerminator(Hyperlink.orgTerminator2); - return tokenizer; - } - - - public String toString(){ - return toMD(0); - } -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedTextElement.java b/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedTextElement.java deleted file mode 100644 index 9a17ce0..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/text/FormattedTextElement.java +++ /dev/null @@ -1,6 +0,0 @@ -package eu.svjatoslav.sixth.core.document.text; - -public interface FormattedTextElement { - String toMD(); -} - diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java b/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java deleted file mode 100644 index 508003c..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/text/Hyperlink.java +++ /dev/null @@ -1,44 +0,0 @@ -package eu.svjatoslav.sixth.core.document.text; - -import eu.svjatoslav.commons.string.tokenizer.Terminator; -import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch; - -import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.PRESERVE; -import static eu.svjatoslav.sixth.core.document.Helper.TG_HYPERLINK; - -public class Hyperlink implements FormattedTextElement { - - public static final Terminator orgTerminator = - new Terminator(PRESERVE, "\\[\\[([\\s\\S]+)\\][ \\t\\r\\n]*\\[([\\s\\S]+)\\]\\]", TG_HYPERLINK); - - public static final Terminator orgTerminator2 = - new Terminator(PRESERVE, "\\[\\[([\\s\\S]+)\\]\\]", TG_HYPERLINK); - - private String label; - private String URL; - - @Override - public String toMD() { - - if (URL.startsWith("id:")) - return label; // TODO - - return "[" + label + "]("+ URL + ")"; - } - - public static Hyperlink fromOrg(TokenizerMatch tokenizerMatch) { - Hyperlink hyperlink = new Hyperlink(); - hyperlink.parseOrg(tokenizerMatch); - return hyperlink; - } - - private void parseOrg(TokenizerMatch tokenizerMatch) { - String[] regExpGroups = tokenizerMatch.getRegExpGroups(); - URL = regExpGroups[0]; - if (tokenizerMatch.terminator == orgTerminator){ - label = regExpGroups[1]; - } - - } - -} diff --git a/src/main/java/eu/svjatoslav/sixth/core/document/text/PlainText.java b/src/main/java/eu/svjatoslav/sixth/core/document/text/PlainText.java deleted file mode 100644 index b025248..0000000 --- a/src/main/java/eu/svjatoslav/sixth/core/document/text/PlainText.java +++ /dev/null @@ -1,17 +0,0 @@ -package eu.svjatoslav.sixth.core.document.text; - -public class PlainText implements FormattedTextElement { - - private String content; - - public PlainText(String content){ - this.content = content; - } - - @Override - public String toMD() { - return content; - } -} - - -- 2.20.1 From 73e6624b6127a89f3f17decf102222b6fbcd023b Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 20 Dec 2020 19:31:55 +0200 Subject: [PATCH 4/5] Use alternative user name for git SCM --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e8e9fea..9ffdb0e 100644 --- a/pom.xml +++ b/pom.xml @@ -116,8 +116,8 @@ - scm:git:ssh://git@svjatoslav.eu/home/git/repositories/sixth.git - scm:git:ssh://git@svjatoslav.eu/home/git/repositories/sixth.git + scm:git:ssh://n0@svjatoslav.eu/home/git/repositories/sixth.git + scm:git:ssh://n0@svjatoslav.eu/home/git/repositories/sixth.git -- 2.20.1 From 919302c645e808b73bfc096f92174dc2f4e5e95e Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 30 Oct 2022 12:27:40 +0200 Subject: [PATCH 5/5] Added mentions for interesting projects --- doc/index.html | 648 +++++++++++++++++++++++++++---------------------- doc/index.org | 41 ++++ 2 files changed, 393 insertions(+), 296 deletions(-) diff --git a/doc/index.html b/doc/index.html index 6700642..168dd1e 100644 --- a/doc/index.html +++ b/doc/index.html @@ -1,12 +1,198 @@ - - + + + + + + Sixth - system for data storage, computation, exploration and interaction - - - - - + + + @@ -14,239 +200,79 @@ footer {background-color: #111 !important;} pre {background-color: #111; color: #ccc;} - - + -
-

Sixth - system for data storage, computation, exploration and interaction

+
+

Sixth - system for data storage, computation, exploration and interaction

+ -
-

1 General

+
+

1. General

-
  • Other software projects hosted at svjatoslav.eu -
  • +
  • Other software projects hosted at svjatoslav.eu
  • -
    -

    1.1 Source code

    +
    +

    1.1. Source code

    -
    -

    2 Vision - A tool to amplify human ability

    +
    +

    2. Vision - A tool to amplify human ability

    Goal is, so called bicycle for the mind. @@ -259,7 +285,7 @@ knowledge.

    -See extensible, programmable computing environment examples. +See extensible, programmable computing environment examples.

    @@ -269,50 +295,43 @@ with the following priorities:

    • Makes data and insights easy to discover, understand, manipulate, -transform and visualize. -
    • +transform and visualize. -
    • Workflow and user interface is intuitive, visual, realtime, +
    • +Workflow and user interface is intuitive, visual, realtime, 3D-first. +

      “Virtual reality holds the key to the evolution of the human mind” Dr. Lawrence Angelo, The Lawnmower Man (1992)

      -
      -
    • +
    • Computations are done primarily in on versioned data in distributed, scalable, arbitrary dimensional hypercube based geometrical -computation engine. -
    • +computation engine. -
    • Free and open. -
    • +
    • Free and open.
    • Network first:
      • Cross device:
        • Easily switch devices and still access same data, workspaces and -visualizations. -
        • +visualizations.
        • Easily access and combine storage and computing resources of -other connected devices. -
        • -
        -
      • +other connected devices. +
    • -
    • Ability to collaborate (multi user). -
    • -
    - +
  • Ability to collaborate (multi user).
  • +
    -
    -

    2.1 Extensible, programmable computing environment examples

    +
    +

    2.1. Extensible, programmable computing environment examples

    • GNU Emacs - At the heart, Emacs is text editor on top of Lisp @@ -322,117 +341,154 @@ be added dynamically. Domain specific languages to fit particular problem could be developed as needed and Emacs extended to support those languages. Emacs provides text buffers that can be used to build user interfaces. So you can customize Emacs and Lisp to fit -any problem domain. -
    • +any problem domain.
    • Eclipse IDE - In essence OSGi platform with a text editor. Computation done in java. Eclipse provides integration, runtime and GUI platform. One can develop Eclipse plugins to add necessary logic and visual parts to fit any problem. (IntelliJ and -NetBeans have similar properties) -
    • +NetBeans have similar properties)
    • IBM Notes/Domino - Custom database engine, software development platform, GUI editor, computation can be done in Java and LotusScript. You can build distributed business applications on it -as a platform. -
    • +as a platform.
    • SAP ABAP - Custom database engine, runtime, GUI platform, development environment and programming language. Is being used as a -platform to build business applications with any logic and UI. -
    • +platform to build business applications with any logic and UI.
    • Microsoft Access - Database management system that combines relational database engine with a graphical user interface and -software-development tools. -
    • +software-development tools.
    -
    -

    3 Current status

    +
    +

    3. Current status

      -
    • Formulated high-level vision / goal. -
    • +
    • Formulated high-level vision / goal.
    • -
    • In the process of implementing some of building blocks. -
    • +
    • In the process of implementing some of building blocks.
    • System is nowhere near complete (given magnitude of effort required and almost non-existent free time available). Contributions are -welcome ! -
    • +welcome !
    -
    -

    4 Architecture / components

    +
    +

    4. Architecture / components

    +
    -
    -

    5 Frequently Given Answers

    +
    +

    5. Frequently Given Answers

    • Why such name ?
        -
      • In short: it's just a number. -
      • +
      • In short: it's just a number.
      • Many years ago inspired by the ideas of Forth (programming language) I decided to create my own implementation Fifth -(computing/programming environment). -
      • +(computing/programming environment).
      • Forth/Fifth felt a bit too low-level language. So current -project/approach is an attempt using Java. -
      • -
      -
    • +project/approach is an attempt using Java. +
    -
    -
    -
    -

    Author: Svjatoslav Agejenko

    -

    Created: 2020-04-20 Mon 22:24

    -

    Emacs 26.1 (Org-mode 9.1.9)

    -
    +
    +
    +
    +

    Author: Svjatoslav Agejenko

    +

    Created: 2022-10-30 Sun 12:26

    +

    Validate

    +
    diff --git a/doc/index.org b/doc/index.org index b98cb04..e758bb7 100644 --- a/doc/index.org +++ b/doc/index.org @@ -128,3 +128,44 @@ with the following priorities: (computing/programming environment). - Forth/Fifth felt a bit too low-level language. So current project/approach is an attempt using Java. +* See also +Following projects are inspiring or have similar goals: + ++ [[https://github.com/kaveh808/kons-9][kons-9]]: An IDE For 3D Production. The intention is to develop a + flexible and extensible system in which can be built a wide variety + of application and domain specific tools and packages. + ++ [[https://gtoolkit.com/][Glamorous Toolkit]]: Moldable development environment. It is a live + notebook. It is a flexible search interface. It is a fancy code + editor. It is a software analysis platform. It is a data + visualization engine. All in one. + +** Computation on multi dimensional data ++ [[https://rd-alliance.org/system/files/Array-Databases_final-report.pdf][Array Databases: Concepts, Standards, Implementations]] + ++ [[https://tiledb.com/][TileDB]] + + Analyze and share complex multi-dimensional data at scale + ++ [[id:01aa65c1-3d44-44a8-9b90-58454bc6be80][CM-1 Connection Machine]] + ++ [[https://lisp-stat.dev/][Lisp-Stat: An environment for Statistical Computing]] +** Distributed, reliable, parallel computing systems ++ [[https://github.com/vygr/ChrysaLisp][ChrysaLisp]] + + Assembler/C-Script/Lisp 64 bit, MIMD, multi CPU, multi threaded, + multi core, multi user Parallel OS. With GUI, Terminal, OO + Assembler, Class libraries, C-Script compiler, Lisp interpreter, + Debugger, and more... + ++ [[http://www.uruk.org/emu/Taos.html][TAOS]] + + Completely distributed operating system/virtual machine: + ++ [[http://esug.org/data/ESUG2015/3%20wednesday/1100-1130%20SQL%20Queries%20on%20Smalltalk%20Objects/SQL%20Queries%20in%20Smalltalk%20(James%20Foster).pdf][Gemstone/S]] + + Completely distributed smalltalk based computing + system. + ++ http://phantomos.org/ + + Programs run forever. System crash or reboot does not destroy + state of running program. + ++ [[http://wiki.squeak.org/squeak/2665][Magma]] + + Multi-user object database for Squeak -- 2.20.1