aboutsummaryrefslogtreecommitdiff
path: root/src/Markdown/markdown.bnf
blob: 79e9e0b497b91acaae8fb9e7f87e9338be3c10fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
  psiPackage = 'org.jetbrains.markdown'
  psiImplPackage = 'org.jetbrains.markdown.impl'

  parserClass="org.jetbrains.markdown.MarkdownParser"
  parserUtilClass="org.jetbrains.dokka.Markdown.GeneratedParserUtilBase"
  elementTypeHolderClass = 'org.jetbrains.markdown.MarkdownElementTypes'

  tokenTypeClass = 'org.jetbrains.dokka.Markdown.MarkdownTokenType'

  generatePsi = false

  tokens=[
    LINE_WS='regexp:[\ \t\f]'
    EOL='"\r"|"\n"|"\r\n"'
    BOM = '\357\273\277'
    Number='regexp:\d+(\.\d*)?'
    String='regexp:[^~\*_`&\[\]()<!#\\ \t\n\r]+'
    AnyChar='regexp:.'
  ]

}

Document ::= BOM? Whitespace* AnonymousSection? (Whitespace* NamedSection)*

AnonymousSection ::= SectionBody
NamedSection ::= SectionHeader SectionBody
private SectionHeader ::= '$' SectionName OptionalSpace ':' OptionalSpace
SectionName ::= SectionNameStart | '{' OptionalSpace SectionNameStart (Spacechar+ String)* OptionalSpace '}'
private SectionNameStart ::= '$'? String
SectionBody::= Block*

BlankLine ::= OptionalSpace Newline

Whitespace ::= Spacechar | Newline
private OptionalSpace ::= Spacechar*
private NonindentSpace ::= ("   " | "  " | " ")?

EndLine ::= TerminalEndline | NormalEndline
private NormalEndline ::=   Newline !BlankLine
private TerminalEndline ::= OptionalSpace <<eof>>
private Indent ::=            "\t" | "    "

// ---- BLOCKS ----
Block ::= BlankLine* (
              OrderedList
            | BulletList
            | HorizontalRule
            | Para
            )

Para ::= Inlines (BlankLine | TerminalEndline)?

HorizontalRule ::= NonindentSpace
                 ( '*' OptionalSpace '*' OptionalSpace '*' (OptionalSpace '*')*
                 | '-' OptionalSpace '-' OptionalSpace '-' (OptionalSpace '-')*
                 | '_' OptionalSpace '_' OptionalSpace '_' (OptionalSpace '_')*)
                 OptionalSpace Newline BlankLine+

Bullet ::= !HorizontalRule NonindentSpace ('+' | '*' | '-') Spacechar+
Enumerator ::= NonindentSpace Number '.' Spacechar+

BulletList ::= &Bullet List
OrderedList ::= &Enumerator List

private List ::=  (ListItem BlankLine*)+
ListItem      ::= (Bullet | Enumerator) ListBlock ( ListContinuationBlock )*

ListBlock ::= !BlankLine Inlines ( ListBlockLine )*
ListBlockLine ::= !BlankLine !(Indent? (Bullet | Enumerator)) !HorizontalRule Indent? Inlines

ListContinuationBlock ::= BlankLine* (Indent ListBlock)+


// ---- INLINES ----
private Inlines ::= (!EndLine Inline | EndLine &Inline )+ EndLine?
Inline  ::= Strong | Emph | Link | PlainText
PlainText ::= (String | Number | Spacechar+)+

Emph ::= EmphStar | EmphUnderscore
private EmphStar ::= '*' !Whitespace (!'*' Inline)+ '*'
private EmphUnderscore ::= '_' !Whitespace (!'_' Inline)+ '_'

Strong ::= StrongStar | StrongUnderscore
StrongStar ::= '**' !Whitespace (!'**' Inline)+ '**'
StrongUnderscore ::= '__' !Whitespace (!'__' Inline)+ '__'

Link ::=  HrefLink | ReferenceLink
private ReferenceLink ::= '[' Target ']'
private HrefLink ::= '[' Target ']' '(' Href ')'
Target ::= String
Href ::= String