forked from andre-simon/highlight
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathasciidoc.lang
273 lines (234 loc) · 11.8 KB
/
asciidoc.lang
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
--[[ "asciidoc.lang" v0.0.4 | 2019/01/01 | Highlight v3.48
********************************************************************************
* *
* AsciiDoc Syntax Definition *
* *
* by Tristano Ajmone *
* *
********************************************************************************
NOTE: Alpha WIP!
Currently implemented elements:
- Comments.
--------------------------------------------------------------------------------
** MANDATORY ELEMENTS **
The bare minimum definitions required for a langDef file to be valid are:
-- Description
-- Keywords
If a langDef file doesn't provide these definitions, Highlight will raise an
error. All other definitions are optional.
--------------------------------------------------------------------------------
** HIGHLIGHT DEFAULTS **
Highlight provides a default definition to the following syntax elements:
-- Identifiers
-- Digits
-- Escape
All other definition are empty/false by default.
--------------------------------------------------------------------------------
Written by Tristano Ajmone:
<tajmone@gmail.com>
https://github.com/tajmone
https://gitlab.com/tajmone
Released into the public domain according to the Unlicense terms:
http://unlicense.org/
------------------------------------------------------------------------------]]
Description = "AsciiDoc" -- Syntax description
Categories = {"markup"}
--==============================================================================
-- SUPPRESSED ELEMENTS
--==============================================================================
NeverMatch = [=[ \A(?!x)x ]=] -- Never-Matching RegEx!
Digits = [=[ \A(?!x)x ]=] -- Not needed! but could use them for somithing else!
--------------------------------------------------------------------------------
--==============================================================================
-- SYNTAX SETTINGS
--==============================================================================
IgnoreCase = false -- Are keywords case-sensitive? (true/false)
EnableIndentation = false -- Syntax may be reformatted and indented? (true/false)
Identifiers = [=[ [a-zA-Z_]\w* ]=] -- Highlight's default Identifiers definition
--[[============================================================================
COMMENTS
================================================================================
AsciiDoc comments delimiters must always be placed at beginning of line and end
the line without other characters.
------------------------------------------------------------------------------]]
Comments = {
-- Define BLOCK-COMMENTS delimiters
{ Block = true,
Nested = false,
Delimiter = {
[=[ ^\/{4}$ ]=], -- ////
[=[ ^\/{4}$ ]=] -- ////
}
},
-- Define SINGLE-LINE-COMMENTS delimiter
{ Block = false,
Delimiter = { [=[ ^\/\/ ]=] } -- //
}
}
--[[============================================================================
STRINGS
================================================================================
Strings = { Delimiter|DelimiterPairs={Open, Close, Raw?}, Escape?, Interpolation?,
RawPrefix?, AssertEqualLength? }
Delimiter: String, regular expression which describes string delimiters
DelimiterPairs: List, includes open and close delimiter expressions if not
equal, includes optional Raw flag as boolean which marks
delimiter pair to contain a raw string
Escape: String, regex of escape sequences (optional)
Interpolation: String, regex of interpolation sequences (optional)
RawPrefix: String, defines raw string indicator (optional)
AssertEqualLength: Boolean, set true if delimiters must have the same length
------------------------------------------------------------------------------]]
--[============================================[
Strings = {
--------------------------------------------------------------------------------
-- STRING DELIMITERS
--------------------------------------------------------------------------------
-- SYMMETRICAL STRINGS DELIMITERS
Delimiter = [=[ "|' ]=], -- Double- and single-quote delimiters: " '
-- ASSYMMETRICAL STRINGS DELIMITERS
-- Example: Lua style string-delimiters:
DelimiterPairs= {
{ Open = [=[ \[=*\[ ]=], -- [[ [=[ [===[ etc.
Close = [=[ \]=*\] ]=], -- ]] ]=] ]===] etc.
Raw = true, -- Are these raw string delimiters? (true/false)
}
},
AssertEqualLength = true, -- Delimiters must have the same length?
-- RAW-STRING PREFIX (if language supports it)
RawPrefix = "R", -- Raw string indicator (optional): R (C style)
--[[----------------------------------------------------------------------------
ESCAPE SEQUENCES
--------------------------------------------------------------------------------
If the language at hand supports escape sequences, define a RegEx pattern to
capture them.
https://en.wikipedia.org/wiki/Escape_sequences_in_C
NOTE: Escape sequences are not restricted to occur inside strings only, they
will be matched anywhere in the source code (some languages, like Perl
and Bash, allow their use anywhere). Usually this doesn't constitute a
problem, but in some languages this uncostrained behaviour might cause
false positives matches; in such cases you'll need to restrict escape
sequences occurence to inside-strings context only by implementing a
custom hook via the OnStateChange() function --- see "Hook Preset #01"
further down. --]]
-- Highlight's default built-in Escape definition:
-- Escape = [=[ \\u[[:xdigit:]]{4}|\\\d{3}|\\x[[:xdigit:]]{2}|\\[ntvbrfa\\\?'"] ]=],
Escape = NeverMatch,
--[[----------------------------------------------------------------------------
INTERPOLATION
--------------------------------------------------------------------------------
String, regex of interpolation sequences (optional)
To understand interpolation, here is an example from Javascript:
var apples = 6;
console.log(`There are ${apples} apples in the basket!`);
which will otuput:
There are 6 apples in the basket!
References:
https://en.wikipedia.org/wiki/String_interpolation
--]]
Interpolation = NeverMatch,
-- Interpolation = [=[ \$\{.+?\} ]=], -- Javascript Interpolation: ${ ... }
}
--]============================================]
--[[============================================================================
PREPROCESSOR
================================================================================
PreProcessor = { Prefix, Continuation? }
Prefix: String, regular expression which describes open delimiter
Continuation: String, contains line continuation character (optional).
NOTE: This element is treated by Highlight parser in a similar way to single-
line comments: it swallows up everything from the matching Prefix up to
the end of the line -- but unlike comment lines (which can't contain
further syntax elements), the parser will still be looking for some
syntax elements (in the current line) which might be reasonably found
within a line of preprocessor directives (eg: strings and comments);
but once these elements are dealt with, the parser will resume the
PreProcessor state to carry on parsing the rest of the line.
Furthermore, the Continuation character allows this element to span
across multiple line (without the need of an opening and closing pair,
unlike multiline comments do).
PreProcessor = {
-- Case sensitive? ** SHOULD TEST!! **
Prefix = [=[ (?:include|tag|end) ]=]
-- Continuation = "\\", -- Backslash ('\') marks continuation of preprocessor line
}
--]]
--[[============================================================================
OPERATORS
============================================================================--]]
-- Operators = [=[ \&|<|>|\!|\||\=|\/|\*|\%|\+|\-|~ ]=] -- Match: &<>!|=/*%+-~
--[[============================================================================
KEYWORDS
================================================================================
Keywords = { Id, List|Regex, Group? }
Id: Integer, keyword group id (values 1-4, can be reused for several keyword
groups)
List: List, list of keywords
Regex: String, regular expression
Group: Integer, capturing group id of regular expression, defines part of regex
which should be returned as keyword (optional; if not set, the match
with the highest group number is returned (counts from left to right))
NOTE: Keyword group Ids are not limited to 4, you can create as many as you
need; but bare in mind that most themes that ship with Highlight usually
provide definitions only for Ids 1-4, so in order to syntax-color Keyword
groups with Ids greater than 4 you'll need to define a theme that covers
their definitions. --]]
Keywords = {
--------------------------------------------------------------------------------
-- Keywords 1
--------------------------------------------------------------------------------
-- NOTE: If you've set `IgnoreCase = false` then all keywords in the list must
-- be in lowercase otherwise they'll never match! With case-insensitive
-- languages, Highlight converts to lowercase the token before comparing
-- it to the entries of the Keywords list, but the list entries are not
-- manipulated before comparison.
-- { Id = 1,
-- List = {
-- -- Keywords list
-- "avracadavrah"
-- }
-- },
--------------------------------------------------------------------------------
-- Keywords 2
--------------------------------------------------------------------------------
-- Preprocessor Directives
{ Id = 4,
Regex = [=[ (?<!\\)((?:include|ifdef|ifndef|ifeval|endif|tag|end)\:\:) ]=],
Group = 1
}
}
-- =============================================================================
-- Hook Preset #01 -- Escape Sequences Only Inside String
-- =============================================================================
--[[
function OnStateChange(oldState, newState, token, kwgroup)
-- This function ensure that escape sequences outside strings are ignored.
-- Based on André Simon's reply to Issue #23:
-- -- https://github.com/andre-simon/highlight/issues/23#issuecomment-332002639
if newState==HL_ESC_SEQ and oldState~=HL_STRING then
return HL_REJECT
end
return newState
end
--]]
--[[============================================================================
CHANGELOG
================================================================================
v0.0.4 | 2019/01/01 | Highlight v3.48
- Define:
- Keywords Id 4 :: Preprocessor Directives
- Fix:
- Single line Comment: Remove '$'
- Suppress:
- Keywords Id 1
v0.0.3 | 2019/01/01 | Highlight v3.48
- Suppress: Operators, Strings.
v0.0.2 | 2019/01/01 | Highlight v3.48
- Fix block comments (delimiters must fill the line.)
- Suppress Preprocessor.
v0.0.1 | 2019/01/01 | Highlight v3.48
- Define comments (single-line and block).
- Suppress some unused elements.
v0.0.0 | 2019/01/01 | Highlight v3.48
- Just the langDef boliterplate.
--]]