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); }
private int ProcessPreprocessorBodyState(CodeEditor editor, Region c) { // still inside the preprocessor body if (c.c != '\n') return (int)State.PreprocessorBody; // RE-LEX ALL PREPROCESSORCODE PARTS // get code region of the block var start = FindLastStyleOf(editor, StateToStyle((int)State.Preprocessor), c.Pos); // re-lex code block defaultLexer.Style(editor, start + 1, c.Pos); // continue styling from the last position editor.StartStyling(c.Pos); return (int)State.Default; }
public virtual int Style(CodeEditor editor, int pos, int endPos) { editor.StartStyling(pos); var textLen = editor.TextLength; // instantiate region class var c = new Region(editor, pos); // continue processing from the last state for (var state = GetPrevState(c); c.Pos < textLen; c.Pos++) { // process current state var lastStyle = c.GetStyleAt(0); state = ProcessState(editor, state, c, textLen); var newStyle = StateToStyle(state); // if (c.Pos >= endPos && (c.Pos >= textLen || (newStyle > 0 && newStyle == lastStyle))) break; // the lexer can no longer handle the code // go to the parent lexer and lex the code there if (state < 0) return parentLexer?.Style(editor, c.Pos, endPos) ?? endPos; // style the current character editor.SetStyling(1, newStyle); } return c.Pos; }
/// <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)); } } }
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); }