Esempio n. 1
0
        public AphidDeclarations(AphidAuthoringScope scope, string text)
        {
            _scope = scope;
            _text = text;
            
            IEnumerable<AphidDeclaration> decls = new[]
            {
                new AphidDeclaration("break", GlyphKeyword),
                new AphidDeclaration("catch", GlyphKeyword),
                new AphidDeclaration("default", GlyphKeyword),
                new AphidDeclaration("defined", GlyphKeyword),
                new AphidDeclaration("delete", GlyphKeyword),
                new AphidDeclaration("else", GlyphKeyword),
                new AphidDeclaration("extend", GlyphKeyword),
                new AphidDeclaration("false", GlyphKeyword),
                new AphidDeclaration("finally", GlyphKeyword),
                new AphidDeclaration("for", GlyphKeyword),
                new AphidDeclaration("if", GlyphKeyword),
                new AphidDeclaration("in", GlyphKeyword),
                new AphidDeclaration("null", GlyphKeyword),
                new AphidDeclaration("ret", GlyphKeyword),
                new AphidDeclaration("switch", GlyphKeyword),
                new AphidDeclaration("this", GlyphKeyword),
                new AphidDeclaration("true", GlyphKeyword),
                new AphidDeclaration("try", GlyphKeyword),
                new AphidDeclaration("while", GlyphKeyword),
            };

            if (_scope.Identifiers != null)
            {
                var ids = _scope.Identifiers
                    .Select(x => new AphidDeclaration(x, GlyphGroupVariable));

                decls = decls.Concat(ids);
            }

            if (text != null)
            {
                decls = decls.Where(x => x.DisplayText.Contains(text));
            }
            else
            {
                decls = decls.Where(x => x.Glyph != GlyphKeyword);
            }

            _declarations = decls.OrderBy(x => x.DisplayText).ToArray();

            Debug.WriteLine("Declaration count: {0}", _declarations.Length);
        }
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            Debug.WriteLine("Parse reason: {0}", req.Reason);

            var scope = new AphidAuthoringScope();

            //scope.Identifiers = GetTokens(req.Text)
            //    .Where(x => x.TokenType == AphidTokenType.Identifier)
            //    .Select(x => x.Lexeme)
            //    .Distinct()
            //    .ToArray();

            switch (req.Reason)
            {
                case ParseReason.QuickInfo:
                    break;

                case ParseReason.MemberSelect:
                    break;

                case ParseReason.DisplayMemberList:
                    break;

                case ParseReason.CompleteWord:
                    break;

                case ParseReason.MatchBraces:
                case ParseReason.MemberSelectAndHighlightBraces:
                case ParseReason.HighlightBraces:
                    var braces = TokenHelper.GetBraces(
                        req.Text,
                        req.Line,
                        req.Col - 1);

                    if (braces != null)
                    {
                        req.Sink.MatchPair(CreateSpan(braces[0][0], braces[0][1]), CreateSpan(braces[1][0], braces[1][1]), 1);
                    }

                    var index = TokenHelper.GetIndex(req.Text, req.Line, req.Col - 1);
                    var str = req.Text.Substring(index);
                    var tokens = new AphidLexer(str).GetAllTokens();

                    var depth = 1;
                    var rightBraceIndex = -1;
                    for (int i = 1; i < tokens.Count; i++)
                    {
                        switch (tokens[i].TokenType)
                        {
                            case AphidTokenType.LeftBrace:
                                depth++;
                                break;

                            case AphidTokenType.RightBrace:
                                depth--;
                                break;
                        }

                        if (depth == 0)
                        {
                            rightBraceIndex = index + tokens[i].Index;
                            break;
                        }
                    }

                    if (rightBraceIndex != -1)
                    {
                        var rightLineCol = TokenHelper.GetLineCol(req.Text, rightBraceIndex);

                        req.Sink.MatchPair(CreateSpan(req.Line, req.Col - 1), CreateSpan(rightLineCol.Item1, rightLineCol.Item2), 1);
                    }

                    break;

                case ParseReason.Check:
                    CheckParseRequest(req);
                    break;

                default:
                    break;
            }

            return scope;
        }
Esempio n. 3
0
        public override AuthoringScope ParseSource(ParseRequest req)
        {
            Debug.WriteLine("Parse reason: {0}", req.Reason);

            var scope = new AphidAuthoringScope();

            //scope.Identifiers = GetTokens(req.Text)
            //    .Where(x => x.TokenType == AphidTokenType.Identifier)
            //    .Select(x => x.Lexeme)
            //    .Distinct()
            //    .ToArray();

            switch (req.Reason)
            {
            case ParseReason.QuickInfo:
                break;

            case ParseReason.MemberSelect:
                break;

            case ParseReason.DisplayMemberList:
                break;

            case ParseReason.CompleteWord:
                break;

            case ParseReason.MatchBraces:
            case ParseReason.MemberSelectAndHighlightBraces:
            case ParseReason.HighlightBraces:
                var braces = TokenHelper.GetBraces(
                    req.Text,
                    req.Line,
                    req.Col - 1);

                if (braces != null)
                {
                    req.Sink.MatchPair(CreateSpan(braces[0][0], braces[0][1]), CreateSpan(braces[1][0], braces[1][1]), 1);
                }

                var index  = TokenHelper.GetIndex(req.Text, req.Line, req.Col - 1);
                var str    = req.Text.Substring(index);
                var tokens = new AphidLexer(str).GetAllTokens();

                var depth           = 1;
                var rightBraceIndex = -1;
                for (int i = 1; i < tokens.Count; i++)
                {
                    switch (tokens[i].TokenType)
                    {
                    case AphidTokenType.LeftBrace:
                        depth++;
                        break;

                    case AphidTokenType.RightBrace:
                        depth--;
                        break;
                    }

                    if (depth == 0)
                    {
                        rightBraceIndex = index + tokens[i].Index;
                        break;
                    }
                }

                if (rightBraceIndex != -1)
                {
                    var rightLineCol = TokenHelper.GetLineCol(req.Text, rightBraceIndex);

                    req.Sink.MatchPair(CreateSpan(req.Line, req.Col - 1), CreateSpan(rightLineCol.Item1, rightLineCol.Item2), 1);
                }

                break;

            case ParseReason.Check:
                CheckParseRequest(req);
                break;

            default:
                break;
            }

            return(scope);
        }
Esempio n. 4
0
 public AphidDeclarations(AphidAuthoringScope scope, string text)
 {
     _scope = scope;
     _text  = text;
     SetDeclarations(text);
 }
Esempio n. 5
0
 public AphidDeclarations(AphidAuthoringScope scope, string text)
 {
     _scope = scope;
     _text = text;
     SetDeclarations(text);
 }