Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Vala language #1658

Merged
merged 14 commits into from
Dec 15, 2018
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 @@ -755,6 +755,11 @@
"alias": "ts",
"owner": "vkbansal"
},
"vala": {
"title": "Vala",
"require": "clike",
"owner": "TemplarVolk"
},
"vbnet": {
"title": "VB.Net",
"require": "basic",
Expand Down
74 changes: 74 additions & 0 deletions components/prism-vala.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
Prism.languages.vala = Prism.languages.extend('clike', {
// Classes copied from prism-csharp
'class-name': [
{
// (Foo bar, Bar baz)
pattern: /\b[A-Z]\w*(?:\.\w+)*\b(?=(?:\?\s+|\*?\s+\*?)\w+)/,
inside: {
punctuation: /\./
}
},
{
// [Foo]
pattern: /(\[)[A-Z]\w*(?:\.\w+)*\b/,
lookbehind: true,
inside: {
punctuation: /\./
}
},
{
// class Foo : Bar
pattern: /(\b(?:class|interface)\s+[A-Z]\w*(?:\.\w+)*\s*:\s*)[A-Z]\w*(?:\.\w+)*\b/,
lookbehind: true,
inside: {
punctuation: /\./
}
},
{
// class Foo
pattern: /((?:\b(?:class|interface|new|struct|enum)\s+)|(?:catch\s+\())[A-Z]\w*(?:\.\w+)*\b/,
lookbehind: true,
inside: {
punctuation: /\./
}
}
],
'constant': /\b[A-Z0-9_]+\b/,
'function': /\w+(?=\s*\()/,
'keyword': /\b(?:bool|char|double|float|null|size_t|ssize_t|string|unichar|void|int|int8|int16|int32|int64|long|short|uchar|uint|uint8|uint16|uint32|uint64|ulong|ushort|class|delegate|enum|errordomain|interface|namespace|struct|break|continue|do|for|foreach|return|while|else|if|switch|assert|case|default|abstract|const|dynamic|ensures|extern|inline|internal|override|private|protected|public|requires|signal|static|virtual|volatile|weak|async|owned|unowned|try|catch|finally|throw|as|base|construct|delete|get|in|is|lock|new|out|params|ref|sizeof|set|this|throws|typeof|using|value|var|yield)\b/i,
'number': /(?:\b0x[\da-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:e[+-]?\d+)?)(?:f|u?l?)?/i,
'operator': /\+\+|--|&&|\|\||<<=?|>>=?|=>|->|~|[+\-*\/%&^|=!<>]=?|\?\??|\.\.\./,
'punctuation': /[{}[\];(),.:]/
});

Prism.languages.insertBefore('vala','string', {
'raw-string': {
pattern: /"""[\s\S]*?"""/,
greedy: true,
alias: 'string'
},
'template-string': {
pattern: /@"[\s\S]*?"/,
greedy: true,
inside: {
'interpolation': {
pattern: /\$(?:\([^)]*\)|[a-zA-Z]\w*)/,
inside: {
'delimiter': {
pattern: /^\$\(?|\)$/,
alias: 'punctuation'
},
rest: Prism.languages.vala
}
},
'string': /[\s\S]+/
}
}
});

Prism.languages.insertBefore('vala', 'keyword', {
'regex': {
pattern: /\/(\[(?:[^\]\\\r\n]|\\.)*]|\\.|[^/\\\[\r\n])+\/[imsx]{0,4}(?=\s*($|[\r\n,.;})\]]))/,
greedy: true
}
});
1 change: 1 addition & 0 deletions components/prism-vala.min.js

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

33 changes: 33 additions & 0 deletions examples/prism-vala.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h2>Comments</h2>
<pre><code">// Single line comment
/** Multi-line
doc comment */</code></pre>

<h2>Strings</h2>
<pre><code">"foo \"bar\" baz"
"Multi-line strings ending with a \
are supported too."
"""Verbatim strings
You can create
multi-line strings like this too."""
@"Template string with variables $var1 $(var2 * 2)"</code></pre>

<h2>Regex</h2>
<pre><code">/foo?[ ]*bar/</code></pre>

<h2>Full example</h2>
<pre><code">using Gtk;

int main (string[] args) {
Gtk.init(ref args);

var window = new Window();

var button = new Button.with_label("Click me!");

window.add(button);
window.show_all();

Gtk.main();
return 0;
}</code></pre>
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vala":"clike","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;

var lang_data = {};

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.

37 changes: 37 additions & 0 deletions tests/languages/vala/class-name_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Foo
enum Bar
interface BarBaz
class Foo : Bar
[Foobar]
void Foo(Bar bar, Baz baz)

