Added support for BrightScript (#2096)

This adds support for BrightScript.
This commit is contained in:
Michael Schmidt 2019-10-26 18:53:47 +02:00 committed by GitHub
parent f31946b366
commit 631f1e34a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 402 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -181,6 +181,10 @@
"title": "Brainfuck",
"owner": "Golmote"
},
"brightscript": {
"title": "BrightScript",
"owner": "RunDevelopment"
},
"bro": {
"title": "Bro",
"owner": "wayward710"

View File

@ -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;

1
components/prism-brightscript.min.js vendored Normal file
View File

@ -0,0 +1 @@
Prism.languages.brightscript={comment:/(?:\brem|').*/i,"directive-statement":{pattern:/(^[\t ]*)#(?:const|else(?:[\t ]+if)?|end[\t ]+if|error|if).*/im,lookbehind:!0,alias:"property",inside:{"error-message":{pattern:/(^#error).+/,lookbehind:!0},directive:{pattern:/^#(?:const|else(?:[\t ]+if)?|end[\t ]+if|error|if)/,alias:"keyword"},expression:{pattern:/[\s\S]+/,inside:null}}},property:{pattern:/([\r\n{,][\t ]*)(?:(?!\d)\w+|"(?:[^"\r\n]|"")*"(?!"))(?=[ \t]*:)/,lookbehind:!0,greedy:!0},string:{pattern:/"(?:[^"\r\n]|"")*"(?!")/,greedy:!0},"class-name":{pattern:/(\bAs[\t ]+)\w+/i,lookbehind:!0},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;

View File

@ -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>

View File

@ -0,0 +1,13 @@
true
false
----------------------------------------------------
[
["boolean", "true"],
["boolean", "false"]
]
----------------------------------------------------
Checks for booleans.

View File

@ -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.

View File

@ -0,0 +1,13 @@
REM I'm a comment
' me too!
----------------------------------------------------
[
["comment", "REM I'm a comment"],
["comment", "' me too!"]
]
----------------------------------------------------
Checks for comments.

View File

@ -0,0 +1,11 @@
LINE_NUM
----------------------------------------------------
[
["constant", "LINE_NUM"]
]
----------------------------------------------------
Checks for constants.

View File

@ -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).

View File

@ -0,0 +1,50 @@
As;
Dim
Each
Else
Elseif
End
Exit
For
Function
Goto
If
In
Print
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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -0,0 +1,20 @@
() [] {}
. , ;
----------------------------------------------------
[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", "."],
["punctuation", ","],
["punctuation", ";"]
]
----------------------------------------------------
Checks for punctuation.

View File

@ -0,0 +1,13 @@
"foo bar"
""""
----------------------------------------------------
[
["string", "\"foo bar\""],
["string", "\"\"\"\""]
]
----------------------------------------------------
Checks for strings.