Skip to content

Instantly share code, notes, and snippets.

@12Me21
Created May 25, 2019 03:47
Show Gist options
  • Save 12Me21/45ef3e32a4157dd39afca25702b8d30c to your computer and use it in GitHub Desktop.
Save 12Me21/45ef3e32a4157dd39afca25702b8d30c to your computer and use it in GitHub Desktop.
heck
// Create your own language definition here
// You can safely look at other samples without losing modifications.
// Modifications are not saved on browser refresh/close though -- copy often!
return {
// Set defaultToken to invalid to see what you do not tokenize yet
// defaultToken: 'invalid',
ignoreCase: true,
defaultToken: "invalid",
outdentTriggers: ["D","E","F","L","T","P"],
keywords: [
"BREAK","COMMON","CONTINUE","ELSE","END","ENDIF","REM","REPEAT","STOP","THEN","WEND"
],
argKeywords: [
"CALL","DATA","DEC","DIM","ELSEIF","EXEC","FOR","GOSUB","GOTO","IF","INC","INPUT","LINPUT","NEXT","ON","OUT","PRINT","READ","RESTORE","RETURN","SWAP","UNTIL","USE","VAR","WHILE"
],
builtinFunctions: [
"ABS","ACCEL","ACLS","ACOS","ARYOP","ASC","ASIN","ATAN","ATTR","BACKCOLOR","BACKTRACE","BEEP","BGANIM","BGCHK","BGCLIP","BGCLR","BGCOLOR","BGCOORD","BGCOPY","BGFILL","BGFUNC","BGGET","BGHIDE","BGHOME","BGLOAD","BGMCHK","BGMCLEAR","BGMCONT","BGMPAUSE","BGMPLAY","BGMPRG","BGMPRGA","BGMSET","BGMSETD","BGMSTOP","BGMVAR","BGMVOL","BGOFS","BGPAGE","BGPUT","BGROT","BGSAVE","BGSCALE","BGSCREEN","BGSHOW","BGSTART","BGSTOP","BGVAR","BIN$","BIQUAD","BQPARAM","BREPEAT","BUTTON","CEIL","CHKCALL","CHKCHR","CHKFILE","CHKLABEL","CHKMML","CHKVAR","CHR$","CLASSIFY","CLIPBOARD","CLS","COLOR","CONTROLLER","COPY","COS","COSH","DEG","DELETE","DIALOG","DISPLAY","DLCOPEN","DTREAD","EFCOFF","EFCON","EFCSET","EFCWET","EXP","FADE","FADECHK","FFT","FFTWFN","FILES","FILL","FLOOR","FONTDEF","FORMAT$","GBOX","GCIRCLE","GCLIP","GCLS","GCOLOR","GCOPY","GFILL","GLINE","GLOAD","GOFS","GPAGE","GPAINT","GPRIO","GPSET","GPUTCHR","GSAVE","GSPOIT","GTRI","GYROA","GYROSYNC","GYROV","HEX$","IFFT","INKEY$","INSTR","KEY","LEFT$","LEN","LOAD","LOCATE","LOG","MAX","MICDATA","MICSAVE","MICSTART","MICSTOP","MID$","MIN","MPEND","MPGET","MPNAME$","MPRECV","MPSEND","MPSET","MPSTART","MPSTAT","OPTION","PCMCONT","PCMSTOP","PCMSTREAM","PCMVOL","POP","POW","PRGDEL","PRGEDIT","PRGGET$","PRGINS","PRGNAME$","PRGSET","PRGSIZE","PROJECT","PUSH","RAD","RANDOMIZE","RENAME","RGB","RGBREAD","RIGHT$","RINGCOPY","RND","RNDF","ROUND","RSORT","SAVE","SCROLL","SGN","SHIFT","SIN","SINH","SNDSTOP","SORT","SPANIM","SPCHK","SPCHR","SPCLIP","SPCLR","SPCOL","SPCOLOR","SPCOLVEC","SPDEF","SPFUNC","SPHIDE","SPHITINFO","SPHITRC","SPHITSP","SPHOME","SPLINK","SPOFS","SPPAGE","SPROT","SPSCALE","SPSET","SPSHOW","SPSTART","SPSTOP","SPUNLINK","SPUSED","SPVAR","SQR","STICK","STICKEX","STR$","SUBST$","TALK","TALKCHK","TALKSTOP","TAN","TANH","TIME$","TMREAD","TOUCH","UNSHIFT","VAL","VISIBLE","VSYNC","WAIT","WAVSET","WAVSETA","WIDTH","XOFF","XON","XSCREEN"
],
systemVariables: [
"CALLIDX","CSRX","CSRY","CSRZ","DATE$","ERRLINE","ERRNUM","ERRPRG","EXTFEATURE","FREEMEM","HARDWARE","MAINCNT","MICPOS","MICSIZE","MILLISEC","MPCOUNT","MPHOST","MPLOCAL","PCMPOS","PRGSLOT","RESULT","SYSBEEP","TABSTEP","VERSION"
],
numberKeywords: [
"TRUE","FALSE"
],
def: [
"DEF"
],
wordOperators: [
"DIV","MOD","AND","OR","XOR","NOT"
],
// The main tokenizer for our languages
tokenizer: {
root: [ //next token is not value
{include: "@common"},
[/[A-Z_]\w*[#$%]?(?=[ \t]*(\[|=(?!=)))$/,{ //might be variable
cases:{
"@keywords": {token: "keyword", next: "root"}, //technically these are invalid oh well
"@argKeywords": {token: "keyword", next: "root"},
"@wordOperators": {token: "operators", next: "root"},
"@numberKeywords": {token: "number", next: "root"},
"@systemVariables": {token: "regexp", next: "root"},
"@default": {token:"identifier", next: "root"},
}
}],
[/[A-Z_]\w*[#$%]?(?=[ \t]*(\[|=(?!=)))/,{ //might be variable
cases:{
"@keywords": {token: "keyword", next: "root"}, //technically these are invalid oh well
"@argKeywords": {token: "keyword", next: "expr"},
"@wordOperators": {token: "operators", next: "expr"},
"@numberKeywords": {token: "number", next: "root"},
"@systemVariables": {token: "regexp", next: "root"},
"@default": {token:"identifier", next: "root"},
}
}],
[/[A-Z_]\w*[$%#]?$/,{ //not variable
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "root"},
"@def": {token: "keyword", next: "root"},
"@wordOperators": {token: "operators", next: "root"},
"@numberKeywords": {token: "number", next: "root"},
"@builtinFunctions": {token: "regexp", next: "root"},
"@default": {token:"type", next: "root"},
},
}],
[/[A-Z_]\w*[$%#]?/,{ //not variable
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "expr"},
"@def": {token: "keyword", next: "root"},
"@wordOperators": {token: "operators", next: "expr"},
"@numberKeywords": {token: "number", next: "root"},
"@builtinFunctions": {token: "regexp", next: "expr"},
"@default": {token:"type", next: "expr"},
},
}],
[/@\w+/,"label","root"],
],
expr: [ //next token could be a VALUE
{include: "@common"},
//end of line
[/[A-Z_]\w*[#$%]?(?=[ \t]*\()$/,{ //might be function call
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "root"},
"@wordOperators": {token: "operators", next: "root"},
"@numberKeywords": {token: "number", next: "root"},
"@builtinFunctions": {token: "regexp", next: "root"},
"@default": {token:"type", next: "root"},
}
}],
[/[A-Z_]\w*[#$%]?(?=[ \t]*\()/,{ //might be function call
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "expr"},
"@wordOperators": {token: "operators", next: "expr"},
"@numberKeywords": {token: "number", next: "root"},
"@builtinFunctions": {token: "regexp", next: "expr"},
"@default": {token:"type", next: "expr"},
}
}],
//end of line
[/[A-Z_]\w*[$%#]?$/,{ //not function call
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "root"},
"@wordOperators": {token: "operators", next: "root"},
"@numberKeywords": {token: "number", next: "root"},
"@systemVariables": {token: "regexp", next: "root"},
"@default": {token:"identifier", next:"root"},
},
}],
[/[A-Z_]\w*[$%#]?/,{ //not function call
cases:{
"@keywords": {token: "keyword", next: "root"},
"@argKeywords": {token: "keyword", next: "expr"},
"@wordOperators": {token: "operators", next: "expr"},
"@numberKeywords": {token: "number", next: "root"},
"@systemVariables": {token: "regexp", next: "root"},
"@default": {token:"identifier", next:"root"},
},
}],
[/@\w+/,"string","root"],
],
common: [
[/[ \t]+$/,"","root"],
[/&&|\|\||<[=<]?|>[=>]?|==?|!=?|[+\-*/]$/,"operators","root"],
[/[,;]$/,"delimiter","root"],
[/[\[(]$/,{token:"brackets",kind:"open",next:"root"}],
[/\?$/,"keyword","root"],
[/[ \t]+/,""],
[/(?:\d*\.)?\d+(?=E)/,"invalid","root"],
[/\d*\.#?|(?:\d*\.)?\d+(?:E[+\-]?\d+)?#?/,"number","root"],
[/&H[\dA-F]+/,"number.hex","root"],
[/&B[01]+/,"number.binary","root"],
[/"[^"]*?(?:"|$)/,"string","root"],
[/'.*$/,"comment","root"],
[/&&|\|\||<[=<]?|>[=>]?|==?|!=?|[+\-*/]/,"operators","expr"],
[/[,;]/,"delimiter","expr"],
[/#\w+/,"number","root"],
[/[\[(]/,{token:"brackets",kind:"open",next:"expr"}],
[/[\])]/,{token:"brackets",kind:"close",next:"root"}],
[/[:\r\n]/,"delimiter","root"],
[/\?/,"keyword","expr"],
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment