Exemplo n.º 1
0
 public ALittleScriptClassVarDecReference(ABnfElement element) : base(element)
 {
 }
 public ALittleScriptStructVarDecReference(ABnfElement element) : base(element)
 {
 }
 public ALittleScriptReturnExprReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 4
0
        ABnfElement m_target;               // 本来要匹配的目标元素

        public ABnfErrorElement(ABnfFactory factory, ABnfFile file, int line, int col, int offset, string value, ABnfElement target)
            : base(factory, file, line, col, offset)
        {
            m_value  = value;
            m_target = target;
        }
        private ABnfGuessError CheckJsonStruct(ABnfElement element, ABnfGuess guess, HashSet <string> map)
        {
            if (guess is ALittleScriptGuessList)
            {
                var guess_list = guess as ALittleScriptGuessList;
                var error      = CheckJsonStruct(element, guess_list.sub_type, map);
                if (error != null)
                {
                    return(error);
                }
            }
            else if (guess is ALittleScriptGuessMap)
            {
                var guess_map = guess as ALittleScriptGuessMap;
                if (!(guess_map.key_type is ALittleScriptGuessString))
                {
                    return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部使用的Map的key必须是string类型"));
                }
                var error = CheckJsonStruct(element, guess_map.value_type, map);
                if (error != null)
                {
                    return(error);
                }
            }
            else if (guess is ALittleScriptGuessStruct)
            {
                var guess_struct = guess as ALittleScriptGuessStruct;
                // 如果有继承,那么就检查一下继承
                if (guess_struct.struct_dec.GetStructExtendsDec() != null)
                {
                    var extends_name = guess_struct.struct_dec.GetStructExtendsDec().GetStructNameDec();
                    if (extends_name != null)
                    {
                        var extends_error = extends_name.GuessType(out ABnfGuess extends_guess);
                        if (extends_error != null)
                        {
                            return(extends_error);
                        }
                        var extends_struct_guess = extends_guess as ALittleScriptGuessStruct;
                        extends_error = CheckJsonStruct(element, extends_struct_guess, map);
                        if (extends_error != null)
                        {
                            return(extends_error);
                        }
                    }
                }

                // 如果已经识别了,那么就直接返回
                if (map.Contains(guess_struct.GetValueWithoutConst()))
                {
                    return(null);
                }
                map.Add(guess_struct.GetValueWithoutConst());

                var body_dec = guess_struct.struct_dec.GetStructBodyDec();
                if (body_dec == null)
                {
                    return(new ABnfGuessError(element, "struct不完整"));
                }

                var var_dec_list = body_dec.GetStructVarDecList();
                foreach (var var_dec in var_dec_list)
                {
                    var error = var_dec.GuessType(out guess);
                    if (error != null)
                    {
                        return(error);
                    }
                    error = CheckJsonStruct(element, guess, map);
                    if (error != null)
                    {
                        return(error);
                    }
                }
            }
            else if (guess is ALittleScriptGuessClass)
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用类"));
            }
            else if (guess is ALittleScriptGuessFunctor)
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用函数"));
            }
            else if (guess.HasAny())
            {
                return(new ABnfGuessError(element, "http协议接口的参数使用json序列化,内部不能使用any"));
            }

            return(null);
        }
Exemplo n.º 6
0
 public virtual string ShowKeyWordCompletion(string input, ABnfElement pick)
 {
     return(input);
 }
Exemplo n.º 7
0
 public ALittleScriptNamespaceDecReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 8
