public virtual void OnStyleNeeded(StyleNeededEventArgs e) { if (StyleNeeded != null) { StyleNeeded(this, e); } }
public virtual void OnStyleNeeded(StyleNeededEventArgs e) { try { StyleNeeded.Invoke(this, e); } catch (Exception ex) { ; } }
public virtual void OnStyleNeeded(StyleNeededEventArgs e) => StyleNeeded?.Invoke(this, e);
protected virtual void DoHighlighting() { if (parser == null) { return; } //parse text ParseTree tree; try { tree = parser.Parse(Text); } catch (Exception ex) { Debug.WriteLine(ex.Message); //oops... return; } //highlight errors if (tree.Status == ParseTreeStatus.Error) { ClearStyle(GetStyleIndexMask(new Style[] { WavyStyle })); foreach (var msg in tree.ParserMessages) { var loc = msg.Location; var place = new Place(loc.Column, loc.Line); var r = new Range(this, place, place); var f = r.GetFragment(@"[\S]"); f.SetStyle(WavyStyle); } return; } SolidBrush brush1 = new SolidBrush(VariablesColor); SyntaxHighlighter.VariableStyle = new TextStyle(brush1, null, FontStyle.Regular); //highlight syntax ClearStyle(StyleIndex.All); foreach (var t in tree.Tokens) { var arg = new StyleNeededEventArgs(t); OnStyleNeeded(arg); if (arg.Cancel) { continue; } if (arg.Style != null) { GetTokenRange(t).SetStyle(arg.Style); continue; } switch (t.Terminal.Name) { case "INTERVAL": GetTokenRange(t).SetStyle(SyntaxHighlighter.FunctionsStyle); break; case "Identifier": GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); break; } switch (t.Terminal.GetType().Name) { case "KeyTerm": if ((t.Terminal.Flags & TermFlags.IsKeyword) != 0) //keywords are highlighted only { GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); } break; case "FreeTextLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.CommentStyle); break; case "Identifier": GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); break; case "NumberLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.NumberStyle); break; case "StringLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.StringStyle); break; case "CommentTerminal": GetTokenRange(t).SetStyle(SyntaxHighlighter.CommentStyle); break; } } }
protected virtual void DoHighlighting() { if (parser == null) { return; } //parse text ParseTree tree; try { tree = parser.Parse(Text); } catch (Exception ex) { Console.WriteLine(ex.Message); //oops... return; } //highlight errors if (tree.Status == ParseTreeStatus.Error) { ClearStyle(GetStyleIndexMask(new Style[] { WavyStyle })); foreach (var msg in tree.ParserMessages) { var loc = msg.Location; var place = new Place(loc.Column, loc.Line); var r = new Range(this, place, place); var f = r.GetFragment(@"[\S]"); f.SetStyle(WavyStyle); } return; } //highlight syntax ClearStyle(StyleIndex.All); foreach (var t in tree.Tokens) { var arg = new StyleNeededEventArgs(t); OnStyleNeeded(arg); if (arg.Cancel) { continue; } if (arg.Style != null) { GetTokenRange(t).SetStyle(arg.Style); continue; } switch (t.Terminal.GetType().Name) { case "KeyTerm": if ((t.Terminal.Flags & TermFlags.IsKeyword) != 0) //keywords are highlighted only { GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); } break; case "NumberLiteral": GetTokenRange(t).SetStyle(purpleStyle); break; case "StringLiteral": GetTokenRange(t).SetStyle(orangeStyle); break; case "CommentTerminal": GetTokenRange(t).SetStyle(SyntaxHighlighter.GrayStyle); break; //estes default no viene por defecto se puede utilizar para pintar id, u otros terminales default: if (t.Terminal.Name.Equals(Constante.Etiqueta)) { GetTokenRange(t).SetStyle(SyntaxHighlighter.GreenStyle); } break; } } }
protected virtual void DoHighlighting() { //if (parser == null) // return; //parse text ParseTree tree; try { tree = parser.Parse(Text); } catch (Exception ex) { Debug.WriteLine(ex.Message); //oops... return; } //highlight errors if (tree.Status == ParseTreeStatus.Error) { ClearStyle(GetStyleIndexMask(new Style[] { WavyStyle })); foreach (var msg in tree.ParserMessages) { var loc = msg.Location; var place = new Place(loc.Column, loc.Line); var r = new Range(this, place, place); var f = r.GetFragment(@"[\S]"); f.SetStyle(WavyStyle); } return; } //highlight syntax ClearStyle(StyleIndex.All); foreach (var t in tree.Tokens) { var arg = new StyleNeededEventArgs(t); OnStyleNeeded(arg); if (arg.Cancel) { continue; } if (arg.Style != null) { GetTokenRange(t).SetStyle(arg.Style); continue; } switch (t.Terminal.Name) { case "INTERVAL": //Sample of how to color a single TOKEN, not working yet GetTokenRange(t).SetStyle(SyntaxHighlighter.FunctionsStyle); break; case "Identifier": //GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); //Identifier: Discover the correct type for identifier and hihglight. int CPIndex = 0; var IdentType = CoderHelper.GetTypeIdentifier(Identifiers, t.Text, out CPIndex); switch (IdentType) { case PCODE_CONST.OUTPOINTTYPE: GetTokenRange(t).SetStyle(SyntaxHighlighter.OutputStyle); break; case PCODE_CONST.INPOINTTYPE: GetTokenRange(t).SetStyle(SyntaxHighlighter.InputStyle); break; case PCODE_CONST.VARPOINTTYPE: GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); break; case PCODE_CONST.PIDPOINTTYPE: GetTokenRange(t).SetStyle(SyntaxHighlighter.PidStyle); break; default: GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); break; } break; case "INS": GetTokenRange(t).SetStyle(SyntaxHighlighter.InputStyle); break; case "OUTS": GetTokenRange(t).SetStyle(SyntaxHighlighter.OutputStyle); break; case "VARS": GetTokenRange(t).SetStyle(SyntaxHighlighter.VariableStyle); break; case "PIDS": GetTokenRange(t).SetStyle(SyntaxHighlighter.PidStyle); break; case "LineNumber": GetTokenRange(t).SetStyle(SyntaxHighlighter.InnerLinesNumberStyle); break; default: //parse by type: General highlighting switch (t.Terminal.GetType().Name) { case "KeyTerm": if ((t.Terminal.Flags & TermFlags.IsKeyword) != 0) //keywords are highlighted only { GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); } break; case "FreeTextLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.CommentStyle); break; case "NumberLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.NumberStyle); break; case "StringLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.StringStyle); break; case "CommentTerminal": GetTokenRange(t).SetStyle(SyntaxHighlighter.CommentStyle); break; } break; } } }
protected virtual void DoHighlighting() { if(parser == null) return; //parse text ParseTree tree; try { tree = parser.Parse(Text); } catch (Exception ex) { Console.WriteLine(ex.Message); //oops... return; } //highlight errors if (tree.Status == ParseTreeStatus.Error) { ClearStyle(GetStyleIndexMask(new Style[] {WavyStyle})); foreach (var msg in tree.ParserMessages) { var loc = msg.Location; var place = new Place(loc.Column, loc.Line); var r = new Range(this, place, place); var f = r.GetFragment(@"[\S]"); f.SetStyle(WavyStyle); } return; } //highlight syntax ClearStyle(StyleIndex.All); foreach (var t in tree.Tokens) { var arg = new StyleNeededEventArgs(t); OnStyleNeeded(arg); if (arg.Cancel) continue; if(arg.Style != null) { GetTokenRange(t).SetStyle(arg.Style); continue; } switch (t.Terminal.GetType().Name) { case "KeyTerm": if ((t.Terminal.Flags & TermFlags.IsKeyword) != 0) //keywords are highlighted only GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; case "NumberLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.NumberStyle); break; case "StringLiteral": GetTokenRange(t).SetStyle(SyntaxHighlighter.StringStyle); break; case "CommentTerminal": GetTokenRange(t).SetStyle(SyntaxHighlighter.CommentStyle); break; } } }
public virtual void OnStyleNeeded(StyleNeededEventArgs e) { if (StyleNeeded != null) StyleNeeded(this, e); }
protected virtual void DoHighlighting() { if (parser == null) { return; } //parse text ParseTree tree; try { tree = parser.Parse(Text); } catch (Exception ex) { Console.WriteLine(ex.Message); //oops... return; } //highlight errors if (tree.Status == ParseTreeStatus.Error) { ClearStyle(GetStyleIndexMask(new Style[] { WavyStyle })); foreach (var msg in tree.ParserMessages) { var loc = msg.Location; var place = new Place(loc.Column, loc.Line); var r = new Range(this, place, place); var f = r.GetFragment(@"[\S]"); f.SetStyle(WavyStyle); } return; } //highlight syntax ClearStyle(StyleIndex.All); foreach (var t in tree.Tokens) { var arg = new StyleNeededEventArgs(t); OnStyleNeeded(arg); if (arg.Cancel) { continue; } if (arg.Style != null) { GetTokenRange(t).SetStyle(arg.Style); continue; } switch (t.Terminal.GetType().Name) { case "KeyTerm": if ((t.Terminal.Flags & TermFlags.IsKeyword) != 0) //keywords are highlighted only { GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); } break; case "CommentTerminal": GetTokenRange(t).SetStyle(grayStyle); break; default: switch (t.Terminal.Name) { case "er_cadena": GetTokenRange(t).SetStyle(orangeStyle); break; case "er_caracter": GetTokenRange(t).SetStyle(orangeStyle); break; case "er_entero": GetTokenRange(t).SetStyle(purpleStyle); break; case "er_decimal": GetTokenRange(t).SetStyle(purpleStyle); break; case "er_visibilidad": GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; case "er_tipo": GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; case "er_etiq": GetTokenRange(t).SetStyle(redStyle); break; case "er_importar": GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; case "er_booleano": GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; case "numero": GetTokenRange(t).SetStyle(purpleStyle); break; case "er_casteo": GetTokenRange(t).SetStyle(SyntaxHighlighter.KeywordStyle); break; } break; } } }