1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
|
//This is a basic comment
//Multiline comments do not exist
//And comments should be able to exist anywhere, provided they aren't being written as part of a string.
//Comments cannot be terminated early, and cubescript has no concept of Line Continuations in the context of comments either. ie \
echo "This is a normally parsed and executed line"
//Comments should also support relatively standard comment markers, They're reproduced in full right below.
//ALERT ATTENTION DANGER
//HACK SECURITY BUG FIXME
//DEPRECATED TASK TODO TBD
//WARNING NOLINT ### NOTE
//NOTICE TEST TESTING
//This is a string being highlighted; cubescript defines that that a \n, \r or \0 terminates the string unless prefixed by a "^".
// ^t, and ^f has a special meaning, the first inserts a tab, the second defines a colour code.
// in an ^f# sequence, the ^f token will be displayed with the colour the parser will print the 8 common codes with.
// Some parsers have much more complex rules for the ^f tokens, allowing full 24bit RGB codes, multiple codes for flickering text and with many additional one character colour codes; they are not supported here.
//The colour changes cannot be more involved without compromising readability and making the highlighter itself very complex.
echo "^A^B^C^D^E^F^G^H^I^J^K^L^M^N ^f0^f1^f2^f3The first half of the alphabet has been escaped, followed by several ^^f tokens, which has special meaning, the last of which colours this message red."
echo "Also note that strings cannot contain //comments in them at all. This makes them handy for storing URLs like http://www.example.com"
echo "$lookups, (script commands) [nor [nested [blocks] exist] in] cubescript strings either"
echo "in order, the 7 colour codes are ^fs^f0Lime Green ^f1Navy Blue ^f2Orange/Yellow, ^f3Red, ^f4Grey, ^f5Purple, ^f6Orange, and ^f7White, ^frother values, including charcters symbols and tokens should be marked as Escaped, like 's' and 'r' in this string."
//Any character following a ^ is escaped, including newlines, as follows.
//The highlighter should mark the whole thing as s "String" or an "MLString" as my workaround for supporting it is called.
//The escape characters are obviously coloured with an Escape marker.
echo "A string^
over multiple^
lines"
//Numbers also have their own hints, cubescript recognises C-style octal, hex, floating point and decimal.
//Suffixes like 'UL' have no significance to the parser.
echo 0xFFFF 077 128 3.14159
//This is a few builtin commands and operators being highlighted
alias (concatword str (divf 20 2)) test
//These are valid samples of lookups, everything but the brackets should be marked as such part of the lookup.
//Do note they work under slightly different rules these highlight rules don't currently represent accurately.
//They use the alias defined above by str concat (20 / 2).
echo $str10//this portion should be treated as a valid comment
//The opening and closing brackets should be treated as part of the internal context.
//If the opening bracket is '(' - normal highlighting will be used inside that as the executed result is used for the lookup
//otherwise it'll be marked as part of the lookup.
//To start a lookup, prefix the alias with either one or more $ or @ characters. @ can appear multiple times at later parts.
echo $[str10]
do [
echo $str@(+ 5 5)
echo @str10
]
echo $(concatword str 10)
str30 = str20
str20 = str10
i = 20
echo $[str10//This is a comment, you won't find this used since it's somewhat problematic in this context as the resulting lookup name is "str10\n"
]
//Lookups can be recursive as well,
echo $$str20
echo $$$str30
echo $[@str20]
echo $$[str@(+ 10 10)]
do [echo $str@[(+ 5 5)]]
do [echo $$str@i]
//Amusingly, this highlighter acted as a means of discovering the erroneous behaviour of this construct and getting it fixed and recognised as an actual feature.
//Useful for looking up literals, the two below below lookup str20 like the above, but...
//You'll never find this used in the wild, a given as the bugs in question went unreported for years.
echo $$"str20"
echo $[@"str20"]
do echo $$str@"i"
//Just as a demonstration of the ridiculousness this can get to.
"^"//n^f3ot a^tcom^f5ment^n^"" = "Told you it wasn't a comment!"
echo $"^"//n^f3ot a^tcom^f5ment^n^""
echo $(result "^"//n^f3ot a^tcom^f5ment^n^"")
echo $["//n^f3ot a^tcom^f5ment^n"] //the quotes are not stripped in this version
// Most of these aren't classed as syntax errors, but as logic errors.
// They can still be used to write perfectly tenable CubeScript.
// But they are obfuscated and can produce unexpected results. for example $str$str will actually look up the alias "str$str"
// So this is effectively more of a warning than anything else
// You'll be hard pressed to find any of these in the wild.
do [ echo @str$str ]
do [echo @str$str]//the closing ] and this comment should not be marked as an error.
do [echo @str$[]]// like above, but the middle [] should be tagged as part of the lookup.
do [echo @str$[str$str[]]]//$[ like above, but with nesting
echo $$$$@$
echo $str$str
echo $st[()]
echo $str[]
//We also have some reserved aliases, these will be highlighted via the Key/Others hint.
mycommand = [
echo $commandbuf $editing $mainmenu $numargs
echo $arg1 $arg2 $arg3 $arg4 $arg5
echo $[commandbuf] $[editing] $[mainmenu] $[numargs]
echo $[arg1] $[arg2] $[arg3] $[arg4] $[arg5]
]
//Examples of the bind command that should not be marked as an error
//Also note that the bind specific things should terminate after the first operand. If anything beyond that is marked as "Key" or "Error" as part of the Bind context, this is an error.
key = TAB //this is so the lookup based examples below are valid.
bind TAB [echo it works]
// The first operand in these cases should be marked neither as "Key" or as "Error"
bind "TAB" [echo it works]
bind [TAB] [echo it works]
bind (result TAB) [echo it works]
bind $key [echo it works]
do [ bind @key [echo it works] ]
bind //whilst technically an error, this comment should not be marked as one
//These binds are valid, the keynames are not case sensitive, and it should be reflected here,
bind f1 [echo it works]
bind rCtRl [echo it works]
// "forward" here should be with the Normal hint.
bind W forward
//These binds use invalid keys and should be marked as an error.
bind TBA [echo it's not working!]
bind WW forward
//Cubescript allows multiple statements on a line by separating them via semicolons.
//As such, the contexts other than string that end at line's end must terminate there.
echo $str10;echo hi
//the one inside the ()'s is part of the lookup; you'd never find code like this though
do [ echo $str@(;+ 5 5);echo hi ]
//string context should end before the ;
echo "hi";echo $str10
echo [(+ 5 5)];
//Bind context should end after the correct key was identified. Failing that if a suitable delimiter is encountered
bind W;echo "hi"
bind WW;echo hi
do [bind WW]; echo
//These bracket combinations should not result in errors
echo (
result (
result (
result (
result (
result (
result (
result (
result (
result (rnd 10000 400)
)
)
)
)
)
)
)
)
)
echo (+ 5 4) (^ 15 7) (& 24 32) ([+] [10] [25])
do ([
result "echo cake!"
])
//These combination of brackets should result in errors
//strays, will cause actual parser errors too.
)
]
// if the next one, among )'s and ]'s does not match the last [/(, mark it as an error and will not adjust the region.
//the parser will report these as errors too and interpret them in a similar way.
//Too many opening ['s and ('s are not marked by the highlighter.
do [)] [))))))))))))))))] [(])]
do [
(]) //"Block" region shouldn't end here
] //"Block" region should end here
//same applies for Curly braces, but they do not define regions, they can be used for multi-line statements but are not ideal for it.
//As such, they are not associated with a "region."
do (])
do ( //note this one is "valid"
[] () () []
[]
()
)
//Everything beyond this point is actual read-world code samples
//I repeat everything beyond this point is code that runs in the wild.
//These samples are copyrighted by their respective owners (Hirato Kirata, Lee Salzman, Nieb, et all) and licensed under zlib/libpng.
ColourField = [
uivlist 0 [
UIHSlider (concatword $arg1 1) 0 255 [ updateval @arg1 (mergecolour [@@arg1]) [@@arg2] ] 0.6 0.02 1 50 [ uimodcolor 1 .7 .7 0 0 [uiclamp 1 1 1 1] ]
UIHSlider (concatword $arg1 2) 0 255 [ updateval @arg1 (mergecolour [@@arg1]) [@@arg2] ] 0.6 0.02 1 50 [ uimodcolor .6 1 .6 0 0 [uiclamp 1 1 1 1] ]
UIHSlider (concatword $arg1 3) 0 255 [ updateval @arg1 (mergecolour [@@arg1]) [@@arg2] ] 0.6 0.02 1 50 [ uimodcolor .6 .8 1 0 0 [uiclamp 1 1 1 1] ]
]
]
splitcolour = [
(concatword $arg1 1) = (& (>> $arg2 16) 255)
(concatword $arg1 2) = (& (>> $arg2 8) 255)
(concatword $arg1 3) = (& (>> $arg2 0) 255)
]
mergecolour = [
result (| (<< $(concatword $arg1 1) 16) (<< $(concatword $arg1 2) 8) (<< $(concatword $arg1 3) 0))
]
iterprops = [
loop i (listlen $arg1) [
uitext (at $arg1 $i) 1 0 [ uialign -1 0 ]
EntNormalField (concatword tmp (+ $i $arg3)) (at $arg2 (* $i 2)) (at $arg2 (+ (* $i 2) 1))
]
]
deffield = [
guilist [
(concatword "r_select_" $arg1) $(concatword $arg1 "index") [
(concatword $arg1 $arg2) = ((concatword "r_" $arg1 "_" $arg2 "_get"))
]
guitext (tabify (concatword $arg2 ":") 3)
guifield (concatword $arg1 $arg2) -14 [
(concatword "r_select_" @arg1) $(concatword @arg1 "index") [
@(concat (concatword "r_" @@@arg1 "_" @@@arg2) $(concatword @@@arg1 @@@arg2))
]
]
]
]
blendpaintmodes = ["off" "replace" "dig" "fill" "inverted dig" "inverted fill"]
setblendpaintmode = [
if (> $numargs 0) [blendpaintmode $arg1] [blendpaintmode 0]
echo "blend paint mode set to:" (at $blendpaintmodes $blendpaintmode)
]
scrollblendbrush = [
if (> $numargs 0) [nextblendbrush $arg1] [nextblendbrush]
echo "blend brush set to:" (getblendbrushname (curblendbrush))
]
entdirection = [
if ( && [enthavesel] [ = (havesel) 0 ] ) [
if (>= (indexof $entswithdirection (enttype)) 0) [
if (> $arg1 0) [
entproperty 0 $arg2
if (> (entattr 0) 360) [ entproperty 0 -360 ]
] [
entproperty 0 (- 0 $arg2)
if (< (entattr 0) 0) [ entproperty 0 360 ]
]
]
result 1
] [
result 0
]
]
macro = [
$arg1 = (concat [format [@@arg2]] (loopconcat i $numargs [concatword " $arg" (+ $i 1)]))
]
bindvar = [
bind $arg1 [@arg2 (= $@arg2 0); if (= $@arg2 0) [echo @@arg2 OFF] [ echo @@arg2 ON]]
]
macro resbutton [
guibutton "%1x%2" "screenres %1 %2" (if (&& (= $scr_w %1) (= $scr_h %2)) [result "radio_on"] [result "radio_off"])
]
newgui options [
guitext "field of view (default: 100)"
guislider fov
guistayopen [
guilist [
guilist [
guitext "4:3"
@@@@(resbutton 320 240)
@@@@(resbutton 640 480)
@@@@(resbutton 800 600)
@@@@(resbutton 1024 768)
@@@@(resbutton 1152 864)
@@@@(resbutton 1280 960)
@@@@(resbutton 1400 1050)
@@@@(resbutton 1600 1200)
@@@@(resbutton 1792 1344)
@@@@(resbutton 1856 1392)
@@@@(resbutton 1920 1440)
@@@@(resbutton 2048 1536)
@@@@(resbutton 2800 2100)
@@@@(resbutton 3200 2400)
]
guibar
guilist [
guitext "16:10"
@@@@(resbutton 320 200)
@@@@(resbutton 640 400)
@@@@(resbutton 1024 640)
@@@@(resbutton 1280 800)
@@@@(resbutton 1440 900)
@@@@(resbutton 1600 1000)
@@@@(resbutton 1680 1050)
@@@@(resbutton 1920 1200)
@@@@(resbutton 2048 1280)
@@@@(resbutton 2560 1600)
@@@@(resbutton 3840 2400)
]
guibar
guilist [
guitext "16:9"
@@@@(resbutton 1024 600)
@@@@(resbutton 1280 720)
@@@@(resbutton 1366 768)
@@@@(resbutton 1600 900)
@@@@(resbutton 1920 1080)
@@@@(resbutton 2048 1152)
@@@@(resbutton 3840 2160)
]
guibar
guilist [
guitext "5:4"
@@@@(resbutton 600 480)
@@@@(resbutton 1280 1024)
@@@@(resbutton 1600 1280)
@@@@(resbutton 2560 2048)
]
guibar
guilist [
guitext "5:3"
@@@@(resbutton 800 480)
@@@@(resbutton 1280 768)
guibar
guitext "Custom"
guilist [
customw = $scr_w
customh = $scr_h
guifield customw 4 [scr_w $customw]
guifield customh 4 [scr_h $customh]
]
]
]
]
] "game"
newentgui = [
genentattributes $arg1 $arg2 $arg3
newgui $arg1 [
guitext $tmpt
guibar
@entattributes
guitab type
guilistsplit n 2 $enttypelist [
guibutton $n [ entset @n ]
]
guitab misc
@quickeditmenu
]
]
//kate: space-indent on; indent-width 4; replace-tabs on
|