public override ABnfGuessError CheckError() { // 检查这次所在的函数必须要有await或者async修饰 ABnfElement parent = m_element; while (parent != null) { if (parent is ALittleScriptNamespaceDecElement) { break; } else if (parent is ALittleScriptClassCtorDecElement) { break; } else if (parent is ALittleScriptClassGetterDecElement) { break; } else if (parent is ALittleScriptClassSetterDecElement) { break; } else if (parent is ALittleScriptClassMethodDecElement) { var modifier = (parent.GetParent() as ALittleScriptClassElementDecElement).GetModifierList(); if (ALittleScriptUtility.GetCoroutineType(modifier) == "await") { return(null); } break; } else if (parent is ALittleScriptClassStaticDecElement) { var modifier = (parent.GetParent() as ALittleScriptClassElementDecElement).GetModifierList(); if (ALittleScriptUtility.GetCoroutineType(modifier) == "await") { return(null); } break; } else if (parent is ALittleScriptGlobalMethodDecElement) { var modifier = (parent.GetParent() as ALittleScriptNamespaceElementDecElement).GetModifierList(); if (ALittleScriptUtility.GetCoroutineType(modifier) == "await") { return(null); } break; } parent = parent.GetParent(); } return(new ABnfGuessError(m_element, "co关键字只能在await修饰的函数中使用")); }
public ALittleScriptCustomTypeDotIdNameReference(ABnfElement element) : base(element.GetParent().GetParent() as ALittleScriptCustomTypeElement, element) { var custom_type = element.GetParent().GetParent() as ALittleScriptCustomTypeElement; var custom_type_name = custom_type.GetCustomTypeName(); if (custom_type_name != null) { m_namespace_name = custom_type_name.GetElementText(); } else { m_namespace_name = ""; } m_key = m_element.GetElementText(); }
public override ABnfGuessError CheckError() { // 获取对应的函数对象 ABnfElement parent = m_element; while (parent != null) { if (parent is ALittleScriptClassGetterDecElement || parent is ALittleScriptClassSetterDecElement || parent is ALittleScriptClassMethodDecElement || parent is ALittleScriptClassCtorDecElement || parent is ALittleScriptClassStaticDecElement || parent is ALittleScriptGlobalMethodDecElement) { break; } if (parent is ALittleScriptForExprElement || parent is ALittleScriptWhileExprElement || parent is ALittleScriptDoWhileExprElement) { return(null); } parent = parent.GetParent(); } return(new ABnfGuessError(m_element, "break和continue只能在for,while,do while中")); }
private void ReloadInfo() { m_class_dec = null; m_class_ctor_dec = null; m_class_setter_dec = null; m_class_method_dec = null; m_class_static_dec = null; ABnfElement parent = m_element; while (true) { if (parent == null) { break; } if (parent is ALittleScriptNamespaceDecElement) { break; } else if (parent is ALittleScriptClassDecElement) { m_class_dec = (ALittleScriptClassDecElement)parent; break; } else if (parent is ALittleScriptClassCtorDecElement) { m_class_ctor_dec = (ALittleScriptClassCtorDecElement)parent; } else if (parent is ALittleScriptClassGetterDecElement) { m_class_getter_dec = (ALittleScriptClassGetterDecElement)parent; var modifier = (m_class_getter_dec.GetParent() as ALittleScriptClassElementDecElement).GetModifierList(); m_is_const = ALittleScriptUtility.IsConst(modifier); } else if (parent is ALittleScriptClassSetterDecElement) { m_class_setter_dec = (ALittleScriptClassSetterDecElement)parent; var modifier = (m_class_setter_dec.GetParent() as ALittleScriptClassElementDecElement).GetModifierList(); m_is_const = ALittleScriptUtility.IsConst(modifier); } else if (parent is ALittleScriptClassMethodDecElement) { m_class_method_dec = (ALittleScriptClassMethodDecElement)parent; var modifier = (m_class_method_dec.GetParent() as ALittleScriptClassElementDecElement).GetModifierList(); m_is_const = ALittleScriptUtility.IsConst(modifier); } else if (parent is ALittleScriptClassStaticDecElement) { m_class_static_dec = (ALittleScriptClassStaticDecElement)parent; } else if (parent is ALittleScriptGlobalMethodDecElement) { m_global_method_dec = (ALittleScriptGlobalMethodDecElement)parent; } parent = parent.GetParent(); } }
private void ReloadInfo() { m_method_dec = null; ABnfElement parent = m_element; while (parent != null) { if (parent is ALittleScriptNamespaceDecElement) { break; } else if (parent is ALittleScriptClassDecElement) { break; } else if (parent is ALittleScriptClassCtorDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptClassCtorDecElement).GetMethodBodyDec(); break; } else if (parent is ALittleScriptClassSetterDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptClassSetterDecElement).GetMethodBodyDec(); break; } else if (parent is ALittleScriptClassGetterDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptClassGetterDecElement).GetMethodBodyDec(); break; } else if (parent is ALittleScriptClassMethodDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptClassMethodDecElement).GetMethodBodyDec(); break; } else if (parent is ALittleScriptClassStaticDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptClassStaticDecElement).GetMethodBodyDec(); break; } else if (parent is ALittleScriptGlobalMethodDecElement) { m_method_dec = parent; m_method_body_dec = (parent as ALittleScriptGlobalMethodDecElement).GetMethodBodyDec(); break; } parent = parent.GetParent(); } }
public override int ReCalcSignature(ABnfElement element, int offset) { ABnfElement parent = element; while (parent != null) { List <ALittleScriptStringElement> string_element_list = null; if (parent is ALittleScriptPropertyValueMethodCallElement) { var call_element = parent as ALittleScriptPropertyValueMethodCallElement; string_element_list = call_element.GetStringList(); } else if (parent is ALittleScriptOpNewStatElement) { var call_element = parent as ALittleScriptOpNewStatElement; string_element_list = call_element.GetStringList(); } if (string_element_list != null) { int index = 0; int jump = 0; for (int i = 0; i < string_element_list.Count; ++i) { if (string_element_list[i].GetElementText() != ",") { ++jump; continue; } if (offset > string_element_list[i].GetStart()) { index = i - jump + 1; } else { break; } } return(index); } if (parent is ALittleScriptMethodBodyDecElement) { return(-1); } if (parent is ALittleScriptAllExprElement) { return(-1); } parent = parent.GetParent(); } return(-1); }
// 拾取高亮 public void PeekHighlightWord(int offset, long version) { ABnfElement element = GetException(offset); if (element == null) { return; } if (element is ABnfErrorElement) { return; } var target = element; string value = element.GetElementText(); if (!m_left_pairs.ContainsKey(value) && !m_right_pairs.ContainsKey(value)) { target = null; } ABnfNodeElement node = element as ABnfNodeElement; if (node == null) { node = element.GetParent(); } if (node == null) { return; } if (node.GetReference().PeekHighlightWord()) { target = node; } if (target == null) { return; } var list = new List <ALanguageHighlightWordInfo>(); QueryHighlightWordTag(element, list); Application.Current.Dispatcher.Invoke(() => { if (m_view.Properties.TryGetProperty(nameof(ALanguageHighlightWordTagger), out ALanguageHighlightWordTagger tagger)) { tagger.Refresh(version, list); } }); }
public ALittleScriptStructNameDecReference(ABnfElement element) : base(element) { m_key = m_element.GetElementText(); m_namespace_name = ALittleScriptUtility.GetNamespaceName(m_element); // 如果父节点是extends,那么就获取指定的命名域 var parent = element.GetParent(); if (parent is ALittleScriptStructExtendsDecElement) { var namespace_name_dec = ((ALittleScriptStructExtendsDecElement)parent).GetNamespaceNameDec(); if (namespace_name_dec != null) { m_namespace_name = namespace_name_dec.GetElementText(); } } }
public override string ShowKeyWordCompletion(string input, ABnfElement pick) { var node = pick as ABnfNodeElement; if (node == null && pick != null) { node = pick.GetParent(); } if (node is ALittleScriptVarAssignDecElement) { return(input); } if (node is ALittleScriptTextElement) { return(input); } if (node is ALittleScriptPropertyValueDotIdElement) { return(null); } if (node is ALittleScriptLineCommentElement) { return(null); } if (node is ALittleScriptBlockCommentElement) { return(null); } if (node is ALittleScriptClassExtendsDecElement) { return(null); } if (node != null && node is ALittleScriptIdElement && !(node.GetParent() is ALittleScriptCustomTypeNameElement) && !(node.GetParent() is ALittleScriptPropertyValueCustomTypeElement)) { return(null); } return(input); }
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 AProtobufEnumVarNameElement) { 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); }
// 高亮标签 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); }
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); }
public ALittleScriptCustomTypeNameReference(ABnfElement element) : base(element.GetParent() as ALittleScriptCustomTypeElement, element) { }
public override ALanguageSignatureInfo QuerySignatureHelp(out int start, out int length) { start = 0; length = 0; ABnfElement parent = m_element; while (parent != null) { if (parent is ALittleScriptPropertyValueMethodCallElement) { var refe = parent.GetReference() as ALittleScriptPropertyValueMethodCallReference; if (refe == null) { return(null); } var error = refe.GuessPreType(out ABnfGuess guess); if (error != null) { return(null); } var guess_functor = guess as ALittleScriptGuessFunctor; if (guess_functor == null) { return(null); } var info = new ALanguageSignatureInfo(); for (int i = 0; i < guess_functor.param_name_list.Count; ++i) { string type = ""; if (i < guess_functor.param_nullable_list.Count && guess_functor.param_nullable_list[i]) { type = "[Nullable] "; } if (i < guess_functor.param_list.Count) { type += guess_functor.param_list[i].GetValue(); } var param = new ALanguageParameterInfo(); param.name = type + " " + guess_functor.param_name_list[i]; info.param_list.Add(param); } if (guess_functor.param_tail != null) { var param = new ALanguageParameterInfo(); param.name = guess_functor.param_tail.GetValue(); info.param_list.Add(param); } start = parent.GetStart(); length = parent.GetLengthWithoutError(); var method_call = parent as ALittleScriptPropertyValueMethodCallElement; var string_list = method_call.GetStringList(); if (string_list.Count > 1) { start = string_list[0].GetStart(); length = parent.GetLength() - (string_list[0].GetStart() - parent.GetStart()) - 1; } return(info); } else if (parent is ALittleScriptOpNewStatElement) { var custom_type = (parent as ALittleScriptOpNewStatElement).GetCustomType(); if (custom_type == null) { return(null); } var error = custom_type.GuessType(out ABnfGuess guess); if (error != null) { return(null); } if (guess is ALittleScriptGuessTemplate) { var guess_template = guess as ALittleScriptGuessTemplate; if (guess_template.template_extends != null) { guess = guess_template.template_extends; } } if (guess is ALittleScriptGuessClass) { var class_dec = ((ALittleScriptGuessClass)guess).class_dec; var ctor = ALittleScriptUtility.FindFirstCtorDecFromExtends(class_dec, 100); if (ctor == null) { return(null); } var param_dec = ctor.GetMethodParamDec(); if (param_dec == null) { return(null); } var param_one_dec_list = param_dec.GetMethodParamOneDecList(); if (param_one_dec_list.Count == 0) { return(null); } var info = new ALanguageSignatureInfo(); for (int i = 0; i < param_one_dec_list.Count; ++i) { var param_one_dec = param_one_dec_list[i]; var tail_dec = param_one_dec.GetMethodParamTailDec(); if (tail_dec != null) { var param_info = new ALanguageParameterInfo(); param_info.name = tail_dec.GetElementText(); info.param_list.Add(param_info); continue; } var nullable = ALittleScriptUtility.IsNullable(param_one_dec.GetModifierList()); var all_type = param_one_dec.GetAllType(); if (all_type == null) { return(null); } error = all_type.GuessType(out ABnfGuess all_type_guess); if (error != null) { return(null); } var param = new ALanguageParameterInfo(); param.name = all_type_guess.GetValue(); if (param_one_dec.GetMethodParamNameDec() != null) { if (nullable) { param.name += " [Nullable]"; } param.name += " " + param_one_dec.GetMethodParamNameDec().GetElementText(); } info.param_list.Add(param); } start = parent.GetStart(); length = parent.GetLengthWithoutError(); var new_stat = parent as ALittleScriptOpNewStatElement; var string_list = new_stat.GetStringList(); if (string_list.Count > 1) { start = string_list[0].GetStart(); length = parent.GetLength() - (string_list[0].GetStart() - parent.GetStart()) - 1; } return(info); } return(null); } if (parent is ALittleScriptMethodBodyDecElement) { return(null); } if (parent is ALittleScriptAllExprElement) { return(null); } parent = parent.GetParent(); } return(null); }