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

Added support for Squirrel #2721

Merged
merged 3 commits into from Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions components.json
Expand Up @@ -1126,6 +1126,11 @@
"title": "SQL",
"owner": "multipetros"
},
"squirrel": {
"title": "Squirrel",
"require": "clike",
"owner": "RunDevelopment"
},
"stan": {
"title": "Stan",
"owner": "RunDevelopment"
Expand Down
46 changes: 46 additions & 0 deletions components/prism-squirrel.js
@@ -0,0 +1,46 @@
Prism.languages.squirrel = Prism.languages.extend('clike', {
'comment': [
Prism.languages.clike['comment'][0],
{
pattern: /(^|[^\\:])(?:\/\/|#).*/,
lookbehind: true,
greedy: true
}
],
'string': [
{
pattern: /(^|[^\\"'@])(?:@"(?:[^"]|"")*"(?!")|"(?:[^\\\r\n"]|\\.)*")/,
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\"'])'(?:[^\\']|\\(?:[xuU][0-9a-fA-F]{0,8}|[^]))'/,
lookbehind: true,
greedy: true
}
],

'class-name': {
pattern: /(\b(?:class|enum|extends|instanceof)\s+)\w+(?:\.\w+)*/,
lookbehind: true,
inside: {
'punctuation': /\./
}
},
'keyword': /\b(?:base|break|case|catch|class|clone|const|constructor|continue|default|delete|else|enum|extends|for|foreach|function|if|in|instanceof|local|null|resume|return|static|switch|this|throw|try|typeof|while|yield|__LINE__|__FILE__)\b/,

'number': /\b(?:0x[0-9a-fA-F]+|\d+(?:\.(?:\d+|[eE][+-]?\d+))?)\b/,
'operator': /\+\+|--|<=>|<[-<]|>>>?|&&?|\|\|?|[-+*/%!=<>]=?|[~^]|::?/,
'punctuation': /[(){}\[\],;.]/
});

Prism.languages.insertBefore('squirrel', 'operator', {
'attribute-punctuation': {
pattern: /<\/|\/>/,
alias: 'important'
},
'lambda': {
pattern: /@(?=\()/,
alias: 'operator'
}
});
1 change: 1 addition & 0 deletions components/prism-squirrel.min.js

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

57 changes: 57 additions & 0 deletions examples/prism-squirrel.html
@@ -0,0 +1,57 @@
<h2>Full example</h2>
<pre><code> // source: http://www.squirrel-lang.org/#look

local table = {
a = "10"
subtable = {
array = [1,2,3]
},
[10 + 123] = "expression index"
}

local array=[ 1, 2, 3, { a = 10, b = "string" } ];

foreach (i,val in array)
{
::print("the type of val is"+typeof val);
}

/////////////////////////////////////////////

class Entity
{
constructor(etype,entityname)
{
name = entityname;
type = etype;
}

x = 0;
y = 0;
z = 0;
name = null;
type = null;
}

function Entity::MoveTo(newx,newy,newz)
{
x = newx;
y = newy;
z = newz;
}

class Player extends Entity {
constructor(entityname)
{
base.constructor("Player",entityname)
}
function DoDomething()
{
::print("something");
}

}

local newplayer = Player("da playar");

newplayer.MoveTo(100,200,300);</code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Expand Up @@ -128,6 +128,7 @@
"soy": "markup-templating",
"sparql": "turtle",
"sqf": "clike",
"squirrel": "clike",
"swift": "clike",
"t4-cs": [
"t4-templating",
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.

93 changes: 93 additions & 0 deletions tests/languages/squirrel/attribute_feature.test
@@ -0,0 +1,93 @@
class Foo </ test = "I'm a class level attribute" />{
</ test = "freakin attribute" /> //attributes of PrintTesty
function PrintTesty()
{
foreach(i,val in testy)
{
::print("idx = "+i+" = "+val+" \n");
}
}
</ flippy = 10 , second = [1,2,3] /> //attributes of testy
testy = null;
}

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

[
["keyword", "class"],
["class-name", ["Foo"]],
["attribute-punctuation", "</"],
" test ",
["operator", "="],
["string", "\"I'm a class level attribute\""],
["attribute-punctuation", "/>"],
["punctuation", "{"],

["attribute-punctuation", "</"],
" test ",
["operator", "="],
["string", "\"freakin attribute\""],
["attribute-punctuation", "/>"],
["comment", "//attributes of PrintTesty"],

["keyword", "function"],
["function", "PrintTesty"],
["punctuation", "("],
["punctuation", ")"],

["punctuation", "{"],

["keyword", "foreach"],
["punctuation", "("],
"i",
["punctuation", ","],
"val ",
["keyword", "in"],
" testy",
["punctuation", ")"],

["punctuation", "{"],

["operator", "::"],
["function", "print"],
["punctuation", "("],
["string", "\"idx = \""],
["operator", "+"],
"i",
["operator", "+"],
["string", "\" = \""],
["operator", "+"],
"val",
["operator", "+"],
["string", "\" \\n\""],
["punctuation", ")"],
["punctuation", ";"],

["punctuation", "}"],

["punctuation", "}"],

["attribute-punctuation", "</"],
" flippy ",
["operator", "="],
["number", "10"],
["punctuation", ","],
" second ",
["operator", "="],
["punctuation", "["],
["number", "1"],
["punctuation", ","],
["number", "2"],
["punctuation", ","],
["number", "3"],
["punctuation", "]"],
["attribute-punctuation", "/>"],
["comment", "//attributes of testy"],

"\r\n testy ",
["operator", "="],
["keyword", "null"],
["punctuation", ";"],

["punctuation", "}"]
]
9 changes: 9 additions & 0 deletions tests/languages/squirrel/boolean_feature.test
@@ -0,0 +1,9 @@
false
true

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

[
["boolean", "false"],
["boolean", "true"]
]
45 changes: 45 additions & 0 deletions tests/languages/squirrel/class-name_feature.test
@@ -0,0 +1,45 @@
class Foo {}
class FakeNamespace.Utils.SuperClass {}
class SuperFoo extends Foo {}
log(b instanceof Kid);
enum Stuff {}

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

[
["keyword", "class"],
["class-name", ["Foo"]],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "class"],
["class-name", [
"FakeNamespace",
["punctuation", "."],
"Utils",
["punctuation", "."],
"SuperClass"
]],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "class"],
["class-name", ["SuperFoo"]],
["keyword", "extends"],
["class-name", ["Foo"]],
["punctuation", "{"],
["punctuation", "}"],

["function", "log"],
["punctuation", "("],
"b ",
["keyword", "instanceof"],
["class-name", ["Kid"]],
["punctuation", ")"],
["punctuation", ";"],

["keyword", "enum"],
["class-name", ["Stuff"]],
["punctuation", "{"],
["punctuation", "}"]
]
15 changes: 15 additions & 0 deletions tests/languages/squirrel/comment_feature.test
@@ -0,0 +1,15 @@
/*
this is
a multiline comment.
this lines will be ignored by the compiler
*/
//this is a single line comment. this line will be ignored by the compiler
# this is also a single line comment.

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

[
["comment", "/*\r\nthis is\r\na multiline comment.\r\nthis lines will be ignored by the compiler\r\n*/"],
["comment", "//this is a single line comment. this line will be ignored by the compiler"],
["comment", "# this is also a single line comment."]
]
44 changes: 44 additions & 0 deletions tests/languages/squirrel/function_feature.test
@@ -0,0 +1,44 @@
function abc(a,b,c) {}
function(a,b,c) {}
local myexp = @(a,b) a + b;

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

[
["keyword", "function"],
["function", "abc"],
["punctuation", "("],
"a",
["punctuation", ","],
"b",
["punctuation", ","],
"c",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "function"],
["punctuation", "("],
"a",
["punctuation", ","],
"b",
["punctuation", ","],
"c",
["punctuation", ")"],
["punctuation", "{"],
["punctuation", "}"],

["keyword", "local"],
" myexp ",
["operator", "="],
["lambda", "@"],
["punctuation", "("],
"a",
["punctuation", ","],
"b",
["punctuation", ")"],
" a ",
["operator", "+"],
" b",
["punctuation", ";"]
]