Skip to content

Commit 87e5a37

Browse files
authoredSep 6, 2021
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",

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

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
record MyRecord {
2+
string @order("ascending") myAscendingSortField;
3+
string @order("descending") myDescendingField;
4+
string @order("ignore") myIgnoredField;
5+
}
6+
7+
@java-class("java.util.ArrayList") array<string> myStrings;
8+
9+
@namespace("org.apache.avro.firstNamespace")
10+
11+
union { MD5, null} @aliases(["hash"]) nullableHash;
12+
13+
----------------------------------------------------
14+
15+
[
16+
["keyword", "record"],
17+
["class-name", "MyRecord"],
18+
["punctuation", "{"],
19+
20+
["keyword", "string"],
21+
["annotation", "@order"],
22+
["punctuation", "("],
23+
["string", "\"ascending\""],
24+
["punctuation", ")"],
25+
" myAscendingSortField",
26+
["punctuation", ";"],
27+
28+
["keyword", "string"],
29+
["annotation", "@order"],
30+
["punctuation", "("],
31+
["string", "\"descending\""],
32+
["punctuation", ")"],
33+
" myDescendingField",
34+
["punctuation", ";"],
35+
36+
["keyword", "string"],
37+
["annotation", "@order"],
38+
["punctuation", "("],
39+
["string", "\"ignore\""],
40+
["punctuation", ")"],
41+
" myIgnoredField",
42+
["punctuation", ";"],
43+
44+
["punctuation", "}"],
45+
46+
["annotation", "@java-class"],
47+
["punctuation", "("],
48+
["string", "\"java.util.ArrayList\""],
49+
["punctuation", ")"],
50+
["keyword", "array"],
51+
["punctuation", "<"],
52+
["keyword", "string"],
53+
["punctuation", ">"],
54+
" myStrings",
55+
["punctuation", ";"],
56+
57+
["annotation", "@namespace"],
58+
["punctuation", "("],
59+
["string", "\"org.apache.avro.firstNamespace\""],
60+
["punctuation", ")"],
61+
62+
["keyword", "union"],
63+
["punctuation", "{"],
64+
" MD5",
65+
["punctuation", ","],
66+
["keyword", "null"],
67+
["punctuation", "}"],
68+
["annotation", "@aliases"],
69+
["punctuation", "("],
70+
["punctuation", "["],
71+
["string", "\"hash\""],
72+
["punctuation", "]"],
73+
["punctuation", ")"],
74+
" nullableHash",
75+
["punctuation", ";"]
76+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
protocol MyProto {
2+
@namespace("org.apache.avro.someOtherNamespace")
3+
record Foo {}
4+
5+
record Bar {}
6+
7+
enum Kind {
8+
FOO,
9+
BAR, // the bar enum value
10+
BAZ
11+
}
12+
13+
error TestError {
14+
string message;
15+
}
16+
17+
}
18+
19+
----------------------------------------------------
20+
21+
[
22+
["keyword", "protocol"],
23+
["class-name", "MyProto"],
24+
["punctuation", "{"],
25+
26+
["annotation", "@namespace"],
27+
["punctuation", "("],
28+
["string", "\"org.apache.avro.someOtherNamespace\""],
29+
["punctuation", ")"],
30+
31+
["keyword", "record"],
32+
["class-name", "Foo"],
33+
["punctuation", "{"],
34+
["punctuation", "}"],
35+
36+
["keyword", "record"],
37+
["class-name", "Bar"],
38+
["punctuation", "{"],
39+
["punctuation", "}"],
40+
41+
["keyword", "enum"], ["class-name", "Kind"], ["punctuation", "{"],
42+
"\r\n FOO", ["punctuation", ","],
43+
"\r\n BAR", ["punctuation", ","], ["comment", "// the bar enum value"],
44+
"\r\n BAZ\r\n ",
45+
["punctuation", "}"],
46+
47+
["keyword", "error"], ["class-name", "TestError"], ["punctuation", "{"],
48+
["keyword", "string"], " message", ["punctuation", ";"],
49+
["punctuation", "}"],
50+
51+
["punctuation", "}"]
52+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* comment */
2+
/*
3+
comment
4+
*/
5+
6+
// comment
7+
8+
----------------------------------------------------
9+
10+
[
11+
["comment", "/* comment */"],
12+
["comment", "/*\r\n comment\r\n */"],
13+
14+
["comment", "// comment"]
15+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
int add(int foo, int bar = 0);
2+
3+
void logMessage(string message);
4+
5+
void goKaboom() throws Kaboom;
6+
7+
void fireAndForget(string message) oneway;
8+
9+
void `error`();
10+
11+
----------------------------------------------------
12+
13+
[
14+
["keyword", "int"],
15+
["function", "add"],
16+
["punctuation", "("],
17+
["keyword", "int"],
18+
" foo",
19+
["punctuation", ","],
20+
["keyword", "int"],
21+
" bar ",
22+
["operator", "="],
23+
["number", "0"],
24+
["punctuation", ")"],
25+
["punctuation", ";"],
26+
27+
["keyword", "void"],
28+
["function", "logMessage"],
29+
["punctuation", "("],
30+
["keyword", "string"],
31+
" message",
32+
["punctuation", ")"],
33+
["punctuation", ";"],
34+
35+
["keyword", "void"],
36+
["function", "goKaboom"],
37+
["punctuation", "("],
38+
["punctuation", ")"],
39+
["keyword", "throws"],
40+
["class-name", "Kaboom"],
41+
["punctuation", ";"],
42+
43+
["keyword", "void"],
44+
["function", "fireAndForget"],
45+
["punctuation", "("],
46+
["keyword", "string"],
47+
" message",
48+
["punctuation", ")"],
49+
["keyword", "oneway"],
50+
["punctuation", ";"],
51+
52+
["keyword", "void"],
53+
["function-identifier", "`error`"],
54+
["punctuation", "("],
55+
["punctuation", ")"],
56+
["punctuation", ";"]
57+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
array;
2+
boolean;
3+
bytes;
4+
date;
5+
decimal;
6+
double;
7+
enum;
8+
error;
9+
false;
10+
fixed;
11+
float;
12+
idl;
13+
import;
14+
int;
15+
local_timestamp_ms;
16+
long;
17+
map;
18+
null;
19+
oneway;
20+
protocol;
21+
record;
22+
schema;
23+
string;
24+
throws;
25+
time_ms;
26+
timestamp_ms;
27+
true;
28+
union;
29+
uuid;
30+
void;
31+
32+
----------------------------------------------------
33+
34+
[
35+
["keyword", "array"], ["punctuation", ";"],
36+
["keyword", "boolean"], ["punctuation", ";"],
37+
["keyword", "bytes"], ["punctuation", ";"],
38+
["keyword", "date"], ["punctuation", ";"],
39+
["keyword", "decimal"], ["punctuation", ";"],
40+
["keyword", "double"], ["punctuation", ";"],
41+
["keyword", "enum"], ["punctuation", ";"],
42+
["keyword", "error"], ["punctuation", ";"],
43+
["keyword", "false"], ["punctuation", ";"],
44+
["keyword", "fixed"], ["punctuation", ";"],
45+
["keyword", "float"], ["punctuation", ";"],
46+
["keyword", "idl"], ["punctuation", ";"],
47+
["keyword", "import"], ["punctuation", ";"],
48+
["keyword", "int"], ["punctuation", ";"],
49+
["keyword", "local_timestamp_ms"], ["punctuation", ";"],
50+
["keyword", "long"], ["punctuation", ";"],
51+
["keyword", "map"], ["punctuation", ";"],
52+
["keyword", "null"], ["punctuation", ";"],
53+
["keyword", "oneway"], ["punctuation", ";"],
54+
["keyword", "protocol"], ["punctuation", ";"],
55+
["keyword", "record"], ["punctuation", ";"],
56+
["keyword", "schema"], ["punctuation", ";"],
57+
["keyword", "string"], ["punctuation", ";"],
58+
["keyword", "throws"], ["punctuation", ";"],
59+
["keyword", "time_ms"], ["punctuation", ";"],
60+
["keyword", "timestamp_ms"], ["punctuation", ";"],
61+
["keyword", "true"], ["punctuation", ";"],
62+
["keyword", "union"], ["punctuation", ";"],
63+
["keyword", "uuid"], ["punctuation", ";"],
64+
["keyword", "void"], ["punctuation", ";"]
65+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
0
2+
123
3+
0xFFF
4+
-0
5+
-123
6+
-0xFF
7+
12343324234L
8+
0xFFFFFFFFFl
9+
10+
0.342e4
11+
0.342e-4f
12+
0.342e-4d
13+
.324
14+
123.
15+
0x.2Fp+323f
16+
0x234.p+323d
17+
18+
NaN
19+
Infinity
20+
21+
----------------------------------------------------
22+
23+
[
24+
["number", "0"],
25+
["number", "123"],
26+
["number", "0xFFF"],
27+
["number", "-0"],
28+
["number", "-123"],
29+
["number", "-0xFF"],
30+
["number", "12343324234L"],
31+
["number", "0xFFFFFFFFFl"],
32+
33+
["number", "0.342e4"],
34+
["number", "0.342e-4f"],
35+
["number", "0.342e-4d"],
36+
["number", ".324"],
37+
["number", "123."],
38+
["number", "0x.2Fp+323f"],
39+
["number", "0x234.p+323d"],
40+
41+
["number", "NaN"],
42+
["number", "Infinity"]
43+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=
2+
3+
----------------------------------------------------
4+
5+
[
6+
["operator", "="]
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
( ) [ ] { } < >
2+
. : , ;
3+
4+
----------------------------------------------------
5+
6+
[
7+
["punctuation", "("],
8+
["punctuation", ")"],
9+
["punctuation", "["],
10+
["punctuation", "]"],
11+
["punctuation", "{"],
12+
["punctuation", "}"],
13+
["punctuation", "<"],
14+
["punctuation", ">"],
15+
16+
["punctuation", "."],
17+
["punctuation", ":"],
18+
["punctuation", ","],
19+
["punctuation", ";"]
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
""
2+
"foo"
3+
"\""
4+
"\n\n"
5+
6+
'f'
7+
'\n'
8+
'\34'
9+
10+
----------------------------------------------------
11+
12+
[
13+
["string", "\"\""],
14+
["string", "\"foo\""],
15+
["string", "\"\\\"\""],
16+
["string", "\"\\n\\n\""],
17+
18+
["string", "'f'"],
19+
["string", "'\\n'"],
20+
["string", "'\\34'"]
21+
]

0 commit comments

Comments
 (0)
Please sign in to comment.