Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created May 17, 2017 02:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unitycoder/81f6e2451a8b53e196a9d2d65deac51c to your computer and use it in GitHub Desktop.
Save unitycoder/81f6e2451a8b53e196a9d2d65deac51c to your computer and use it in GitHub Desktop.
MiniScript AceCodeEditor Syntax Highlight Rules
// MiniScript Syntax Highlighter (WIP)
// to be used with https://ace.c9.io/tool/mode_creator.html
// MiniScript: https://forum.unity3d.com/threads/miniscript-lightweight-scripting-language-for-your-game.373853/
define(function(require, exports, module) {
"use strict";
var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
// template taken from JAVA
var MiniScriptHighlightRules = function() {
// TODO: missing these
var builtinFunctions = ("print");
var keywords = ("and|break|continue|else|end|for|function|if|in|new|not|null|or|repeat|return|then|while");
// var buildinConstants = ("null|Infinity|NaN|undefined");
var keywordMapper = this.createKeywordMapper({
"variable.language": "this",
"keyword": keywords,
"support.function": builtinFunctions
}, "identifier");
// TODO: nothing below is edited for miniscript yet..
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
"start" : [
{
token : "comment",
regex : "\\/\\/.*$"
},
DocCommentHighlightRules.getStartRule("doc-start"),
{
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "string", // single line
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
}, {
token : "string", // single line
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
}, {
token : "constant.numeric", // hex
regex : /0(?:[xX][0-9a-fA-F][0-9a-fA-F_]*|[bB][01][01_]*)[LlSsDdFfYy]?\b/
}, {
token : "constant.numeric", // float
regex : /[+-]?\d[\d_]*(?:(?:\.[\d_]*)?(?:[eE][+-]?[\d_]+)?)?[LlSsDdFfYy]?\b/
}, {
token : "constant.language.boolean",
regex : "(?:true|false)\\b"
}, {
token : keywordMapper,
// TODO: Unicode escape sequences
// TODO: Unicode identifiers
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
}, {
token : "keyword.operator",
regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
}, {
token : "lparen",
regex : "[[({]"
}, {
token : "rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
],
"comment" : [
{
token : "comment", // closing comment
regex : ".*?\\*\\/",
next : "start"
}, {
token : "comment", // comment spanning whole line
regex : ".+"
}
]
};
this.embedRules(DocCommentHighlightRules, "doc-",
[ DocCommentHighlightRules.getEndRule("start") ]);
};
oop.inherits(MiniScriptHighlightRules, TextHighlightRules);
exports.MiniScriptHighlightRules = MiniScriptHighlightRules;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment