Define parsed item
Inheritance: ParsedItem
示例#1
0
文件: Parser.cs 项目: massreuy/3P
        /// <summary>
        /// Create a new parsed define item according to its type
        /// </summary>
        private ParsedDefine NewParsedDefined(string name, ParseFlag flags, Token token, ParsedAsLike asLike, string left, ParseDefineType type, string tempPrimitiveType, string viewAs, string bufferFor)
        {
            // set flags
            flags |= _context.Scope is ParsedFile ? ParseFlag.FileScope : ParseFlag.LocalScope;

            switch (type)
            {
            case ParseDefineType.Parameter:
                flags |= ParseFlag.Parameter;
                break;

            case ParseDefineType.Buffer:
                flags |= ParseFlag.Buffer;

                var newBuffer = new ParsedBuffer(name, token, asLike, left, type, tempPrimitiveType, viewAs, bufferFor, ConvertStringToParsedPrimitiveType(tempPrimitiveType, asLike == ParsedAsLike.Like))
                {
                    TargetTable = FindAnyTableByName(bufferFor)
                };

                flags          |= !bufferFor.Contains(".") && newBuffer.TargetTable != null && !newBuffer.TargetTable.IsTempTable ? ParseFlag.MissingDbName : 0;
                newBuffer.Flags = flags;

                return(newBuffer);
            }
            var newDefine = new ParsedDefine(name, token, asLike, left, type, tempPrimitiveType, viewAs, ConvertStringToParsedPrimitiveType(tempPrimitiveType, asLike == ParsedAsLike.Like))
            {
                Flags = flags
            };

            return(newDefine);
        }
示例#2
0
        /// <summary>
        /// Defined variables
        /// </summary>
        /// <param name="pars"></param>
        public void Visit(ParsedDefine pars)
        {
            // set flags
            var flag = pars.Scope is ParsedFile ? ParseFlag.FileScope : ParseFlag.LocalScope;

            if (pars.Type == ParseDefineType.Parameter)
            {
                flag = flag | ParseFlag.Parameter;
            }
            if (pars.IsExtended)
            {
                flag = flag | ParseFlag.Extent;
            }

            // find primitive type
            var hasPrimitive = !string.IsNullOrEmpty(pars.TempPrimitiveType);

            if (hasPrimitive)
            {
                pars.PrimitiveType = ConvertStringToParsedPrimitiveType(pars.TempPrimitiveType, pars.AsLike == ParsedAsLike.Like);
            }

            // which completionData type is it?
            CompletionType type;
            string         subString;

            // special case for buffers, they go into the temptable or table section
            if (pars.PrimitiveType == ParsedPrimitiveType.Buffer && pars.Type != ParseDefineType.Parameter)
            {
                flag      = flag | ParseFlag.Buffer;
                subString = "?";
                type      = CompletionType.TempTable;

                // find the table or temp table that the buffer is FOR
                var foundTable = FindAnyTableByName(pars.BufferFor);
                if (foundTable != null)
                {
                    subString = foundTable.Name;
                    type      = foundTable.IsTempTable ? CompletionType.TempTable : CompletionType.Table;

                    // To code explorer, list buffers and associated tables
                    _parsedExplorerItemsList.Add(new CodeExplorerItem {
                        DisplayText   = foundTable.Name,
                        Branch        = foundTable.IsTempTable ? CodeExplorerBranch.TempTableUsed : CodeExplorerBranch.TableUsed,
                        IconType      = foundTable.IsTempTable ? CodeExplorerIconType.TempTable : CodeExplorerIconType.Table,
                        Flag          = AddExternalFlag(((!pars.BufferFor.Contains(".") && !foundTable.IsTempTable) ?  CodeExplorerFlag.MissingDbName : 0) | CodeExplorerFlag.Buffer),
                        IsNotBlock    = true,
                        DocumentOwner = pars.FilePath,
                        GoToLine      = pars.Line,
                        GoToColumn    = pars.Column,
                        SubString     = SetExternalInclude(null)
                    });
                }
            }
            else
            {
                // match type for everything else
                subString = hasPrimitive ? pars.PrimitiveType.ToString() : pars.Type.ToString();
                switch (pars.Type)
                {
                case ParseDefineType.Parameter:
                    type = CompletionType.VariablePrimitive;

                    // To code explorer, program parameters
                    if (_isBaseFile && pars.Scope is ParsedFile)
                    {
                        _parsedExplorerItemsList.Add(new CodeExplorerItem {
                            DisplayText   = pars.Name,
                            Branch        = CodeExplorerBranch.ProgramParameter,
                            IconType      = CodeExplorerIconType.Parameter,
                            IsNotBlock    = true,
                            Flag          = AddExternalFlag((CodeExplorerFlag)0),
                            DocumentOwner = pars.FilePath,
                            GoToLine      = pars.Line,
                            GoToColumn    = pars.Column,
                            SubString     = subString
                        });
                    }
                    break;

                case ParseDefineType.Variable:
                    if (!string.IsNullOrEmpty(pars.ViewAs))
                    {
                        type = CompletionType.Widget;
                    }
                    else if ((int)pars.PrimitiveType < 30)
                    {
                        type = CompletionType.VariablePrimitive;
                    }
                    else
                    {
                        type = CompletionType.VariableComplex;
                    }
                    break;

                case ParseDefineType.Button:
                case ParseDefineType.Browse:
                case ParseDefineType.Frame:
                case ParseDefineType.Image:
                case ParseDefineType.SubMenu:
                case ParseDefineType.Menu:
                case ParseDefineType.Rectangle:
                    type = CompletionType.Widget;
                    break;

                default:
                    type = CompletionType.VariableComplex;
                    break;
                }
            }

            // To explorer code for browse
            if (pars.Type == ParseDefineType.Browse)
            {
                _parsedExplorerItemsList.Add(new CodeExplorerItem {
                    DisplayText   = pars.Name,
                    Branch        = CodeExplorerBranch.Browse,
                    Flag          = AddExternalFlag((CodeExplorerFlag)0),
                    DocumentOwner = pars.FilePath,
                    GoToLine      = pars.Line,
                    GoToColumn    = pars.Column,
                    SubString     = SetExternalInclude(null)
                });
            }

            // to completion data
            _parsedCompletionItemsList.Add(new CompletionItem {
                DisplayText = pars.Name,
                Type        = type,
                SubString   = subString,
                Flag        = AddExternalFlag(SetFlags(flag, pars.LcFlagString)),
                Ranking     = AutoComplete.FindRankingOfParsedItem(pars.Name),
                ParsedItem  = pars,
                FromParser  = true
            });
        }
示例#3
0
        /// <summary>
        /// Defined variables
        /// </summary>
        /// <param name="pars"></param>
        public void Visit(ParsedDefine pars)
        {
            var            subString = pars.PrimitiveType == ParsedPrimitiveType.Unknow ? pars.Type.ToString() : pars.PrimitiveType.ToString();
            CompletionType type;

            switch (pars.Type)
            {
            case ParseDefineType.Parameter:
                type = CompletionType.VariablePrimitive;

                // To code explorer, program parameters
                if (_isBaseFile && pars.Scope is ParsedFile)
                {
                    PushToCodeExplorer(
                        GetExplorerListNode("Program parameters", CodeExplorerIconType.ProgramParameter),
                        new ParameterCodeItem {
                        DisplayText   = pars.Name,
                        Flags         = pars.Flags,
                        SubText       = subString,
                        DocumentOwner = pars.FilePath,
                        GoToLine      = pars.Line,
                        GoToColumn    = pars.Column
                    });
                }
                break;

            case ParseDefineType.Variable:
                if (!String.IsNullOrEmpty(pars.ViewAs))
                {
                    type = CompletionType.Widget;
                }
                else if ((int)pars.PrimitiveType < 30)
                {
                    type = CompletionType.VariablePrimitive;
                }
                else
                {
                    type = CompletionType.VariableComplex;
                }
                break;

            case ParseDefineType.Button:
            case ParseDefineType.Frame:
            case ParseDefineType.Image:
            case ParseDefineType.SubMenu:
            case ParseDefineType.Menu:
            case ParseDefineType.Rectangle:
                type = CompletionType.Widget;
                break;

            case ParseDefineType.Browse:
                type = CompletionType.Widget;

                // To explorer code for browse
                PushToCodeExplorer(
                    GetExplorerListNode("Browse definitions", CodeExplorerIconType.Browse),
                    new BrowseCodeItem {
                    DisplayText   = pars.Name,
                    Flags         = pars.Flags,
                    SubText       = subString,
                    DocumentOwner = pars.FilePath,
                    GoToLine      = pars.Line,
                    GoToColumn    = pars.Column
                });
                break;

            default:
                type = CompletionType.VariableComplex;
                break;
            }

            // to completion data
            var curItem = CompletionItem.Factory.New(type);

            curItem.DisplayText = pars.Name;
            curItem.Flags       = pars.Flags;
            curItem.SubText     = subString;
            PushToAutoCompletion(curItem, pars);
        }