----------------------------------------------------

[
["keyword", "class"],
["class-name", ["Foo"]],
["keyword", "enum"],
["class-name", ["Bar"]],
["keyword", "interface"],
["class-name", ["BarBaz"]],
["keyword", "class"],
["class-name", ["Foo"]],
["punctuation", ":"],
["class-name", ["Bar"]],
["punctuation", "["],
["class-name", ["Foobar"]],
["punctuation", "]"],
["keyword", "void"],
["function", "Foo"],
["punctuation", "("],
["class-name", ["Bar"]],
" bar",
["punctuation", ","],
["class-name", ["Baz"]],
" baz",
["punctuation", ")"]
]

----------------------------------------------------

Checks for class names.
189 changes: 189 additions & 0 deletions tests/languages/vala/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
bool
char
double
float
null
size_t
ssize_t
string
unichar
void
int
int8
int16
int32
int64
long
short
uchar
uint
uint8
uint16
uint32
uint64
ulong
ushort
class
delegate
enum
errordomain
interface
namespace
struct
break
continue
do
for
foreach
return
while
else
if
switch
assert
case
default
abstract
const
dynamic
ensures
extern
inline
internal
override
private
protected
public
requires
signal
static
virtual
volatile
weak
async
owned
unowned
try
catch
finally
throw
as
base
construct
delete
get
in
is
lock
new
out
params
ref
sizeof
set
this
throws
typeof
using
value
var
yield

----------------------------------------------------

[
["keyword", "bool"],
["keyword", "char"],
["keyword", "double"],
["keyword", "float"],
["keyword", "null"],
["keyword", "size_t"],
["keyword", "ssize_t"],
["keyword", "string"],
["keyword", "unichar"],
["keyword", "void"],
["keyword", "int"],
["keyword", "int8"],
["keyword", "int16"],
["keyword", "int32"],
["keyword", "int64"],
["keyword", "long"],
["keyword", "short"],
["keyword", "uchar"],
["keyword", "uint"],
["keyword", "uint8"],
["keyword", "uint16"],
["keyword", "uint32"],
["keyword", "uint64"],
["keyword", "ulong"],
["keyword", "ushort"],
["keyword", "class"],
["keyword", "delegate"],
["keyword", "enum"],
["keyword", "errordomain"],
["keyword", "interface"],
["keyword", "namespace"],
["keyword", "struct"],
["keyword", "break"],
["keyword", "continue"],
["keyword", "do"],
["keyword", "for"],
["keyword", "foreach"],
["keyword", "return"],
["keyword", "while"],
["keyword", "else"],
["keyword", "if"],
["keyword", "switch"],
["keyword", "assert"],
["keyword", "case"],
["keyword", "default"],
["keyword", "abstract"],
["keyword", "const"],
["keyword", "dynamic"],
["keyword", "ensures"],
["keyword", "extern"],
["keyword", "inline"],
["keyword", "internal"],
["keyword", "override"],
["keyword", "private"],
["keyword", "protected"],
["keyword", "public"],
["keyword", "requires"],
["keyword", "signal"],
["keyword", "static"],
["keyword", "virtual"],
["keyword", "volatile"],
["keyword", "weak"],
["keyword", "async"],
["keyword", "owned"],
["keyword", "unowned"],
["keyword", "try"],
["keyword", "catch"],
["keyword", "finally"],
["keyword", "throw"],
["keyword", "as"],
["keyword", "base"],
["keyword", "construct"],
["keyword", "delete"],
["keyword", "get"],
["keyword", "in"],
["keyword", "is"],
["keyword", "lock"],
["keyword", "new"],
["keyword", "out"],
["keyword", "params"],
["keyword", "ref"],
["keyword", "sizeof"],
["keyword", "set"],
["keyword", "this"],
["keyword", "throws"],
["keyword", "typeof"],
["keyword", "using"],
["keyword", "value"],
["keyword", "var"],
["keyword", "yield"]
]

----------------------------------------------------

Checks for all keywords.
27 changes: 27 additions & 0 deletions tests/languages/vala/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
42
3.14159
5ul
0.75f
4e10
2.1e-10
0.4e+2
0xbabe
0xBABE

----------------------------------------------------

[
["number", "42"],
["number", "3.14159"],
["number", "5ul"],
["number", "0.75f"],
["number", "4e10"],
["number", "2.1e-10"],
["number", "0.4e+2"],
["number", "0xbabe"],
["number", "0xBABE"]
]

----------------------------------------------------

Checks for decimal numbers and hexadecimal numbers.
Loading