/// <summary> /// Relex the first word directly before the current position. /// </summary> /// <param name="editor"></param> /// <param name="pos"></param> protected void RelexPreviousWord(CodeEditor editor, int pos) { // get previous word and start position var start = editor.WordStartPosition(pos, false); var word = editor.GetWordFromPosition(start); // find out if the previous word is a keyword for (int i = 0; i < keywords.Length; i++) { // reset the style of the word if it is a keyword if (keywords[i]?[word].Any(x => x.word == word) ?? false) { editor.StartStyling(start); editor.SetStyling(pos - start, StateToStyle(i)); } } }
private int ProcessBracesState(CodeEditor editor, Region c, int endPos) { // get the lexer type of the body string type = null; switch (c[-1]) { case '(': // get preceding word from brace position var wordStart = editor.WordStartPosition(c.Pos - 1, false); type = editor.GetWordFromPosition(wordStart); if (type != "layout") type = "functionheader"; break; case '{': // get preceding non-whitespace position from brace position var bracePos = c.Pos - 2; while (bracePos >= 0 && (char)editor.GetCharAt(bracePos) != ';' && char.IsWhiteSpace((char)editor.GetCharAt(bracePos))) bracePos--; // if the preceding char is a closing brace, we have to lex a function body var braceChar = (char)editor.GetCharAt(bracePos); type = braceChar == ')' ? "function" : "struct"; break; case '}': return -1; default: return ProcessDefaultState(editor, c); } // find lexer that can lex this code block var lex = lexer.Where(x => x.IsLexerForType(type)).FirstOr(null); // re-lex body of the uniform block, struct, layout or function c.Pos = lex?.Style(editor, c.Pos, endPos) ?? c.Pos; // continue styling from the last position editor.StartStyling(c.Pos); return ProcessDefaultState(editor, c); }
protected int ProcessBraceState(CodeEditor editor, Region c, int endPos) { if (c[-1] == closingBrace) return -1; // get the lexer type of the body if (c[-1] == '(') { // get preceding word from brace position var wordStart = editor.WordStartPosition(c.Pos - 1, false); var type = editor.GetWordFromPosition(wordStart); if (type == "layout") { // find lexer that can lex this code block var lex = lexer.Where(x => x.IsLexerForType(type)).FirstOr(null); // re-lex body of the uniform block, struct, layout or function c.Pos = lex?.Style(editor, c.Pos, endPos) ?? c.Pos; // continue styling from the last position editor.StartStyling(c.Pos); } } return ProcessDefaultState(editor, c); }