-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for the GDScript language.
- Loading branch information
1 parent
af5a36a
commit e2b99f4
Showing
13 changed files
with
400 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Prism.languages.gdscript = { | ||
'comment': /#.*/, | ||
'string': { | ||
pattern: /@?(?:("|')(?:(?!\1)[^\n\\]|\\[\s\S])*\1(?!"|')|"""(?:[^\\]|\\[\s\S])*?""")/, | ||
greedy: true | ||
}, | ||
'class-name': { | ||
// class_name Foo, extends Bar, class InnerClass | ||
// export(int) var baz, export(int, 0) var i | ||
// as Node | ||
// const FOO: int = 9, var bar: bool = true | ||
// func add(reference: Item, amount: int) -> Item: | ||
pattern: /(^(?:class_name|class|extends)[ \t]+|^export\([ \t]*|\bas[ \t]+|(?:\b(?:const|var)[ \t]|[,(])[ \t]*\w+[ \t]*:[ \t]*|->[ \t]*)[a-zA-Z_]\w*/m, | ||
lookbehind: true | ||
}, | ||
'keyword': /\b(?:and|as|assert|break|breakpoint|class|class_name|const|continue|elif|else|enum|export|extends|for|func|if|in|is|master|mastersync|match|not|null|onready|or|pass|preload|puppet|puppetsync|remote|remotesync|return|self|setget|signal|static|tool|var|while|yield)\b/, | ||
'function': /[a-z_]\w*(?=[ \t]*\()/i, | ||
'variable': /\$\w+/, | ||
'number': [ | ||
/\b0b[01_]+\b|\b0x[\da-fA-F_]+\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.[\d_]+)(?:e[+-]?[\d_]+)?\b/, | ||
/\b(?:INF|NAN|PI|TAU)\b/ | ||
], | ||
'constant': /\b[A-Z][A-Z_\d]*\b/, | ||
'boolean': /\b(?:false|true)\b/, | ||
'operator': /->|:=|&&|\|\||<<|>>|[-+*/%&|!<>=]=?|[~^]/, | ||
'punctuation': /[.:,;()[\]{}]/ | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<h2>Full example</h2> | ||
<pre><code>extends BaseClass | ||
class_name MyClass, "res://path/to/optional/icon.svg" | ||
|
||
# Member Variables | ||
|
||
var a = 5 | ||
var s = "Hello" | ||
var arr = [1, 2, 3] | ||
var dict = {"key": "value", 2:3} | ||
var typed_var: int | ||
var inferred_type := "String" | ||
|
||
# Constants | ||
|
||
const ANSWER = 42 | ||
const THE_NAME = "Charly" | ||
|
||
# Enums | ||
|
||
enum {UNIT_NEUTRAL, UNIT_ENEMY, UNIT_ALLY} | ||
enum Named {THING_1, THING_2, ANOTHER_THING = -1} | ||
|
||
# Built-in Vector Types | ||
|
||
var v2 = Vector2(1, 2) | ||
var v3 = Vector3(1, 2, 3) | ||
|
||
# Function | ||
|
||
func some_function(param1, param2): | ||
var local_var = 5 | ||
|
||
if param1 < local_var: | ||
print(param1) | ||
elif param2 > 5: | ||
print(param2) | ||
else: | ||
print("Fail!") | ||
|
||
for i in range(20): | ||
print(i) | ||
|
||
while param2 != 0: | ||
param2 -= 1 | ||
|
||
var local_var2 = param1 + 3 | ||
return local_var2 | ||
|
||
# Functions override functions with the same name on the base/parent class. | ||
# If you still want to call them, use '.' (like 'super' in other languages). | ||
|
||
func something(p1, p2): | ||
.something(p1, p2) | ||
|
||
# Inner Class | ||
|
||
class Something: | ||
var a = 10 | ||
|
||
# Constructor | ||
|
||
func _init(): | ||
print("Constructed!") | ||
var lv = Something.new() | ||
print(lv.a)</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
class_name Foo | ||
extends Bar | ||
|
||
class InnerClass: | ||
|
||
export(int) var baz | ||
export(int, 0) var i | ||
|
||
return foo as Node | ||
|
||
const FOO: int = 9 | ||
var bar: bool = true | ||
|
||
func add(reference: Item, amount: int) -> Item: | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "class_name"], | ||
["class-name", "Foo"], | ||
["keyword", "extends"], | ||
["class-name", "Bar"], | ||
|
||
["keyword", "class"], | ||
["class-name", "InnerClass"], | ||
["punctuation", ":"], | ||
|
||
["keyword", "export"], | ||
["punctuation", "("], | ||
["class-name", "int"], | ||
["punctuation", ")"], | ||
["keyword", "var"], | ||
" baz\n", | ||
["keyword", "export"], | ||
["punctuation", "("], | ||
["class-name", "int"], | ||
["punctuation", ","], | ||
["number", "0"], | ||
["punctuation", ")"], | ||
["keyword", "var"], | ||
" i\n\n", | ||
|
||
["keyword", "return"], | ||
" foo ", | ||
["keyword", "as"], | ||
["class-name", "Node"], | ||
|
||
["keyword", "const"], | ||
["constant", "FOO"], | ||
["punctuation", ":"], | ||
["class-name", "int"], | ||
["operator", "="], | ||
["number", "9"], | ||
["keyword", "var"], | ||
" bar", | ||
["punctuation", ":"], | ||
["class-name", "bool"], | ||
["operator", "="], | ||
["boolean", "true"], | ||
|
||
["keyword", "func"], | ||
["function", "add"], | ||
["punctuation", "("], | ||
"reference", | ||
["punctuation", ":"], | ||
["class-name", "Item"], | ||
["punctuation", ","], | ||
" amount", | ||
["punctuation", ":"], | ||
["class-name", "int"], | ||
["punctuation", ")"], | ||
["operator", "->"], | ||
["class-name", "Item"], | ||
["punctuation", ":"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for class names. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
and | ||
as | ||
assert | ||
break | ||
breakpoint | ||
class | ||
class_name | ||
const | ||
continue | ||
elif | ||
else | ||
enum | ||
export | ||
extends | ||
for | ||
func | ||
if | ||
in | ||
is | ||
master | ||
mastersync | ||
match | ||
not | ||
null | ||
onready | ||
or | ||
pass | ||
preload | ||
puppet | ||
puppetsync | ||
remote | ||
remotesync | ||
return | ||
self | ||
setget | ||
signal | ||
static | ||
tool | ||
var | ||
while | ||
yield | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "and"], | ||
["keyword", "as"], | ||
["keyword", "assert"], | ||
["keyword", "break"], | ||
["keyword", "breakpoint"], | ||
["keyword", "class"], | ||
["keyword", "class_name"], | ||
["keyword", "const"], | ||
["keyword", "continue"], | ||
["keyword", "elif"], | ||
["keyword", "else"], | ||
["keyword", "enum"], | ||
["keyword", "export"], | ||
["keyword", "extends"], | ||
["keyword", "for"], | ||
["keyword", "func"], | ||
["keyword", "if"], | ||
["keyword", "in"], | ||
["keyword", "is"], | ||
["keyword", "master"], | ||
["keyword", "mastersync"], | ||
["keyword", "match"], | ||
["keyword", "not"], | ||
["keyword", "null"], | ||
["keyword", "onready"], | ||
["keyword", "or"], | ||
["keyword", "pass"], | ||
["keyword", "preload"], | ||
["keyword", "puppet"], | ||
["keyword", "puppetsync"], | ||
["keyword", "remote"], | ||
["keyword", "remotesync"], | ||
["keyword", "return"], | ||
["keyword", "self"], | ||
["keyword", "setget"], | ||
["keyword", "signal"], | ||
["keyword", "static"], | ||
["keyword", "tool"], | ||
["keyword", "var"], | ||
["keyword", "while"], | ||
["keyword", "yield"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for keywords. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
123 | ||
-123 | ||
123.456 | ||
.5 | ||
1.2e-34 | ||
|
||
0xBadFace | ||
0b01010101 | ||
|
||
1_000_000_000_000 | ||
0xBAD_FACE | ||
0b_0010_0010_0100_0100 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "123"], | ||
["operator", "-"], | ||
["number", "123"], | ||
["number", "123.456"], | ||
["number", ".5"], | ||
["number", "1.2e-34"], | ||
|
||
["number", "0xBadFace"], | ||
["number", "0b01010101"], | ||
|
||
["number", "1_000_000_000_000"], | ||
["number", "0xBAD_FACE"], | ||
["number", "0b_0010_0010_0100_0100"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for numbers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
+ - * / % | ||
& | ~ ^ >> << | ||
&& || ! | ||
> < = == != >= <= | ||
:= | ||
-> | ||
+= -= *= /= %= &= |= | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "+"], | ||
["operator", "-"], | ||
["operator", "*"], | ||
["operator", "/"], | ||
["operator", "%"], | ||
["operator", "&"], | ||
["operator", "|"], | ||
["operator", "~"], | ||
["operator", "^"], | ||
["operator", ">>"], | ||
["operator", "<<"], | ||
["operator", "&&"], | ||
["operator", "||"], | ||
["operator", "!"], | ||
["operator", ">"], | ||
["operator", "<"], | ||
["operator", "="], | ||
["operator", "=="], | ||
["operator", "!="], | ||
["operator", ">="], | ||
["operator", "<="], | ||
["operator", ":="], | ||
["operator", "->"], | ||
["operator", "+="], | ||
["operator", "-="], | ||
["operator", "*="], | ||
["operator", "/="], | ||
["operator", "%="], | ||
["operator", "&="], | ||
["operator", "|="] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
. : , ; [] () {} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "."], | ||
["punctuation", ":"], | ||
["punctuation", ","], | ||
["punctuation", ";"], | ||
["punctuation", "["], | ||
["punctuation", "]"], | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["punctuation", "{"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for punctuation. |
Oops, something went wrong.