-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scopes tokenizer: new implementation #5628
base: master
Are you sure you want to change the base?
Changes from 1 commit
0ff5751
b1ab920
1b7d9c3
b52aea3
92db310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ oop.inherits(FoldMode, BaseFoldMode); | |
|
||
|
||
this.$getMode = function(state) { | ||
if (typeof state != "string") | ||
if (Array.isArray(state)) | ||
state = state[0]; | ||
for (var key in this.subModes) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add .syntax property to Scope to make this simpler? |
||
if (state.indexOf(key) === 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,13 @@ var LuaHighlightRules = function() { | |
|
||
var keywords = ( | ||
"break|do|else|elseif|end|for|function|if|in|local|repeat|"+ | ||
"return|then|until|while|or|and|not" | ||
"return|then|until|while|or|and|not" | ||
); | ||
|
||
var builtinConstants = ("true|false|nil|_G|_VERSION"); | ||
|
||
var functions = ( | ||
// builtinFunctions | ||
// builtinFunctions | ||
"string|xpcall|package|tostring|print|os|unpack|require|"+ | ||
"getfenv|setmetatable|next|assert|tonumber|io|rawequal|"+ | ||
"collectgarbage|getmetatable|module|rawset|math|debug|"+ | ||
|
@@ -34,9 +34,9 @@ var LuaHighlightRules = function() { | |
"setupvalue|getlocal|getregistry|getfenv|setn|insert|getn|"+ | ||
"foreachi|maxn|foreach|concat|sort|remove|resume|yield|"+ | ||
"status|wrap|create|running|"+ | ||
// metatableMethods | ||
// metatableMethods | ||
"__add|__sub|__mod|__unm|__concat|__lt|__index|__call|__gc|__metatable|"+ | ||
"__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber" | ||
"__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber" | ||
); | ||
|
||
var stdLibaries = ("string|package|os|io|math|debug|table|coroutine"); | ||
|
@@ -64,92 +64,86 @@ var LuaHighlightRules = function() { | |
this.$rules = { | ||
"start" : [{ | ||
stateName: "bracketedComment", | ||
onMatch : function(value, currentState, stack){ | ||
stack.unshift(this.next, value.length - 2, currentState); | ||
return "comment"; | ||
onMatch2 : function(value, scope){ | ||
var parent = scope.get("bracketedComment" + (value.length - 2)) | ||
parent.meta = (value.length - 2); | ||
return parent.get(this.next).get("comment"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should use |
||
}, | ||
regex : /\-\-\[=*\[/, | ||
next : [ | ||
{ | ||
onMatch : function(value, currentState, stack) { | ||
if (value.length == stack[1]) { | ||
stack.shift(); | ||
stack.shift(); | ||
this.next = stack.shift(); | ||
onMatch2 : function(value, scope) { | ||
if (scope.parent && value.length == scope.parent.meta) { | ||
return scope.parent.parent.get("comment"); | ||
} else { | ||
this.next = ""; | ||
return scope.get("comment"); | ||
} | ||
return "comment"; | ||
}, | ||
regex : /\]=*\]/, | ||
next : "start" | ||
}, { | ||
defaultToken: "comment.body" | ||
mkslanc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
defaultToken : "comment" | ||
} | ||
] | ||
}, | ||
|
||
{ | ||
token : "comment", | ||
regex : "\\-\\-.*$" | ||
}, | ||
{ | ||
stateName: "bracketedString", | ||
onMatch : function(value, currentState, stack){ | ||
stack.unshift(this.next, value.length, currentState); | ||
return "string.start"; | ||
{ | ||
token : "comment", | ||
regex : "\\-\\-.*$" | ||
}, | ||
regex : /\[=*\[/, | ||
next : [ | ||
{ | ||
onMatch : function(value, currentState, stack) { | ||
if (value.length == stack[1]) { | ||
stack.shift(); | ||
stack.shift(); | ||
this.next = stack.shift(); | ||
} else { | ||
this.next = ""; | ||
} | ||
return "string.end"; | ||
}, | ||
|
||
regex : /\]=*\]/, | ||
next : "start" | ||
}, { | ||
defaultToken : "string" | ||
} | ||
] | ||
}, | ||
{ | ||
token : "string", // " string | ||
regex : '"(?:[^\\\\]|\\\\.)*?"' | ||
}, { | ||
token : "string", // ' string | ||
regex : "'(?:[^\\\\]|\\\\.)*?'" | ||
}, { | ||
token : "constant.numeric", // float | ||
regex : floatNumber | ||
}, { | ||
token : "constant.numeric", // integer | ||
regex : integer + "\\b" | ||
}, { | ||
token : keywordMapper, | ||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" | ||
}, { | ||
token : "keyword.operator", | ||
regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\." | ||
}, { | ||
token : "paren.lparen", | ||
regex : "[\\[\\(\\{]" | ||
}, { | ||
token : "paren.rparen", | ||
regex : "[\\]\\)\\}]" | ||
}, { | ||
token : "text", | ||
regex : "\\s+|\\w+" | ||
} ] | ||
{ | ||
stateName: "bracketedString", | ||
onMatch2 : function(value, scope){ | ||
var parent = scope.get("bracketedString" + value.length); | ||
parent.meta = value.length; | ||
return parent.get(this.next).get("string.start"); | ||
}, | ||
regex : /\[=*\[/, | ||
next : [ | ||
{ | ||
onMatch2 : function(value, scope) { | ||
if (scope.parent && value.length == scope.parent.meta) { | ||
return scope.parent.parent.get("string.end"); | ||
} else { | ||
return scope.get("string.end"); | ||
} | ||
}, | ||
|
||
regex : /\]=*\]/, | ||
}, { | ||
defaultToken : "string" | ||
} | ||
] | ||
}, | ||
{ | ||
token : "string", // " string | ||
regex : '"(?:[^\\\\]|\\\\.)*?"' | ||
}, { | ||
token : "string", // ' string | ||
regex : "'(?:[^\\\\]|\\\\.)*?'" | ||
}, { | ||
token : "constant.numeric", // float | ||
regex : floatNumber | ||
}, { | ||
token : "constant.numeric", // integer | ||
regex : integer + "\\b" | ||
}, { | ||
token : keywordMapper, | ||
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" | ||
}, { | ||
token : "keyword.operator", | ||
regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\." | ||
}, { | ||
token : "paren.lparen", | ||
regex : "[\\[\\(\\{]" | ||
}, { | ||
token : "paren.rparen", | ||
regex : "[\\]\\)\\}]" | ||
}, { | ||
token : "text", | ||
regex : "\\s+|\\w+" | ||
} ] | ||
}; | ||
|
||
this.normalizeRules(); | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,12 +99,16 @@ TextHighlightRules = function() { | |
}; | ||
|
||
var pushState = function(currentState, stack) { | ||
if (currentState != "start" || stack.length) | ||
stack.unshift(this.nextState, currentState); | ||
if (typeof currentState.get == "function") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we keep only the scope variant here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We would need to make significant changes in |
||
return currentState.get(this.nextState); | ||
} | ||
if (currentState !== "start" || stack.length) stack.unshift(this.nextState, currentState); | ||
return this.nextState; | ||
}; | ||
var popState = function(currentState, stack) { | ||
// if (stack[0] === currentState) | ||
if (typeof currentState.get == "function") { | ||
return (currentState.parent.parent) ? currentState.parent : currentState.get("start"); | ||
} | ||
stack.shift(); | ||
return stack.shift() || "start"; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without it simple_tokenizer is not working as expected