Ejemplo n.º 1
0
        public void ParseModeline(int numLine)
        {
            ITextBuffer buffer   = this.theView.TextBuffer;
            var         snapshot = buffer.CurrentSnapshot;

            if (snapshot.LineCount <= numLine)
            {
                return;
            }
            ILanguage language = langFactory.TryCreateLanguage(snapshot);

            if (language == null)
            {
                return;
            }

            var firstLine = snapshot.GetLineFromLineNumber(numLine);

            ITextChars tc          = new LineChars(firstLine);
            String     commentText = language.NewFirstLineCommentParser().Parse(tc);

            if (String.IsNullOrEmpty(commentText))
            {
                return;
            }
            VsfPackage.LogInfo("Found possible modeline: {0}", commentText);

            var modelineParser = new ModeLineParser();
            var options        = modelineParser.Parse(commentText);

            ApplyModelines(options);
        }
Ejemplo n.º 2
0
        public void ParseModeline(int numLine)
        {
            ITextBuffer buffer   = this.theView.TextBuffer;
            var         snapshot = buffer.CurrentSnapshot;

            if (snapshot.LineCount <= numLine)
            {
                return;
            }
            ILanguage language = this.langFactory.TryCreateLanguage(snapshot);

            if (language == null)
            {
                return;
            }

            var firstLine = snapshot.GetLineFromLineNumber(numLine);

            ITextChars tc          = new LineChars(firstLine);
            var        svc         = language.GetService <IFirstLineCommentParser>();
            String     commentText = svc.Parse(tc);

            if (String.IsNullOrEmpty(commentText))
            {
                return;
            }

            var modelineParser = new ModeLineParser();
            var options        = modelineParser.Parse(commentText);

            ApplyModelines(options);
        }
Ejemplo n.º 3
0
        private void ExtractFromLine(Stack <BracePos> pairs, ITextSnapshotLine line, int lineOffset)
        {
            var lc           = new LineChars(line, lineOffset);
            var bracesInLine = this.braceExtractor.Extract(lc) /*.ToArray() */;

            foreach (var cp in bracesInLine)
            {
                if (IsOpeningBrace(cp))
                {
                    BracePos p = cp.AsBrace(pairs.Count);
                    pairs.Push(p);
                    Add(p);
                    // we don't need to check if it's a closing brace
                    // because the extractor won't return anything else
                }
                else if (pairs.Count > 0)
                {
                    BracePos p = pairs.Peek();
                    if (braceList[p.Brace] == cp.Char)
                    {
                        // yield closing brace
                        pairs.Pop();
                        BracePos c = cp.AsBrace(p.Depth);
                        Add(c);
                    }
                }
            }
            this.LastParsedPosition = line.End;
        }
Ejemplo n.º 4
0
        private void ExtractFromLine(IBraceStacker pairs, ITextSnapshotLine line, int lineOffset)
        {
            var     lc = new LineChars(line, lineOffset);
            CharPos cp = CharPos.Empty;

            while (!lc.EndOfLine)
            {
                if (!this.braceScanner.Extract(lc, ref cp))
                {
                    continue;
                }
                MatchBrace(pairs, cp);
            }
            this.LastParsedPosition = line.End;
        }
Ejemplo n.º 5
0
        public static char GetLineChar(ConsoleLineStyle style, LineChars edge)
        {
            switch (style)
            {
            case ConsoleLineStyle.None:
                return(' ');

            case ConsoleLineStyle.Single:
                return(SingleLines[(int)edge]);

            case ConsoleLineStyle.Double:
                return(DoubleLines[(int)edge]);

            case ConsoleLineStyle.Block:
                return(Shades[4]);
            }
            return(' ');
        }
Ejemplo n.º 6
0
        public static char GetLineChar(ConsoleLineStyle style, LineChars edge)
        {
            switch (style)
            {
                case ConsoleLineStyle.None:
                    return ' ';

                case ConsoleLineStyle.Single:
                    return SingleLines[(int) edge];

                case ConsoleLineStyle.Double:
                    return DoubleLines[(int) edge];

                case ConsoleLineStyle.Block:
                    return Shades[4];
            }
            return ' ';
        }
Ejemplo n.º 7
0
        private void ExtractFromLine(Stack <BracePos> pairs, ITextSnapshotLine line, int lineOffset)
        {
            var     lc = new LineChars(line, lineOffset);
            CharPos cp = CharPos.Empty;

            while (!lc.EndOfLine)
            {
                if (!this.braceScanner.Extract(lc, ref cp))
                {
                    continue;
                }
                if (IsOpeningBrace(cp))
                {
                    BracePos p = cp.AsBrace(pairs.Count);
                    pairs.Push(p);
                    Add(p);
                    // we don't need to check if it's a closing brace
                    // because the extractor won't return anything else
                }
                else if (pairs.Count > 0)
                {
                    BracePos p = pairs.Peek();
                    if (braceList[p.Brace] == cp.Char)
                    {
                        // yield closing brace
                        pairs.Pop();
                        BracePos c = cp.AsBrace(p.Depth);
                        Add(c);
                    }
                    else
                    {
                        // closing brace does not correspond
                        // to opening brace at same depth
                        this.braceErrors.Add(cp);
                    }
                }
                else
                {
                    // closing brace has no opening brace
                    this.braceErrors.Add(cp);
                }
            }
            this.LastParsedPosition = line.End;
        }
Ejemplo n.º 8
0
 public static void BitwiseOrSafe <TKey1, TKey2>(this Dictionary <TKey1, Dictionary <TKey2, LineChars> > source, TKey1 key1, TKey2 key2, LineChars value)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     if (!source.ContainsKey(key1))
     {
         source[key1] = new Dictionary <TKey2, LineChars>();
     }
     if (!source[key1].ContainsKey(key2))
     {
         source[key1][key2] = value;
     }
     else
     {
         source[key1][key2] |= value;
     }
 }