Exemple #1
0
        }         // func GetColorableItem

        #endregion

        #region -- ParseSource -------------------------------------------------------------

        public override AuthoringScope ParseSource(ParseRequest req)
        {
            // Get the source
            NeoLuaSource s = GetSource(req.View) as NeoLuaSource;

            if (s == null)
            {
                return(null);
            }
            Debug.Print("ParseSource: {0} -> {1}", req.Reason, s.IsDirty);

            NeoLuaAuthoringScope scope = s.AuthoringScope;
            NeoLuaChunk          c;

            switch (req.Reason)
            {
                #region -- check --
            case ParseReason.Check:
            {
                c = s.ParseChunk(req.Text);

                // Add errors, Regions
                NeoLuaToken currentToken = c.FirstToken;
                string      sFileName    = s.GetFilePath();
                while (currentToken != null)
                {
                    if (!String.IsNullOrEmpty(currentToken.Error))
                    {
                        req.Sink.AddError(sFileName, currentToken.Error, currentToken.Span, currentToken.ErrorSeverity);
                    }
                    if (currentToken.Token == LuaToken.Comment && currentToken.EndLine - currentToken.StartLine >= 2)
                    {
                        req.Sink.ProcessHiddenRegions = true;
                        string sHiddenHint = s.GetText(currentToken.StartLine, currentToken.StartIndex, currentToken.StartLine, Math.Min(66, s.GetLineLength(currentToken.StartLine))) + " ...";
                        req.Sink.AddHiddenRegion(currentToken.Span, sHiddenHint);
                    }

                    currentToken = currentToken.Next;
                }

                // Add hidden regions
                NeoLuaScope currentScope = c.FirstScope;
                while (currentScope != null)
                {
                    if (currentScope.CanHiddenRegion)
                    {
                        NeoLuaToken f = currentScope.FirstToken;
                        NeoLuaToken l = currentScope.LastToken;

                        req.Sink.ProcessHiddenRegions = true;
                        req.Sink.AddHiddenRegion(new TextSpan()
                            {
                                iStartLine = f.StartLine, iStartIndex = f.StartIndex, iEndLine = l.EndLine, iEndIndex = l.EndIndex
                            }, currentScope.FirstLine);
                    }
                    currentScope = currentScope.NextScope;
                }
            }
            break;

                #endregion
                #region -- braces --
            case ParseReason.MatchBraces:
            case ParseReason.HighlightBraces:
            {
                c = s.ParseChunk(req.Text);
                NeoLuaToken tStart = c.FindToken(req.Line, req.Col);
                if (tStart != null)
                {
                    NeoLuaToken tEnd = null;
                    switch (tStart.Token)
                    {
                    case LuaToken.BracketOpen:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketOpen, LuaToken.BracketClose, true);
                        break;

                    case LuaToken.BracketCurlyOpen:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketCurlyOpen, LuaToken.BracketCurlyClose, true);
                        break;

                    case LuaToken.BracketSquareOpen:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketSquareOpen, LuaToken.BracketSquareClose, true);
                        break;

                    case LuaToken.BracketClose:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketClose, LuaToken.BracketOpen, false);
                        break;

                    case LuaToken.BracketCurlyClose:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketCurlyClose, LuaToken.BracketCurlyOpen, false);
                        break;

                    case LuaToken.BracketSquareClose:
                        tEnd = FindMatchToken(tStart, LuaToken.BracketSquareClose, LuaToken.BracketSquareOpen, false);
                        break;

                    case LuaToken.KwEnd:
                    case LuaToken.KwBreak:
                        TextSpan[] matches = FindEndMatchToken(tStart);
                        if (matches != null)
                        {
                            req.Sink.MatchMultiple(matches, 1);
                        }
                        break;
                    }

                    if (tEnd != null)
                    {
                        req.Sink.MatchPair(tStart.Span, tEnd.Span, 1);
                    }
                }
            }
            break;

                #endregion
            case ParseReason.DisplayMemberList:
            case ParseReason.MemberSelect:
            case ParseReason.CompleteWord:
            {
                c = s.ParseChunk(req.Text);
                NeoLuaToken     t         = c.FindToken(req.Line, req.Col);
                NeoLuaTypeScope typeScope = t.Parent as NeoLuaTypeScope ?? (t.Next != null ? t.Next.Parent as NeoLuaTypeScope : null);
                if (typeScope != null)
                {
                    scope.CurrentToken = t;
                    scope.Declarations = s.FindDeclarations(true, typeScope.TypeName);
                }
                //else if (t.Prev.Token == LuaToken.Identifier && t.Prev.Value == "clr")
                //{



                //}
                else
                {
                    scope.Declarations = null;
                }
            }
            break;

            case ParseReason.QuickInfo:
                break;

            case ParseReason.MethodTip:
                break;

            case ParseReason.Goto:
                break;

            case ParseReason.CodeSpan:
                break;
            }

            return(scope);
        }         // func ParseSource
Exemple #2
0
 public NeoLuaAuthoringScope(NeoLuaSource source)
 {
     this.source = source;
 }         // ctor