Skip to content

Instantly share code, notes, and snippets.

@akira-cn
Last active June 13, 2022 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akira-cn/cc146546b3818cc27739f3c7d7c07604 to your computer and use it in GitHub Desktop.
Save akira-cn/cc146546b3818cc27739f3c7d7c07604 to your computer and use it in GitHub Desktop.
#!/jcode/lang/glsl
export default {
// Set defaultToken to invalid to see what you do not tokenize yet
// defaultToken: 'invalid',
keywords: `break continue discard return
for while do if else struct
in out inout
for while do if else struct`.split(/\s+/),
typeKeywords: `float int bool void
vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4
mat2 mat3 mat4
sampler2D sampler3D samplerCube
const attribute uniform varying`.split(/\s+/),
operators: ['=', '>', '<', '==', '<=', '>=', '!=', '<>', '+', '-', '*', '/',
'&&', '||', '++', '--'],
digits: /\d+(_+\d+)*/,
octaldigits: /[0-7]+(_+[0-7]+)*/,
binarydigits: /[0-1]+(_+[0-1]+)*/,
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
// The main tokenizer for our languages
tokenizer: {
root: [
// identifiers and keywords
[/[a-z_$][\w$]*/, {
cases: {
'@typeKeywords': 'keyword',
'@keywords': 'keyword',
'@default': 'identifier',
},
}],
[/[A-Z][\w$]*/, 'type.identifier'], // to show class names nicely
// whitespace
{include: '@whitespace'},
[/^\s*#\s*\w+/, 'keyword'],
// delimiters and operators
[/[{}()[\]]/, '@brackets'],
// @ 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.
// eslint-disable-next-line no-useless-escape
[/@\s*[a-zA-Z_\$][\w\$]*/, {token: 'annotation', log: 'annotation token: $0'}],
// numbers
[/\d*\.\d+([eE][-+]?\d+)?/, 'number.float'],
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
[/\d+/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid'],
// non-teminated string
[/"/, {token: 'string.quote', bracket: '@open', next: '@string'}],
// characters
[/'[^\\']'/, 'string'],
[/'/, 'string.invalid']],
comment: [
[/[^/*]+/, 'comment'],
[/\/\*/, 'comment', '@push'],
// nested comment
['\\*/', 'comment', '@pop'],
[/[/*]/, 'comment'],
],
string: [
[/[^\\"]+/, 'string'],
[/\\./, 'string.escape.invalid'],
[/"/, {token: 'string.quote', bracket: '@close', next: '@pop'}],
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment'],
[/\/\/.*$/, 'comment'],
],
},
};
#!/jcode/lang/wenyan
// wy-language.js
export default {
storageType: "元|物|爻|術|言|列|數",
constantNumeric: "負|·|又|零|〇|一|二|三|四|五|六|七|八|九|十|百|千|萬|億|兆|京|垓|秭|穰|溝|澗|正|載|極|分|釐|毫|絲|忽|微|纖|沙|塵|埃|渺|漠",
constantLang: "陰|陽|其",
keywordsModifier: "吾有|今有|有",
keywordsType: "數|列|言|術|爻|物",
keywordsControl: "乃行是術曰|若其不然者|乃止是遍|乃歸空無|欲行是術|若其然者|其物如是|乃得矣|恆為是|之術也|必先得|是術曰|之物也|云云|其餘|中之|為是|之長|乃止|若非|或若|乃得|是謂|蓋謂|或云|者|若|遍|充|銜|凡|也",
keywordsOperator: "中有陽乎|所餘幾何|中無陰乎|不等於|不大於|不小於|等於|大於|小於|加|乘|除|變|以|於|減",
keywordsOther: "不知何禍歟|不復存矣|如事不諧|姑妄行此|吾嘗觀|之禍歟|乃作罷|名之曰|書之|以施|之禍|嗚呼|之義|昔之|方悟|是矣|今有|吾有|之書|物之|夫|中|今|取|噫|曰|施|豈|有",
tokenizer: {
root: [
[/(注曰|疏曰|批曰)。「「/, 'comment', '@blockComment'],
[/(注曰|疏曰|批曰).*$/, 'comment'],
[/「「/, 'string', '@string'],
[/「/, 'variable.name', '@variableName'],
[/。/, 'delimiter'],
[/@constantNumeric/, "constant.numeric"],
[/@constantLang/, "constant.language"],
[/@keywordsModifier/, "keyword"],
[/@keywordsType/, "type"],
[/@keywordsControl/, "keyword.control"],
[/@keywordsOperator/, "operators"],
[/@keywordsOther/, "keyword"],
[/@storageType/, "storage.type"]
],
blockComment:[
[/[^」]+/, 'comment'],
[/」」/, 'comment', '@pop'],
[/[」]/, 'comment']
],
string:[
[/[^」]+/, 'string'],
[/」」/, 'string', '@pop'],
[/[」]/, 'string']
],
variableName:[
[/[^」]+/, 'variable.name'],
[/」/, 'variable.name', '@pop']
]
},
brackets:[['「','」','bracket']]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment