Skip to content

Commit

Permalink
Added support for Apache Avro IDL (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Sep 6, 2021
1 parent 247fd9a commit 87e5a37
Show file tree
Hide file tree
Showing 18 changed files with 469 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@
"title": "AutoIt",
"owner": "Golmote"
},
"avro-idl": {
"title":"Avro IDL",
"alias": "avdl",
"owner": "RunDevelopment"
},
"bash": {
"title": "Bash",
"alias": "shell",
Expand Down
57 changes: 57 additions & 0 deletions components/prism-avro-idl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// GitHub: https://github.com/apache/avro
// Docs: https://avro.apache.org/docs/current/idl.html

Prism.languages['avro-idl'] = {
'comment': {
pattern: /\/\/.*|\/\*[\s\S]*?\*\//,
greedy: true
},
'string': [
{
pattern: /(^|[^\\])"(?:[^\r\n"\\]|\\.)*"/,
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\])'(?:[^\r\n'\\]|\\(?:[\s\S]|\d{1,3}))'/,
lookbehind: true,
greedy: true
}
],

'annotation': {
pattern: /@(?:[$\w.-]|`[^\r\n`]+`)+/,
greedy: true,
alias: 'function'
},
'function-identifier': {
pattern: /`[^\r\n`]+`(?=\s*\()/,
greedy: true,
alias: 'function'
},
'identifier': {
pattern: /`[^\r\n`]+`/,
greedy: true
},

'class-name': {
pattern: /(\b(?:enum|error|protocol|record|throws)\b\s+)[$\w]+/,
lookbehind: true,
greedy: true
},
'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/,
'function': /\b[a-z_]\w*(?=\s*\()/i,

'number': [
{
pattern: /(^|[^\w.])-?(?:(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?|0x(?:[a-f0-9]+(?:\.[a-f0-9]*)?|\.[a-f0-9]+)(?:p[+-]?\d+)?)[dfl]?(?![\w.])/i,
lookbehind: true
},
/-?\b(?:NaN|Infinity)\b/
],

'operator': /=/,
'punctuation': /[()\[\]{}<>.:,;-]/
};

Prism.languages.avdl = Prism.languages['avro-idl'];
1 change: 1 addition & 0 deletions components/prism-avro-idl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions examples/prism-avro-idl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<h2>Full example</h2>
<pre><code>// Source: https://avro.apache.org/docs/current/idl.html#example

/**
* An example protocol in Avro IDL
*/
@namespace("org.apache.avro.test")
protocol Simple {

@aliases(["org.foo.KindOf"])
enum Kind {
FOO,
BAR, // the bar enum value
BAZ
}

fixed MD5(16);

record TestRecord {
@order("ignore")
string name;

@order("descending")
Kind kind;

MD5 hash;

union { MD5, null} @aliases(["hash"]) nullableHash;

array&lt;long> arrayOfLongs;
}

error TestError {
string message;
}

string hello(string greeting);
TestRecord echo(TestRecord `record`);
int add(int arg1, int arg2);
bytes echoBytes(bytes data);
void `error`() throws TestError;
void ping() oneway;
}
</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
"js": "javascript",
"g4": "antlr4",
"adoc": "asciidoc",
"avdl": "avro-idl",
"shell": "bash",
"shortcode": "bbcode",
"rbnf": "bnf",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"asm6502": "6502 Assembly",
"autohotkey": "AutoHotkey",
"autoit": "AutoIt",
"avro-idl": "Avro IDL",
"avdl": "Avro IDL",
"basic": "BASIC",
"bbcode": "BBcode",
"bnf": "BNF",
Expand Down
Loading

0 comments on commit 87e5a37

Please sign in to comment.