Skip to content

Commit

Permalink
Support dash-identifiers in code mirror. (#221)
Browse files Browse the repository at this point in the history
Support dash-identifiers, and also fix the constant/type heuristics.

They weren't checking the whole input. As long as a subpart
matched they would trigger. This meant that we colored types very often
as constants.
  • Loading branch information
floitsch authored Aug 7, 2023
1 parent b6cbf32 commit 055efe8
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions code_mirror/toit.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
var atoms = makeJsObject("true|false|null");
var specialVars = makeJsObject("this|super|it");

var IDENTIFIER = /[a-zA-Z_]\w*/;
var TYPE = /[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)?/;
var IDENTIFIER = /[a-zA-Z_]([\w-]*\w)?/;
var TYPE = /[a-zA-Z_]([\w-]*\w)?(\.[a-zA-Z_]([\w-]*\w)?)?/;
var OVERRIDABLE_OPERATOR = /==|>=|<=|<<|>>>|>>|\*|\+|-|%|\/|<|>|&|\||\^|~|\[\]\=|\[\]|\[\.\.\]/

var CONSTANT_HEURISTIC = /_?[A-Z][A-Z_0-9]+/;
var TYPE_HEURISTIC = /_?[A-Z]\w*[a-z]\w*/;
var CONSTANT_HEURISTIC = /^_?[A-Z][A-Z_0-9-]*$/;
var TYPE_HEURISTIC = /^_?[A-Z][\w-]*[a-z][\w-]*$/;
var CONTROL = /[?:;]/;

function isKeyword(str) {
Expand Down Expand Up @@ -419,15 +419,10 @@
if (isKeyword(id)) return "keyword";
if (isSpecialVar(id)) return "special_var";
if (isAtom(id)) return "atom";
if (id.match(CONSTANT_HEURISTIC)) {
return "constant";
}
if (id.match(TYPE_HEURISTIC)) {
return "type";
}
if (stream.match(/[ ]*:?:=/, false)) {
return "declaration";
}
if (id.match(CONSTANT_HEURISTIC)) return "constant";
if (id.match(TYPE_HEURISTIC)) return "type";
if (stream.match(/[ ]*:?:=/, false)) return "declaration";

if (stream.match(/[ ]*[/][ ]*[\w_.]+[?]?[ ]*:?:=/, false)) {
state.context.push([localAnnotation, -1]);
state.subState.push(LOCAL_ANNOTATION_DIV);
Expand Down

0 comments on commit 055efe8

Please sign in to comment.