Skip to content

Instantly share code, notes, and snippets.

@jrnold
Created June 29, 2014 13:33
Show Gist options
  • Select an option

  • Save jrnold/6a2e3b565cf78d871ca0 to your computer and use it in GitHub Desktop.

Select an option

Save jrnold/6a2e3b565cf78d871ca0 to your computer and use it in GitHub Desktop.
ACE editor mode for Stan
define(function(require, exports, module) {
var oop = require("../lib/oop");
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var StanHighlightRules = function() {
var keywords = (
"for|in|while|repeat|until|if|then|else|true|false|return|void"
);
var storageType = (
"int|real|vector|simplex|unit_vector|ordered|positive_ordered|row_vector|" +
"matrix|cholesky_factor_cov|corr_matrix|cov_matrix"
);
var builtinConstants = (
"lp__"
);
var keywordMapper = this.$keywords = this.createKeywordMapper({
"keyword" : keywords,
"keyword.storagetype" : storageType,
"variable.language": builtinConstants
}, "identifier");
// regexp must not have capturing parentheses. Use (?:) instead.
// regexps are ordered -> the first match is used
this.$rules = {
"start" : [
{
token : "comment",
regex : "(:?\\/\\/|#).*$"
}, {
token : "comment", // multi line comment
regex : "\\/\\*",
next : "comment"
}, {
token : "keyword.blockid",
regex : "(?:(?:transformed\\s+)?(?:data|parameters)|functions|model|generated\\s+quantities)(?=\\s*{)"
}, {
token : "string", // single line
regex : '["][^"]*["]'
}, {
token : "string", // multi line string start
regex : '["].*\\\\$',
next : "qqstring"
}, {
token : "constant.numeric",
regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
}, {
token : "keyword.operator", // truncation
regex : "\\bT(?=\\s*\\[)"
}, {
token : keywordMapper,
regex : "[a-zA-Z][a-zA-Z0-9_]*\\b"
}, {
token : "keyword.operator",
regex : "<-|~"
}, {
token : "keyword.operator",
regex : "\\|\\||&&|==|!=|<=?|>=?|\\+|-|\\.?\\*|\\.?/|\\\\|!|'"
}, {
token : "punctuation.operator",
regex : "\\:|\\,|\\;|="
}, {
token : "paren.lparen",
regex : "[[({]"
}, {
token : "paren.rparen",
regex : "[\\])}]"
}, {
token : "text",
regex : "\\s+"
}
],
"comment" : [
{
token : "comment", // closing comment
regex : ".*?\\*\\/",
next : "start"
}, {
token : "comment", // comment spanning whole line
regex : ".+"
}
],
};
};
oop.inherits(StanHighlightRules, TextHighlightRules);
exports.StanHighlightRules = StanHighlightRules;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment