Skip to content

Commit 87e5a37

Browse files
Added support for Apache Avro IDL (#3051)
1 parent 247fd9a commit 87e5a37

18 files changed

+469
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
"title": "AutoIt",
161161
"owner": "Golmote"
162162
},
163+
"avro-idl": {
164+
"title":"Avro IDL",
165+
"alias": "avdl",
166+
"owner": "RunDevelopment"
167+
},
163168
"bash": {
164169
"title": "Bash",
165170
"alias": "shell",

components/prism-avro-idl.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// GitHub: https://github.com/apache/avro
2+
// Docs: https://avro.apache.org/docs/current/idl.html
3+
4+
Prism.languages['avro-idl'] = {
5+
'comment': {
6+
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
7+
greedy: true
8+
},
9+
'string': [
10+
{
11+
pattern: /(^|[^\\])"(?:[^\r\n"\\]|\\.)*"/,
12+
lookbehind: true,
13+
greedy: true
14+
},
15+
{
16+
pattern: /(^|[^\\])'(?:[^\r\n'\\]|\\(?:[\s\S]|\d{1,3}))'/,
17+
lookbehind: true,
18+
greedy: true
19+
}
20+
],
21+
22+
'annotation': {
23+
pattern: /@(?:[$\w.-]|`[^\r\n`]+`)+/,
24+
greedy: true,
25+
alias: 'function'
26+
},
27+
'function-identifier': {
28+
pattern: /`[^\r\n`]+`(?=\s*\()/,
29+
greedy: true,
30+
alias: 'function'
31+
},
32+
'identifier': {
33+
pattern: /`[^\r\n`]+`/,
34+
greedy: true
35+
},
36+
37+
'class-name': {
38+
pattern: /(\b(?:enum|error|protocol|record|throws)\b\s+)[$\w]+/,
39+
lookbehind: true,
40+
greedy: true
41+
},
42+
'keyword': /\b(?:array|boolean|bytes|date|decimal|double|enum|error|false|fixed|float|idl|import|int|local_timestamp_ms|long|map|null|oneway|protocol|record|schema|string|throws|time_ms|timestamp_ms|true|union|uuid|void)\b/,
43+
'function': /\b[a-z_]\w*(?=\s*\()/i,
44+
45+
'number': [
46+
{
47+
pattern: /(^|[^\w.])-?(?:(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|0x(?:[a-f0-9]+(?:\.[a-f0-9]*)?|\.[a-f0-9]+)(?:p[+-]?\d+)?)[dfl]?(?![\w.])/i,
48+
lookbehind: true
49+
},
50+
/-?\b(?:NaN|Infinity)\b/
51+
],
52+
53+
'operator': /=/,
54+
'punctuation': /[()\[\]{}<>.:,;-]/
55+
};
56+
57+
Prism.languages.avdl = Prism.languages['avro-idl'];

components/prism-avro-idl.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-avro-idl.html

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: https://avro.apache.org/docs/current/idl.html#example
3+
4+
/**
5+
* An example protocol in Avro IDL
6+
*/
7+
@namespace("org.apache.avro.test")
8+
protocol Simple {
9+
10+
@aliases(["org.foo.KindOf"])
11+
enum Kind {
12+
FOO,
13+
BAR, // the bar enum value
14+
BAZ
15+
}
16+
17+
fixed MD5(16);
18+
19+
record TestRecord {
20+
@order("ignore")
21+
string name;
22+
23+
@order("descending")
24+
Kind kind;
25+
26+
MD5 hash;
27+
28+
union { MD5, null} @aliases(["hash"]) nullableHash;
29+
30+
array&lt;long> arrayOfLongs;
31+
}
32+
33+
error TestError {
34+
string message;
35+
}
36+
37+
string hello(string greeting);
38+
TestRecord echo(TestRecord `record`);
39+
int add(int arg1, int arg2);
40+
bytes echoBytes(bytes data);
41+
void `error`() throws TestError;
42+
void ping() oneway;
43+
}
44+
</code></pre>

plugins/autoloader/prism-autoloader.js

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
"js": "javascript",
173173
"g4": "antlr4",
174174
"adoc": "asciidoc",
175+
"avdl": "avro-idl",
175176
"shell": "bash",
176177
"shortcode": "bbcode",
177178
"rbnf": "bnf",

plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
"asm6502": "6502 Assembly",
4444
"autohotkey": "AutoHotkey",
4545
"autoit": "AutoIt",
46+
"avro-idl": "Avro IDL",
47+
"avdl": "Avro IDL",
4648
"basic": "BASIC",
4749
"bbcode": "BBcode",
4850
"bnf": "BNF",

0 commit comments

Comments
 (0)