0
        public override string FastGoto(ALanguageServer server, Dictionary <string, ProjectInfo> projects, string text)
        {
            // 按::切割
            char[]   sy         = { ':', '.' };
            string[] split      = text.Split(sy);
            var      temp_split = new List <string>();

            foreach (var c in split)
            {
                if (c != "")
                {
                    temp_split.Add(c);
                }
            }
            if (temp_split.Count == 0)
            {
                return(null);
            }

            var    package = "";
            string name    = temp_split[temp_split.Count - 1];

            temp_split.RemoveAt(temp_split.Count - 1);

            package = string.Join(".", temp_split);

            ABnfElement element = null;

            // 获取所有工程
            foreach (var pair in projects)
            {
                if (GeneralOptions.Instance.ProjectTeam == ProjectTeamTypes.LW)
                {
                    if (name.EndsWith("_struct"))
                    {
                        name = name.Substring(0, name.Length - "_struct".Length);
                    }
                    else if (name.EndsWith("_dirty"))
                    {
                        name = name.Substring(0, name.Length - "_dirty".Length);
                    }
                }

                var project = pair.Value as AProtobufProjectInfo;
                if (project == null)
                {
                    continue;
                }

                if (package == "")
                {
                    element = project.FindElementInAllPackage(name);
                    if (element != null)
                    {
                        break;
                    }
                }
                else
                {
                    element = project.FindElement(package, name);
                    if (element != null)
                    {
                        break;
                    }
                }
            }

            // 把package当做 enum枚举名,name当做枚举项名
            if (element == null)
            {
                if (temp_split.Count == 1 || temp_split.Count == 2)
                {
                    foreach (var pair in projects)
                    {
                        var project = pair.Value as AProtobufProjectInfo;
                        if (project == null)
                        {
                            continue;
                        }

                        if (temp_split.Count == 1)
                        {
                            element = project.FindElementInAllPackage(temp_split[0]);
                            if (element != null)
                            {
                                break;
                            }
                        }
                        else if (temp_split.Count == 2)
                        {
                            element = project.FindElement(temp_split[0], temp_split[1]);
                            if (element != null)
                            {
                                break;
                            }
                        }
                    }
                }
                else if (GeneralOptions.Instance.ProjectTeam == ProjectTeamTypes.LW && temp_split.Count == 0)
                {
                    if (name.EndsWith("_struct") || name.EndsWith("_dirty"))
                    {
                        var sub_name = name;
                        if (sub_name.EndsWith("_struct"))
                        {
                            sub_name = sub_name.Substring(0, sub_name.Length - "_struct".Length);
                        }
                        else if (sub_name.EndsWith("_dirty"))
                        {
                            sub_name = sub_name.Substring(0, sub_name.Length - "_dirty".Length);
                        }

                        foreach (var pair in projects)
                        {
                            var project = pair.Value as AProtobufProjectInfo;
                            if (project == null)
                            {
                                continue;
                            }

                            element = project.FindElementInAllPackage(sub_name);
                            if (element != null)
                            {
                                break;
                            }
                        }
                    }

                    if (element == null)
                    {
                        foreach (var pair in projects)
                        {
                            var project = pair.Value as AProtobufProjectInfo;
                            if (project == null)
                            {
                                continue;
                            }

                            element = project.FindElementInAllPackage(name);
                            if (element != null)
                            {
                                break;
                            }
                        }
                    }

                    if (element == null)
                    {
                        foreach (var pair in projects)
                        {
                            var project = pair.Value as AProtobufProjectInfo;
                            if (project == null)
                            {
                                continue;
                            }

                            element = project.FindElement("", "EMsgErrorCode");
                            if (element != null)
                            {
                                break;
                            }
                        }
                    }
                }

                if (element is AProtobufEnumElement)
                {
                    var body_dec = (element as AProtobufEnumElement).GetEnumBody();
                    if (body_dec != null)
                    {
                        foreach (var pair in body_dec.GetEnumVarList())
                        {
                            if (pair.GetEnumVarName().GetElementText() == name)
                            {
                                element = pair.GetEnumVarName();
                                break;
                            }
                        }
                    }
                }
            }

            // 把name当做枚举字段名查找
            if (element == null)
            {
                // 获取所有工程
                foreach (var pair in projects)
                {
                    var project = pair.Value as AProtobufProjectInfo;
                    if (project == null)
                    {
                        continue;
                    }

                    element = project.FindEnumVarNameInAllPackgae(name);
                    if (element != null)
                    {
                        break;
                    }
                }
            }

            if (element == null)
            {
                return("找不到在包(" + package + ")的协议或枚举(" + name + ")");
            }

            if (element is AProtobufMessageElement)
            {
                element = (element as AProtobufMessageElement).GetMessageName();
            }
            else if (element is AProtobufEnumElement)
            {
                element = (element as AProtobufEnumElement).GetEnumName();
            }

            string full_path = element.GetFullPath();
            int    start     = element.GetStart();
            int    length    = element.GetLength();

            Application.Current.Dispatcher.Invoke(() =>
            {
                ALanguageUtility.OpenFile(m_open_document, m_adapters_factory
                                          , full_path, start, length);
            });

            return(null);
        }
