getTextStyle method

TextStyle getTextStyle(
  1. String token,
  2. dynamic spans,
  3. dynamic lastToken
)

Implementation

TextStyle getTextStyle(String token , spans , lastToken){
  var keywords = const [
    'False',	'await',	'else',	'import',	'pass',
    'None',	'break',	'except',	'in'	,'raise',
    'True',	'class',	'finally',	'is',	'return',
    'and',	'continue',	'for',	'lambda',	'try',
    'as',	'def',	'from',	'nonlocal'	,'while',
    'assert',	'del',	'global',	'not',	'with',
    'async'	,'elif'	,'if',	'or'	,'yield',
  ];
  var defaultFunctions =const ["abs", "all", "any", "bin", "bool", "bytearray", "callable", "chr",
    "classmethod", "compile", "complex", "delattr", "dict", "dir", "divmod",
    "enumerate", "eval", "filter", "float", "format", "frozenset",
    "getattr", "globals", "hasattr", "hash", "help", "hex", "id",
    "input", "int", "isinstance", "issubclass", "iter", "len",
    "list", "locals", "map", "max", "memoryview", "min", "next",
    "object", "oct", "open", "ord", "pow", "property", "range",
    "repr", "reversed", "round", "set", "setattr", "slice",
    "sorted", "staticmethod", "str", "sum", "super", "tuple",
    "type", "vars", "zip", "__import__", "NotImplemented",
    "Ellipsis", "__debug__"];
  var operators =const ['+','-','*','/','//','%','^','&','|','~','=','<','>','>>','<<','**','!=','<=','>=','+=','-=','*=','==','/=','//=','%=','|=','&=','^=','>>=','<<=','**='];
  var re = new RegExp(r'\w+');
  if(re.stringMatch(token) == token){
    if (keywords.contains(token)) {
      return theme.keyword;
    } else if (defaultFunctions.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'#.*')).stringMatch(token) == token)
      return theme.comment;
    else if((new RegExp(r'''('(.|\n)*')|("(.|\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 && !(defaultFunctions.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;
  }
}