Skip to content

Commit

Permalink
[haxe mode] Add support for globalVars
Browse files Browse the repository at this point in the history
  • Loading branch information
increpare authored and marijnh committed Oct 7, 2015
1 parent d16f4d8 commit 897586c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions mode/haxe/haxe.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,20 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
return true;
}
function register(varname) {
function inList(list) {
for (var v = list; v; v = v.next)
if (v.name == varname) return true;
return false;
}
var state = cx.state;
if (state.context) {
cx.marked = "def";
for (var v = state.localVars; v; v = v.next)
if (v.name == varname) return;
if (inList(state.localVars)) return;
state.localVars = {name: varname, next: state.localVars};
} else {
if (inList(state.globalVars)) return;
if (parserConfig.globalVars)
state.globalVars = {name: varname, next: state.globalVars};
}
}

Expand Down Expand Up @@ -380,11 +388,10 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
}

// Interface

return {
startState: function(basecolumn) {
var defaulttypes = ["Int", "Float", "String", "Void", "Std", "Bool", "Dynamic", "Array"];
return {
var state = {
tokenize: haxeTokenBase,
reAllowed: true,
kwAllowed: true,
Expand All @@ -395,6 +402,9 @@ CodeMirror.defineMode("haxe", function(config, parserConfig) {
context: parserConfig.localVars && {vars: parserConfig.localVars},
indented: 0
};
if (parserConfig.globalVars && typeof parserConfig.globalVars == "object")
state.globalVars = parserConfig.globalVars;
return state;
},

token: function(stream, state) {
Expand Down

0 comments on commit 897586c

Please sign in to comment.