Exemplo n.º 9
0
        public override ABnfReference CreateReference(ABnfElement element)
        {
            if (element is AProtobufLineCommentElement)
            {
                return(new AProtobufLineCommentReference(element));
            }
            if (element is AProtobufBlockCommentElement)
            {
                return(new AProtobufBlockCommentReference(element));
            }
            if (element is AProtobufCustomTypeElement)
            {
                return(new AProtobufCustomTypeReference(element));
            }
            if (element is AProtobufEnumElement)
            {
                return(new AProtobufEnumReference(element));
            }
            if (element is AProtobufEnumBodyElement)
            {
                return(new AProtobufEnumBodyReference(element));
            }
            if (element is AProtobufEnumNameElement)
            {
                return(new AProtobufEnumNameReference(element));
            }
            if (element is AProtobufEnumVarNameElement)
            {
                return(new AProtobufEnumVarNameReference(element));
            }
            if (element is AProtobufIdElement)
            {
                return(new AProtobufIdReference(element));
            }
            if (element is AProtobufImportElement)
            {
                return(new AProtobufImportReference(element));
            }
            if (element is AProtobufOneofElement)
            {
                return(new AProtobufOneofReference(element));
            }
            if (element is AProtobufOneofNameElement)
            {
                return(new AProtobufOneofNameReference(element));
            }
            if (element is AProtobufMessageElement)
            {
                return(new AProtobufMessageReference(element));
            }
            if (element is AProtobufMessageNameElement)
            {
                return(new AProtobufMessageNameReference(element));
            }
            if (element is AProtobufMessageBodyElement)
            {
                return(new AProtobufMessageBodyReference(element));
            }
            if (element is AProtobufMessageOptionElement)
            {
                return(new AProtobufMessageOptionReference(element));
            }
            if (element is AProtobufMessageVarNameElement)
            {
                return(new AProtobufMessageVarNameReference(element));
            }
            if (element is AProtobufNumberElement)
            {
                return(new AProtobufNumberReference(element));
            }
            if (element is AProtobufPackageNameElement)
            {
                return(new AProtobufPackageNameReference(element));
            }
            if (element is AProtobufPackageElement)
            {
                return(new AProtobufPackageReference(element));
            }
            if (element is AProtobufPrimitiveTypeElement)
            {
                return(new AProtobufPrimitiveTypeReference(element));
            }
            if (element is AProtobufKeyElement)
            {
                return(new AProtobufKeyReference(element));
            }
            if (element is AProtobufSyntaxElement)
            {
                return(new AProtobufSyntaxReference(element));
            }
            if (element is AProtobufTextElement)
            {
                return(new AProtobufTextReference(element));
            }
            if (element is AProtobufRegexElement)
            {
                return(new AProtobufRegexReference(element));
            }
            if (element is AProtobufServiceElement)
            {
                return(new AProtobufServiceReference(element));
            }
            if (element is AProtobufServiceNameElement)
            {
                return(new AProtobufServiceNameReference(element));
            }
            if (element is AProtobufServiceBodyElement)
            {
                return(new AProtobufServiceBodyReference(element));
            }
            if (element is AProtobufServiceRpcElement)
            {
                return(new AProtobufServiceRpcReference(element));
            }
            if (element is AProtobufServiceRpcNameElement)
            {
                return(new AProtobufServiceRpcNameReference(element));
            }
            if (element is AProtobufServiceRpcBodyElement)
            {
                return(new AProtobufServiceRpcBodyReference(element));
            }

            return(new AProtobufReferenceTemplate <ABnfElement>(element));
        }
Exemplo n.º 10
0
 public AProtobufImportReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 11
0
 public AProtobufTextReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 12
0
 public ABnfReferenceTemplate(ABnfElement element)
 {
     m_element = element as T;
 }
Exemplo n.º 13
0
 // 获取缩进
 public virtual int GetFormateIndentation(int offset, ABnfElement select)
 {
     return(0);
 }
Exemplo n.º 14
0
 // 获取缩进
 public virtual int GetDesiredIndentation(int offset, ABnfElement select)
 {
     return(0);
 }
