Skip to content

Instantly share code, notes, and snippets.

@0xNonCents
Created April 6, 2023 22:06
Show Gist options
  • Save 0xNonCents/a3bc1417df6ba8215654bed7a88481f1 to your computer and use it in GitHub Desktop.
Save 0xNonCents/a3bc1417df6ba8215654bed7a88481f1 to your computer and use it in GitHub Desktop.
Shoshin_lang
// 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',
variables: [
`SelfX`,
"SelfY",
"SelfVelX",
"SelfVelY",
"SelfAccX",
"SelfAccY",
"SelfDir",
"SelfInt",
"SelfSta",
"SelfBodyState",
"SelfBodyCounter",
"OpponentX",
"OpponentY",
"OpponentVelX",
"OpponentVelY",
"OpponentAccX",
"OpponentAccY",
"OpponentDir",
"OpponentInt",
"OpponentSta",
"OpponentBodyState",
"OpponentBodyCounter",
],
operators: [
'==', '<=', '*', '/', '%', '+', '-', '!',
],
// we include these common regular expressions
symbols: /[=><!~?:&|+\-*\/\^%]+/,
// C# style strings
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
// The main tokenizer for our languages
tokenizer: {
root: [
// identifiers and keywords
[/[a-zA-Z_\$][\w$]*/, { cases: { '@variables': 'constant'} }],
// numbers
[/\d+/, 'number'],
// [/[A-Z][\w\$]*/, 'type.identifier' ], // to show class names nicely
// whitespace
{ include: '@whitespace' },
// delimiters and operators
[/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@operators': 'operator',
'@default' : '' } } ],
// @ annotations.
// As an example, we emit a debugging log message on these tokens.
// Note: message are supressed during the first load -- change some lines to see them.
[/@\s*[a-zA-Z_\$][\w\$]*/, { token: 'annotation', log: 'annotation token: $0' }],
// delimiter: after number because of .\d floats
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' } ],
// characters
[/'[^\\']'/, 'string'],
[/(')(@escapes)(')/, ['string','string.escape','string']],
[/'/, 'string.invalid']
],
comment: [
[/[^\/*]+/, 'comment' ],
[/\/\*/, 'comment', '@push' ], // nested comment
["\\*/", 'comment', '@pop' ],
[/[\/*]/, 'comment' ]
],
string: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment' ],
[/\/\/.*$/, 'comment'],
],
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment