-
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.
Added support for BrightScript (#2096)
This adds support for BrightScript.
- Loading branch information
1 parent
f31946b
commit 631f1e3
Showing
16 changed files
with
402 additions
and
1 deletion.
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,44 @@ | ||
Prism.languages.brightscript = { | ||
'comment': /(?:\brem|').*/i, | ||
'directive-statement': { | ||
pattern: /(^[\t ]*)#(?:const|else(?:[\t ]+if)?|end[\t ]+if|error|if).*/im, | ||
lookbehind: true, | ||
alias: 'property', | ||
inside: { | ||
'error-message': { | ||
pattern: /(^#error).+/, | ||
lookbehind: true | ||
}, | ||
'directive': { | ||
pattern: /^#(?:const|else(?:[\t ]+if)?|end[\t ]+if|error|if)/, | ||
alias: 'keyword' | ||
}, | ||
'expression': { | ||
pattern: /[\s\S]+/, | ||
inside: null // see below | ||
} | ||
} | ||
}, | ||
'property': { | ||
pattern: /([\r\n{,][\t ]*)(?:(?!\d)\w+|"(?:[^"\r\n]|"")*"(?!"))(?=[ \t]*:)/, | ||
lookbehind: true, | ||
greedy: true | ||
}, | ||
'string': { | ||
pattern: /"(?:[^"\r\n]|"")*"(?!")/, | ||
greedy: true | ||
}, | ||
'class-name': { | ||
pattern: /(\bAs[\t ]+)\w+/i, | ||
lookbehind: true | ||
}, | ||
'keyword': /\b(?:As|Dim|Each|Else|Elseif|End|Exit|For|Function|Goto|If|In|Print|Return|Step|Stop|Sub|Then|To|While)\b/i, | ||
'boolean': /\b(?:true|false)\b/i, | ||
'function': /\b(?!\d)\w+(?=[\t ]*\()/i, | ||
'number': /(?:\b\d+(?:\.\d+)?(?:[ed][+-]\d+)?|&h[a-f\d]+)\b[%&!#]?/i, | ||
'operator': /--|\+\+|>>=?|<<=?|<>|[-+*/\\<>]=?|[:^=?]|\b(?:and|mod|not|or)\b/i, | ||
'punctuation': /[.,;()[\]{}]/, | ||
'constant': /\b(?:LINE_NUM)\b/i | ||
}; | ||
|
||
Prism.languages.brightscript['directive-statement'].inside.expression.inside = Prism.languages.brightscript; |
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,13 @@ | ||
<h2>Full example</h2> | ||
<pre><code>Function Main() | ||
MyFunA(4) | ||
MyFunB(4) | ||
End Function | ||
|
||
Function MyFunA(p as Object) as Void | ||
print "A",p,type(p) | ||
End Function | ||
|
||
Function MyFunB(p as Integer) as Void | ||
print "B",p,type(p) | ||
End Function</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for booleans. |
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,31 @@ | ||
Function Foo(a as Object, b=1+1 as Integer) as Void | ||
End Function | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "Function"], | ||
["function", "Foo"], | ||
["punctuation", "("], | ||
"a ", | ||
["keyword", "as"], | ||
["class-name", "Object"], | ||
["punctuation", ","], | ||
" b", | ||
["operator", "="], | ||
["number", "1"], | ||
["operator", "+"], | ||
["number", "1"], | ||
["keyword", "as"], | ||
["class-name", "Integer"], | ||
["punctuation", ")"], | ||
["keyword", "as"], | ||
["class-name", "Void"], | ||
|
||
["keyword", "End"], | ||
["keyword", "Function"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,13 @@ | ||
REM I'm a comment | ||
' me too! | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "REM I'm a comment"], | ||
["comment", "' me too!"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
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,11 @@ | ||
LINE_NUM | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["constant", "LINE_NUM"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for constants. |
67 changes: 67 additions & 0 deletions
67
tests/languages/brightscript/directive-statement_feature.test
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,67 @@ | ||
#const someFlag = true | ||
#const anotherFlag = false | ||
#const someOtherFlag = someFlag | ||
|
||
#if FeatureA | ||
#else if FeatureB | ||
#else | ||
#end if | ||
|
||
#error Your device cannot support this feature. | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["directive-statement", [ | ||
["directive", "#const"], | ||
["expression", [ | ||
" someFlag ", | ||
["operator", "="], | ||
["boolean", "true"] | ||
]] | ||
]], | ||
["directive-statement", [ | ||
["directive", "#const"], | ||
["expression", [ | ||
" anotherFlag ", | ||
["operator", "="], | ||
["boolean", "false"] | ||
]] | ||
]], | ||
["directive-statement", [ | ||
["directive", "#const"], | ||
["expression", [ | ||
" someOtherFlag ", | ||
["operator", "="], | ||
" someFlag" | ||
]] | ||
]], | ||
|
||
["directive-statement", [ | ||
["directive", "#if"], | ||
["expression", [ | ||
" FeatureA" | ||
]] | ||
]], | ||
["directive-statement", [ | ||
["directive", "#else if"], | ||
["expression", [ | ||
" FeatureB" | ||
]] | ||
]], | ||
["directive-statement", [ | ||
["directive", "#else"] | ||
]], | ||
["directive-statement", [ | ||
["directive", "#end if"] | ||
]], | ||
|
||
["directive-statement", [ | ||
["directive", "#error"], | ||
["error-message", " Your device cannot support this feature."] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for directives (conditional compilation). |
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,50 @@ | ||
As; | ||
Dim | ||
Each | ||
Else | ||
Elseif | ||
End | ||
Exit | ||
For | ||
Function | ||
Goto | ||
If | ||
In | ||
Return | ||
Step | ||
Stop | ||
Sub | ||
Then | ||
To | ||
While | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "As"], | ||
["punctuation", ";"], | ||
["keyword", "Dim"], | ||
["keyword", "Each"], | ||
["keyword", "Else"], | ||
["keyword", "Elseif"], | ||
["keyword", "End"], | ||
["keyword", "Exit"], | ||
["keyword", "For"], | ||
["keyword", "Function"], | ||
["keyword", "Goto"], | ||
["keyword", "If"], | ||
["keyword", "In"], | ||
["keyword", "Print"], | ||
["keyword", "Return"], | ||
["keyword", "Step"], | ||
["keyword", "Stop"], | ||
["keyword", "Sub"], | ||
["keyword", "Then"], | ||
["keyword", "To"], | ||
["keyword", "While"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,29 @@ | ||
123 | ||
&hBAD | ||
|
||
1.23e-4 | ||
1.23D+45 | ||
|
||
123% | ||
123& | ||
123! | ||
123# | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["number", "123"], | ||
["number", "&hBAD"], | ||
|
||
["number", "1.23e-4"], | ||
["number", "1.23D+45"], | ||
|
||
["number", "123%"], | ||
["number", "123&"], | ||
["number", "123!"], | ||
["number", "123#"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,53 @@ | ||
+ - * / \ ^ ++ -- | ||
+= -= *= /= \= | ||
|
||
>> >>= << <<= | ||
|
||
< > <= >= <> = | ||
|
||
: ? | ||
|
||
Mod | ||
And Or Not | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["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", "Mod"], | ||
["operator", "And"], | ||
["operator", "Or"], | ||
["operator", "Not"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
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,39 @@ | ||
{ | ||
foo: 4 | ||
"bar": 5 | ||
} | ||
|
||
a = { foo: 5, bar: 6, "foo bar": 7 } | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "{"], | ||
["property", "foo"], | ||
["operator", ":"], | ||
["number", "4"], | ||
["property", "\"bar\""], | ||
["operator", ":"], | ||
["number", "5"], | ||
["punctuation", "}"], | ||
|
||
"\n\na ", | ||
["operator", "="], | ||
["punctuation", "{"], | ||
["property", "foo"], | ||
["operator", ":"], | ||
["number", "5"], | ||
["punctuation", ","], | ||
["property", "bar"], | ||
["operator", ":"], | ||
["number", "6"], | ||
["punctuation", ","], | ||
["property", "\"foo bar\""], | ||
["operator", ":"], | ||
["number", "7"], | ||
["punctuation", "}"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for properties. |
Oops, something went wrong.