Uncaught TypeError: this.HighlightRules is not a constructor

347 views
Skip to first unread message

Chris Schuler

unread,
Jul 20, 2016, 2:32:25 PM7/20/16
to Ajax.org Cloud9 Editor (Ace)
I am very new to using Ace.
My task is to build an online editor for a custom mode (clinical quality language).
I have created a custom mode using Ace Mode Creator and added it to my cloned ace build to use in my Angular2 app.
The error is generated from the ace.js file:

this.getTokenizer = function() {
       
if (!this.$tokenizer) {
           
this.$highlightRules = this.$highlightRules || new this.HighlightRules(this.$highlightRuleConfig);
           
this.$tokenizer = new Tokenizer(this.$highlightRules.getRules());
       
}
       
return this.$tokenizer;
   
};

What is going on here?

Let me know if you need me to post any additional code from my project.

Everything works fine when I use a built-in mode like javascript...

Harutyun Amirjanyan

unread,
Jul 20, 2016, 2:36:12 PM7/20/16
to ace-d...@googlegroups.com
do you define HighlightRules similar to https://github.com/ajaxorg/ace/blob/v1.2.3/lib/ace/mode/javascript.js#L44?
Seeing more of your code would help to find the error.​

Chris Schuler

unread,
Jul 20, 2016, 4:26:48 PM7/20/16
to Ajax.org Cloud9 Editor (Ace)
From my ace/mode/cql.js:

