private void syntaxIndicators() { var funcs = highlighter.Functions; int pos = scintilla.CurrentPosition; ELToken currFunc = null; foreach (var f in funcs) { if (pos >= f.pos && pos <= f.pos + f.functionLen) { currFunc = f; } } scintilla.IndicatorCurrent = 1; scintilla.IndicatorClearRange(0, scintilla.TextLength); scintilla.IndicatorCurrent = 2; scintilla.IndicatorClearRange(0, scintilla.TextLength); if (currFunc != null) { scintilla.IndicatorCurrent = 1; scintilla.Indicators[1].Style = IndicatorStyle.StraightBox; scintilla.IndicatorClearRange(0, scintilla.TextLength); // don't highlight the entire text (first function, usually) if (settings.HighlightFunction) { if (currFunc.pos > 2 || currFunc.functionLen < scintilla.Text.Trim().Length - 3 || pos <= currFunc.pos + currFunc.len) { scintilla.IndicatorFillRange(currFunc.pos, currFunc.functionLen); } } scintilla.IndicatorCurrent = 2; scintilla.Indicators[2].Style = IndicatorStyle.FullBox; scintilla.Indicators[2].ForeColor = Color.Red; scintilla.Indicators[2].Alpha = 60; scintilla.IndicatorClearRange(0, scintilla.TextLength); if (settings.HighlightDelimiters) { foreach (int p in currFunc.separators) { scintilla.IndicatorFillRange(p, 1); } } } if (currFunc != selectedFunction) { selectedFunction = currFunc; FunctionChanged?.Invoke(this, selectedFunction); } }
private void expression_FunctionChanged(object sender, ELToken e) { if (splitContainer3.Panel2Collapsed) { return; } if ((sender as ExpressionTab) != currentTab) { return; } string name = e == null ? null : e.function == ELFunctions.Unknown ? null : e.function.ToString(); var func = name == null ? null : ELConstants.ELFunctionWiki.Where(f => f.function.ToLower() == name.ToLower()).FirstOrDefault(); LoadWiki(name ?? e?.text, func); }
private void syntaxHighlight(List <ELToken> tokens) { if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker) delegate { syntaxHighlight(tokens); }); return; } if (changed || !IsHandleCreated) { return; } //txtExpression.ClearDocumentStyle(); // causes problems with Word wrap! scintilla.StartStyling(0); scintilla.SetStyling(scintilla.TextLength, 0); if (settings.HighlightSyntax) { ELToken last = null; foreach (var token in tokens) { int style = (int)token.type; scintilla.StartStyling(token.pos); if (token.pos + token.len == scintilla.TextLength) { last = token; } scintilla.SetStyling(token.len, style); } // bugfix: re-paint last character because it loses the style if (last != null) { scintilla.StartStyling(scintilla.TextLength - 1); scintilla.SetStyling(1, (int)last.type); } } syntaxIndicators(); }
void scanFunction(ELToken token, string expression) { int level = 0; bool skip = false; bool skip2 = false; bool skip3 = false; try { for (int i = token.pos; i < expression.Length - 1; i++) { // block escape content if (skip) { if (expression[i] == '#' && expression[i + 1] == '/') { skip = false; i++; } continue; } if (skip2) { if (expression[i] == ']') { skip2 = false; } continue; } // block escape start if (expression[i] == '/' && expression[i + 1] == '#') { skip = true; i++; continue; } // block escape start if (expression[i] == '/' && expression[i + 1] == '*') { skip3 = !skip3; i++; continue; } // literal char else if (expression[i] == '[') { skip2 = true; } else if (expression[i] == '/') { i++; } else if (expression[i] == '(' && level++ == 0) { token.separators.Add(i); } else if (expression[i] == ')' && --level == 0) { token.separators.Add(i); token.functionLen = i - token.pos + 1; return; } else if (expression[i] == ',' && level == 1) { token.separators.Add(i); } } token.functionLen = expression.Length - token.pos - 1; } catch (Exception ex) { Logger.Log(ex); } }