-
Notifications
You must be signed in to change notification settings - Fork 0
/
orgmode.treetop
206 lines (177 loc) · 3.84 KB
/
orgmode.treetop
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# wrt backreferencing, nathan sobo said in 2008 it isn't yet possible. not sure if it has become available
grammar OrgMode
rule document
(headline / specialblock / comment / list / mixedtext / word / paragraphbreak / multiwhitespace / line)* {
def content
elements.map{ |e| e.content }
end
}
end
rule EOL
("\n" / "\r\n") {
def content
[:EOL, text_value]
end
}
end
rule paragraphbreak
EOL EOL+ {
def content
[:paragraphbreak, text_value]
end
}
end
rule multiwhitespace
[\s]+ {
def content
[:multiwhitespace, text_value]
end
}
end
rule asterisk
[*] {
def content
[:asterisk, text_value]
end
}
end
rule nonasterisk
[^*] {
def content
[:nonasterisk, text_value]
end
}
end
rule mixedLineUntilEOL
multiwhitespace (mixedtext / (!EOL .))+
end
rule headline
asterisk+ mixedLineUntilEOL EOL {
def content
[:headline, text_value[0...-1]]
end
}
end
rule list
(listunordered / listordered)
end
rule listunordered
multiwhitespace ("-" / "+") mixedLineUntilEOL {
def content
[:listunordered, text_value]
end
}
end
rule listordered
multiwhitespace [0-9]+ ("." / ")") mixedLineUntilEOL {
def content
[:listordered, text_value]
end
}
end
rule line
(!EOL .)* EOL {
def content
[:line, text_value]
end
}
end
### v--- plaintext rules ---v
rule mixedtext
(hyperlink / codetext / boldtext / underlinedtext / italicstext / verbatimtext / horizontalrule / word)
end
rule boldtext
"*" (!"*" .)+ "*" {
def content
[:boldtext, text_value[1...-1]]
end
}
end
rule codetext
"=" (!"=" .)+ "=" {
def content
[:codetext, text_value[1...-1]]
end
}
end
rule underlinedtext
"_" (!"_" .)+ "_" {
def content
[:underlinedtext, text_value[1...-1]]
end
}
end
rule italicstext
"/" (!"/" .)+ "/" {
def content
[:italicstext, text_value[1...-1]]
end
}
end
rule verbatimtext
"~" (!"~" .)+ "~" {
def content
[:verbatimtext, text_value[1...-1]]
end
}
end
rule word
(!EOL ![\s] .)+ {
def content
[:word, text_value]
end
}
end
rule plaintext
(!EOL .)+ {
def content
[:plaintext, text_value]
end
}
end
rule horizontalrule
"-----" "-"* EOL {
def content
[:horizontalrule, text_value]
end
}
end
rule hyperlink
"[[" (!"]" .)+ ("][" (!"]" .)+)? "]]" {
def content
[:hyperlink, text_value]
end
}
end
rule specialblock
(specialblocksource / specialblockquote / specialblockcatchall)
end
rule specialblockcatchall
"#+" ("begin" / "BEGIN") (!EOL .)* EOL (!"#+end" !"#+END" .)* ("#+end" / "#+END") (!EOL .)* EOL {
def content
[:specialblockcatchall, text_value]
end
}
end
rule specialblockquote
"#+" ("begin_quote" / "BEGIN_QUOTE") (!EOL .)* EOL (!"#+end_quote" !"#+END_QUOTE" .)* ("#+end_quote" / "#+END_QUOTE") (!EOL [\s])* EOL {
def content
[:specialblockquote, text_value]
end
}
end
rule specialblocksource
"#+" ("begin_src" / "BEGIN_SRC") (!EOL .)* EOL (!"#+end_src" !"#+END_SRC" .)* ("#+end_src" / "#+END_SRC") (!EOL [\s])* EOL {
def content
[:specialblocksource, text_value]
end
}
end
rule comment
EOL? "#" (!EOL .)+ EOL {
def content
[:comment, text_value]
end
}
end
end