define(function(require, exports, module) {
"use strict";

var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var cql_highlight_rules = require("./cql_highlight_rules").cql_highlight_rules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var Range = require("../range").Range;
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;

var Mode = function() {
   
this.HighlightRules = cql_highlight_rules;

   
this.$outdent = new MatchingBraceOutdent();
   
this.$behaviour = new CstyleBehaviour();

   
this.foldingRules = new CStyleFoldMode();
};
oop
.inherits(Mode, TextMode);

(function() {

   
this.lineCommentStart = "//";
   
this.blockComment = {start: "/*", end: "*/"};

   
this.getNextLineIndent = function(state, line, tab) {
       
var indent = this.$getIndent(line);

       
var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
       
var tokens = tokenizedLine.tokens;
       
var endState = tokenizedLine.state;

       
if (tokens.length && tokens[tokens.length-1].type == "comment") {
           
return indent;
       
}

       
if (state == "start") {
           
var match = line.match(/^.*[\{\(\[]\s*$/);
           
if (match) {
                indent
+= tab;
           
}
       
} else if (state == "doc-start") {
           
if (endState == "start") {
               
return "";
           
}
           
var match = line.match(/^\s*(\/?)\*/);
           
if (match) {
               
if (match[1]) {
                    indent
+= " ";
               
}
                indent
+= "* ";
           
}
       
}

       
return indent;
   
};

   
this.checkOutdent = function(state, line, input) {
       
return this.$outdent.checkOutdent(line, input);
   
};

   
this.autoOutdent = function(state, doc, row) {
       
this.$outdent.autoOutdent(doc, row);
   
};

   
this.$id = "ace/mode/cql";
}).call(Mode.prototype);

exports
.Mode = Mode;
});

Anything else you need to see?

Chris Schuler

unread,
Jul 20, 2016, 4:26:48 PM7/20/16
to Ajax.org Cloud9 Editor (Ace)
Here is the relevant parts from my mode file:

define("ace/mode/cql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/cql_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {


define
("ace/mode/cql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], 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;

var CQLHighlightRules = function() {

   
var escapeRe = "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]|37[0-7]?|[4-7][0-7]?|.)";

   
this.$rules = {
       
"start" : [
           
{
                token
: "comment",
                regex
: "//$",
               
next : "start"
           
},
           
{
                token
: "comment",
                regex
: "//",
               
next : "singleLineComment"
           
},

           
DocCommentHighlightRules.getStartRule("doc-start"),

           
{
                token
: "comment", // multi line comment
                regex
: "\\/\\*",
               
next : "comment"
           
},

           
{
                token
: "string.single", // character
                regex
: "'(?:" + escapeRe + "|.)'"
           
},
           
{
                token
: "string.start",
                regex
: '\'',
                stateName
: "qstring",
               
next: [
                   
{ token: "string.single", regex: /\\\s*$/, next: "qstring" },
                   
{ token: "constant.language.escape", regex: escapeRe },
                   
{ token: "constant.language.escape", regex: /%[^'"\\]/ },
                   
{ token: "string.end", regex: '\'|$', next: "start" },
                   
{ defaultToken: "string.single"}
               
]
           
},

           
{
                token
: "string.double", // character
                regex
: "'(?:" + escapeRe + "|.)'"
           
},
           
{
                token
: "namedexpression.start",
                regex
: '"',
                stateName
: "qqstring",
               
next: [
                   
{ token: "string.double", regex: /\\\s*$/, next: "qqstring" },
                   
{ token: "constant.language.escape", regex: escapeRe },
                   
{ token: "constant.language.escape", regex: /%[^'"\\]/ },
                   
{ token: "namedexpression.end", regex: '"|$', next: "start" },
                   
{ defaultToken: "string.double"}
               
]
           
},
           
{
                token
: "constant.date",
                regex
: "@\\b[0-9][0-9][0-9][0-9](\\-[0-1][0-9](\\-[0-3][0-9](T[0-2][0-9](\\:[0-5][0-9](\\:[0-5][0-9](\\.[0-9][0-9]?[0-9]?(Z|((\\+|\\-)[0-2][0-9](\\:[0-5][0-9])?))?)?)?)?)?)?)?\\b"
           
},
           
{
                token
: "constant.time",
                regex
: "@\\bT[0-2][0-9](\\:[0-5][0-9](\\:[0-5][0-9](\\.[0-9][0-9]?[0-9]?(Z|((\\+|\\-)[0-2][0-9](\\:[0-5][0-9])?))?)?)?)?\\b"
           
},
           
{
                token
: "constant.numeric",
                regex
: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)\\b"
           
},
           
{
                token
: "constant.language",
                regex
: "\\b(true|false|null)\\b"
           
},
           
{
                token
: "paren.lparen",
                regex
: "[[({]"
           
},
           
{
                token
: "paren.rparen",
                regex
: "[\\])}]"
           
},
           
{
                token
: "text",
                regex
: "\\s+"
           
},
           
{
                token
: "keyword.declarations",
                regex
: "\\b(library|using|include|version|called|parameter|default|valueset|codesystems?|display|public|private|context +(Patient|Population)|define( +function +([^\\(]+))?)\\b"
           
},
           
{
                token
: "operator.temporal",
                regex
: "\\bsame +((year|month|day|hour|minute|second|millisecond) +)?(or +before|or +after|as)\\b"
           
},
           
{
                token
: "operator.temporal",
                regex
: "\\b(properly +)?within\\s+(\\d+)\\s+(year|month|day|hour|minute|second|millisecond)s? +of\\b"
           
},
           
{
                token
: "operator.temporal",
                regex
: "\\b(starts|ends|occurs|meets|overlaps|(properly +)?(contains|includes|during|included +in)|before|after|(start|end)( +of)?)\\b"
           
},
           
{
                token
: "operator.temporal",
                regex
: "\\b(year|month|day|hour|minute|second|millisecond)s?( +or +(less|more))? (before|after)\\b"
           
},
           
{
                token
: "operator.logical",
                regex
: "\\b(and|or|xor|not)\\b"
           
},
           
{
                token
: "operator.nullological",
                regex
: "\\b(Coalesce|is +null|is +not +null)\\b"
           
},
           
{
                token
: "operator.type",
                regex
: "\\b(cast|as|convert|to|is|ToBoolean|ToConcept|ToDateTime|ToDecimal|ToInteger|ToQuantity|ToString|ToTime)\\b"
           
},
           
{
                token
: "operator.comparison",
                regex
: "=|<|>|matches"
           
},
           
{
                token
: "operator.comparison",
                regex
: "\\b(properly +)?between\\b"
           
},
           
{
                token
: "operator.arithmetic",
                regex
: "\\+|\\-|\\*|\\/|\\^"
           
},
           
{
                token
: "operator.arithmetic",
                regex
: "\\b(Abs|Ceiling|div|Floor|Log|Ln|maximum|minimum|mod|predecessor +of|Round|successor +of|Truncate)\\b"
           
},
           
{
                token
: "operator.string",
                regex
: "\\b(Combine|Length|Lower|PositionOf|Split|Substring|Upper)\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(DateTime|Now|TimeOfDay|Today)\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(year|month|day|hour|minute|second|millisecond|timezone|date|time) +from\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(years|months|days|hours|minutes|seconds|milliseconds) +between\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(duration|difference) +in +(years|months|days|hours|minutes|seconds|milliseconds) +of\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(years?|months?|days?|hours?|minutes?|seconds?|milliseconds?)\\b"
           
},
           
{
                token
: "operator.datetime",
                regex
: "\\b(Calculate)?Age(In(Years|Months|Days|Hours|Minutes|Seconds))?(At)?\\b"
           
},
           
{
                token
: "operator.interval",
                regex
: "\\b(collapse|width +of)\\b"
           
},
           
{
                token
: "operator.list",
                regex
: "\\b(all|distinct|exists|expand|First|IndexOf|Last|Length|singleton +from)\\b"
           
},
           
{
                token
: "operator.intervalOrList",
                regex
: "\\b(contains|except|in|intersect|union)\\b"
           
},
           
{
                token
: "operator.aggregate",
                regex
: "\\b(AllTrue|AnyTrue|Avg|Count|Max|Min|Median|Mode|PopulationStdDev|PopulationVariance|StdDev|Sum|Variance)\\b"
           
},
           
{
                token
: "control",
                regex
: "\\b(if|then|else|case|when)\\b"
           
},
           
{
                token
: "control.query",
                regex
: "\\b(with|without|where|return|such that|sort( +asc(ending)?|desc(ending)?)?( +by)|asc(ending)|desc(ending))\\b"
           
},
           
{
                token
: "support.type",
                regex
: "\\b(Any|Boolean|Code|Concept|DateTime|Decimal|Integer|Interval|List|Quantity|String|Time|Tuple)\\b"
           
}
       
],
       
"comment" : [
           
{
                token
: "comment", // closing comment
                regex
: ".*?\\*\\/",
               
next : "start"
           
}, {
                token
: "comment", // comment spanning whole line
                regex
: ".+"
           
}
       
],
       
"singleLineComment" : [
           
{
                token
: "comment",
                regex
: /\\$/,
               
next : "singleLineComment"
           
}, {
                token
: "comment",
                regex
: /$/,
               
next : "start"
           
}, {
                defaultToken
: "comment"
           
}
       
],
       
"directive" : [
           
{
                token
: "constant.other.multiline",
                regex
: /\\/
           
},
           
{
                token
: "constant.other.multiline",
                regex
: /.*\\/
           
},
           
{
                token
: "constant.other",
                regex
: "\\s*<.+?>",
               
next : "start"
           
},
           
{
                token
: "constant.other", // single line
                regex
: '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
               
next : "start"
           
},
           
{
                token
: "constant.other", // single line
                regex
: "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
               
next : "start"
           
},
           
{
                token
: "constant.other",
                regex
: /[^\\\/]+/,
               
next : "start"
           
}
       
]
   
};

   
this.embedRules(DocCommentHighlightRules, "doc-",
       
[ DocCommentHighlightRules.getEndRule("start") ]);
   
this.normalizeRules();
};

oop
.inherits(CQLHighlightRules, TextHighlightRules);

exports
CQLHighlightRules = CQLHighlightRules;
});


On Wednesday, July 20, 2016 at 12:36:12 PM UTC-6, Harutyun Amirjanyan wrote:

Chris Schuler

unread,
Jul 20, 2016, 4:26:50 PM7/20/16
to Ajax.org Cloud9 Editor (Ace)
Here is my cql.js:

define(function(require, exports, module) {

On Wednesday, July 20, 2016 at 12:36:12 PM UTC-6, Harutyun Amirjanyan wrote:

Harutyun Amirjanyan

unread,
Jul 20, 2016, 4:29:58 PM7/20/16
to ace-d...@googlegroups.com
there is a typo in 
var cql_highlight_rules = require("./cql_highlight_rules").cql_highlight_rules;

it should use the name of exported funtion: CQLHighlightRules
var CQLHighlightRules = require("./cql_highlight_rules").CQLHighlightRules 

--
You received this message because you are subscribed to the Google Groups "Ajax.org Cloud9 Editor (Ace)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ace-discuss...@googlegroups.com.
To post to this group, send email to ace-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/ace-discuss.
For more options, visit https://groups.google.com/d/optout.

Chris Schuler

unread,
Jul 21, 2016, 2:13:48 PM7/21/16
to Ajax.org Cloud9 Editor (Ace)
Thank you kind sir. I knew I was missing something silly like that.
Reply all
Reply to author
Forward
0 new messages