diff options
-rw-r--r-- | gen/org/jetbrains/markdown/MarkdownElementTypes.java | 3 | ||||
-rw-r--r-- | gen/org/jetbrains/markdown/MarkdownParser.java | 72 | ||||
-rw-r--r-- | src/Markdown/markdown.bnf | 7 | ||||
-rw-r--r-- | test/src/markdown/ParserTest.kt | 8 |
4 files changed, 70 insertions, 20 deletions
diff --git a/gen/org/jetbrains/markdown/MarkdownElementTypes.java b/gen/org/jetbrains/markdown/MarkdownElementTypes.java index 337ff1a5..5c4aad41 100644 --- a/gen/org/jetbrains/markdown/MarkdownElementTypes.java +++ b/gen/org/jetbrains/markdown/MarkdownElementTypes.java @@ -12,6 +12,9 @@ public interface MarkdownElementTypes { IElementType BULLET = new IElementType("BULLET", null); IElementType BULLET_LIST = new IElementType("BULLET_LIST", null); IElementType CODE = new IElementType("CODE", null); + IElementType DIRECTIVE = new IElementType("DIRECTIVE", null); + IElementType DIRECTIVE_NAME = new IElementType("DIRECTIVE_NAME", null); + IElementType DIRECTIVE_PARAMS = new IElementType("DIRECTIVE_PARAMS", null); IElementType EMPH = new IElementType("EMPH", null); IElementType END_LINE = new IElementType("END_LINE", null); IElementType ENUMERATOR = new IElementType("ENUMERATOR", null); diff --git a/gen/org/jetbrains/markdown/MarkdownParser.java b/gen/org/jetbrains/markdown/MarkdownParser.java index efad3d6e..ab84cd5e 100644 --- a/gen/org/jetbrains/markdown/MarkdownParser.java +++ b/gen/org/jetbrains/markdown/MarkdownParser.java @@ -40,6 +40,15 @@ public class MarkdownParser implements PsiParser { else if (t == CODE) { r = Code(b, 0); } + else if (t == DIRECTIVE) { + r = Directive(b, 0); + } + else if (t == DIRECTIVE_NAME) { + r = DirectiveName(b, 0); + } + else if (t == DIRECTIVE_PARAMS) { + r = DirectiveParams(b, 0); + } else if (t == EMPH) { r = Emph(b, 0); } @@ -148,6 +157,7 @@ public class MarkdownParser implements PsiParser { // OrderedList // | BulletList // | HorizontalRule + // | Directive // | Para // ) public static boolean Block(PsiBuilder b, int l) { @@ -175,6 +185,7 @@ public class MarkdownParser implements PsiParser { // OrderedList // | BulletList // | HorizontalRule + // | Directive // | Para private static boolean Block_1(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "Block_1")) return false; @@ -183,6 +194,7 @@ public class MarkdownParser implements PsiParser { r = OrderedList(b, l + 1); if (!r) r = BulletList(b, l + 1); if (!r) r = HorizontalRule(b, l + 1); + if (!r) r = Directive(b, l + 1); if (!r) r = Para(b, l + 1); exit_section_(b, m, null, r); return r; @@ -324,6 +336,43 @@ public class MarkdownParser implements PsiParser { } /* ********************************************************** */ + // '{' DirectiveName DirectiveParams '}' + public static boolean Directive(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "Directive")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, "<directive>"); + r = consumeToken(b, "{"); + r = r && DirectiveName(b, l + 1); + r = r && DirectiveParams(b, l + 1); + r = r && consumeToken(b, "}"); + exit_section_(b, l, m, DIRECTIVE, r, false, null); + return r; + } + + /* ********************************************************** */ + // Word + public static boolean DirectiveName(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "DirectiveName")) return false; + if (!nextTokenIs(b, WORD)) return false; + boolean r; + Marker m = enter_section_(b); + r = consumeToken(b, WORD); + exit_section_(b, m, DIRECTIVE_NAME, r); + return r; + } + + /* ********************************************************** */ + // PlainText + public static boolean DirectiveParams(PsiBuilder b, int l) { + if (!recursion_guard_(b, l, "DirectiveParams")) return false; + boolean r; + Marker m = enter_section_(b, l, _NONE_, "<directive params>"); + r = PlainText(b, l + 1); + exit_section_(b, l, m, DIRECTIVE_PARAMS, r, false, null); + return r; + } + + /* ********************************************************** */ // BOM? Whitespace* AnonymousSection? (Whitespace* NamedSection)* static boolean Document(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "Document")) return false; @@ -1322,7 +1371,7 @@ public class MarkdownParser implements PsiParser { } /* ********************************************************** */ - // (Word | Number | Space+)+ + // (Word | Number | Space | ':')+ public static boolean PlainText(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "PlainText")) return false; boolean r; @@ -1338,30 +1387,15 @@ public class MarkdownParser implements PsiParser { return r; } - // Word | Number | Space+ + // Word | Number | Space | ':' private static boolean PlainText_0(PsiBuilder b, int l) { if (!recursion_guard_(b, l, "PlainText_0")) return false; boolean r; Marker m = enter_section_(b); r = consumeToken(b, WORD); if (!r) r = consumeToken(b, NUMBER); - if (!r) r = PlainText_0_2(b, l + 1); - exit_section_(b, m, null, r); - return r; - } - - // Space+ - private static boolean PlainText_0_2(PsiBuilder b, int l) { - if (!recursion_guard_(b, l, "PlainText_0_2")) return false; - boolean r; - Marker m = enter_section_(b); - r = consumeToken(b, SPACE); - int c = current_position_(b); - while (r) { - if (!consumeToken(b, SPACE)) break; - if (!empty_element_parsed_guard_(b, "PlainText_0_2", c)) break; - c = current_position_(b); - } + if (!r) r = consumeToken(b, SPACE); + if (!r) r = consumeToken(b, ":"); exit_section_(b, m, null, r); return r; } diff --git a/src/Markdown/markdown.bnf b/src/Markdown/markdown.bnf index d1cd305c..f3c484d5 100644 --- a/src/Markdown/markdown.bnf +++ b/src/Markdown/markdown.bnf @@ -47,6 +47,7 @@ Block ::= BlankLine* ( OrderedList | BulletList | HorizontalRule + | Directive | Para ) @@ -58,6 +59,10 @@ HorizontalRule ::= NonindentSpace | '_' OptionalSpace '_' OptionalSpace '_' (OptionalSpace '_')*) OptionalSpace EOL BlankLine+ +Directive ::= '{' DirectiveName DirectiveParams '}' +DirectiveName ::= Word +DirectiveParams ::= PlainText + Bullet ::= !HorizontalRule NonindentSpace ('+' | '*' | '-') Space+ Enumerator ::= NonindentSpace Number '.' Space+ @@ -76,7 +81,7 @@ ListContinuationBlock ::= BlankLine* (Indent ListBlock)+ // ---- INLINES ---- private Inlines ::= (!EndLine Inline | EndLine &Inline )+ EndLine? Inline ::= Strong | Emph | Code | Link | PlainText -PlainText ::= (Word | Number | Space+)+ +PlainText ::= (Word | Number | Space | ':')+ Emph ::= EmphStar | EmphUnderscore private EmphStar ::= '*' !Whitespace (!'*' Inline)+ '*' diff --git a/test/src/markdown/ParserTest.kt b/test/src/markdown/ParserTest.kt index 20b95625..201708c6 100644 --- a/test/src/markdown/ParserTest.kt +++ b/test/src/markdown/ParserTest.kt @@ -21,6 +21,10 @@ public class ParserTest { runTestFor("text and string") } + Test fun textWithColon() { + runTestFor("text and string: cool!") + } + Test fun link() { runTestFor("text [links]") } @@ -80,6 +84,10 @@ number two runTestFor("*text*") } + Test fun directive() { + runTestFor("A text {code with.another.value} with directive") + } + Test fun emphAndEmptySection() { runTestFor("*text* \$sec:") } |