void CopyData(TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document(); monoDocument = new Document(); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange(data); copiedDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup(data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset(segment.Offset); var spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation(selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation(selection.Lead); int startCol = System.Math.Min(visStart.Column, visEnd.Column); int endCol = System.Math.Max(visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine(lineNr); int col1 = curLine.GetLogicalColumn(data, startCol) - 1; int col2 = System.Math.Min(curLine.GetLogicalColumn(data, endCol) - 1, curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert(copiedDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert(monoDocument.Length, data.Document.GetTextAt(curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert(copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert(monoDocument.Length, "\r"); } } line = data.Document.GetLine(selection.MinLine); spanStack = line.StartSpan.Clone(); SyntaxModeService.ScanSpans(data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine(DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public DietTemplateSyntaxMode () { var matches = new List<Match>(); if (baseMode == null) { var provider = new ResourceStreamProvider( typeof(DietTemplateSyntaxMode).Assembly, typeof(DietTemplateSyntaxMode).Assembly.GetManifestResourceNames().First(s => s.Contains("DietTemplateSyntaxDefinition"))); using (var s = provider.Open()) baseMode = SyntaxMode.Read(s); } this.rules = new List<Rule>(baseMode.Rules); this.keywords = new List<Keywords>(baseMode.Keywords); this.spans = new List<Span>(baseMode.Spans.Where(span => span.Begin.Pattern != "#")).ToArray(); matches.AddRange(baseMode.Matches); this.prevMarker = baseMode.PrevMarker; this.SemanticRules = new List<SemanticRule>(baseMode.SemanticRules); SemanticRules.Add(InlineDHighlighting.Instance); this.keywordTable = baseMode.keywordTable; this.keywordTableIgnoreCase = baseMode.keywordTableIgnoreCase; this.properties = baseMode.Properties; // D Number literals matches.Add(DSyntaxMode.workaroundMatchCtor( "Number" , @" (?<!\w)(0((x|X)[0-9a-fA-F_]+|(b|B)[0-1_]+)|([0-9]+[_0-9]*)[L|U|u|f|i]*)")); this.matches = matches.ToArray(); }
public static IStreamProvider GetProvider (SyntaxMode mode) { foreach (string mimeType in mode.MimeType.Split (';')) { if (syntaxModeLookup.ContainsKey (mimeType)) return syntaxModeLookup[mimeType]; } return null; }
public static void ScanSpans(TextDocument doc, SyntaxMode mode, Rule rule, CloneableStack <Span> spanStack, int start, int end) { if (mode == null) { return; } SyntaxMode.SpanParser parser = mode.CreateSpanParser(null, spanStack); parser.ParseSpans(start, end - start); }
public UpdateWorker(TextDocument doc, SyntaxMode mode, int startOffset, int endOffset) { this.doc = doc; this.mode = mode; this.startOffset = startOffset; this.endOffset = endOffset; IsFinished = false; ManualResetEvent = new ManualResetEvent(false); }
public static IStreamProvider GetProvider(SyntaxMode mode) { foreach (string mimeType in mode.MimeType.Split(';')) { if (syntaxModeLookup.ContainsKey(mimeType)) { return(syntaxModeLookup[mimeType]); } } return(null); }
public DSyntaxMode() { var matches = new List<Mono.TextEditor.Highlighting.Match>(); if (baseMode == null) { #if STABLE var provider = new ResourceXmlProvider(typeof(DSyntaxMode).Assembly, typeof(DSyntaxMode).Assembly.GetManifestResourceNames().First(s => s.Contains("MonoDevelop.D.DSyntaxHighlightingMode"))); using (XmlReader reader = provider.Open()) baseMode = SyntaxMode.Read(reader); #else var provider = new ResourceStreamProvider( typeof(DSyntaxMode).Assembly, typeof(DSyntaxMode).Assembly.GetManifestResourceNames().First(s => s.Contains("DSyntaxHighlightingMode"))); using (Stream s = provider.Open()) baseMode = SyntaxMode.Read(s); #endif } this.rules = new List<Rule>(baseMode.Rules); this.keywords = new List<Keywords>(baseMode.Keywords); this.spans = new List<Span>(baseMode.Spans.Where(span => span.Begin.Pattern != "#")).ToArray(); matches.AddRange(baseMode.Matches); this.prevMarker = baseMode.PrevMarker; this.SemanticRules = new List<SemanticRule>(baseMode.SemanticRules); this.keywordTable = baseMode.keywordTable; this.keywordTableIgnoreCase = baseMode.keywordTableIgnoreCase; this.properties = baseMode.Properties; // D Number literals matches.Add(workaroundMatchCtor( #if STABLE "constant.digit" #else "Number" #endif , @"(?<!\w)(0((x|X)[0-9a-fA-F_]+|(b|B)[0-1_]+)|([0-9]+[_0-9]*)[L|U|u|f|i]*)")); // extern linkages attributes //matches.Add(workaroundMatchCtor("constant.digit", "(?<=extern[\\s]*\\()[\\s]*(C(\\+\\+)?|D|Windows|System|Pascal|Java)[\\s]*(?=\\))")); // version checks //matches.Add(workaroundMatchCtor("constant.digit", @"(?<=version[\s]*\()[\s]*(DigitalMars|GNU|LDC|Windows|OSX|linux|FreeBSD|OpenBSD|BSD|Solaris|Posix|D_Version2)[\s]*(?=\))")); // type declaration names //matches.Add(workaroundMatchCtor("keyword.semantic.type", @"(?<=(class|struct|union|interface|template)[\s]+)[\w]+")); this.matches = matches.ToArray(); }
public static void Remove(SyntaxMode mode) { foreach (string mimeType in mode.MimeType.Split(';')) { if (syntaxModes.ContainsKey(mimeType)) { syntaxModes.Remove(mimeType); } if (syntaxModeLookup.ContainsKey(mimeType)) { syntaxModeLookup.Remove(mimeType); } } }
public ChunkParser(SpanParser spanParser, Document doc, Style style, SyntaxMode mode, LineSegment line) { this.mode = mode; this.doc = doc; this.line = line; this.spanParser = spanParser; spanParser.FoundSpanBegin += FoundSpanBegin; spanParser.FoundSpanEnd += FoundSpanEnd; spanParser.FoundSpanExit += FoundSpanExit; spanParser.ParseChar += ParseChar; if (line == null) { throw new ArgumentNullException("line"); } }
public JaySyntaxMode() { ResourceXmlProvider provider = new ResourceXmlProvider(typeof(IXmlProvider).Assembly, typeof(IXmlProvider).Assembly.GetManifestResourceNames().First(s => s.Contains("JaySyntaxMode"))); using (XmlReader reader = provider.Open()) { SyntaxMode baseMode = SyntaxMode.Read(reader); this.rules = new List <Rule> (baseMode.Rules); this.keywords = new List <Keywords> (baseMode.Keywords); this.spans = new List <Span> (baseMode.Spans).ToArray(); this.matches = baseMode.Matches; this.prevMarker = baseMode.PrevMarker; this.SemanticRules = new List <SemanticRule> (baseMode.SemanticRules); this.table = baseMode.Table; this.properties = baseMode.Properties; } }
public ChunkParser(SyntaxMode mode, SpanParser spanParser, ColorScheme style, DocumentLine line) { this.mode = mode; this.doc = mode.Document; this.line = line; this.lineOffset = line.Offset; this.spanParser = spanParser; spanParser.FoundSpanBegin = FoundSpanBegin; spanParser.FoundSpanEnd = FoundSpanEnd; spanParser.FoundSpanExit = FoundSpanExit; spanParser.ParseChar += ParseChar; if (line == null) { throw new ArgumentNullException("line"); } }
public JaySyntaxMode(TextDocument doc) : base(doc) { ResourceStreamProvider provider = new ResourceStreamProvider(typeof(IStreamProvider).Assembly, typeof(IStreamProvider).Assembly.GetManifestResourceNames().First(s => s.Contains("JaySyntaxMode"))); using (var stream = provider.Open()) { SyntaxMode baseMode = SyntaxMode.Read(stream); this.rules = new List <Rule> (baseMode.Rules); this.keywords = new List <Keywords> (baseMode.Keywords); this.spans = new List <Span> (baseMode.Spans).ToArray(); this.matches = baseMode.Matches; this.prevMarker = baseMode.PrevMarker; this.SemanticRules = new List <SemanticRule> (baseMode.SemanticRules); this.keywordTable = baseMode.keywordTable; this.keywordTableIgnoreCase = baseMode.keywordTableIgnoreCase; this.properties = baseMode.Properties; } }
public SpanParser(Document doc, SyntaxMode mode, CloneableStack <Span> spanStack) { if (doc == null) { throw new ArgumentNullException("doc"); } this.doc = doc; this.mode = mode; this.SpanStack = spanStack; this.CurRule = mode; this.ruleStack = CreateRuleStack(); this.CurRule = ruleStack.Peek(); this.CurSpan = spanStack.Count > 0 ? spanStack.Peek() : null; FoundSpanBegin = DefaultFoundSpanBegin; FoundSpanEnd = DefaultFoundSpanEnd; FoundSpanExit = DefaultFoundSpanEnd; ParseChar = delegate(ref int i, char ch) {}; }
public static SyntaxMode Read(Stream stream) { var reader = XmlReader.Create(stream); var result = new SyntaxMode(null); var matches = new List <Match> (); var spanList = new List <Span> (); var prevMarkerList = new List <Marker> (); XmlReadHelper.ReadList(reader, Node, delegate() { if (reader == null) { return(true); } switch (reader.LocalName) { case Node: string extends = reader.GetAttribute("extends"); if (!String.IsNullOrEmpty(extends)) { result = (SyntaxMode)SyntaxModeService.GetSyntaxMode(null, extends).MemberwiseClone(); spanList.AddRange(result.spans); prevMarkerList.AddRange(result.prevMarker); matches.AddRange(result.matches); } result.Name = reader.GetAttribute("name"); result.MimeType = reader.GetAttribute(MimeTypesAttribute); if (!String.IsNullOrEmpty(reader.GetAttribute("ignorecase"))) { result.IgnoreCase = Boolean.Parse(reader.GetAttribute("ignorecase")); } return(true); case Rule.Node: result.rules.Add(Rule.Read(result, reader, result.IgnoreCase)); return(true); } return(result.ReadNode(reader, matches, spanList, prevMarkerList)); }); result.spans = spanList.ToArray(); result.prevMarker = prevMarkerList.ToArray(); result.matches = matches.ToArray(); return(result); }
static void LoadSyntaxMode(string mimeType) { if (!syntaxModeLookup.ContainsKey(mimeType)) { throw new System.ArgumentException("Syntax mode for mime:" + mimeType + " not found", "mimeType"); } var reader = syntaxModeLookup [mimeType].Open(); try { var mode = SyntaxMode.Read(reader); foreach (string mime in mode.MimeType.Split(';')) { syntaxModes [mime] = new ProtoTypeSyntaxModeProvider(mode); } } catch (Exception e) { throw new IOException("Error while syntax mode for mime:" + mimeType, e); } finally { reader.Close(); } }
public SpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) { if (mode == null) { throw new ArgumentNullException("mode"); } this.doc = mode.Document; if (this.doc == null) { throw new ArgumentException("Syntax mode isn't bound to any document.", "mode"); } this.mode = mode; this.SpanStack = spanStack; this.CurRule = mode; this.ruleStack = CreateRuleStack(); this.CurRule = ruleStack.Peek(); this.CurSpan = spanStack.Count > 0 ? spanStack.Peek() : null; FoundSpanBegin = DefaultFoundSpanBegin; FoundSpanEnd = DefaultFoundSpanEnd; FoundSpanExit = DefaultFoundSpanEnd; ParseChar = delegate(ref int i, char ch) {}; }
Rule DeepCopy(TextDocument doc, SyntaxMode mode, Rule rule) { var newRule = new Rule(mode); newRule.spans = new Span[rule.Spans.Length]; for (int i = 0; i < rule.Spans.Length; i++) { newRule.spans [i] = rule.Spans [i].Clone(); } newRule.Delimiter = rule.Delimiter; newRule.IgnoreCase = rule.IgnoreCase; newRule.Name = rule.Name; newRule.DefaultColor = rule.DefaultColor; newRule.matches = rule.Matches; newRule.prevMarker = rule.PrevMarker; newRule.keywords = rule.keywords; newRule.keywordTable = rule.keywordTable; newRule.keywordTableIgnoreCase = rule.keywordTableIgnoreCase; foreach (var pair in rule.Properties) { newRule.Properties.Add(pair.Key, pair.Value); } return(newRule); }
public JaySpanParser (SyntaxMode mode, CloneableStack<Span> spanStack) : base (mode, spanStack) { }
public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line) { document = IdeApp.Workbench.GetDocument (doc.FileName); foreach (var tag in ProjectDomService.SpecialCommentTags) { tags.Add (tag.Tag); } ICSharpCode.OldNRefactory.Ast.CompilationUnit unit = null; if (document != null && document.ParsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false)) { resolver = document.GetResolver (); if (!document.ParsedDocument.TryGetTag (out unit)) { try { using (ICSharpCode.OldNRefactory.IParser parser = ICSharpCode.OldNRefactory.ParserFactory.CreateParser (ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, document.Editor.Document.OpenTextReader ())) { parser.Parse (); unit = parser.CompilationUnit; document.ParsedDocument.SetTag (unit); } } catch (Exception) { resolver = null; return; } } resolver.SetupParsedCompilationUnit (unit); } }
public override SpanParser CreateSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack) { return new CSharpSpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ()); }
Rule DeepCopy (TextDocument doc, SyntaxMode mode, Rule rule) { var newRule = new Rule (); newRule.spans = new Span[rule.Spans.Length]; for (int i = 0; i < rule.Spans.Length; i++) { newRule.spans [i] = rule.Spans [i].Clone (); } if (rule.HasDelimiter) newRule.SetDelimiter (rule.GetDelimiter (null)); newRule.IgnoreCase = rule.IgnoreCase; newRule.Name = rule.Name; newRule.DefaultColor = rule.DefaultColor; newRule.matches = rule.Matches; newRule.prevMarker = rule.PrevMarker; newRule.keywords = rule.keywords; newRule.keywordTable = rule.keywordTable; newRule.keywordTableIgnoreCase = rule.keywordTableIgnoreCase; foreach (var pair in rule.Properties) newRule.Properties.Add (pair.Key, pair.Value); return newRule; }
public ProtoTypeSyntaxModeProvider (SyntaxMode prototype) { this.prototype = prototype; }
public static void ScanSpans(Document doc, SyntaxMode mode, Rule rule, CloneableStack <Span> spanStack, int start, int end) { SyntaxMode.SpanParser parser = mode.CreateSpanParser(doc, mode, null, spanStack); parser.ParseSpans(start, end - start); }
public static void Remove (SyntaxMode mode) { foreach (string mimeType in mode.MimeType.Split (';')) { if (syntaxModes.ContainsKey (mimeType)) syntaxModes.Remove (mimeType); if (syntaxModeLookup.ContainsKey (mimeType)) syntaxModeLookup.Remove (mimeType); } }
public JaySpanParser(SyntaxMode mode, CloneableStack <Span> spanStack) : base(mode, spanStack) { }
public JaySpanParser(Document doc, SyntaxMode mode, LineSegment line, Stack <Span> spanStack) : base(doc, mode, line, spanStack) { }
public virtual ChunkParser CreateChunkParser(SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return(new ChunkParser(spanParser, doc, style, mode, line)); }
public virtual SpanParser CreateSpanParser(Document doc, SyntaxMode mode, LineSegment line, CloneableStack <Span> spanStack) { return(new SpanParser(doc, mode, spanStack ?? line.StartSpan.Clone())); }
public Rule(SyntaxMode obsolteMode) { }
public virtual ChunkParser CreateChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return new ChunkParser (spanParser, doc, style, mode, line); }
static string GenerateRtf(Document doc, Mono.TextEditor.Highlighting.SyntaxMode mode, Mono.TextEditor.Highlighting.Style style, ITextEditorOptions options) { StringBuilder rtfText = new StringBuilder(); List <Gdk.Color> colorList = new List <Gdk.Color> (); ISegment selection = new Segment(0, doc.Length); int startLineNumber = doc.OffsetToLineNumber(selection.Offset); int endLineNumber = doc.OffsetToLineNumber(selection.EndOffset); bool isItalic = false; bool isBold = false; int curColor = -1; foreach (var line in doc.GetLinesBetween(startLineNumber, endLineNumber)) { bool appendSpace = false; for (Chunk chunk = mode.GetChunks(doc, style, line, line.Offset, line.EditableLength); chunk != null; chunk = chunk.Next) { int start = System.Math.Max(selection.Offset, chunk.Offset); int end = System.Math.Min(chunk.EndOffset, selection.EndOffset); ChunkStyle chunkStyle = chunk.GetChunkStyle(style); if (start < end) { if (isBold != chunkStyle.Bold) { rtfText.Append(chunkStyle.Bold ? @"\b" : @"\b0"); isBold = chunkStyle.Bold; appendSpace = true; } if (isItalic != chunkStyle.Italic) { rtfText.Append(chunkStyle.Italic ? @"\i" : @"\i0"); isItalic = chunkStyle.Italic; appendSpace = true; } if (!colorList.Contains(chunkStyle.Color)) { colorList.Add(chunkStyle.Color); } int color = colorList.IndexOf(chunkStyle.Color); if (curColor != color) { curColor = color; rtfText.Append(@"\cf" + (curColor + 1)); appendSpace = true; } for (int i = start; i < end; i++) { char ch = chunk.GetCharAt(doc, i); switch (ch) { case '\\': rtfText.Append(@"\\"); break; case '{': rtfText.Append(@"\{"); break; case '}': rtfText.Append(@"\}"); break; case '\t': rtfText.Append(@"\tab"); appendSpace = true; break; default: if (appendSpace) { rtfText.Append(' '); appendSpace = false; } rtfText.Append(ch); break; } } } } rtfText.Append(@"\par"); rtfText.AppendLine(); } // color table StringBuilder colorTable = new StringBuilder(); colorTable.Append(@"{\colortbl ;"); for (int i = 0; i < colorList.Count; i++) { Gdk.Color color = colorList[i]; colorTable.Append(@"\red"); colorTable.Append(color.Red / 256); colorTable.Append(@"\green"); colorTable.Append(color.Green / 256); colorTable.Append(@"\blue"); colorTable.Append(color.Blue / 256); colorTable.Append(";"); } colorTable.Append("}"); StringBuilder rtf = new StringBuilder(); rtf.Append(@"{\rtf1\ansi\deff0\adeflang1025"); // font table rtf.Append(@"{\fonttbl"); rtf.Append(@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}"); rtf.Append("}"); rtf.Append(colorTable.ToString()); rtf.Append(@"\viewkind4\uc1\pard"); rtf.Append(@"\f0"); try { string fontName = options.Font.ToString(); double fontSize = Double.Parse(fontName.Substring(fontName.LastIndexOf(' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2; rtf.Append(@"\fs"); rtf.Append(fontSize); } catch (Exception) {}; rtf.Append(@"\cf1"); rtf.Append(rtfText.ToString()); rtf.Append("}"); // System.Console.WriteLine(rtf); return(rtf.ToString()); }
public ChunkParser (SpanParser spanParser, Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { this.mode = mode; this.doc = doc; this.line = line; this.lineOffset = line.Offset; this.spanParser = spanParser; spanParser.FoundSpanBegin = FoundSpanBegin; spanParser.FoundSpanEnd = FoundSpanEnd; spanParser.FoundSpanExit = FoundSpanExit; spanParser.ParseChar += ParseChar; if (line == null) throw new ArgumentNullException ("line"); }
public LayoutWrapper CreateLinePartLayout (SyntaxMode mode, LineSegment line, int offset, int length, int selectionStart, int selectionEnd) { return CreateLinePartLayout (mode, line, -1, offset, length, selectionStart, selectionEnd); }
public UpdateWorker (TextDocument doc, SyntaxMode mode, int startOffset, int endOffset) { this.doc = doc; this.mode = mode; this.startOffset = startOffset; this.endOffset = endOffset; IsFinished = false; ManualResetEvent = new ManualResetEvent (false); }
public LayoutWrapper CreateLinePartLayout (SyntaxMode mode, LineSegment line, int logicalRulerColumn, int offset, int length, int selectionStart, int selectionEnd) { return GetCachedLayout (line, offset, length, selectionStart, selectionEnd, delegate(LayoutWrapper wrapper) { if (logicalRulerColumn < 0) logicalRulerColumn = line.GetLogicalColumn(textEditor.GetTextEditorData(), textEditor.Options.RulerColumn); var atts = new FastPangoAttrList (); wrapper.Layout.Alignment = Pango.Alignment.Left; wrapper.Layout.FontDescription = textEditor.Options.Font; wrapper.Layout.Tabs = tabArray; StringBuilder textBuilder = new StringBuilder (); Chunk startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, offset, length); for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null) { try { textBuilder.Append (chunk.GetText (Document)); } catch { Console.WriteLine (chunk); } } var spanStack = line.StartSpan; int lineOffset = line.Offset; string lineText = textBuilder.ToString (); bool containsPreedit = !string.IsNullOrEmpty (textEditor.preeditString) && offset <= textEditor.preeditOffset && textEditor.preeditOffset <= offset + length; uint preeditLength = 0; if (containsPreedit) { lineText = lineText.Insert (textEditor.preeditOffset - offset, textEditor.preeditString); preeditLength = (uint)textEditor.preeditString.Length; } char[] lineChars = lineText.ToCharArray (); //int startOffset = offset, endOffset = offset + length; uint curIndex = 0, byteIndex = 0; uint curChunkIndex = 0, byteChunkIndex = 0; uint oldEndIndex = 0; for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null) { ChunkStyle chunkStyle = chunk != null ? chunk.GetChunkStyle (textEditor.ColorStyle) : null; spanStack = chunk.SpanStack ?? spanStack; foreach (TextMarker marker in line.Markers) chunkStyle = marker.GetStyle (chunkStyle); if (chunkStyle != null) { //startOffset = chunk.Offset; //endOffset = chunk.EndOffset; uint startIndex = (uint)(oldEndIndex); uint endIndex = (uint)(startIndex + chunk.Length); oldEndIndex = endIndex; HandleSelection(lineOffset, logicalRulerColumn, selectionStart, selectionEnd, chunk.Offset, chunk.EndOffset, delegate(int start, int end) { if (containsPreedit) { if (textEditor.preeditOffset < start) start += (int)preeditLength; if (textEditor.preeditOffset < end) end += (int)preeditLength; } var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); atts.AddForegroundAttribute (chunkStyle.Color, si, ei); if (!chunkStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (chunkStyle.BackgroundColor)) { wrapper.AddBackground (chunkStyle.CairoBackgroundColor, (int)si, (int)ei); } else if (chunk.SpanStack != null && ColorStyle != null) { foreach (var span in chunk.SpanStack) { if (span == null) continue; var spanStyle = ColorStyle.GetChunkStyle (span.Color); if (!spanStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (spanStyle.BackgroundColor)) { wrapper.AddBackground (spanStyle.CairoBackgroundColor, (int)si, (int)ei); break; } } } }, delegate(int start, int end) { if (containsPreedit) { if (textEditor.preeditOffset < start) start += (int)preeditLength; if (textEditor.preeditOffset < end) end += (int)preeditLength; } var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); atts.AddForegroundAttribute (SelectionColor.Color, si, ei); if (!wrapper.StartSet) wrapper.SelectionStartIndex = (int)si; wrapper.SelectionEndIndex = (int)ei; }); var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex); var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex); if (chunkStyle.Bold) atts.AddWeightAttribute (Pango.Weight.Bold, translatedStartIndex, translatedEndIndex); if (chunkStyle.Italic) atts.AddStyleAttribute (Pango.Style.Italic, translatedStartIndex, translatedEndIndex); if (chunkStyle.Underline) atts.AddUnderlineAttribute (Pango.Underline.Single, translatedStartIndex, translatedEndIndex); } } if (containsPreedit) { var si = TranslateToUTF8Index (lineChars, (uint)(textEditor.preeditOffset - offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(textEditor.preeditOffset - offset + preeditLength), ref curIndex, ref byteIndex); atts.AddUnderlineAttribute (Pango.Underline.Single, si, ei); var parser = Document.SyntaxMode.CreateSpanParser (Document, Document.SyntaxMode, line, line.StartSpan); parser.ParseSpans (line.Offset, textEditor.preeditOffset); var preEditColor = parser.CurSpan != null ? ColorStyle.GetChunkStyle (parser.CurSpan.Color).Color : ColorStyle.Default.Color; atts.AddForegroundAttribute (preEditColor, si, ei); } wrapper.LineChars = lineChars; wrapper.Layout.SetText (lineText); wrapper.EolSpanStack = spanStack; atts.AssignTo (wrapper.Layout); atts.Dispose (); int w, h; wrapper.Layout.GetSize (out w, out h); wrapper.PangoWidth = w; }); }
public ChunkParser (SyntaxMode mode, SpanParser spanParser, ColorScheme style, DocumentLine line) { this.mode = mode; this.doc = mode.Document; this.line = line; this.lineOffset = line.Offset; this.spanParser = spanParser; spanParser.FoundSpanBegin = FoundSpanBegin; spanParser.FoundSpanEnd = FoundSpanEnd; spanParser.FoundSpanExit = FoundSpanExit; spanParser.ParseChar += ParseChar; spanParser.IsAtWordStart = () => wordbuilder.Length == 0; if (line == null) throw new ArgumentNullException ("line"); }
public string GetDelimiter (SyntaxMode mode) { if (mode == null) return delimiter; return !delimiterSet ? mode.GetDelimiter (null) : delimiter; }
SyntaxMode DeepCopy (TextDocument doc, SyntaxMode mode) { var newMode = new SyntaxMode (doc); newMode.MimeType = mode.MimeType; newMode.spans = new Span[mode.Spans.Length]; for( int i = 0; i < mode.Spans.Length; i++) { newMode.spans [i] = mode.Spans [i].Clone (); } newMode.matches = mode.Matches; newMode.prevMarker = mode.PrevMarker; newMode.keywords = mode.keywords; newMode.keywordTable = mode.keywordTable; newMode.keywordTableIgnoreCase = mode.keywordTableIgnoreCase; foreach (var pair in mode.Properties) newMode.Properties.Add (pair.Key, pair.Value); foreach (var rule in mode.Rules) { if (rule is SyntaxMode) { newMode.rules.Add (DeepCopy (doc, (SyntaxMode)rule)); } else { newMode.rules.Add (DeepCopy (doc, newMode, rule)); } } return newMode; }
public virtual SpanParser CreateSpanParser(Document doc, SyntaxMode mode, LineSegment line, Stack <Span> spanStack) { return(new SpanParser(doc, mode, line, spanStack)); }
void CopyData (TextEditorData data, Selection selection) { copiedDocument = null; monoDocument = null; if (selection != null && data != null && data.Document != null) { copiedDocument = new Document (); monoDocument = new Document (); this.docStyle = data.ColorStyle; this.options = data.Options; this.mode = data.Document.SyntaxMode != null && data.Options.EnableSyntaxHighlighting ? data.Document.SyntaxMode : Mono.TextEditor.Highlighting.SyntaxMode.Default; switch (selection.SelectionMode) { case SelectionMode.Normal: isBlockMode = false; ISegment segment = selection.GetSelectionRange (data); copiedDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); monoDocument.Text = this.mode.GetTextWithoutMarkup (data.Document, data.ColorStyle, segment.Offset, segment.Length); LineSegment line = data.Document.GetLineByOffset (segment.Offset); var spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, segment.Offset); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; case SelectionMode.Block: isBlockMode = true; DocumentLocation visStart = data.LogicalToVisualLocation (selection.Anchor); DocumentLocation visEnd = data.LogicalToVisualLocation (selection.Lead); int startCol = System.Math.Min (visStart.Column, visEnd.Column); int endCol = System.Math.Max (visStart.Column, visEnd.Column); for (int lineNr = selection.MinLine; lineNr <= selection.MaxLine; lineNr++) { LineSegment curLine = data.Document.GetLine (lineNr); int col1 = curLine.GetLogicalColumn (data, startCol); int col2 = System.Math.Min (curLine.GetLogicalColumn (data, endCol), curLine.EditableLength); if (col1 < col2) { ((IBuffer)copiedDocument).Insert (copiedDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); ((IBuffer)monoDocument).Insert (monoDocument.Length, data.Document.GetTextAt (curLine.Offset + col1, col2 - col1)); } if (lineNr < selection.MaxLine) { // Clipboard line end needs to be system dependend and not the document one. ((IBuffer)copiedDocument).Insert (copiedDocument.Length, Environment.NewLine); // \r in mono document stands for block selection line end. ((IBuffer)monoDocument).Insert (monoDocument.Length, "\r"); } } line = data.Document.GetLine (selection.MinLine); spanStack = line.StartSpan.Clone (); SyntaxModeService.ScanSpans (data.Document, this.mode, this.mode, spanStack, line.Offset, line.Offset + startCol); this.copiedDocument.GetLine (DocumentLocation.MinLine).StartSpan = spanStack; break; } } else { copiedDocument = null; } }
public LayoutWrapper CreateLinePartLayout (SyntaxMode mode, LineSegment line, int offset, int length, int selectionStart, int selectionEnd) { return GetCachedLayout (line, offset, length, selectionStart, selectionEnd, delegate (LayoutWrapper wrapper) { var atts = new FastPangoAttrList (); wrapper.Layout.Alignment = Pango.Alignment.Left; wrapper.Layout.FontDescription = textEditor.Options.Font; wrapper.Layout.Tabs = tabArray; StringBuilder textBuilder = new StringBuilder (); Chunk startChunk = GetCachedChunks (mode, Document, textEditor.ColorStyle, line, offset, length); for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null) { try { textBuilder.Append (chunk.GetText (Document)); } catch { Console.WriteLine (chunk); } } string lineText = textBuilder.ToString (); bool containsPreedit = offset <= textEditor.preeditOffset && textEditor.preeditOffset <= offset + length; uint preeditLength = 0; if (containsPreedit) { lineText = lineText.Insert (textEditor.preeditOffset - offset, textEditor.preeditString); preeditLength = (uint)textEditor.preeditString.Length; } char[] lineChars = lineText.ToCharArray (); int startOffset = offset, endOffset = offset + length; uint curIndex = 0, byteIndex = 0; uint curChunkIndex = 0, byteChunkIndex = 0; uint oldEndIndex = 0; for (Chunk chunk = startChunk; chunk != null; chunk = chunk != null ? chunk.Next : null) { ChunkStyle chunkStyle = chunk != null ? chunk.GetChunkStyle (textEditor.ColorStyle) : null; foreach (TextMarker marker in line.Markers) chunkStyle = marker.GetStyle (chunkStyle); if (chunkStyle != null) { startOffset = chunk.Offset; endOffset = chunk.EndOffset; uint startIndex = (uint)(oldEndIndex); uint endIndex = (uint)(startIndex + chunk.Length); oldEndIndex = endIndex; if (containsPreedit) { if (textEditor.preeditOffset < startOffset) startIndex += preeditLength; if (textEditor.preeditOffset < endOffset) endIndex += preeditLength; } HandleSelection (line, selectionStart, selectionEnd, chunk.Offset, chunk.EndOffset, delegate(int start, int end) { var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); atts.AddForegroundAttribute (chunkStyle.Color, si, ei); if (!chunkStyle.TransparentBackround && GetPixel (ColorStyle.Default.BackgroundColor) != GetPixel (chunkStyle.BackgroundColor)) { atts.AddBackgroundAttribute (chunkStyle.BackgroundColor, si, ei); } }, delegate(int start, int end) { var si = TranslateToUTF8Index (lineChars, (uint)(startIndex + start - chunk.Offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(startIndex + end - chunk.Offset), ref curIndex, ref byteIndex); atts.AddForegroundAttribute (SelectionColor.Color, si, ei); if (!wrapper.StartSet) wrapper.SelectionStartIndex = (int)si; wrapper.SelectionEndIndex = (int)ei; }); var translatedStartIndex = TranslateToUTF8Index (lineChars, (uint)startIndex, ref curChunkIndex, ref byteChunkIndex); var translatedEndIndex = TranslateToUTF8Index (lineChars, (uint)endIndex, ref curChunkIndex, ref byteChunkIndex); if (chunkStyle.Bold) atts.AddWeightAttribute (Pango.Weight.Bold, translatedStartIndex, translatedEndIndex); if (chunkStyle.Italic) atts.AddStyleAttribute (Pango.Style.Italic, translatedStartIndex, translatedEndIndex); if (chunkStyle.Underline) atts.AddUnderlineAttribute (Pango.Underline.Single, translatedStartIndex, translatedEndIndex); } } if (containsPreedit) { var si = TranslateToUTF8Index (lineChars, (uint)(textEditor.preeditOffset - offset), ref curIndex, ref byteIndex); var ei = TranslateToUTF8Index (lineChars, (uint)(si + preeditLength), ref curIndex, ref byteIndex); atts.AddUnderlineAttribute (Pango.Underline.Single, si, ei); } wrapper.LineChars = lineChars; wrapper.Layout.SetText (lineText); atts.AssignTo (wrapper.Layout); atts.Dispose (); int w, h; wrapper.Layout.GetSize (out w, out h); wrapper.PangoWidth = w; }); }
public override ChunkParser CreateChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) { return new CSharpChunkParser (spanParser, doc, style, mode, line); }
Chunk GetCachedChunks (SyntaxMode mode, Document doc, Mono.TextEditor.Highlighting.Style style, LineSegment line, int offset, int length) { // return mode.GetChunks (doc, style, line, offset, length); ChunkDescriptor descriptor; if (chunkDict.TryGetValue (line, out descriptor)) { bool isInvalid; if (descriptor.Equals (line, offset, length, out isInvalid)) return descriptor.Chunk; chunkDict.Remove (line); } Chunk chunk = mode.GetChunks (doc, style, line, offset, length); descriptor = new ChunkDescriptor (line, offset, length, chunk); chunkDict.Add (line, descriptor); return chunk; }
// Span preprocessorSpan; // Rule preprocessorRule; public CSharpSpanParser (Mono.TextEditor.Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) : base (doc, mode, spanStack) { // foreach (Span span in mode.Spans) { // if (span.Rule == "text.preprocessor") { // preprocessorSpan = span; // preprocessorRule = GetRule (span); // } // } }
public static void StartUpdate (TextDocument doc, SyntaxMode mode, int startOffset, int endOffset) { lock (updateQueue) { updateQueue.Enqueue (new UpdateWorker (doc, mode, startOffset, endOffset)); } queueSignal.Set (); }
public virtual SpanParser CreateSpanParser (Document doc, SyntaxMode mode, LineSegment line, CloneableStack<Span> spanStack) { return new SpanParser (doc, mode, spanStack ?? line.StartSpan.Clone ()); }
public void InnerRun() { try { bool doUpdate = false; int startLine = doc.OffsetToLineNumber(startOffset); if (startLine < 0 || mode.Document == null) { return; } try { var lineSegment = doc.GetLine(startLine); if (lineSegment == null) { return; } var span = lineSegment.StartSpan; if (span == null) { return; } var spanStack = span.Clone(); SyntaxMode.SpanParser parser = mode.CreateSpanParser(null, spanStack); foreach (var line in doc.GetLinesStartingAt(startLine)) { if (line == null) { return; } if (line.Offset > endOffset) { span = line.StartSpan; if (span == null) { return; } bool equal = span.Equals(spanStack); doUpdate |= !equal; if (equal) { break; } } line.StartSpan = spanStack.Clone(); parser.ParseSpans(line.Offset, line.LengthIncludingDelimiter); while (spanStack.Count > 0 && !EndsWithContinuation(spanStack.Peek(), line)) { parser.PopSpan(); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Syntax highlighting exception:" + e); } if (doUpdate) { var storedDoc = doc; Application.Invoke(delegate { storedDoc.CommitUpdateAll(); }); } IsFinished = true; } finally { doc = null; mode = null; ManualResetEvent.Set(); } }
public SpanParser (Document doc, SyntaxMode mode, CloneableStack<Span> spanStack) { if (doc == null) throw new ArgumentNullException ("doc"); this.doc = doc; this.mode = mode; this.SpanStack = spanStack; this.CurRule = mode; this.ruleStack = CreateRuleStack (); this.CurRule = ruleStack.Peek (); this.CurSpan = spanStack.Count > 0 ? spanStack.Peek () : null; FoundSpanBegin = DefaultFoundSpanBegin; FoundSpanEnd = DefaultFoundSpanEnd; FoundSpanExit = DefaultFoundSpanEnd; ParseChar = delegate (ref int i, char ch) {}; }
public JaySpanParser(Document doc, SyntaxMode mode, CloneableStack <Span> spanStack) : base(doc, mode, spanStack) { }
public static SyntaxMode Read (XmlReader reader) { SyntaxMode result = new SyntaxMode (); List<Match> matches = new List<Match> (); List<Span> spanList = new List<Span> (); List<Marker> prevMarkerList = new List<Marker> (); XmlReadHelper.ReadList (reader, Node, delegate () { switch (reader.LocalName) { case Node: string extends = reader.GetAttribute ("extends"); if (!String.IsNullOrEmpty (extends)) { result = (SyntaxMode)SyntaxModeService.GetSyntaxMode (extends).MemberwiseClone (); } result.Name = reader.GetAttribute ("name"); result.MimeType = reader.GetAttribute (MimeTypesAttribute); if (!String.IsNullOrEmpty (reader.GetAttribute ("ignorecase"))) result.IgnoreCase = Boolean.Parse (reader.GetAttribute ("ignorecase")); return true; case Rule.Node: result.rules.Add (Rule.Read (result, reader, result.IgnoreCase)); return true; } return result.ReadNode (reader, matches, spanList, prevMarkerList); }); result.spans = spanList.ToArray (); result.prevMarker = prevMarkerList.ToArray (); result.matches = matches.ToArray (); return result; }
public ProtoTypeSyntaxModeProvider(SyntaxMode prototype) { this.prototype = prototype; }
public static void ScanSpans (TextDocument doc, SyntaxMode mode, Rule rule, CloneableStack<Span> spanStack, int start, int end) { if (mode == null) return; SyntaxMode.SpanParser parser = mode.CreateSpanParser (null, spanStack); parser.ParseSpans (start, end - start); }
public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, Style style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line) { foreach (var tag in ProjectDomService.SpecialCommentTags) { tags.Add (tag.Tag); } }
public void InnerRun () { try { bool doUpdate = false; int startLine = doc.OffsetToLineNumber (startOffset); if (startLine < 0 || mode.Document == null) return; try { var lineSegment = doc.GetLine (startLine); if (lineSegment == null) return; var span = lineSegment.StartSpan; if (span == null) return; var spanStack = span.Clone (); SyntaxMode.SpanParser parser = mode.CreateSpanParser(null, spanStack); foreach (var line in doc.GetLinesStartingAt (startLine)) { if (line == null) return; if (line.Offset > endOffset) { span = line.StartSpan; if (span == null) return; bool equal = span.Equals(spanStack); doUpdate |= !equal; if (equal) break; } line.StartSpan = spanStack.Clone(); parser.ParseSpans(line.Offset, line.LengthIncludingDelimiter); while (spanStack.Count > 0 && !EndsWithContinuation(spanStack.Peek(), line)) parser.PopSpan(); } } catch (Exception e) { Console.WriteLine ("Syntax highlighting exception:" + e); } if (doUpdate) { var storedDoc = doc; Gtk.Application.Invoke (delegate { storedDoc.CommitUpdateAll (); }); } IsFinished = true; } finally { doc = null; mode = null; ManualResetEvent.Set (); } }
public Rule(SyntaxMode mode) { this.mode = mode; }
public static Rule Read (SyntaxMode mode, XmlReader reader, bool ignoreCaseDefault) { Rule result = new Rule (); result.Name = reader.GetAttribute ("name"); result.DefaultColor = reader.GetAttribute ("color"); result.IgnoreCase = ignoreCaseDefault; if (!String.IsNullOrEmpty (reader.GetAttribute ("ignorecase"))) result.IgnoreCase = Boolean.Parse (reader.GetAttribute ("ignorecase")); List<Match> matches = new List<Match> (); List<Span> spanList = new List<Span> (); List<Marker> prevMarkerList = new List<Marker> (); XmlReadHelper.ReadList (reader, Node, delegate () { switch (reader.LocalName) { case Node: return true; } return result.ReadNode (reader, matches, spanList, prevMarkerList); }); result.matches = matches.ToArray (); result.spans = spanList.ToArray (); result.prevMarker = prevMarkerList.ToArray (); return result; }
public override SpanParser CreateSpanParser(Document doc, SyntaxMode mode, LineSegment line, Stack <Span> spanStack) { return(new JaySpanParser(doc, mode, line, spanStack)); }