Exemplo n.º 15
0
 public virtual ABnfReference CreateReference(ABnfElement element)
 {
     return(new ABnfReferenceTemplate <ABnfElement>(element));
 }
Exemplo n.º 16
0
        public override string ShowKeyWordCompletion(string input, ABnfElement pick)
        {
            if (pick is AProtobufTextElement)
            {
                return(null);
            }

            if (pick is AProtobufIdElement)
            {
                pick = pick.GetParent();
            }

            if (pick is AProtobufMessageNameElement)
            {
                return(null);
            }
            if (pick is AProtobufEnumNameElement)
            {
                return(null);
            }
            if (pick is AProtobufOneofNameElement)
            {
                return(null);
            }
            if (pick is AProtobufMessageVarNameElement)
            {
                return(null);
            }

            if (pick is AProtobufCustomTypeElement)
            {
                var element = pick as AProtobufCustomTypeElement;
                // 如果出现点,那么就不要显示关键字
                if (element.GetStringList().Count > 0)
                {
                    return(null);
                }
                return(element.GetElementText());
            }
            else if (pick is AProtobufPackageNameElement)
            {
                var element = pick as AProtobufPackageNameElement;
                // 如果出现点,那么就不要显示关键字
                if (element.GetStringList().Count > 0)
                {
                    return(null);
                }
            }

            var node = pick as ABnfNodeElement;

            if (node == null && pick != null)
            {
                node = pick.GetParent();
            }
            if (node is AProtobufLineCommentElement)
            {
                return(null);
            }
            if (node is AProtobufBlockCommentElement)
            {
                return(null);
            }
            return(input);
        }
Exemplo n.º 17
0
 public virtual ABnfGuessError GuessTypes(ABnfElement element, out List <ABnfGuess> guess_list)
 {
     guess_list = new List <ABnfGuess>();
     return(null);
 }
