Implementation
TextStyle getTextStyle(String token , spans, lastToken){
var keywords = [
'abstract', 'else', 'import', 'super', 'as', 'enum', 'in', 'switch', 'assert', 'export', 'interface',
'sync', 'async', 'extends', 'is', 'this', 'await', 'extension', 'library', 'throw', 'break', 'external',
'mixin', 'true', 'case', 'factory', 'new', 'try', 'catch', 'false', 'null', 'typedef', 'class', 'final',
'on', 'var', 'const', 'finally', 'operator', 'void', 'continue', 'for', 'part', 'while', 'covariant',
'Function', 'rethrow', 'with', 'default', 'get', 'return', 'yield', 'deferred', 'hide', 'set', 'do',
'if', 'show', 'dynamic', 'implements', 'static'
];
var specialIdentifiers = ["main","override",'String', 'print' , 'readLineSync' , 'tryParse',
'List' , 'Map' ,
];
var operators = ['+','-','*','/', '~/', '%', '!','?' , '??=', '??', ':' ,'^','&','|','=','<','>','>>','<<','++','--','!=','<=','>=','+=','-=','*=','==','/=','%=','|=','&=','^=','>>=','<<=','&&','||' ,'=>'];
var re = new RegExp(r'\w+');
if(re.stringMatch(token) == token){
if (keywords.contains(token)) {
return theme.keyword;
} else if (specialIdentifiers.contains(token))
return theme.specialIdentifier;
else if((new RegExp(r'\d+')).stringMatch(token) == token)
return theme.numberConstant;
return theme.identifier;
}else{
if((new RegExp(r'(//.*)|(/\*(.|\n)*?\*/)')).stringMatch(token) == token)
return theme.comment;
else if((new RegExp(r'r?"(\\\n|\\"|[^"\n])*"' + '|' + r"r?'(\\\n|\\'|[^'\n])*'" + '|' + r'r?"""(.|\n)*?"""' + '|' + r"r?'''(.|\n)*?'''")).stringMatch(token) == token)
return theme.stringConstant;
else if(operators.contains(token.trim()))
return theme.operator;
var lt = token.trimLeft();
if(lt.length>0)
if(lt[0]=="(" && (new RegExp(r'\w+')).stringMatch(lastToken) == lastToken && !(specialIdentifiers.contains(lastToken) || keywords.contains(lastToken))){//it is a function
spans.removeAt(spans.length-1);
spans.add(TextSpan(text: lastToken, style: theme.functionIdentifier));
}
return theme.specialCharacter;
}
}