Exemplo n.º 18
0
 public AProtobufReferenceTemplate(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 19
0
 public virtual int ReCalcSignature(ABnfElement element, int offset)
 {
     return(-1);
 }
Exemplo n.º 20
0
        // 高亮标签
        public void QueryHighlightWordTag(ABnfElement element, List <ALanguageHighlightWordInfo> info_list)
        {
            // 找到对应的配对
            string value = element.GetElementText();

            if (m_left_pairs.TryGetValue(value, out string right_pair))
            {
                var parent = element.GetParent();
                if (parent == null)
                {
                    return;
                }

                // 找到所在的位置
                var childs = parent.GetChilds();
                int index  = childs.IndexOf(element);
                if (index < 0)
                {
                    return;
                }

                // 往后找到对应的匹配
                for (int i = index + 1; i < childs.Count; ++i)
                {
                    if (childs[i].GetElementText() == right_pair)
                    {
                        var info = new ALanguageHighlightWordInfo();
                        info.start = element.GetStart();
                        info.end   = element.GetEnd();
                        info_list.Add(info);

                        info       = new ALanguageHighlightWordInfo();
                        info.start = childs[i].GetStart();
                        info.end   = childs[i].GetEnd();
                        info_list.Add(info);

                        break;
                    }
                }
                return;
            }

            // 找到对应的配对
            if (m_right_pairs.TryGetValue(value, out string left_pair))
            {
                var parent = element.GetParent();
                if (parent == null)
                {
                    return;
                }

                // 找到所在的位置
                var childs = parent.GetChilds();
                int index  = childs.IndexOf(element);
                if (index < 0)
                {
                    return;
                }

                // 往前找到对应的匹配
                for (int i = index - 1; i >= 0; --i)
                {
                    if (childs[i].GetElementText() == left_pair)
                    {
                        var info = new ALanguageHighlightWordInfo();
                        info.start = element.GetStart();
                        info.end   = element.GetEnd();
                        info_list.Add(info);

                        info       = new ALanguageHighlightWordInfo();
                        info.start = childs[i].GetStart();
                        info.end   = childs[i].GetEnd();
                        info_list.Add(info);

                        break;
                    }
                }
                return;
            }

            ABnfNodeElement node = element as ABnfNodeElement;

            if (node == null)
            {
                node = element.GetParent();
            }
            if (node == null)
            {
                return;
            }

            // 找到高亮配对
            node.GetReference().QueryHighlightWordTag(info_list);
        }
Exemplo n.º 21
0
 public ALittleScriptMethodParamOneDecReference(ABnfElement element) : base(element)
 {
 }
 public ALittleScriptCustomTypeNameReference(ABnfElement element) : base(element.GetParent() as ALittleScriptCustomTypeElement, element)
 {
 }
Exemplo n.º 23
0
 public ABnfKeyReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 24
0
 public ALittleScriptValueStatReference(ABnfElement element) : base(element)
 {
 }
 public ALittleScriptGlobalMethodDecReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 26
0
 public AProtobufCustomTypeReference(ABnfElement element) : base(element)
 {
 }
        public override ABnfGuessError CheckError()
        {
            ABnfElement parent = null;

            if (m_element.GetReturnYield() != null)
            {
                // 对于ReturnYield就不需要做返回值检查
                // 对所在函数进行检查,必须要有async和await表示
                // 获取对应的函数对象
                ABnfElement element = null;

                parent = m_element;
                while (parent != null)
                {
                    if (parent is ALittleScriptClassMethodDecElement)
                    {
                        var method_dec = parent as ALittleScriptClassMethodDecElement;
                        var modifier   = (method_dec.GetParent() as ALittleScriptClassElementDecElement).GetModifierList();
                        if (ALittleScriptUtility.GetCoroutineType(modifier) == null)
                        {
                            element = method_dec.GetMethodNameDec();
                            if (element == null)
                            {
                                element = method_dec;
                            }
                        }
                        break;
                    }
                    else if (parent is ALittleScriptClassStaticDecElement)
                    {
                        var method_dec = parent as ALittleScriptClassStaticDecElement;
                        var modifier   = (method_dec.GetParent() as ALittleScriptClassElementDecElement).GetModifierList();
                        if (ALittleScriptUtility.GetCoroutineType(modifier) == null)
                        {
                            element = method_dec.GetMethodNameDec();
                            if (element == null)
                            {
                                element = method_dec;
                            }
                        }
                        break;
                    }
                    else if (parent is ALittleScriptGlobalMethodDecElement)
                    {
                        var method_dec = parent as ALittleScriptGlobalMethodDecElement;
                        var modifier   = (method_dec.GetParent() as ALittleScriptNamespaceElementDecElement).GetModifierList();
                        if (ALittleScriptUtility.GetCoroutineType(modifier) == null)
                        {
                            element = method_dec.GetMethodNameDec();
                            if (element == null)
                            {
                                element = method_dec;
                            }
                        }
                        break;
                    }

                    parent = parent.GetParent();
                }

                if (element != null)
                {
                    return(new ABnfGuessError(element, "函数内部使用了return yield表达式,所以必须使用async或await修饰"));
                }
                return(null);
            }

            var value_stat_list  = m_element.GetValueStatList();
            var return_type_list = new List <ALittleScriptAllTypeElement>();
            ALittleScriptMethodReturnTailDecElement return_tail_dec = null;

            // 获取对应的函数对象
            parent = m_element;
            while (parent != null)
            {
                if (parent is ALittleScriptClassGetterDecElement)
                {
                    var getterDec = parent as ALittleScriptClassGetterDecElement;
                    return_type_list.Clear();
                    var return_type_dec = getterDec.GetAllType();
                    if (return_type_dec != null)
                    {
                        return_type_list.Add(return_type_dec);
                    }
                    break;
                }
                else if (parent is ALittleScriptClassSetterDecElement)
                {
                    break;
                }
                else if (parent is ALittleScriptClassMethodDecElement)
                {
                    var method_dec = parent as ALittleScriptClassMethodDecElement;
                    var return_dec = method_dec.GetMethodReturnDec();
                    if (return_dec != null)
                    {
                        var return_one_list = return_dec.GetMethodReturnOneDecList();
                        foreach (var return_one in return_one_list)
                        {
                            var all_type = return_one.GetAllType();
                            if (all_type != null)
                            {
                                return_type_list.Add(all_type);
                            }

                            var return_tail = return_one.GetMethodReturnTailDec();
                            if (return_tail != null)
                            {
                                return_tail_dec = return_tail;
                            }
                        }
                    }
                    break;
                }
                else if (parent is ALittleScriptClassStaticDecElement)
                {
                    var method_dec = parent as ALittleScriptClassStaticDecElement;
                    var return_dec = method_dec.GetMethodReturnDec();
                    if (return_dec != null)
                    {
                        var return_one_list = return_dec.GetMethodReturnOneDecList();
                        foreach (var return_one in return_one_list)
                        {
                            var all_type = return_one.GetAllType();
                            if (all_type != null)
                            {
                                return_type_list.Add(all_type);
                            }

                            var return_tail = return_one.GetMethodReturnTailDec();
                            if (return_tail != null)
                            {
                                return_tail_dec = return_tail;
                            }
                        }
                    }
                    break;
                }
                else if (parent is ALittleScriptGlobalMethodDecElement)
                {
                    var method_dec = parent as ALittleScriptGlobalMethodDecElement;
                    var return_dec = method_dec.GetMethodReturnDec();
                    if (return_dec != null)
                    {
                        var return_one_list = return_dec.GetMethodReturnOneDecList();
                        foreach (var return_one in return_one_list)
                        {
                            var all_type = return_one.GetAllType();
                            if (all_type != null)
                            {
                                return_type_list.Add(all_type);
                            }

                            var return_tail = return_one.GetMethodReturnTailDec();
                            if (return_tail != null)
                            {
                                return_tail_dec = return_tail;
                            }
                        }
                    }
                    break;
                }

                parent = parent.GetParent();
            }

            // 参数的类型
            List <ABnfGuess> guess_list = null;

            // 如果返回值只有一个函数调用
            if (value_stat_list.Count == 1 && (return_type_list.Count > 1 || return_tail_dec != null))
            {
                var value_stat = value_stat_list[0];
                var error      = value_stat.GuessTypes(out guess_list);
                if (error != null)
                {
                    return(error);
                }
                bool has_value_tail = guess_list.Count > 0 &&
                                      guess_list[guess_list.Count - 1] is ALittleScriptGuessReturnTail;

                if (return_tail_dec == null)
                {
                    if (has_value_tail)
                    {
                        if (guess_list.Count < return_type_list.Count - 1)
                        {
                            return(new ABnfGuessError(m_element, "return的函数调用的返回值数量超过函数定义的返回值数量"));
                        }
                    }
                    else
                    {
                        if (guess_list.Count != return_type_list.Count)
                        {
                            return(new ABnfGuessError(m_element, "return的函数调用的返回值数量和函数定义的返回值数量不相等"));
                        }
                    }
                }
                else
                {
                    if (has_value_tail)
                    {
                        // 不用检查
                    }
                    else
                    {
                        if (guess_list.Count < return_type_list.Count)
                        {
                            return(new ABnfGuessError(m_element, "return的函数调用的返回值数量少于函数定义的返回值数量"));
                        }
                    }
                }
            }
            else
            {
                if (return_tail_dec == null)
                {
                    if (value_stat_list.Count != return_type_list.Count)
                    {
                        return(new ABnfGuessError(m_element, "return的返回值数量和函数定义的返回值数量不相等"));
                    }
                }
                else
                {
                    if (value_stat_list.Count < return_type_list.Count)
                    {
                        return(new ABnfGuessError(m_element, "return的返回值数量少于函数定义的返回值数量"));
                    }
                }
                guess_list = new List <ABnfGuess>();
                foreach (var value_stat in value_stat_list)
                {
                    var error = ALittleScriptUtility.CalcReturnCount(value_stat, out int return_count, out _);
                    if (error != null)
                    {
                        return(error);
                    }
                    if (return_count != 1)
                    {
                        return(new ABnfGuessError(value_stat, "表达式必须只能是一个返回值"));
                    }

                    error = value_stat.GuessType(out ABnfGuess guess);
                    if (error != null)
                    {
                        return(error);
                    }
                    if (guess is ALittleScriptGuessParamTail)
                    {
                        return(new ABnfGuessError(value_stat, "return表达式不能返回\"...\""));
                    }
                    error = value_stat.GuessType(out ABnfGuess value_stat_guess);
                    if (error != null)
                    {
                        return(error);
                    }
                    guess_list.Add(value_stat_guess);
                }
            }

            // 每个类型依次检查
            for (int i = 0; i < guess_list.Count; ++i)
            {
                ALittleScriptValueStatElement target_value_stat = null;
                if (i < value_stat_list.Count)
                {
                    target_value_stat = value_stat_list[i];
                }
                else
                {
                    target_value_stat = value_stat_list[0];
                }

                if (guess_list[i] is ALittleScriptGuessReturnTail)
                {
                    break;
                }
                if (i >= return_type_list.Count)
                {
                    break;
                }
                var error = return_type_list[i].GuessType(out ABnfGuess return_type_guess);
                if (error != null)
                {
                    return(error);
                }
                if (return_type_guess is ALittleScriptGuessReturnTail)
                {
                    break;
                }

                error = ALittleScriptOp.GuessTypeEqual(return_type_guess, target_value_stat, guess_list[i], false, true);
                if (error != null)
                {
                    return(new ABnfGuessError(target_value_stat, "return的第" + (i + 1) + "个返回值数量和函数定义的返回值类型不同:" + error.GetError()));
                }
            }

            return(null);
        }
Exemplo n.º 28
0
 public ALittleScriptGenericTypeReference(ABnfElement element) : base(element)
 {
 }
Exemplo n.º 29
0
 public ALittleScriptOpNewStatReference(ABnfElement element) : base(element)
 {
 }
        public override int GetFormateIndentation(int offset, ABnfElement select)
        {
            if (m_format_indent >= 0)
            {
                return(m_format_indent);
            }

            ABnfElement parent = m_element.GetParent();

            if (parent == null)
            {
                m_format_indent = 0;
                return(m_format_indent);
            }

            if (m_element is ALittleScriptAllExprElement ||
                m_element is ALittleScriptLineCommentElement ||
                m_element is ALittleScriptBlockCommentElement)
            {
                m_format_indent = parent.GetReference().GetFormateIndentation(offset, null);
                if (parent is ALittleScriptForExprElement ||
                    parent is ALittleScriptWhileExprElement ||
                    parent is ALittleScriptIfExprElement ||
                    parent is ALittleScriptElseIfExprElement ||
                    parent is ALittleScriptElseExprElement

                    || parent is ALittleScriptClassBodyDecElement ||
                    parent is ALittleScriptEnumBodyDecElement ||
                    parent is ALittleScriptStructBodyDecElement

                    || parent is ALittleScriptMethodBodyDecElement ||
                    parent is ALittleScriptForBodyElement ||
                    parent is ALittleScriptWhileBodyElement ||
                    parent is ALittleScriptDoWhileBodyElement ||
                    parent is ALittleScriptIfBodyElement ||
                    parent is ALittleScriptElseIfBodyElement ||
                    parent is ALittleScriptElseBodyElement ||
                    parent is ALittleScriptWrapExprElement)
                {
                    m_format_indent += ALanguageSmartIndentProvider.s_indent_size;
                }
                return(m_format_indent);
            }
            else if (m_element is ALittleScriptClassElementDecElement ||
                     m_element is ALittleScriptEnumVarDecElement ||
                     m_element is ALittleScriptStructVarDecElement ||
                     m_element is ALittleScriptStructOptionDecElement)
            {
                m_format_indent = parent.GetReference().GetFormateIndentation(offset, null) + ALanguageSmartIndentProvider.s_indent_size;
                return(m_format_indent);
            }
            else if (m_element is ALittleScriptMethodParamDecElement ||
                     m_element is ALittleScriptOpNewListStatElement)
            {
                var element = m_element as ABnfNodeElement;
                var childs  = element.GetChilds();
                if (childs.Count > 0)
                {
                    m_format_indent = childs[0].GetStartIndent();
                    return(m_format_indent);
                }
            }
            else if (m_element is ALittleScriptOp8Element ||
                     m_element is ALittleScriptOp7Element ||
                     m_element is ALittleScriptOp6Element ||
                     m_element is ALittleScriptOp5Element ||
                     m_element is ALittleScriptOp4Element ||
                     m_element is ALittleScriptOp3Element ||
                     m_element is ALittleScriptOp2Element)
            {
                m_format_indent = parent.GetReference().GetFormateIndentation(offset, null) + ALanguageSmartIndentProvider.s_indent_size;
                return(m_format_indent);
            }

            m_format_indent = parent.GetReference().GetFormateIndentation(offset, null);
            return(m_format_indent);
        }