diff --git a/CodeCompletion/DomConverter.cs b/CodeCompletion/DomConverter.cs index 37a1ec6e3..65d00821f 100644 --- a/CodeCompletion/DomConverter.cs +++ b/CodeCompletion/DomConverter.cs @@ -1016,7 +1016,12 @@ namespace CodeCompletion } if (ss != null && ss.si != null) { - ss = ss.WithRefreshedDescription(); + // в случае операции преобразования типа эта ветка срабатывает + if (ss is ElementScope && string.IsNullOrEmpty(ss.si.description) && (ss as ElementScope).sc is TypeScope) + ss.si.description = (ss as ElementScope).sc.Description; + else + // обновление описания + ss = ss.WithRefreshedDescription(); try { @@ -1050,19 +1055,16 @@ namespace CodeCompletion else ss.AddDocumentation(UnitDocCache.GetDocumentation(ps)); } - else if (ss is InterfaceUnitScope) ss.AddDocumentation(UnitDocCache.GetDocumentation(ss as InterfaceUnitScope)); - else if (ss is ElementScope && string.IsNullOrEmpty(ss.si.description) && (ss as ElementScope).sc is TypeScope) - ss.si.description = (ss as ElementScope).sc.Description; } } catch (Exception e) - { + { #if DEBUG - File.AppendAllText("log.txt", e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine); + File.AppendAllText("log.txt", e.Message + Environment.NewLine + e.StackTrace + Environment.NewLine); #endif - } + } RestoreCurrentUsedAssemblies(); string description = ss.si.description; if (description != null) diff --git a/CodeCompletion/DomSyntaxTreeVisitor.cs b/CodeCompletion/DomSyntaxTreeVisitor.cs index 2e095230a..9c17cc42a 100644 --- a/CodeCompletion/DomSyntaxTreeVisitor.cs +++ b/CodeCompletion/DomSyntaxTreeVisitor.cs @@ -3077,11 +3077,14 @@ namespace CodeCompletion } string aliasName = asStatementsList.as_statements.Find(st => st.real_name.name == importedModuleName).alias.name; - fictiveUnit.AddName(aliasName, importedModuleScope); + + SymScope moduleScope = importedModuleScope.CopyWithNewSymInfo(); + + fictiveUnit.AddName(aliasName, moduleScope); // Поправляем реальное имя, которое портится в InterfaceUnitScope.AddName() EVA - importedModuleScope.si.name = importedModuleName; - importedModuleScope.si.addit_name = aliasName; + moduleScope.si.name = importedModuleName; + moduleScope.si.aliasName = aliasName; } else if (importStatement is from_import_statement fromImport) { @@ -3102,13 +3105,13 @@ namespace CodeCompletion foreach (var asStatement in asStatementsList.as_statements) { - SymScope nameScope = importedModuleScope.FindNameOnlyInType(asStatement.real_name.name); + SymScope nameScope = importedModuleScope.FindNameOnlyInType(asStatement.real_name.name)?.CopyWithNewSymInfo(); if (nameScope != null) { fictiveUnit.AddName(asStatement.alias.name, nameScope); // Поправляем реальное имя, которое портится в InterfaceUnitScope.AddName() EVA nameScope.si.name = asStatement.real_name.name; - nameScope.si.addit_name = asStatement.alias.name; + nameScope.si.aliasName = asStatement.alias.name; } } } diff --git a/CodeCompletion/ExpressionVisitor.cs b/CodeCompletion/ExpressionVisitor.cs index 01bdc6e1e..37de377ed 100644 --- a/CodeCompletion/ExpressionVisitor.cs +++ b/CodeCompletion/ExpressionVisitor.cs @@ -200,6 +200,11 @@ namespace CodeCompletion } } } + else if (returned_scopes[i] is TypeScope) + { + // операция преобразования типа не поддерживается здесь EVA + continue; + } else if (i == 0) return proces; } @@ -1161,7 +1166,8 @@ namespace CodeCompletion method_call_cache[_method_call] = returned_scope; return; } - if (names.Length > 0 && names[0] is TypeScope) + // Срабатывает на операции преобразования типа + if (names.All(name => name is TypeScope)) { returned_scope = new ElementScope(names[0]); method_call_cache[_method_call] = returned_scope; @@ -1208,17 +1214,38 @@ namespace CodeCompletion if (ps == null && names.Length > 0) { returned_scope = null; - foreach (SymScope ss in names) - if (ss is ProcScope) + + // Если есть ProcScope, то приоритет отдаем ему. + // Неверно в случае, когда есть подходящая операция преобразования типа у TypeScope, + // но операция преобразования типа по хорошему должна обрабатываться в select_method EVA + if (names[0] is TypeScope && names.Length > 1) + { + var p = names.FirstOrDefault(s => s is ProcScope); + + if (p != null) + returned_scope = p; + else { - returned_scope = ss; - break; - } - else if (ss is TypeScope) - { - returned_scope = new ElementScope(ss); + returned_scope = new ElementScope(names[0]); return; } + } + else + { + foreach (SymScope ss in names) + { + if (ss is ProcScope) + { + returned_scope = ss; + break; + } + else if (ss is TypeScope) + { + returned_scope = new ElementScope(ss); + return; + } + } + } } if (returned_scope != null) { @@ -1237,7 +1264,8 @@ namespace CodeCompletion else returned_scope = new ElementScope(ps); } - else if (returned_scope is ProcRealization) + // ниже мертый код, поскольку эти типы наследники ProcScope EVA + /*else if (returned_scope is ProcRealization) { if ((returned_scope as ProcRealization).def_proc != null && (returned_scope as ProcRealization).def_proc.return_type != null) returned_scope = new ElementScope((returned_scope as ProcRealization).def_proc.return_type); @@ -1248,7 +1276,7 @@ namespace CodeCompletion if ((returned_scope as CompiledMethodScope).return_type != null) returned_scope = new ElementScope((returned_scope as CompiledMethodScope).return_type); else returned_scope = null; - } + }*/ /*else if (ret_tn is ElementScope && (ret_tn as ElementScope).sc is ProcScope) { ret_tn = new ElementScope(((ret_tn as ElementScope).sc as ProcScope).return_type); diff --git a/CodeCompletion/SymTable.cs b/CodeCompletion/SymTable.cs index 1fa96f8b6..01edb6484 100644 --- a/CodeCompletion/SymTable.cs +++ b/CodeCompletion/SymTable.cs @@ -185,6 +185,16 @@ namespace CodeCompletion members = new List(); } + /// + /// Использует глубокое копирование SymInfo для создания нового экземпляра, остальное копируется поверхностно + /// + public SymScope CopyWithNewSymInfo() + { + var s = (SymScope)MemberwiseClone(); + s.si = new SymInfo(si); + return s; + } + public virtual void Clear() { if (members != null) @@ -363,7 +373,7 @@ namespace CodeCompletion { /*if (ts is ArrayScope && !(ts as ArrayScope).is_dynamic_arr) return new List();*/ - List meths = GetExtensionMethods(ts, name); + /*List meths = GetExtensionMethods(ts, name); List lst = new List(); for (int i = 0; i < meths.Count; i++) @@ -372,12 +382,14 @@ namespace CodeCompletion { lst.Add(meths[i]); } - } - return lst; + }*/ + return GetExtensionMethods(ts, name); } public List GetExtensionMethods(TypeScope ts, string name=null) { + StringComparison comparison = CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; + if (ts is TypeSynonim) return GetExtensionMethods((ts as TypeSynonim).actType, name); if (ts.original_type != null) @@ -398,7 +410,7 @@ namespace CodeCompletion { foreach (var meth in meths) { - if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0)) + if (!lst.Contains(meth) && (name == null || meth.si.name.Equals(name, comparison))) lst.Add(meth); } } @@ -418,7 +430,7 @@ namespace CodeCompletion var meth_list = extension_methods[t]; foreach (var meth in meth_list) { - if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0)) + if (!lst.Contains(meth) && (name == null || meth.si.name.Equals(name, comparison))) lst.Add(meth); } } @@ -444,7 +456,7 @@ namespace CodeCompletion { foreach (var meth in meths) { - if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0)) + if (!lst.Contains(meth) && (name == null || meth.si.name.Equals(name, comparison))) lst.Add(meth); } } @@ -461,7 +473,7 @@ namespace CodeCompletion var meth_list = extension_methods[t]; foreach (var meth in meth_list) { - if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0)) + if (!lst.Contains(meth) && (name == null || meth.si.name.Equals(name, comparison))) lst.Add(meth); } //break; @@ -481,7 +493,7 @@ namespace CodeCompletion var unit_meth_lst = this.used_units[i].GetExtensionMethods(ts, name); foreach (var meth in unit_meth_lst) { - if (!lst.Contains(meth) && (name == null || string.Compare(meth.si.name, name, true) == 0)) + if (!lst.Contains(meth) && (name == null || meth.si.name.Equals(name, comparison))) lst.Add(meth); } } @@ -972,23 +984,30 @@ namespace CodeCompletion else { List lst = o as List; + + // у generic типов надо убрать префикс + string shortName = System.Text.RegularExpressions.Regex.Replace(name, @"`\d+$", ""); + foreach (SymScope s in lst) { - // Добавил второе условие с addit_name, чтобы работали подсказки для anotherName при использовании from ... import name as anotherName EVA - if (s.si.name == name || s.si.addit_name == name) + // Добавил второе условие с aliasName, чтобы работали подсказки для anotherName при использовании from ... import name as anotherName EVA + if (s.si.name == shortName || s.si.aliasName == shortName) { ss = s; // изменил на возврат первого совпадения для стандартных типов в SPython пока они не в фиктивном модуле, а в SPythonSystem EVA break; } - } } if (ss == null) return null; TypeScope ts = ss as TypeScope; if (CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive) - if (ss.si.name != name && ss.si.addit_name != name) + { + string shortName = System.Text.RegularExpressions.Regex.Replace(name, @"`\d+$", ""); + + if (ss.si.name != shortName && ss.si.aliasName != shortName) return null; + } if (ss.loc != null && loc != null && check_for_def && cur_line != -1 && cur_col != -1) { if (string.Compare(ss.loc.doc.file_name, loc.doc.file_name, true) == 0 && this != ss) @@ -7038,8 +7057,10 @@ namespace CodeCompletion public override List FindOverloadNames(string name) { + StringComparison comparison = CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; + List names = new List(); - List sil = PascalABCCompiler.NetHelper.NetHelper.FindNameIncludeProtected(ctn, name); + List sil = PascalABCCompiler.NetHelper.NetHelper.FindNameIncludeProtected(ctn, name, CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive); //IEnumerable ext_meths = PascalABCCompiler.NetHelper.NetHelper.GetExtensionMethods(ctn); List pascal_ext_meths = this.GetExtensionMethods(name, this); if (sil != null && sil.Count > 1 && sil.FirstOrDefault().sym_info.semantic_node_type == semantic_node_type.basic_property_node) @@ -7049,7 +7070,7 @@ namespace CodeCompletion } if (sil == null && names.Count == 0) { - if (string.Compare(name, StringConstants.default_constructor_name, true) == 0 && this.ctn != typeof(object)) + if (name.Equals(StringConstants.default_constructor_name, comparison) && this.ctn != typeof(object)) sil = PascalABCCompiler.NetHelper.NetHelper.GetConstructor(ctn); if (sil == null) { @@ -7205,12 +7226,14 @@ namespace CodeCompletion public override SymScope FindName(string name) { - List sil = PascalABCCompiler.NetHelper.NetHelper.FindNameIncludeProtected(ctn, name); + StringComparison comparison = CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; + + List sil = PascalABCCompiler.NetHelper.NetHelper.FindNameIncludeProtected(ctn, name, CodeCompletionController.CurrentParser.LanguageInformation.CaseSensitive); if (!CodeCompletionController.CurrentParser.LanguageInformation.IncludeDotNetEntities) return null; if (sil == null) { - if (string.Compare(name, StringConstants.default_constructor_name, true) == 0) + if (name.Equals(StringConstants.default_constructor_name, comparison)) sil = PascalABCCompiler.NetHelper.NetHelper.GetConstructor(ctn); if (sil == null) { diff --git a/LanguagePlugins/SPython/SPythonLanguageInfo/SPythonLanguageInformation.cs b/LanguagePlugins/SPython/SPythonLanguageInfo/SPythonLanguageInformation.cs index 8fb70ef0c..906237748 100644 --- a/LanguagePlugins/SPython/SPythonLanguageInfo/SPythonLanguageInformation.cs +++ b/LanguagePlugins/SPython/SPythonLanguageInfo/SPythonLanguageInformation.cs @@ -41,7 +41,7 @@ namespace Languages.SPython.Frontend.Data public override bool AddStandardUnitNamesToUserScope => false; - public override bool AddStandardNetNamespacesToUserScope => false; + public override bool AddStandardNetNamespacesToUserScope => true; public override bool UsesFunctionsOverlappingSourceContext => true; @@ -59,7 +59,7 @@ namespace Languages.SPython.Frontend.Data private readonly HashSet exclutions = new HashSet { - "__NewSetCreatorInternal" + // "__NewSetCreatorInternal" }; private readonly Dictionary specialModulesAliases = new Dictionary @@ -1030,24 +1030,22 @@ namespace Languages.SPython.Frontend.Data case ScopeKind.Type: return GetDescriptionForType(scope as ITypeScope); case ScopeKind.CompiledType: return GetDescriptionForCompiledType(scope as ICompiledTypeScope); case ScopeKind.Delegate: return GetDescriptionForDelegate(scope as IProcType); - case ScopeKind.Procedure: return GetDescriptionForProcedure(scope as IProcScope); - case ScopeKind.ElementScope: return GetDescriptionForElementScope(scope as IElementScope); case ScopeKind.TypeSynonim: return GetSynonimDescription(scope as ITypeSynonimScope); - case ScopeKind.Namespace: return GetDescriptionForNamespace(scope as INamespaceScope); - case ScopeKind.CompiledMethod: return GetDescriptionForCompiledMethod(scope as ICompiledMethodScope); - case ScopeKind.Enum: return GetDescriptionForEnum(scope as IEnumScope); case ScopeKind.Array: return GetDescriptionForArray(scope as IArrayScope); - - - - /*case ScopeKind.Set: return GetDescriptionForSet(scope as ISetScope); - + case ScopeKind.Diapason: return GetDescriptionForDiapason(scope as IDiapasonScope); + case ScopeKind.File: return GetDescriptionForFile(scope as IFileScope); + case ScopeKind.Pointer: return GetDescriptionForPointer(scope as IPointerScope); + case ScopeKind.Enum: return GetDescriptionForEnum(scope as IEnumScope); + case ScopeKind.Set: return GetDescriptionForSet(scope as ISetScope); + case ScopeKind.ElementScope: return GetDescriptionForElementScope(scope as IElementScope); case ScopeKind.CompiledField: return GetDescriptionForCompiledField(scope as ICompiledFieldScope); case ScopeKind.CompiledProperty: return GetDescriptionForCompiledProperty(scope as ICompiledPropertyScope); - - - case ScopeKind.CompiledConstructor: return GetDescriptionForCompiledConstructor(scope as ICompiledConstructorScope);*/ - + case ScopeKind.CompiledMethod: return GetDescriptionForCompiledMethod(scope as ICompiledMethodScope); + case ScopeKind.Namespace: return GetDescriptionForNamespace(scope as INamespaceScope); + case ScopeKind.Procedure: return GetDescriptionForProcedure(scope as IProcScope); + case ScopeKind.CompiledEvent: return GetDescriptionForCompiledEvent(scope as ICompiledEventScope); + case ScopeKind.CompiledConstructor: return GetDescriptionForCompiledConstructor(scope as ICompiledConstructorScope); + case ScopeKind.ShortString: return GetDescriptionForShortString(scope as IShortStringScope); } return ""; } @@ -1202,9 +1200,14 @@ namespace Languages.SPython.Frontend.Data return ""; switch (scope.Kind) { + case ScopeKind.Delegate: case ScopeKind.Array: + case ScopeKind.Diapason: + case ScopeKind.File: + case ScopeKind.Pointer: case ScopeKind.Enum: case ScopeKind.Set: + case ScopeKind.ShortString: if (scope is ITypeScope && (scope as ITypeScope).Aliased) return scope.Name; break; @@ -1217,25 +1220,26 @@ namespace Languages.SPython.Frontend.Data switch (scope.Kind) { case ScopeKind.Type: return GetSimpleDescriptionForType(scope as ITypeScope); - case ScopeKind.CompiledType: return GetSimpleDescriptionForCompiledType(scope as ICompiledTypeScope, false); + case ScopeKind.CompiledType: return GetSimpleDescriptionForCompiledType(scope as ICompiledTypeScope); case ScopeKind.Delegate: return GetDescriptionForDelegate(scope as IProcType); - case ScopeKind.Procedure: return GetSimpleDescriptionForProcedure(scope as IProcScope); - case ScopeKind.ElementScope: return GetSimpleDescriptionForElementScope(scope as IElementScope); case ScopeKind.TypeSynonim: return GetSimpleSynonimDescription(scope as ITypeSynonimScope); case ScopeKind.Array: return GetDescriptionForArray(scope as IArrayScope); - case ScopeKind.UnitInterface: return GetDescriptionForModule(scope as IInterfaceUnitScope); - case ScopeKind.Namespace: return GetDescriptionForNamespace(scope as INamespaceScope); - case ScopeKind.CompiledMethod: return GetDescriptionForCompiledMethod(scope as ICompiledMethodScope); + case ScopeKind.Diapason: return GetDescriptionForDiapason(scope as IDiapasonScope); + case ScopeKind.File: return GetDescriptionForFile(scope as IFileScope); + case ScopeKind.Pointer: return GetDescriptionForPointer(scope as IPointerScope); case ScopeKind.Enum: return GetDescriptionForEnum(scope as IEnumScope); - - /* case ScopeKind.Set: return GetDescriptionForSet(scope as ISetScope); - + case ScopeKind.ElementScope: return GetSimpleDescriptionForElementScope(scope as IElementScope); case ScopeKind.CompiledField: return GetDescriptionForCompiledField(scope as ICompiledFieldScope); case ScopeKind.CompiledProperty: return GetDescriptionForCompiledProperty(scope as ICompiledPropertyScope); - - - case ScopeKind.CompiledConstructor: return GetDescriptionForCompiledConstructor(scope as ICompiledConstructorScope);*/ + case ScopeKind.CompiledMethod: return GetDescriptionForCompiledMethod(scope as ICompiledMethodScope); + case ScopeKind.Namespace: return GetDescriptionForNamespace(scope as INamespaceScope); + case ScopeKind.Procedure: return GetSimpleDescriptionForProcedure(scope as IProcScope); + case ScopeKind.CompiledEvent: return GetDescriptionForCompiledEvent(scope as ICompiledEventScope); + case ScopeKind.CompiledConstructor: return GetDescriptionForCompiledConstructor(scope as ICompiledConstructorScope); + case ScopeKind.ShortString: return GetDescriptionForShortString(scope as IShortStringScope); + case ScopeKind.UnitInterface: return GetDescriptionForModule(scope as IInterfaceUnitScope); + //case ScopeKind.Procedure : return GetDescriptionForProcedure(scope as IProcScope); } return ""; } @@ -1250,6 +1254,55 @@ namespace Languages.SPython.Frontend.Data return "unit " + scope.Name; } + private string GetDescriptionForFile(IFileScope scope) + { + StringBuilder sb = new StringBuilder(); + sb.Append("file"); + if (scope.ElementType != null) + { + string s = GetSimpleDescription(scope.ElementType); + if (s.Length > 0 && s[0] == '$') s = s.Substring(1, s.Length - 1); + sb.Append("[" + s + "]"); + } + return sb.ToString(); + } + + private string GetDescriptionForSet(ISetScope scope) + { + StringBuilder sb = new StringBuilder(); + + sb.Append("set["); + + if (scope.ElementType != null) + { + string s = GetSimpleDescription(scope.ElementType); + if (s.Length > 0 && s[0] == '$') s = s.Substring(1, s.Length - 1); + sb.Append(s); + } + + sb.Append("]"); + + return sb.ToString(); + } + + private string GetDescriptionForDiapason(IDiapasonScope scope) + { + return scope.Left.ToString() + ".." + scope.Right.ToString(); + } + + private string GetDescriptionForPointer(IPointerScope scope) + { + string s = ""; + if (scope.ElementType != null) + { + s = "^" + GetSimpleDescription(scope.ElementType); + } + else + s = "pointer"; + + return s; + } + private string GetDescriptionForNamespace(INamespaceScope scope) { return "namespace " + scope.Name; diff --git a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonLexer.cs b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonLexer.cs index 07ddec874..ec9c47d0e 100644 --- a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonLexer.cs +++ b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonLexer.cs @@ -1,9 +1,9 @@ // // This CSharp output file generated by Gardens Point LEX // Version: 1.1.3.301 -// Machine: DESKTOP-56159VE -// DateTime: 17.06.2025 14:06:30 -// UserName: ???? +// Machine: DESKTOP-V3E9T2U +// DateTime: 03.09.2025 11:37:43 +// UserName: alex // GPLEX input file // GPLEX frame file // diff --git a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParser.y b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParser.y index bbc9dda99..21d96bf30 100644 --- a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParser.y +++ b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParser.y @@ -66,7 +66,7 @@ %left BINNOT %type ident dotted_ident func_name_ident type_decl_identifier -%type expr proc_func_call const_value variable optional_condition act_param new_expr is_expr variable_as_type +%type extended_expr expr intellisense_dotted_ident proc_func_call const_value variable optional_condition act_param extended_new_expr new_expr is_expr variable_as_type %type act_param_list optional_act_param_list proc_func_decl return_stmt break_stmt continue_stmt global_stmt pass_stmt %type var_stmt assign_stmt if_stmt stmt proc_func_call_stmt while_stmt for_stmt optional_else optional_elif exit_stmt %type expr_list @@ -130,7 +130,7 @@ program ; parts - : tkParseModeExpression expr + : tkParseModeExpression extended_expr { $$ = $2; } | tkParseModeExpression DECLTYPE type_decl_identifier { $$ = $3; } @@ -140,6 +140,28 @@ parts { $$ = $2; } ; +extended_expr + : expr + { + $$ = $1; + } + | extended_new_expr + { + $$ = $1; + } + ; + +extended_new_expr + : new_expr + { + $$ = $1; + } + | NEW type_ref + { + $$ = new new_expr($2, null, false, null, @$); + } + ; + type_decl_identifier : ident { @@ -152,11 +174,11 @@ type_decl_identifier ; variable_as_type - : dotted_ident + : intellisense_dotted_ident { $$ = $1; } - | dotted_ident template_type_params + | intellisense_dotted_ident template_type_params { $$ = new ident_with_templateparams($1 as addressed_value, $2 as template_param_list, @$); } @@ -295,6 +317,17 @@ dotted_ident } ; +// этот нетерминал аналог dotted_identifier из ABCPascal.y +intellisense_dotted_ident + : ident + { + $$ = $1; + } + | intellisense_dotted_ident DOT ident + { + $$ = new dot_node($1 as addressed_value, $3 as addressed_value, @$); + } + ; dotted_ident_list : dotted_ident { @@ -805,14 +838,12 @@ variable // list generator | LBRACKET generator_object RBRACKET { - dot_node dn = new dot_node($2 as addressed_value, (new ident("ToList")) as addressed_value, $2.source_context); - $$ = new method_call(dn as addressed_value, null, $2.source_context); + $$ = new method_call(new ident("list", $2.source_context), new expression_list($2, $2.source_context), $2.source_context); } // set generator | LBRACE generator_object RBRACE { - dot_node dn = new dot_node($2 as addressed_value, (new ident("ToSet")) as addressed_value, $2.source_context); - $$ = new method_call(dn as addressed_value, null, $2.source_context); + $$ = new method_call(new ident("set", $2.source_context), new expression_list($2, $2.source_context), $2.source_context); } // dict generator | LBRACE generator_object_for_dict RBRACE @@ -852,7 +883,7 @@ generator_object_for_dict dict_constant : LBRACE expr_mapping_list RBRACE { - $$ = new method_call(new ident("Dict", @$), $2 as expression_list, @$); + $$ = new method_call(new ident("dict", @$), $2 as expression_list, @$); } | LBRACE RBRACE { @@ -863,7 +894,8 @@ dict_constant set_constant : LBRACE expr_list RBRACE { - $$ = new pascal_set_constant($2 as expression_list, @$); + var acn = new array_const_new($2 as expression_list, '|', @$); + $$ = new method_call(new ident("set", @$), new expression_list(acn, @$), @$); } ; @@ -871,8 +903,7 @@ list_constant : LBRACKET expr_list RBRACKET { var acn = new array_const_new($2 as expression_list, '|', @$); - var dn = new dot_node(acn as addressed_value, (new ident("ToList", @$)) as addressed_value, @$); - $$ = new method_call(dn as addressed_value, null, @$); + $$ = new method_call(new ident("list", @$), new expression_list(acn, @$), @$); } | LBRACKET RBRACKET { diff --git a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParserYacc.cs b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParserYacc.cs index fb50a6ecd..273a4127d 100644 --- a/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParserYacc.cs +++ b/LanguagePlugins/SPython/SPythonParserKrylovMovchan/SPythonParserYacc.cs @@ -3,9 +3,9 @@ // (see accompanying GPPGcopyright.rtf) // GPPG version 1.3.6 -// Machine: DESKTOP-56159VE -// DateTime: 17.06.2025 14:06:30 -// UserName: ???? +// Machine: DESKTOP-V3E9T2U +// DateTime: 14.09.2025 15:38:38 +// UserName: alex // Input file // options: no-lines gplex @@ -81,18 +81,19 @@ public partial class SPythonGPPGParser: ShiftReduceParser aliasses; #pragma warning restore 649 - private static Rule[] rules = new Rule[182]; - private static State[] states = new State[337]; + private static Rule[] rules = new Rule[188]; + private static State[] states = new State[345]; private static string[] nonTerms = new string[] { - "ident", "dotted_ident", "func_name_ident", "type_decl_identifier", "expr", - "proc_func_call", "const_value", "variable", "optional_condition", "act_param", - "new_expr", "is_expr", "variable_as_type", "act_param_list", "optional_act_param_list", - "proc_func_decl", "return_stmt", "break_stmt", "continue_stmt", "global_stmt", - "pass_stmt", "var_stmt", "assign_stmt", "if_stmt", "stmt", "proc_func_call_stmt", - "while_stmt", "for_stmt", "optional_else", "optional_elif", "exit_stmt", - "expr_list", "stmt_list", "block", "program", "param_name", "form_param_sect", - "form_param_list", "optional_form_param_list", "dotted_ident_list", "ident_as_ident", - "ident_as_ident_list", "ident_list", "proc_func_header", "type_ref", "simple_type_identifier", + "ident", "dotted_ident", "func_name_ident", "type_decl_identifier", "extended_expr", + "expr", "intellisense_dotted_ident", "proc_func_call", "const_value", "variable", + "optional_condition", "act_param", "extended_new_expr", "new_expr", "is_expr", + "variable_as_type", "act_param_list", "optional_act_param_list", "proc_func_decl", + "return_stmt", "break_stmt", "continue_stmt", "global_stmt", "pass_stmt", + "var_stmt", "assign_stmt", "if_stmt", "stmt", "proc_func_call_stmt", "while_stmt", + "for_stmt", "optional_else", "optional_elif", "exit_stmt", "expr_list", + "stmt_list", "block", "program", "param_name", "form_param_sect", "form_param_list", + "optional_form_param_list", "dotted_ident_list", "ident_as_ident", "ident_as_ident_list", + "ident_list", "proc_func_header", "type_ref", "simple_type_identifier", "template_type", "import_clause", "template_type_params", "template_param_list", "parts", "stmt_or_expression", "expr_mapping_list", "optional_semicolon", "end_of_line", "variable_list", "assign_type", "expr_mapping", "list_constant", @@ -100,525 +101,539 @@ public partial class SPythonGPPGParser: ShiftReduceParser tkParseModeExpression, expr + case 4: // parts -> tkParseModeExpression, extended_expr { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].ex; } break; case 5: // parts -> tkParseModeExpression, DECLTYPE, type_decl_identifier @@ -673,243 +688,273 @@ public partial class SPythonGPPGParser: ShiftReduceParser tkParseModeStatement, stmt_or_expression { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 8: // type_decl_identifier -> ident + case 8: // extended_expr -> expr +{ + CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; + } + break; + case 9: // extended_expr -> extended_new_expr +{ + CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; + } + break; + case 10: // extended_new_expr -> new_expr +{ + CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; + } + break; + case 11: // extended_new_expr -> NEW, type_ref +{ + CurrentSemanticValue.ex = new new_expr(ValueStack[ValueStack.Depth-1].td, null, false, null, CurrentLocationSpan); + } + break; + case 12: // type_decl_identifier -> ident { CurrentSemanticValue.id = ValueStack[ValueStack.Depth-1].id; } break; - case 9: // type_decl_identifier -> ident, template_type_params + case 13: // type_decl_identifier -> ident, template_type_params { CurrentSemanticValue.id = new template_type_name(ValueStack[ValueStack.Depth-2].id.name, ValueStack[ValueStack.Depth-1].stn as ident_list, CurrentLocationSpan); } break; - case 10: // variable_as_type -> dotted_ident + case 14: // variable_as_type -> intellisense_dotted_ident { - CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].id; + CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 11: // variable_as_type -> dotted_ident, template_type_params + case 15: // variable_as_type -> intellisense_dotted_ident, template_type_params { - CurrentSemanticValue.ex = new ident_with_templateparams(ValueStack[ValueStack.Depth-2].id as addressed_value, ValueStack[ValueStack.Depth-1].stn as template_param_list, CurrentLocationSpan); + CurrentSemanticValue.ex = new ident_with_templateparams(ValueStack[ValueStack.Depth-2].ex as addressed_value, ValueStack[ValueStack.Depth-1].stn as template_param_list, CurrentLocationSpan); } break; - case 12: // stmt_or_expression -> expr + case 16: // stmt_or_expression -> expr { CurrentSemanticValue.stn = new expression_as_statement(ValueStack[ValueStack.Depth-1].ex,CurrentLocationSpan);} break; - case 13: // stmt_or_expression -> assign_stmt + case 17: // stmt_or_expression -> assign_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 14: // stmt_or_expression -> var_stmt + case 18: // stmt_or_expression -> var_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 15: // stmt_list -> stmt + case 19: // stmt_list -> stmt { CurrentSemanticValue.stn = new statement_list(ValueStack[ValueStack.Depth-1].stn as statement, CurrentLocationSpan); } break; - case 16: // stmt_list -> stmt_list, end_of_line, stmt + case 20: // stmt_list -> stmt_list, end_of_line, stmt { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as statement_list).Add(ValueStack[ValueStack.Depth-1].stn as statement, CurrentLocationSpan); } break; - case 17: // stmt -> assign_stmt + case 21: // stmt -> assign_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 18: // stmt -> var_stmt + case 22: // stmt -> var_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 19: // stmt -> if_stmt + case 23: // stmt -> if_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 20: // stmt -> proc_func_call_stmt + case 24: // stmt -> proc_func_call_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 21: // stmt -> while_stmt + case 25: // stmt -> while_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 22: // stmt -> for_stmt + case 26: // stmt -> for_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 23: // stmt -> return_stmt + case 27: // stmt -> return_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 24: // stmt -> break_stmt + case 28: // stmt -> break_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 25: // stmt -> continue_stmt + case 29: // stmt -> continue_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 26: // stmt -> global_stmt + case 30: // stmt -> global_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 27: // stmt -> pass_stmt + case 31: // stmt -> pass_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 28: // stmt -> exit_stmt + case 32: // stmt -> exit_stmt { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 29: // stmt -> proc_func_decl + case 33: // stmt -> proc_func_decl { CurrentSemanticValue.stn = new declarations_as_statement(new declarations(ValueStack[ValueStack.Depth-1].stn as procedure_definition, CurrentLocationSpan), CurrentLocationSpan); } break; - case 30: // stmt -> import_clause + case 34: // stmt -> import_clause { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 31: // import_clause -> IMPORT, ident_as_ident_list + case 35: // import_clause -> IMPORT, ident_as_ident_list { CurrentSemanticValue.stn = new import_statement(ValueStack[ValueStack.Depth-1].stn as as_statement_list, CurrentLocationSpan); } break; - case 32: // import_clause -> FROM, ident, IMPORT, ident_as_ident_list + case 36: // import_clause -> FROM, ident, IMPORT, ident_as_ident_list { CurrentSemanticValue.stn = new from_import_statement(ValueStack[ValueStack.Depth-3].id as ident, false, ValueStack[ValueStack.Depth-1].stn as as_statement_list, CurrentLocationSpan); } break; - case 33: // import_clause -> FROM, ident, IMPORT, STAR + case 37: // import_clause -> FROM, ident, IMPORT, STAR { CurrentSemanticValue.stn = new from_import_statement(ValueStack[ValueStack.Depth-3].id as ident, true, null, CurrentLocationSpan); } break; - case 34: // pass_stmt -> PASS + case 38: // pass_stmt -> PASS { CurrentSemanticValue.stn = new empty_statement(); } break; - case 35: // exit_stmt -> EXIT, LPAR, optional_act_param_list, RPAR + case 39: // exit_stmt -> EXIT, LPAR, optional_act_param_list, RPAR { parserTools.AddErrorFromResource("UNSUPPORTED_CONSTRUCTION_{0}", CurrentLocationSpan, "exit"); } break; - case 36: // global_stmt -> GLOBAL, dotted_ident_list + case 40: // global_stmt -> GLOBAL, dotted_ident_list { CurrentSemanticValue.stn = new global_statement(ValueStack[ValueStack.Depth-1].stn as ident_list, CurrentLocationSpan); } break; - case 37: // ident -> ID + case 41: // ident -> ID { CurrentSemanticValue.id = ValueStack[ValueStack.Depth-1].id; } break; - case 38: // dotted_ident -> ident + case 42: // dotted_ident -> ident { CurrentSemanticValue.id = ValueStack[ValueStack.Depth-1].id; } break; - case 39: // dotted_ident -> dotted_ident, DOT, ident + case 43: // dotted_ident -> dotted_ident, DOT, ident { CurrentSemanticValue.id = new ident(ValueStack[ValueStack.Depth-3].id.name + "." + ValueStack[ValueStack.Depth-1].id.name, CurrentLocationSpan); } break; - case 40: // dotted_ident_list -> dotted_ident + case 44: // intellisense_dotted_ident -> ident +{ + CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].id; + } + break; + case 45: // intellisense_dotted_ident -> intellisense_dotted_ident, DOT, ident +{ + CurrentSemanticValue.ex = new dot_node(ValueStack[ValueStack.Depth-3].ex as addressed_value, ValueStack[ValueStack.Depth-1].id as addressed_value, CurrentLocationSpan); + } + break; + case 46: // dotted_ident_list -> dotted_ident { CurrentSemanticValue.stn = new ident_list(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 41: // dotted_ident_list -> dotted_ident_list, COMMA, dotted_ident + case 47: // dotted_ident_list -> dotted_ident_list, COMMA, dotted_ident { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as ident_list).Add(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 42: // ident_as_ident -> ident, AS, ident + case 48: // ident_as_ident -> ident, AS, ident { CurrentSemanticValue.stn = new as_statement(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 43: // ident_as_ident -> ident + case 49: // ident_as_ident -> ident { CurrentSemanticValue.stn = new as_statement(ValueStack[ValueStack.Depth-1].id, ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 44: // ident_as_ident_list -> ident_as_ident + case 50: // ident_as_ident_list -> ident_as_ident { CurrentSemanticValue.stn = new as_statement_list(ValueStack[ValueStack.Depth-1].stn as as_statement, CurrentLocationSpan); } break; - case 45: // ident_as_ident_list -> ident_as_ident_list, COMMA, ident_as_ident + case 51: // ident_as_ident_list -> ident_as_ident_list, COMMA, ident_as_ident { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as as_statement_list).Add(ValueStack[ValueStack.Depth-1].stn as as_statement, CurrentLocationSpan); } break; - case 46: // expr_mapping -> expr, COLON, expr + case 52: // expr_mapping -> expr, COLON, expr { expression_list el = new expression_list(new List { ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex }, CurrentLocationSpan); CurrentSemanticValue.ex = new tuple_node(el, CurrentLocationSpan); } break; - case 47: // expr_mapping_list -> expr_mapping + case 53: // expr_mapping_list -> expr_mapping { CurrentSemanticValue.stn = new expression_list(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 48: // expr_mapping_list -> expr_mapping_list, COMMA, expr_mapping + case 54: // expr_mapping_list -> expr_mapping_list, COMMA, expr_mapping { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as expression_list).Add(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 49: // var_stmt -> variable, COLON, type_ref + case 55: // var_stmt -> variable, COLON, type_ref { var vds = new var_def_statement(new ident_list(ValueStack[ValueStack.Depth-3].ex as ident, LocationStack[LocationStack.Depth-3]), ValueStack[ValueStack.Depth-1].td, null, definition_attribute.None, false, CurrentLocationSpan); CurrentSemanticValue.stn = new var_statement(vds, CurrentLocationSpan); } break; - case 50: // var_stmt -> variable, COLON, type_ref, ASSIGN, expr + case 56: // var_stmt -> variable, COLON, type_ref, ASSIGN, expr { var vds = new var_def_statement(new ident_list(ValueStack[ValueStack.Depth-5].ex as ident, LocationStack[LocationStack.Depth-5]), ValueStack[ValueStack.Depth-3].td, ValueStack[ValueStack.Depth-1].ex, definition_attribute.None, false, CurrentLocationSpan); CurrentSemanticValue.stn = new var_statement(vds, CurrentLocationSpan); } break; - case 51: // assign_right_part -> expr + case 57: // assign_right_part -> expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 52: // assign_right_part -> turbo_tuple_expr + case 58: // assign_right_part -> turbo_tuple_expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 53: // assign_stmt -> variable, ASSIGN, assign_right_part + case 59: // assign_stmt -> variable, ASSIGN, assign_right_part { if (!(ValueStack[ValueStack.Depth-3].ex is addressed_value)) parserTools.AddErrorFromResource("LEFT_SIDE_CANNOT_BE_ASSIGNED_TO", CurrentLocationSpan); CurrentSemanticValue.stn = new assign(ValueStack[ValueStack.Depth-3].ex as addressed_value, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 54: // assign_stmt -> variable, assign_type, assign_right_part + case 60: // assign_stmt -> variable, assign_type, assign_right_part { if (!(ValueStack[ValueStack.Depth-3].ex is addressed_value)) parserTools.AddErrorFromResource("LEFT_SIDE_CANNOT_BE_ASSIGNED_TO", CurrentLocationSpan); CurrentSemanticValue.stn = new assign(ValueStack[ValueStack.Depth-3].ex as addressed_value, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 55: // assign_stmt -> LPAR, variable, COMMA, variable_list, RPAR, ASSIGN, + case 61: // assign_stmt -> LPAR, variable, COMMA, variable_list, RPAR, ASSIGN, // assign_right_part { // if False: @@ -920,7 +965,7 @@ public partial class SPythonGPPGParser: ShiftReduceParser variable, COMMA, variable_list, ASSIGN, assign_right_part + case 62: // assign_stmt -> variable, COMMA, variable_list, ASSIGN, assign_right_part { // if False: if (ValueStack[ValueStack.Depth-2].op.type != Operators.Assignment) @@ -930,220 +975,220 @@ public partial class SPythonGPPGParser: ShiftReduceParser PLUSEQUAL + case 63: // assign_type -> PLUSEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 58: // assign_type -> MINUSEQUAL + case 64: // assign_type -> MINUSEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 59: // assign_type -> STAREQUAL + case 65: // assign_type -> STAREQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 60: // assign_type -> DIVEQUAL + case 66: // assign_type -> DIVEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 61: // assign_type -> BINXOREQUAL + case 67: // assign_type -> BINXOREQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 62: // assign_type -> SHLEQUAL + case 68: // assign_type -> SHLEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 63: // assign_type -> SHREQUAL + case 69: // assign_type -> SHREQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 64: // assign_type -> BINANDEQUAL + case 70: // assign_type -> BINANDEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 65: // assign_type -> BINOREQUAL + case 71: // assign_type -> BINOREQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 66: // assign_type -> INTDIVISIONEQUAL + case 72: // assign_type -> INTDIVISIONEQUAL { CurrentSemanticValue.op = ValueStack[ValueStack.Depth-1].op; } break; - case 67: // expr -> expr, IF, expr, ELSE, expr + case 73: // expr -> expr, IF, expr, ELSE, expr { CurrentSemanticValue.ex = new question_colon_expression(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-5].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 68: // expr -> expr, PLUS, expr + case 74: // expr -> expr, PLUS, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 69: // expr -> expr, STAR, expr + case 75: // expr -> expr, STAR, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 70: // expr -> expr, DIVIDE, expr + case 76: // expr -> expr, DIVIDE, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 71: // expr -> expr, MINUS, expr + case 77: // expr -> expr, MINUS, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 72: // expr -> expr, LESS, expr + case 78: // expr -> expr, LESS, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 73: // expr -> expr, GREATER, expr + case 79: // expr -> expr, GREATER, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 74: // expr -> expr, LESSEQUAL, expr + case 80: // expr -> expr, LESSEQUAL, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 75: // expr -> expr, GREATEREQUAL, expr + case 81: // expr -> expr, GREATEREQUAL, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 76: // expr -> expr, EQUAL, expr + case 82: // expr -> expr, EQUAL, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 77: // expr -> expr, NOTEQUAL, expr + case 83: // expr -> expr, NOTEQUAL, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 78: // expr -> expr, AND, expr + case 84: // expr -> expr, AND, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 79: // expr -> expr, OR, expr + case 85: // expr -> expr, OR, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 80: // expr -> expr, SLASHSLASH, expr + case 86: // expr -> expr, SLASHSLASH, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 81: // expr -> expr, PERCENTAGE, expr + case 87: // expr -> expr, PERCENTAGE, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 82: // expr -> expr, SHL, expr + case 88: // expr -> expr, SHL, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 83: // expr -> expr, SHR, expr + case 89: // expr -> expr, SHR, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 84: // expr -> expr, BINAND, expr + case 90: // expr -> expr, BINAND, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 85: // expr -> expr, BINOR, expr + case 91: // expr -> expr, BINOR, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 86: // expr -> expr, BINXOR, expr + case 92: // expr -> expr, BINXOR, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 87: // expr -> expr, STARSTAR, expr + case 93: // expr -> expr, STARSTAR, expr { addressed_value method_name = new ident("!pow", CurrentLocationSpan); expression_list el = new expression_list(new List { ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex }, CurrentLocationSpan); CurrentSemanticValue.ex = new method_call(method_name, el, CurrentLocationSpan); } break; - case 88: // expr -> expr, IN, expr + case 94: // expr -> expr, IN, expr { CurrentSemanticValue.ex = new bin_expr(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].ex, Operators.In, CurrentLocationSpan); } break; - case 89: // expr -> expr, NOT, IN, expr + case 95: // expr -> expr, NOT, IN, expr { // $$ = new bin_expr($1, $4, Operators.NotIn, @$); CurrentSemanticValue.ex = new un_expr(new bin_expr(ValueStack[ValueStack.Depth-4].ex, ValueStack[ValueStack.Depth-1].ex, Operators.In, CurrentLocationSpan),Operators.LogicalNOT,CurrentLocationSpan); } break; - case 90: // expr -> MINUS, expr + case 96: // expr -> MINUS, expr { CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 91: // expr -> NOT, expr + case 97: // expr -> NOT, expr { CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 92: // expr -> BINNOT, expr + case 98: // expr -> BINNOT, expr { CurrentSemanticValue.ex = new un_expr(ValueStack[ValueStack.Depth-1].ex, ValueStack[ValueStack.Depth-2].op.type, CurrentLocationSpan); } break; - case 93: // expr -> variable + case 99: // expr -> variable { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 94: // expr -> const_value + case 100: // expr -> const_value { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 95: // expr -> new_expr + case 101: // expr -> new_expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 96: // expr -> is_expr + case 102: // expr -> is_expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 97: // expr -> tuple_expr + case 103: // expr -> tuple_expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 98: // expr -> LPAR, expr, RPAR + case 104: // expr -> LPAR, expr, RPAR { CurrentSemanticValue.ex = new bracket_expr(ValueStack[ValueStack.Depth-2].ex, CurrentLocationSpan); } break; - case 99: // tuple_expr -> LPAR, expr, COMMA, expr_list, RPAR + case 105: // tuple_expr -> LPAR, expr, COMMA, expr_list, RPAR { // inherited from PABC if ((ValueStack[ValueStack.Depth-2].stn as expression_list).Count > 6) @@ -1152,7 +1197,7 @@ public partial class SPythonGPPGParser: ShiftReduceParser expr, COMMA, expr_list + case 106: // turbo_tuple_expr -> expr, COMMA, expr_list { // inherited from PABC if ((ValueStack[ValueStack.Depth-1].stn as expression_list).Count > 6) @@ -1161,97 +1206,97 @@ public partial class SPythonGPPGParser: ShiftReduceParser variable, IS, type_ref + case 107: // is_expr -> variable, IS, type_ref { CurrentSemanticValue.ex = parserTools.NewAsIsExpr(ValueStack[ValueStack.Depth-3].ex, op_typecast.is_op, ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); } break; - case 102: // new_expr -> NEW, type_ref, LPAR, optional_act_param_list, RPAR + case 108: // new_expr -> NEW, type_ref, LPAR, optional_act_param_list, RPAR { CurrentSemanticValue.ex = new new_expr(ValueStack[ValueStack.Depth-4].td, ValueStack[ValueStack.Depth-2].stn as expression_list, false, null, CurrentLocationSpan); } break; - case 103: // const_value -> INTNUM + case 109: // const_value -> INTNUM { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 104: // const_value -> REALNUM + case 110: // const_value -> REALNUM { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 105: // const_value -> TRUE + case 111: // const_value -> TRUE { CurrentSemanticValue.ex = new ident("true", CurrentLocationSpan); } break; - case 106: // const_value -> FALSE + case 112: // const_value -> FALSE { CurrentSemanticValue.ex = new ident("false", CurrentLocationSpan); } break; - case 107: // const_value -> STRINGNUM + case 113: // const_value -> STRINGNUM { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].stn as literal; } break; - case 108: // const_value -> FSTRINGNUM + case 114: // const_value -> FSTRINGNUM { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 109: // const_value -> BIGINT + case 115: // const_value -> BIGINT { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 110: // expr_list -> expr + case 116: // expr_list -> expr { CurrentSemanticValue.stn = new expression_list(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 111: // expr_list -> expr_list, COMMA, expr + case 117: // expr_list -> expr_list, COMMA, expr { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as expression_list).Add(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 112: // if_stmt -> IF, expr, COLON, block, optional_elif + case 118: // if_stmt -> IF, expr, COLON, block, optional_elif { CurrentSemanticValue.stn = new if_node(ValueStack[ValueStack.Depth-4].ex, ValueStack[ValueStack.Depth-2].stn as statement, ValueStack[ValueStack.Depth-1].stn as statement, CurrentLocationSpan); } break; - case 113: // optional_elif -> ELIF, expr, COLON, block, optional_elif + case 119: // optional_elif -> ELIF, expr, COLON, block, optional_elif { CurrentSemanticValue.stn = new if_node(ValueStack[ValueStack.Depth-4].ex, ValueStack[ValueStack.Depth-2].stn as statement, ValueStack[ValueStack.Depth-1].stn as statement, CurrentLocationSpan); } break; - case 114: // optional_elif -> optional_else + case 120: // optional_elif -> optional_else { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 115: // optional_else -> ELSE, COLON, block + case 121: // optional_else -> ELSE, COLON, block { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 116: // optional_else -> /* empty */ + case 122: // optional_else -> /* empty */ { CurrentSemanticValue.stn = null; } break; - case 117: // while_stmt -> WHILE, expr, COLON, block + case 123: // while_stmt -> WHILE, expr, COLON, block { CurrentSemanticValue.stn = new while_node(ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].stn as statement, WhileCycleType.While, CurrentLocationSpan); } break; - case 118: // for_stmt -> FOR, ident, IN, expr, COLON, block + case 124: // for_stmt -> FOR, ident, IN, expr, COLON, block { CurrentSemanticValue.stn = new foreach_stmt(ValueStack[ValueStack.Depth-5].id, new no_type_foreach(), ValueStack[ValueStack.Depth-3].ex, ValueStack[ValueStack.Depth-1].stn as statement, null, CurrentLocationSpan); } break; - case 119: // for_stmt -> FOR, ident, COMMA, ident_list, IN, expr, COLON, block + case 125: // for_stmt -> FOR, ident, COMMA, ident_list, IN, expr, COLON, block { (ValueStack[ValueStack.Depth-5].stn as ident_list).AddFirst(ValueStack[ValueStack.Depth-7].id); var id = parserTools.NewId("#fe",LocationStack[LocationStack.Depth-5]); @@ -1263,166 +1308,164 @@ public partial class SPythonGPPGParser: ShiftReduceParser ident + case 126: // ident_list -> ident { CurrentSemanticValue.stn = new ident_list(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 121: // ident_list -> ident_list, COMMA, ident + case 127: // ident_list -> ident_list, COMMA, ident { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as ident_list).Add(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 122: // func_name_ident -> ident + case 128: // func_name_ident -> ident { CurrentSemanticValue.id = ValueStack[ValueStack.Depth-1].id; } break; - case 123: // return_stmt -> RETURN, assign_right_part + case 129: // return_stmt -> RETURN, assign_right_part { CurrentSemanticValue.stn = new return_statement(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 124: // return_stmt -> RETURN + case 130: // return_stmt -> RETURN { CurrentSemanticValue.stn = new return_statement(null, CurrentLocationSpan); } break; - case 125: // break_stmt -> BREAK + case 131: // break_stmt -> BREAK { CurrentSemanticValue.stn = new procedure_call(new ident("break", CurrentLocationSpan), true, CurrentLocationSpan); } break; - case 126: // continue_stmt -> CONTINUE + case 132: // continue_stmt -> CONTINUE { CurrentSemanticValue.stn = new procedure_call(new ident("continue", CurrentLocationSpan), true, CurrentLocationSpan); } break; - case 127: // proc_func_call_stmt -> proc_func_call + case 133: // proc_func_call_stmt -> proc_func_call { CurrentSemanticValue.stn = new procedure_call(ValueStack[ValueStack.Depth-1].ex as addressed_value, ValueStack[ValueStack.Depth-1].ex is ident, CurrentLocationSpan); } break; - case 128: // variable -> ident + case 134: // variable -> ident { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].id; } break; - case 129: // variable -> proc_func_call + case 135: // variable -> proc_func_call { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 130: // variable -> variable, DOT, ident + case 136: // variable -> variable, DOT, ident { CurrentSemanticValue.ex = new dot_node(ValueStack[ValueStack.Depth-3].ex as addressed_value, ValueStack[ValueStack.Depth-1].id as addressed_value, CurrentLocationSpan); } break; - case 131: // variable -> const_value, DOT, ident + case 137: // variable -> const_value, DOT, ident { CurrentSemanticValue.ex = new dot_node(ValueStack[ValueStack.Depth-3].ex as addressed_value, ValueStack[ValueStack.Depth-1].id as addressed_value, CurrentLocationSpan); } break; - case 132: // variable -> list_constant + case 138: // variable -> list_constant { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 133: // variable -> set_constant + case 139: // variable -> set_constant { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 134: // variable -> dict_constant + case 140: // variable -> dict_constant { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 135: // variable -> variable, LBRACKET, expr, RBRACKET + case 141: // variable -> variable, LBRACKET, expr, RBRACKET { var el = new expression_list(ValueStack[ValueStack.Depth-2].ex as expression, CurrentLocationSpan); CurrentSemanticValue.ex = new indexer(ValueStack[ValueStack.Depth-4].ex as addressed_value, el, CurrentLocationSpan); } break; - case 136: // variable -> LBRACKET, generator_object, RBRACKET + case 142: // variable -> LBRACKET, generator_object, RBRACKET { - dot_node dn = new dot_node(ValueStack[ValueStack.Depth-2].ex as addressed_value, (new ident("ToList")) as addressed_value, ValueStack[ValueStack.Depth-2].ex.source_context); - CurrentSemanticValue.ex = new method_call(dn as addressed_value, null, ValueStack[ValueStack.Depth-2].ex.source_context); + CurrentSemanticValue.ex = new method_call(new ident("list", ValueStack[ValueStack.Depth-2].ex.source_context), new expression_list(ValueStack[ValueStack.Depth-2].ex, ValueStack[ValueStack.Depth-2].ex.source_context), ValueStack[ValueStack.Depth-2].ex.source_context); } break; - case 137: // variable -> LBRACE, generator_object, RBRACE + case 143: // variable -> LBRACE, generator_object, RBRACE { - dot_node dn = new dot_node(ValueStack[ValueStack.Depth-2].ex as addressed_value, (new ident("ToSet")) as addressed_value, ValueStack[ValueStack.Depth-2].ex.source_context); - CurrentSemanticValue.ex = new method_call(dn as addressed_value, null, ValueStack[ValueStack.Depth-2].ex.source_context); + CurrentSemanticValue.ex = new method_call(new ident("set", ValueStack[ValueStack.Depth-2].ex.source_context), new expression_list(ValueStack[ValueStack.Depth-2].ex, ValueStack[ValueStack.Depth-2].ex.source_context), ValueStack[ValueStack.Depth-2].ex.source_context); } break; - case 138: // variable -> LBRACE, generator_object_for_dict, RBRACE + case 144: // variable -> LBRACE, generator_object_for_dict, RBRACE { dot_node dn = new dot_node(ValueStack[ValueStack.Depth-2].ex as addressed_value, (new ident("ToDictionary")) as addressed_value, ValueStack[ValueStack.Depth-2].ex.source_context); CurrentSemanticValue.ex = new method_call(dn as addressed_value, null, ValueStack[ValueStack.Depth-2].ex.source_context); } break; - case 139: // variable_list -> variable + case 145: // variable_list -> variable { CurrentSemanticValue.ob = new addressed_value_list(ValueStack[ValueStack.Depth-1].ex as addressed_value,LocationStack[LocationStack.Depth-1]); } break; - case 140: // variable_list -> variable_list, COMMA, variable + case 146: // variable_list -> variable_list, COMMA, variable { (ValueStack[ValueStack.Depth-3].ob as addressed_value_list).Add(ValueStack[ValueStack.Depth-1].ex as addressed_value); (ValueStack[ValueStack.Depth-3].ob as syntax_tree_node).source_context = LexLocation.MergeAll(LocationStack[LocationStack.Depth-3],LocationStack[LocationStack.Depth-2],LocationStack[LocationStack.Depth-1]); CurrentSemanticValue.ob = ValueStack[ValueStack.Depth-3].ob; } break; - case 141: // generator_object -> expr, FOR, ident, IN, expr, optional_condition + case 147: // generator_object -> expr, FOR, ident, IN, expr, optional_condition { CurrentSemanticValue.ex = new generator_object(ValueStack[ValueStack.Depth-6].ex, ValueStack[ValueStack.Depth-4].id, ValueStack[ValueStack.Depth-2].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 142: // generator_object_for_dict -> expr_mapping, FOR, ident, IN, expr, + case 148: // generator_object_for_dict -> expr_mapping, FOR, ident, IN, expr, // optional_condition { CurrentSemanticValue.ex = new generator_object(ValueStack[ValueStack.Depth-6].ex, ValueStack[ValueStack.Depth-4].id, ValueStack[ValueStack.Depth-2].ex, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 143: // dict_constant -> LBRACE, expr_mapping_list, RBRACE + case 149: // dict_constant -> LBRACE, expr_mapping_list, RBRACE { - CurrentSemanticValue.ex = new method_call(new ident("Dict", CurrentLocationSpan), ValueStack[ValueStack.Depth-2].stn as expression_list, CurrentLocationSpan); + CurrentSemanticValue.ex = new method_call(new ident("dict", CurrentLocationSpan), ValueStack[ValueStack.Depth-2].stn as expression_list, CurrentLocationSpan); } break; - case 144: // dict_constant -> LBRACE, RBRACE + case 150: // dict_constant -> LBRACE, RBRACE { CurrentSemanticValue.ex = new method_call(new ident("!empty_dict", CurrentLocationSpan), null, CurrentLocationSpan); } break; - case 145: // set_constant -> LBRACE, expr_list, RBRACE -{ - CurrentSemanticValue.ex = new pascal_set_constant(ValueStack[ValueStack.Depth-2].stn as expression_list, CurrentLocationSpan); - } - break; - case 146: // list_constant -> LBRACKET, expr_list, RBRACKET + case 151: // set_constant -> LBRACE, expr_list, RBRACE { var acn = new array_const_new(ValueStack[ValueStack.Depth-2].stn as expression_list, '|', CurrentLocationSpan); - var dn = new dot_node(acn as addressed_value, (new ident("ToList", CurrentLocationSpan)) as addressed_value, CurrentLocationSpan); - CurrentSemanticValue.ex = new method_call(dn as addressed_value, null, CurrentLocationSpan); + CurrentSemanticValue.ex = new method_call(new ident("set", CurrentLocationSpan), new expression_list(acn, CurrentLocationSpan), CurrentLocationSpan); } break; - case 147: // list_constant -> LBRACKET, RBRACKET + case 152: // list_constant -> LBRACKET, expr_list, RBRACKET +{ + var acn = new array_const_new(ValueStack[ValueStack.Depth-2].stn as expression_list, '|', CurrentLocationSpan); + CurrentSemanticValue.ex = new method_call(new ident("list", CurrentLocationSpan), new expression_list(acn, CurrentLocationSpan), CurrentLocationSpan); + } + break; + case 153: // list_constant -> LBRACKET, RBRACKET { CurrentSemanticValue.ex = new method_call(new ident("!empty_list", CurrentLocationSpan), null, CurrentLocationSpan); } break; - case 148: // optional_condition -> /* empty */ + case 154: // optional_condition -> /* empty */ { CurrentSemanticValue.ex = null; } break; - case 149: // optional_condition -> IF, expr + case 155: // optional_condition -> IF, expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 150: // block -> INDENT, stmt_list, end_of_line, UNINDENT + case 156: // block -> INDENT, stmt_list, end_of_line, UNINDENT { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-3].stn as statement_list; (CurrentSemanticValue.stn as statement_list).left_logical_bracket = ValueStack[ValueStack.Depth-4].ti; @@ -1430,161 +1473,161 @@ public partial class SPythonGPPGParser: ShiftReduceParser proc_func_header, block + case 157: // proc_func_decl -> proc_func_header, block { CurrentSemanticValue.stn = new procedure_definition(ValueStack[ValueStack.Depth-2].td as procedure_header, new block(null, ValueStack[ValueStack.Depth-1].stn as statement_list, LocationStack[LocationStack.Depth-1]), CurrentLocationSpan); } break; - case 152: // proc_func_header -> DEF, func_name_ident, LPAR, optional_form_param_list, RPAR, + case 158: // proc_func_header -> DEF, func_name_ident, LPAR, optional_form_param_list, RPAR, // COLON { CurrentSemanticValue.td = new procedure_header(ValueStack[ValueStack.Depth-3].stn as formal_parameters, new procedure_attributes_list(new List()), new method_name(null,null, ValueStack[ValueStack.Depth-5].id, null, LocationStack[LocationStack.Depth-5]), null, CurrentLocationSpan); } break; - case 153: // proc_func_header -> DEF, func_name_ident, LPAR, optional_form_param_list, RPAR, + case 159: // proc_func_header -> DEF, func_name_ident, LPAR, optional_form_param_list, RPAR, // ARROW, type_ref, COLON { CurrentSemanticValue.td = new function_header(ValueStack[ValueStack.Depth-5].stn as formal_parameters, new procedure_attributes_list(new List()), new method_name(null,null, ValueStack[ValueStack.Depth-7].id, null, LocationStack[LocationStack.Depth-7]), null, ValueStack[ValueStack.Depth-2].td as type_definition, CurrentLocationSpan); } break; - case 154: // proc_func_call -> variable, LPAR, optional_act_param_list, RPAR + case 160: // proc_func_call -> variable, LPAR, optional_act_param_list, RPAR { CurrentSemanticValue.ex = new method_call(ValueStack[ValueStack.Depth-4].ex as addressed_value, ValueStack[ValueStack.Depth-2].stn as expression_list, CurrentLocationSpan); } break; - case 155: // simple_type_identifier -> ident + case 161: // simple_type_identifier -> ident { CurrentSemanticValue.td = new named_type_reference(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 156: // simple_type_identifier -> simple_type_identifier, DOT, ident + case 162: // simple_type_identifier -> simple_type_identifier, DOT, ident { CurrentSemanticValue.td = (ValueStack[ValueStack.Depth-3].td as named_type_reference).Add(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 157: // type_ref -> simple_type_identifier + case 163: // type_ref -> simple_type_identifier { CurrentSemanticValue.td = ValueStack[ValueStack.Depth-1].td as named_type_reference; } break; - case 158: // type_ref -> template_type + case 164: // type_ref -> template_type { CurrentSemanticValue.td = ValueStack[ValueStack.Depth-1].td; } break; - case 159: // template_type -> simple_type_identifier, template_type_params + case 165: // template_type -> simple_type_identifier, template_type_params { CurrentSemanticValue.td = new template_type_reference(ValueStack[ValueStack.Depth-2].td as named_type_reference, ValueStack[ValueStack.Depth-1].stn as template_param_list, CurrentLocationSpan); } break; - case 160: // template_type_params -> LBRACKET, template_param_list, RBRACKET + case 166: // template_type_params -> LBRACKET, template_param_list, RBRACKET { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-2].stn; CurrentSemanticValue.stn.source_context = CurrentLocationSpan; } break; - case 161: // template_param_list -> type_ref + case 167: // template_param_list -> type_ref { CurrentSemanticValue.stn = new template_param_list(ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); } break; - case 162: // template_param_list -> template_param_list, COMMA, type_ref + case 168: // template_param_list -> template_param_list, COMMA, type_ref { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as template_param_list).Add(ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); } break; - case 163: // param_name -> ident + case 169: // param_name -> ident { CurrentSemanticValue.stn = new ident_list(ValueStack[ValueStack.Depth-1].id, CurrentLocationSpan); } break; - case 164: // form_param_sect -> param_name, COLON, type_ref + case 170: // form_param_sect -> param_name, COLON, type_ref { CurrentSemanticValue.stn = new typed_parameters(ValueStack[ValueStack.Depth-3].stn as ident_list, ValueStack[ValueStack.Depth-1].td, parametr_kind.none, null, CurrentLocationSpan); } break; - case 165: // form_param_sect -> STAR, param_name, COLON, type_ref + case 171: // form_param_sect -> STAR, param_name, COLON, type_ref { var at = new array_type(null, ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); CurrentSemanticValue.stn = new typed_parameters(ValueStack[ValueStack.Depth-3].stn as ident_list, at, parametr_kind.params_parametr, null, CurrentLocationSpan); } break; - case 166: // form_param_sect -> STARSTAR, param_name, COLON, type_ref + case 172: // form_param_sect -> STARSTAR, param_name, COLON, type_ref { CurrentSemanticValue.stn = new typed_parameters(ValueStack[ValueStack.Depth-3].stn as ident_list, ValueStack[ValueStack.Depth-1].td, parametr_kind.kwargs_parameter, null, CurrentLocationSpan); } break; - case 167: // form_param_list -> form_param_sect + case 173: // form_param_list -> form_param_sect { CurrentSemanticValue.stn = new formal_parameters(ValueStack[ValueStack.Depth-1].stn as typed_parameters, CurrentLocationSpan); } break; - case 168: // form_param_list -> form_param_list, COMMA, form_param_sect + case 174: // form_param_list -> form_param_list, COMMA, form_param_sect { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as formal_parameters).Add(ValueStack[ValueStack.Depth-1].stn as typed_parameters, CurrentLocationSpan); } break; - case 169: // optional_form_param_list -> form_param_list + case 175: // optional_form_param_list -> form_param_list { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 170: // optional_form_param_list -> /* empty */ + case 176: // optional_form_param_list -> /* empty */ { CurrentSemanticValue.stn = null; } break; - case 171: // act_param -> expr + case 177: // act_param -> expr { CurrentSemanticValue.ex = ValueStack[ValueStack.Depth-1].ex; } break; - case 172: // act_param -> ident, ASSIGN, expr + case 178: // act_param -> ident, ASSIGN, expr { CurrentSemanticValue.ex = new name_assign_expr(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 173: // act_param_list -> act_param + case 179: // act_param_list -> act_param { CurrentSemanticValue.stn = new expression_list(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 174: // act_param_list -> act_param_list, COMMA, act_param + case 180: // act_param_list -> act_param_list, COMMA, act_param { CurrentSemanticValue.stn = (ValueStack[ValueStack.Depth-3].stn as expression_list).Add(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 175: // optional_act_param_list -> act_param_list + case 181: // optional_act_param_list -> act_param_list { CurrentSemanticValue.stn = ValueStack[ValueStack.Depth-1].stn; } break; - case 176: // optional_act_param_list -> generator_object + case 182: // optional_act_param_list -> generator_object { CurrentSemanticValue.stn = new expression_list(ValueStack[ValueStack.Depth-1].ex, CurrentLocationSpan); } break; - case 177: // optional_act_param_list -> /* empty */ + case 183: // optional_act_param_list -> /* empty */ { CurrentSemanticValue.stn = null; } break; - case 178: // end_of_line -> END_OF_LINE + case 184: // end_of_line -> END_OF_LINE { CurrentSemanticValue.ob = ValueStack[ValueStack.Depth-1].ti; } break; - case 179: // end_of_line -> SEMICOLON + case 185: // end_of_line -> SEMICOLON { CurrentSemanticValue.ob = ValueStack[ValueStack.Depth-1].ti; } break; - case 180: // optional_semicolon -> SEMICOLON + case 186: // optional_semicolon -> SEMICOLON { CurrentSemanticValue.ob = ValueStack[ValueStack.Depth-1].ti; } break; - case 181: // optional_semicolon -> /* empty */ + case 187: // optional_semicolon -> /* empty */ { CurrentSemanticValue.ob = null; } diff --git a/LanguagePlugins/SPython/SemanticAnalyzers/SPythonSyntaxTreeVisitor/spython_syntax_tree_visitor.cs b/LanguagePlugins/SPython/SemanticAnalyzers/SPythonSyntaxTreeVisitor/spython_syntax_tree_visitor.cs index 9c98f8b44..c8e6428c7 100644 --- a/LanguagePlugins/SPython/SemanticAnalyzers/SPythonSyntaxTreeVisitor/spython_syntax_tree_visitor.cs +++ b/LanguagePlugins/SPython/SemanticAnalyzers/SPythonSyntaxTreeVisitor/spython_syntax_tree_visitor.cs @@ -118,6 +118,8 @@ namespace SPythonSyntaxTreeVisitor base.AddError(new OperatorCanNotBeAppliedToThisTypes("%", _op_err.left, _op_err.right, _op_err.loc), shouldReturn); else if (_op_err.operator_name == "div") base.AddError(new OperatorCanNotBeAppliedToThisTypes("//", _op_err.left, _op_err.right, _op_err.loc), shouldReturn); + else + break; return; case FunctionExpectedProcedureMeet _proc_meet: base.AddError(new SPythonSemanticError(_proc_meet.loc, "SPYTHONSEMANTIC_FUNCTION_{0}_NO_RETURN", _proc_meet.function.name)); @@ -133,83 +135,6 @@ namespace SPythonSyntaxTreeVisitor } - private Dictionary> containersNamesMapping = new Dictionary> - { - {"List", - new Dictionary { - { "append", "Add" }, - { "clear", "Clear" }, - { "insert", "Insert" }, - { "remove", "Remove" }, - { "pop", "pop" }, - { "index", "IndexOf" }, - { "count", "!count" }, - { "sort", "Sort" }, - { "reverse", "Reverse" }, - { "copy", "ToList" }, - { "Select", "Select" }, - { "Where", "Where" }, - } }, - - {"NewSet", - new Dictionary { - { "add", "add" }, - { "remove", "remove" }, - { "copy", "copy" }, - { "Select", "Select" }, - { "Where", "Where" }, - } }, - - {"Dictionary", - new Dictionary { - { "keys", "get_keys" }, - { "values", "get_values" }, - { "copy", "copy" }, - { "Select", "Select" }, - { "Where", "Where" }, - } } - }; - - - HashSet visited_method_calls = new HashSet(); - - public override void visit(method_call _method_call) - { - if (visited_method_calls.Contains(_method_call)) - { - base.visit(_method_call); - return; - } - visited_method_calls.Add(_method_call); - if (_method_call.dereferencing_value is dot_node dn && dn.right is ident id) - { - try - { - expression_node left = convert_strong(dn.left); - //dn.left = new semantic_addr_value(left); - if (left?.type != null) - foreach (string tName in containersNamesMapping.Keys) - { - if (left.type.name.StartsWith(tName)) - { - if (!containersNamesMapping[tName].ContainsKey(id.name)) - { - AddError(left.location, "SPYTHONSEMANTIC_TYPE_{0}_HAS_NO_{1}_METHOD", ConvertTypeNameToSPythonTypeName(left.type), id.name); - } - else - { - id.name = containersNamesMapping[tName][id.name]; - } - } - } - } - catch (ExpectedAnotherKindOfObject e) - { - } - } - base.visit(_method_call); - } - public override void visit(assign _assign) { @@ -221,17 +146,26 @@ namespace SPythonSyntaxTreeVisitor expression_node to = convert_strong(_assign.to); SourceContext sc = _assign.source_context; - if (to.type.name.StartsWith("NewSet")) + if (to.type.is_generic_type_instance && to.type.name.StartsWith("set")) { if (be.operation_type == Operators.LogicalAND) { - var replace = new assign(new semantic_addr_value(to), be.right, Operators.AssignmentMultiplication, sc); + var replace = new method_call(new dot_node(new semantic_addr_value(to, to.location), new ident("!andEqual")), + new expression_list(be.right), sc); base.visit(replace); return; } if (be.operation_type == Operators.LogicalOR) { - var replace = new assign(new semantic_addr_value(to), be.right, Operators.AssignmentAddition, sc); + var replace = new method_call(new dot_node(new semantic_addr_value(to, to.location), new ident("!orEqual")), + new expression_list(be.right), sc); + base.visit(replace); + return; + } + if (be.operation_type == Operators.BitwiseXOR) + { + var replace = new method_call(new dot_node(new semantic_addr_value(to, to.location), new ident("!xorEqual")), + new expression_list(be.right), sc); base.visit(replace); return; } @@ -251,18 +185,6 @@ namespace SPythonSyntaxTreeVisitor switch (_bin_expr.operation_type) { - case Operators.LogicalOR: - if (left.type.name.StartsWith("NewSet") && left.type.name == right.type.name) - { - new_bin_expr.operation_type = Operators.Plus; - } - break; - case Operators.LogicalAND: - if (left.type.name.StartsWith("NewSet") && left.type.name == right.type.name) - { - new_bin_expr.operation_type = Operators.Multiplication; - } - break; /*case Operators.Plus: if (left.type == right.type && left.type.name == "boolean") { diff --git a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/NameCorrectVisitor.cs b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/NameCorrectVisitor.cs index 80e2301ab..d0f240eca 100644 --- a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/NameCorrectVisitor.cs +++ b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/NameCorrectVisitor.cs @@ -79,7 +79,7 @@ namespace Languages.SPython.Frontend.Converters ident id = _named_type_reference.names[0]; string name = id.name; - if (name == "int" || name == "str" || name == "bool" || name == "float" || name == "set" || name == "list" || name == "dict") + if (name == "int" || name == "str" || name == "bool" || name == "float") { return; } @@ -102,6 +102,29 @@ namespace Languages.SPython.Frontend.Converters } } + public override void visit(template_type_reference _template_type_reference) + { + named_type_reference _named_type_reference = _template_type_reference.name; + string name = _named_type_reference.names[0].name; + + string fullName = name + $"`{_template_type_reference.params_list.Count}"; + + NameKind nameKind = symbolTable[fullName]; + + switch (nameKind) + { + + case NameKind.ImportedNameAlias: + _named_type_reference.names.Insert(0, new ident(symbolTable.AliasToModuleName(fullName), _named_type_reference.names[0].source_context)); + _named_type_reference.names[1].name = symbolTable.AliasToRealName(fullName); + break; + + case NameKind.Unknown: + throw new SPythonSyntaxVisitorError("UNKNOWN_NAME_{0}", + _named_type_reference.names[0].source_context, name); + } + } + public override void visit(ident _ident) { SourceContext sc = _ident.source_context; diff --git a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TreeNodesRearrangementVisitor.cs b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TreeNodesRearrangementVisitor.cs index df84f358e..6244ec537 100644 --- a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TreeNodesRearrangementVisitor.cs +++ b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TreeNodesRearrangementVisitor.cs @@ -53,6 +53,7 @@ namespace Languages.SPython.Frontend.Converters private void BuildMainFunction(statement_list _statement_list) { statement_list mainBody = _statement_list.TypedClone(); + mainBody.source_context = mainBody.Parent.source_context; // source context для MAIN охватывает весь файл procedure_header _procedure_header = new procedure_header(mainFunctionName); block _block = new block(null, mainBody, mainBody.source_context); //block _block = new block(null, new statement_list(), _statement_list.source_context); diff --git a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TypeCorrectVisitor.cs b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TypeCorrectVisitor.cs index 2ffa24cf0..02f7c6a7d 100644 --- a/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TypeCorrectVisitor.cs +++ b/LanguagePlugins/SPython/SyntaxTreeConverters/SPythonStandardTreeConverter/TypeCorrectVisitor.cs @@ -25,6 +25,7 @@ namespace Languages.SPython.Frontend.Converters } ttr.name.names[index].name += cnt; } + base.visit(ttr); } @@ -69,19 +70,6 @@ namespace Languages.SPython.Frontend.Converters id.source_context, id.name, "bigint"); } } - - switch (id.name) - { - case "list": - id.name = "!list"; - break; - case "dict": - id.name = "!dict"; - break; - case "set": - id.name = "!set"; - break; - } } } } diff --git a/ParserTools/ParserTools/BaseLanguageInformation.cs b/ParserTools/ParserTools/BaseLanguageInformation.cs index 468493826..a584e61fb 100644 --- a/ParserTools/ParserTools/BaseLanguageInformation.cs +++ b/ParserTools/ParserTools/BaseLanguageInformation.cs @@ -430,6 +430,16 @@ namespace PascalABCCompiler.Parsers return sb.ToString(); } + protected string GetDescriptionForCompiledEvent(ICompiledEventScope scope) + { + return (scope.IsStatic ? "static " : "") + "event " + GetShortTypeName(scope.CompiledEvent.DeclaringType, true) + "." + scope.CompiledEvent.Name + ": " + GetSimpleDescription(scope.Type) + ";"; + } + + protected string GetDescriptionForShortString(IShortStringScope scope) + { + return "string" + "[" + scope.Length + "]"; + } + public abstract string GetKeyword(SymbolKind kind); public KeywordKind GetKeywordKind(string name) @@ -758,6 +768,102 @@ namespace PascalABCCompiler.Parsers return sb.ToString(); } + protected string GetDescriptionForCompiledField(ICompiledFieldScope scope) + { + StringBuilder sb = new StringBuilder(); + if (!scope.CompiledField.IsLiteral) + if (scope.CompiledField.IsStatic && !scope.IsGlobal) sb.Append("static "); + else sb.Append("var "); + string inst_type = null; + if (scope.GenericArgs != null) + { + inst_type = get_type_instance(scope.CompiledField.FieldType, scope.GenericArgs); + } + if (!scope.CompiledField.IsLiteral) + sb.Append(GetShortTypeName(scope.CompiledField.DeclaringType) + "." + scope.CompiledField.Name + ": " + (inst_type != null ? inst_type : GetSimpleDescription(scope.Type))); + else + sb.Append("const " + GetShortTypeName(scope.CompiledField.DeclaringType) + "." + scope.CompiledField.Name + ": " + GetSimpleDescription(scope.Type)); + //if (scope.CompiledField.IsStatic) sb.Append("; static"); + if (scope.IsReadOnly) sb.Append("; readonly"); + sb.Append(';'); + return sb.ToString(); + } + + protected string GetDescriptionForCompiledProperty(ICompiledPropertyScope scope) + { + StringBuilder sb = new StringBuilder(); + MethodInfo acc = scope.CompiledProperty.GetGetMethod(); + string inst_type = null; + if (acc != null) + if (acc.IsStatic) sb.Append("static "); + if (scope.Type is ICompiledTypeScope && scope.GenericArgs != null) + { + Type t = (scope.Type as ICompiledTypeScope).CompiledType; + inst_type = get_type_instance(t, scope.GenericArgs); + } + sb.Append("property " + GetShortTypeName(scope.CompiledProperty.DeclaringType) + "." + scope.CompiledProperty.Name + get_indexer_for_prop(scope)); + if (inst_type == null) + { + if (scope.Type is ICompiledTypeScope) + sb.Append(": " + GetFullTypeName((scope.Type as ICompiledTypeScope).CompiledType, false)); + else + sb.Append(": " + GetSimpleDescription(scope.Type)); + } + else + sb.Append(": " + inst_type); + if (acc != null) + //if (acc.IsStatic) sb.Append("; static"); + if (acc.IsVirtual) sb.Append("; "); + else if (acc.IsAbstract) sb.Append("; abstract"); + if (scope.IsReadOnly) sb.Append("; readonly"); + sb.Append(';'); + return sb.ToString(); + } + + protected string GetDescriptionForCompiledConstructor(ICompiledConstructorScope scope) + { + StringBuilder sb = new StringBuilder(); + sb.Append("constructor "); + sb.Append(GetShortTypeName(scope.CompiledConstructor.DeclaringType)); + //sb.Append("."); + //sb.Append("Create"); + sb.Append('('); + ParameterInfo[] pis = scope.CompiledConstructor.GetParameters(); + for (int i = 0; i < pis.Length; i++) + { + if (pis[i].ParameterType.IsByRef) + sb.Append("var "); + else if (IsParams(pis[i])) + sb.Append("params "); + sb.Append(pis[i].Name); + sb.Append(": "); + if (!pis[i].ParameterType.IsByRef) + sb.Append(GetFullTypeName(pis[i].ParameterType)); + else sb.Append(GetFullTypeName(pis[i].ParameterType.GetElementType())); + if (i < pis.Length - 1) + sb.Append(ParameterDelimiter + " "); + } + sb.Append(')'); + sb.Append(';'); + return sb.ToString(); + } + + private string get_indexer_for_prop(ICompiledPropertyScope scope) + { + ITypeScope[] indexers = scope.Indexers; + if (indexers.Length == 0) return ""; + StringBuilder sb = new StringBuilder(); + sb.Append('['); + for (int i = 0; i < indexers.Length; i++) + { + sb.Append(GetSimpleDescriptionWithoutNamespace(indexers[i])); + if (i < indexers.Length - 1) + sb.Append(','); + } + sb.Append(']'); + return sb.ToString(); + } + protected string prepare_member_name(string s) { if (IsKeyword(s)) diff --git a/ParserTools/ParserTools/ILanguageInformation.cs b/ParserTools/ParserTools/ILanguageInformation.cs index b6d93c081..aab1422f5 100644 --- a/ParserTools/ParserTools/ILanguageInformation.cs +++ b/ParserTools/ParserTools/ILanguageInformation.cs @@ -185,6 +185,12 @@ namespace PascalABCCompiler.Parsers get; } + /// + /// Добавить пространства имен .NET, подключаемые по умолчанию. Полной поддержки false нет (см. комментарий) + /// + // Если поставить false, то CorrectTreeWithSemantic из DomSyntaxTreeVisitor будет поправлять типы неправильно + // из-за того, что полное имя типа integer, например, System.Int32, + // а имя System не будет добавлено в Scope и значит выведется Int32 без преобразования в кастомное название типа для языка bool AddStandardNetNamespacesToUserScope { get; @@ -379,6 +385,7 @@ namespace PascalABCCompiler.Parsers { public string name; public string addit_name; + public string aliasName; public string description; public SymbolKind kind; public bool IsUnitNamespace; @@ -398,6 +405,7 @@ namespace PascalABCCompiler.Parsers { this.name = si.name; this.addit_name = si.addit_name; + this.aliasName = si.aliasName; this.description = si.description; this.kind = si.kind; this.IsUnitNamespace = si.IsUnitNamespace; diff --git a/PascalABCLanguageInfo/PascalABCLanguageInformation.cs b/PascalABCLanguageInfo/PascalABCLanguageInformation.cs index ef18a761b..97c05256d 100644 --- a/PascalABCLanguageInfo/PascalABCLanguageInformation.cs +++ b/PascalABCLanguageInfo/PascalABCLanguageInformation.cs @@ -188,7 +188,6 @@ namespace Languages.Pascal.Frontend.Data case ScopeKind.CompiledEvent: return GetDescriptionForCompiledEvent(scope as ICompiledEventScope); case ScopeKind.CompiledConstructor: return GetDescriptionForCompiledConstructor(scope as ICompiledConstructorScope); case ScopeKind.ShortString: return GetDescriptionForShortString(scope as IShortStringScope); - //case ScopeKind.Procedure : return GetDescriptionForProcedure(scope as IProcScope); } return ""; } @@ -986,12 +985,12 @@ namespace Languages.Pascal.Frontend.Data return s; } - protected string GetDescriptionForDiapason(IDiapasonScope scope) + private string GetDescriptionForDiapason(IDiapasonScope scope) { return scope.Left.ToString() + ".." + scope.Right.ToString(); } - protected string GetDescriptionForFile(IFileScope scope) + private string GetDescriptionForFile(IFileScope scope) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("file"); @@ -1004,29 +1003,20 @@ namespace Languages.Pascal.Frontend.Data return sb.ToString(); } - private Stack typs = new Stack(); - - protected string GetDescriptionForPointer(IPointerScope scope) + private string GetDescriptionForPointer(IPointerScope scope) { string s = ""; if (scope.ElementType != null) { - if (!typs.Contains(scope)) - { - typs.Push(scope); - s = "^" + GetSimpleDescription(scope.ElementType); - } - else - s = ""; + s = "^" + GetSimpleDescription(scope.ElementType); } else s = "pointer"; - if (typs.Count > 0) - typs.Pop(); + return s; } - protected string GetDescriptionForSet(ISetScope scope) + private string GetDescriptionForSet(ISetScope scope) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("set of "); @@ -1063,43 +1053,6 @@ namespace Languages.Pascal.Frontend.Data return sb.ToString(); } - protected string GetDescriptionForCompiledField(ICompiledFieldScope scope) - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - if (!scope.CompiledField.IsLiteral) - if (scope.CompiledField.IsStatic && !scope.IsGlobal) sb.Append("static "); - else sb.Append("var "); - string inst_type = null; - if (scope.GenericArgs != null) - { - inst_type = get_type_instance(scope.CompiledField.FieldType, scope.GenericArgs); - } - if (!scope.CompiledField.IsLiteral) - sb.Append(GetShortTypeName(scope.CompiledField.DeclaringType) + "." + scope.CompiledField.Name + ": " + (inst_type != null ? inst_type : GetSimpleDescription(scope.Type))); - else - sb.Append("const " + GetShortTypeName(scope.CompiledField.DeclaringType) + "." + scope.CompiledField.Name + ": " + GetSimpleDescription(scope.Type)); - //if (scope.CompiledField.IsStatic) sb.Append("; static"); - if (scope.IsReadOnly) sb.Append("; readonly"); - sb.Append(';'); - return sb.ToString(); - } - - private string get_indexer_for_prop(ICompiledPropertyScope scope) - { - ITypeScope[] indexers = scope.Indexers; - if (indexers.Length == 0) return ""; - StringBuilder sb = new StringBuilder(); - sb.Append('['); - for (int i = 0; i < indexers.Length; i++) - { - sb.Append(GetSimpleDescriptionWithoutNamespace(indexers[i])); - if (i < indexers.Length - 1) - sb.Append(','); - } - sb.Append(']'); - return sb.ToString(); - } - public string GetDescriptionForCompiledProperty(PropertyInfo pi) { StringBuilder sb = new StringBuilder(); @@ -1132,37 +1085,6 @@ namespace Languages.Pascal.Frontend.Data return sb.ToString(); } - protected string GetDescriptionForCompiledProperty(ICompiledPropertyScope scope) - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - MethodInfo acc = scope.CompiledProperty.GetGetMethod(); - string inst_type = null; - if (acc != null) - if (acc.IsStatic) sb.Append("static "); - if (scope.Type is ICompiledTypeScope && scope.GenericArgs != null) - { - Type t = (scope.Type as ICompiledTypeScope).CompiledType; - inst_type = get_type_instance(t, scope.GenericArgs); - } - sb.Append("property " + GetShortTypeName(scope.CompiledProperty.DeclaringType) + "." + scope.CompiledProperty.Name + get_indexer_for_prop(scope)); - if (inst_type == null) - { - if (scope.Type is ICompiledTypeScope) - sb.Append(": " + GetFullTypeName((scope.Type as ICompiledTypeScope).CompiledType, false)); - else - sb.Append(": " + GetSimpleDescription(scope.Type)); - } - else - sb.Append(": " + inst_type); - if (acc != null) - //if (acc.IsStatic) sb.Append("; static"); - if (acc.IsVirtual) sb.Append("; "); - else if (acc.IsAbstract) sb.Append("; abstract"); - if (scope.IsReadOnly) sb.Append("; readonly"); - sb.Append(';'); - return sb.ToString(); - } - private string GetDescriptionForNamespace(INamespaceScope scope) { return "namespace " + scope.Name; @@ -1180,11 +1102,6 @@ namespace Languages.Pascal.Frontend.Data return sb.ToString(); } - protected string GetDescriptionForCompiledEvent(ICompiledEventScope scope) - { - return (scope.IsStatic ? "static " : "") + "event " + GetShortTypeName(scope.CompiledEvent.DeclaringType, true) + "." + scope.CompiledEvent.Name + ": " + GetSimpleDescription(scope.Type) + ";"; - } - protected string GetDescriptionForCompiledConstructor(ConstructorInfo ci) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); @@ -1218,39 +1135,6 @@ namespace Languages.Pascal.Frontend.Data return sb.ToString(); } - protected string GetDescriptionForCompiledConstructor(ICompiledConstructorScope scope) - { - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - sb.Append("constructor "); - sb.Append(GetShortTypeName(scope.CompiledConstructor.DeclaringType)); - //sb.Append("."); - //sb.Append("Create"); - sb.Append('('); - ParameterInfo[] pis = scope.CompiledConstructor.GetParameters(); - for (int i = 0; i < pis.Length; i++) - { - if (pis[i].ParameterType.IsByRef) - sb.Append("var "); - else if (IsParams(pis[i])) - sb.Append("params "); - sb.Append(pis[i].Name); - sb.Append(": "); - if (!pis[i].ParameterType.IsByRef) - sb.Append(GetFullTypeName(pis[i].ParameterType)); - else sb.Append(GetFullTypeName(pis[i].ParameterType.GetElementType())); - if (i < pis.Length - 1) - sb.Append("; "); - } - sb.Append(')'); - sb.Append(';'); - return sb.ToString(); - } - - protected string GetDescriptionForShortString(IShortStringScope scope) - { - return "string" + "[" + scope.Length + "]"; - } - public override string GetSynonimDescription(ITypeScope scope) { return "type " + scope.Name + GetGenericString(scope.TemplateArguments) + " = " + scope.Description; diff --git a/TreeConverter/NetWrappers/NetHelper.cs b/TreeConverter/NetWrappers/NetHelper.cs index 992718281..918440635 100644 --- a/TreeConverter/NetWrappers/NetHelper.cs +++ b/TreeConverter/NetWrappers/NetHelper.cs @@ -1494,7 +1494,7 @@ namespace PascalABCCompiler.NetHelper return FindType(name) != null; } - public static List FindNameIncludeProtected(Type t, string name) + public static List FindNameIncludeProtected(Type t, string name, bool caseSensitiveSearch) { if (name == null) return null; if (name == StringConstants.assign_name) return null; @@ -1506,7 +1506,20 @@ namespace PascalABCCompiler.NetHelper } List sil=null; List mis = GetMembers(t,name); - + + // вообще, фильтровать лучше в GetMembers EVA + mis = new List(mis); + if (caseSensitiveSearch) + { + for (int i = 0; i < mis.Count;) + { + if (mis[i].Name != name) + mis.RemoveAt(i); + else + i++; + } + } + foreach (MemberInfo mi in mis) { if (mi.DeclaringType != null && PABCSystemType != null && mi.DeclaringType.Assembly == PABCSystemType.Assembly && !UsePABCRtl) @@ -1543,7 +1556,7 @@ namespace PascalABCCompiler.NetHelper Type nested_t = null; foreach (Type nt in t.GetNestedTypes()) { - if (string.Compare(nt.Name, name, true) == 0) + if (nt.Name.Equals(name, caseSensitiveSearch ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase)) { nested_t = nt; break; diff --git a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs index 065d3c3f9..721afb957 100644 --- a/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs +++ b/VisualPascalABCNET/IB/CodeCompletion/CodeCompletionProvider.cs @@ -1,15 +1,14 @@ // Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; -using System.Windows.Forms; using ICSharpCode.TextEditor; using ICSharpCode.TextEditor.Gui.CompletionWindow; -using PascalABCCompiler.Parsers; using Languages.Facade; +using PascalABCCompiler.Parsers; +using System; +using System.Collections.Generic; using System.Linq; +using System.Text; +using System.Windows.Forms; namespace VisualPascalABC { @@ -393,7 +392,7 @@ namespace VisualPascalABC { if (symInfo == null || symInfo.not_include) continue; - string nameToShow = symInfo.addit_name != null ? symInfo.addit_name : symInfo.name; + string nameToShow = GetDisplayedName(symInfo); if (symbolsAdded.Contains(nameToShow + symInfo.kind)) continue; @@ -563,8 +562,8 @@ namespace VisualPascalABC if (symInfo == null || symInfo.not_include) continue; - string nameToShow = symInfo.addit_name != null ? symInfo.addit_name : symInfo.name; - + string nameToShow = GetDisplayedName(symInfo); + if (symbolsAdded.Contains(nameToShow + symInfo.kind)) continue; @@ -808,5 +807,16 @@ namespace VisualPascalABC //GC.Collect(); return data; } + + private string GetDisplayedName(SymInfo symInfo) + { + if (symInfo.aliasName != null) + return symInfo.aliasName; + + if (symInfo.addit_name != null) + return symInfo.addit_name; + + return symInfo.name; + } } } diff --git a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs index cf5dbbe26..cfd57fee1 100644 --- a/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs +++ b/VisualPascalABCNETLinux/IB/CodeCompletion/CodeCompletionProvider.cs @@ -393,21 +393,23 @@ namespace VisualPascalABC { if (symInfo == null || symInfo.not_include) continue; - if (symbolsAdded.Contains(symInfo.name)) + string nameToShow = GetDisplayedName(symInfo); + + if (symbolsAdded.Contains(nameToShow + symInfo.kind)) continue; - UserDefaultCompletionData completionData = new UserDefaultCompletionData(symInfo.name, symInfo.description, ImagesProvider.GetPictureNum(symInfo), false); + UserDefaultCompletionData completionData = new UserDefaultCompletionData(nameToShow, symInfo.description, ImagesProvider.GetPictureNum(symInfo), false); StringComparison stringComparison = languageCaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase; // если мы выбирали что-то раньше из списка подсказок, то считаем это элементом по умолчанию - if (!stop && lastUsedItem != null && string.Equals(symInfo.name, lastUsedItem.Text, stringComparison)) + if (!stop && lastUsedItem != null && string.Equals(nameToShow, lastUsedItem.Text, stringComparison)) { defaultCompletionElement = completionData; stop = true; } // иначе формируем список подходящих подсказок - "кандидатов" для элемента по умолчанию - else if (!stop && lastUsedItem == null && symInfo.name.StartsWith(charTyped.ToString(), stringComparison)) + else if (!stop && lastUsedItem == null && nameToShow.StartsWith(charTyped.ToString(), stringComparison)) { //defaultCompletionElement = ddd; candidatesForDefault.Add(completionData); @@ -418,7 +420,7 @@ namespace VisualPascalABC resultList.Add(completionData); - symbolsAdded.Add(symInfo.name); + symbolsAdded.Add(nameToShow + symInfo.kind); } if (candidatesForDefault.Count > 0) @@ -561,19 +563,18 @@ namespace VisualPascalABC if (symInfo == null || symInfo.not_include) continue; - if (symbolsAdded.Contains(symInfo.name + symInfo.kind)) + string nameToShow = GetDisplayedName(symInfo); + + if (symbolsAdded.Contains(nameToShow + symInfo.kind)) continue; - UserDefaultCompletionData completionData = new UserDefaultCompletionData( - symInfo.addit_name != null ? symInfo.addit_name : symInfo.name, - symInfo.description, ImagesProvider.GetPictureNum(symInfo), false - ); + UserDefaultCompletionData completionData = new UserDefaultCompletionData(nameToShow, symInfo.description, ImagesProvider.GetPictureNum(symInfo), false); disp.Add(symInfo, completionData); resultList.Add(completionData); - symbolsAdded.Add(symInfo.name + symInfo.kind); + symbolsAdded.Add(nameToShow + symInfo.kind); /*if (VisualPABCSingleton.MainForm.UserOptions.EnableSmartIntellisense && mi.name != null && mi.name != "" && data == null) { @@ -581,7 +582,7 @@ namespace VisualPascalABC if (data != null && data.Text == ddd.Text) data = ddd; }*/ - if (lastUsedMember != null && lastUsedMember == symInfo.name || selectedSymInfo != null && symInfo == selectedSymInfo) + if (lastUsedMember != null && lastUsedMember == nameToShow || selectedSymInfo != null && symInfo == selectedSymInfo) { defaultCompletionElement = completionData; } @@ -807,5 +808,16 @@ namespace VisualPascalABC //GC.Collect(); return data; } + + private string GetDisplayedName(SymInfo symInfo) + { + if (symInfo.aliasName != null) + return symInfo.aliasName; + + if (symInfo.addit_name != null) + return symInfo.addit_name; + + return symInfo.name; + } } } diff --git a/bin/Lib/SPythonHidden.pas b/bin/Lib/SPythonHidden.pas index c1a5cafa4..cde9322e1 100644 --- a/bin/Lib/SPythonHidden.pas +++ b/bin/Lib/SPythonHidden.pas @@ -3,7 +3,7 @@ unit SPythonHidden; interface -// uses PABCSystem; +uses SPythonSystem; function !Floor(x : real) : integer; @@ -14,8 +14,36 @@ function !FloorMod(x: real; y: real): real; type !UnknownType = class end; +// TODO: Перенести в SPythonSystemPys следующие методы +function list(sq: sequence of T): SPythonSystem.list; + +function list(d : dict) : SPythonSystem.list; + +function &set(sq: sequence of T): &set; + +function &set(): empty_set; + +function dict(params pairs: array of (TKey, TVal)): dict; + +function dict(seqOfPairs: IEnumerable>) : dict; + implementation +function list(sq: sequence of T): SPythonSystem.list := new SPythonSystem.list(sq); + +function list(d : dict) : SPythonSystem.list := new SPythonSystem.list(d.keys()); + +function &set(sq: sequence of T): &set; +begin + Result := new &set(sq); +end; + +function &set(): empty_set := new empty_set; + +function dict(params pairs: array of (TKey, TVal)): dict := new dict(pairs); + +function dict(seqOfPairs: sequence of (TKey, TVal)): dict := new dict(seqOfPairs); + function !Floor(x : real) : integer := PABCSystem.Floor(x); function !FloorDiv(x: real; y: real): integer := PABCSystem.Floor(x / y); diff --git a/bin/Lib/SPythonSystem.pas b/bin/Lib/SPythonSystem.pas index c47ee1f55..6c0a15b2b 100644 --- a/bin/Lib/SPythonSystem.pas +++ b/bin/Lib/SPythonSystem.pas @@ -17,6 +17,7 @@ function input(): string; function input(s: string): string; +///- type kwargs_gen = class public !kwargs: Dictionary := new Dictionary(); @@ -50,10 +51,6 @@ function filter(cond: T -> boolean; s: sequence of T): sequence of T; function sorted(s: sequence of T; reverse: boolean := false): sequence of T; function sorted(s: sequence of T; key: T -> T1; reverse: boolean := false): sequence of T; -function __NewSetCreatorInternal(params a: array of T): NewSet; - -procedure clear(var st: set of T); - function int(val: string): integer; function int(val: real): integer; @@ -102,18 +99,395 @@ function abs(x: real): real; // function floor(x: real): real; +type list = class(IEnumerable) + private + wrappee : PABCSystem.List; + + constructor Create(l : PABCSystem.List) := wrappee := l; + + function GetItem(ind : integer) : T := wrappee[ind]; + + procedure SetItem(ind : integer; newItem : T) := wrappee[ind] := newItem; + + public + + static function operator implicit(l : PABCSystem.List) : list := new list(l); + + constructor Create() := wrappee := new PABCSystem.List(); + + constructor Create(capacity : integer) := wrappee := new PABCSystem.List(capacity); + + constructor Create(collection : sequence of T) := wrappee := new PABCSystem.List(collection); + + property ByIndex[ind : integer] : T read GetItem write SetItem; default; + + ///-- + property !count : integer read wrappee.Count; + + procedure append(item : T) := wrappee.Add(item); + + procedure extend(seq : sequence of T) := wrappee.AddRange(seq); + + procedure clear() := wrappee.Clear(); + + procedure insert(index : integer; item : T) := wrappee.Insert(index, item); + + procedure remove(item : T); + begin + if not wrappee.Remove(item) then + raise new System.ArgumentException($'ValueError: {item} is not in list'); + end; + + function pop() : T; + begin + var lastIndex := wrappee.Count - 1; + Result := wrappee[lastIndex]; + wrappee.RemoveAt(lastIndex); + end; + + function pop(index : integer) : T; + begin + Result := wrappee[index]; + wrappee.RemoveAt(index); + end; + + function index(item : T) : integer := index(item, 0, wrappee.Count); + + function index(item : T; start : integer) : integer := index(item, start, wrappee.Count); + + function index(item : T; start : integer; &end : integer) : integer; + begin + Result := wrappee.IndexOf(item, start, &end - start); + if Result = -1 then + raise new System.ArgumentException($'ValueError: {item} is not in list'); + end; + + function count(item : T) : integer; + begin + var comparer := System.Collections.Generic.EqualityComparer&.Default; + + Result := 0; + for var i := 0 to wrappee.Count - 1 do + begin + if comparer.Equals(wrappee[i], item) then + Result += 1; + end; + end; + + procedure sort() := wrappee.Sort(); + + procedure sort(reverse : boolean) := wrappee.OrderByDescending(x -> x); + + procedure sort(key : T -> TKey) := wrappee.OrderBy(key); + + procedure sort(key : T -> TKey; reverse : boolean) := wrappee.OrderByDescending(key); + + procedure reverse() := wrappee.Reverse(); + + function copy() : list := new list(wrappee.ToList()); + + function GetEnumerator() : IEnumerator := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); + end; + +type &set = record(IEnumerable) + private + wrappee : PABCSystem.HashSet; + + constructor Create(h : PABCSystem.HashSet) := wrappee := h; + + public + + constructor Create() := wrappee := new PABCSystem.HashSet(); + + constructor Create(collection : sequence of T) := wrappee := new PABCSystem.HashSet(collection); + + constructor Create(collection : sequence of T; comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.HashSet(collection, comparer); + + constructor Create(comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.HashSet(comparer); + + ///-- + property !count : integer read wrappee.Count; + + procedure add(elem : T) := wrappee.Add(elem); + + procedure remove(elem : T); + begin + if not wrappee.Remove(elem) then + raise new System.Collections.Generic.KeyNotFoundException('KeyError: ' + elem.ToString()); + end; + + procedure discard(elem : T) := wrappee.Remove(elem); + + function pop() : T; + begin + if wrappee.Count = 0 then + raise new System.Collections.Generic.KeyNotFoundException('KeyError: ''pop from an empty set'''); + + Result := wrappee.First(); + wrappee.Remove(Result); + end; + + procedure clear() := wrappee.Clear(); + + function copy() : &set := new &set(wrappee.ToHashSet()); + + static function operator in(elem: T; Self: &set): boolean; + begin + Result := Self.wrappee.Contains(elem); + end; + + private + function setOperation1(op : (HashSet, sequence of T) -> (); params others : array of sequence of T) : &set; + begin + Result.wrappee := wrappee.ToHashSet(); + foreach var seq in others do + op(Result.wrappee, seq); + end; + + procedure setOperation2(op : (HashSet, sequence of T) -> (); params others : array of sequence of T); + begin + foreach var seq in others do + op(wrappee, seq); + end; + + public + function intersection(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.IntersectWith(h2), others); + + function union(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.UnionWith(h2), others); + + function difference(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.ExceptWith(h2), others); + + function symmetric_difference(params others : array of sequence of T) : &set := setOperation1((h1, h2) -> h1.SymmetricExceptWith(h2), others); + + procedure update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.UnionWith(h2), others); + + procedure update(other : sequence of T) := wrappee.UnionWith(other); + + procedure intersection_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.IntersectWith(h2), others); + + procedure intersection_update(other : sequence of T) := wrappee.IntersectWith(other); + + procedure difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.ExceptWith(h2), others); + + procedure difference_update(other : sequence of T) := wrappee.ExceptWith(other); + + procedure symmetric_difference_update(params others : array of sequence of T) := setOperation2((h1, h2) -> h1.SymmetricExceptWith(h2), others); + + procedure symmetric_difference_update(other : sequence of T) := wrappee.SymmetricExceptWith(other); + + function isdisjoint(other : sequence of T) : boolean; + + function issubset(other : sequence of T) : boolean := wrappee.IsSubsetOf(other); + + function issuperset(other : sequence of T) : boolean := wrappee.IsSupersetOf(other); + + static function operator=(s1 : &set; s2 : &set) : boolean := s1.wrappee.SetEquals(s2.wrappee); + + static function operator<>(s1 : &set; s2 : &set) : boolean := not (s1 = s2); + + static function operator<=(s1 : &set; s2 : &set) : boolean := s1.issubset(s2); + + static function operator<(s1 : &set; s2 : &set) : boolean := (s1 <= s2) and (s1 <> s2); + + static function operator>=(s1 : &set; s2 : &set) : boolean := s1.issuperset(s2); + + static function operator>(s1 : &set; s2 : &set) : boolean := (s1 >= s2) and (s1 <> s2); + + static function operator or(s1 : &set; s2 : &set) : &set := s1.union(s2); + + ///- + function !orEqual(other : &set) : &set; + begin + update(other); + Result := Self; + end; + + static function operator and(s1 : &set; s2 : &set) : &set := s1.intersection(s2); + + ///- + function !andEqual(other : &set) : &set; + begin + intersection_update(other); + Result := Self; + end; + + static function operator-(s1 : &set; s2 : &set) : &set := s1.difference(s2); + + static function operator -=(var s1 : &set; s2 : &set) : &set; + begin + s1.difference_update(s2); + end; + + static function operator xor(s1 : &set; s2 : &set) : &set := s1.symmetric_difference(s2); + + ///- + function !xorEqual(other : &set) : &set; + begin + symmetric_difference_update(other); + Result := Self; + end; + +// static function operator:=(var s1: &set; s2: &set): &set; +// begin +// s1.wrappee := s2.wrappee.ToHashSet(); +// end; + + static function operator implicit(s : HashSet) : &set := new &set(s); + + function GetEnumerator() : IEnumerator := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); +end; + +type dict = class(IEnumerable>) + private + wrappee : PABCSystem.Dictionary; + + constructor Create(d : PABCSystem.Dictionary) := wrappee := d; + + function GetValue(key : K) : V := wrappee[key]; + + procedure SetValue(key : K; val : V) := wrappee[key] := val; + + public + + constructor Create() := wrappee := new PABCSystem.Dictionary(); + + constructor Create(capacity : integer) := wrappee := new PABCSystem.Dictionary(capacity); + + constructor Create(comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.Dictionary(comparer); + + constructor Create(capacity : integer; comparer : PABCSystem.IEqualityComparer) := wrappee := new PABCSystem.Dictionary(capacity, comparer); + + constructor Create(params pairs: array of (K, V)); + begin + wrappee := new PABCSystem.Dictionary(); + + for var i := 0 to pairs.Length - 1 do + wrappee[pairs[i].Item1] := pairs[i].Item2; + end; + + constructor Create(seqOfPairs : sequence of (K, V)); + begin + wrappee := new PABCSystem.Dictionary(); + + foreach var p in seqOfPairs do + wrappee[p.Item1] := p.Item2; + end; + + ///-- + property !count : integer read wrappee.Count; + + property ByKey[key : K] : V read GetValue write SetValue; default; + + static function operator in(key: K; Self: dict): boolean; + begin + Result := Self.wrappee.ContainsKey(key); + end; + + procedure clear() := wrappee.Clear(); + + function copy() : dict := new dict(new Dictionary(wrappee)); + + static function fromkeys(sq : sequence of K; val : V := default(V)) : dict; + begin + Result := new dict(); + + foreach var key in sq do + Result[key] := val; + end; + + function get(key : K; &default : V := default(V)) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + Result := val + else + Result := &default; + end; + + function items() : sequence of KeyValuePair := wrappee; + + function keys() := wrappee.Keys; + + function pop(key : K) : V; + begin + Result := wrappee[key]; + wrappee.Remove(key); + end; + + function pop(key : K; &default : V) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + begin + Result := val; + wrappee.Remove(key); + end + else + Result := &default; + end; + + function popitem() : KeyValuePair; + begin + Result := wrappee.Last(); + wrappee.Remove(Result.Key); + end; + + function setdefault(key : K; &default : V := default(V)) : V; + begin + var val : V; + if wrappee.TryGetValue(key, val) then + Result := val + else + begin + wrappee[key] := &default; + Result := &default; + end; + end; + + procedure update(params pairs: array of (K, V)); + begin + for var i := 0 to pairs.Length - 1 do + wrappee[pairs[i].Item1] := pairs[i].Item2; + end; + + procedure update(seqOfPairs : sequence of (K, V)); + begin + foreach var p in seqOfPairs do + wrappee[p.Item1] := p.Item2; + end; + + function values() := wrappee.Values; + + static function operator or(d1 : dict; d2 : dict) : dict; + begin + Result := new dict(d1.wrappee); + + foreach var p in d2.wrappee do + Result[p.Key] := p.Value; + end; + + static function operator implicit(d : PABCSystem.Dictionary) : dict := new dict(d); + + function GetEnumerator() : IEnumerator> := wrappee.GetEnumerator(); + + function System.Collections.IEnumerable.GetEnumerator() : System.Collections.IEnumerator := GetEnumerator(); +end; + //Standard functions with Lists -function len(lst: PABCSystem.List): integer; -function len(st: set of T): integer; -function len(dct: PABCSystem.Dictionary): integer; +function len(lst: list): integer; +function len(st: &set): integer; +function len(dct: dict): integer; function len(arr: array of T): integer; function len(s: string): integer; -function &set(sq: sequence of T): set of T; -function &list(sq: sequence of T): PABCSystem.List; +// function &set(sq: sequence of T): &set; -function sorted(lst: PABCSystem.List): PABCSystem.List; +function sorted(lst: list): list; function sum(lst: sequence of integer): integer; @@ -162,14 +536,8 @@ function CreateTuple( // TUPLES END -function Dict(params pairs: array of (TKey, TVal)): Dictionary; - type biginteger = PABCSystem.BigInteger; - !list = PABCSystem.List; - !dict = PABCSystem.Dictionary; - dct = PABCSystem.Dictionary; - !set = set of T; tuple2 = System.Tuple; tuple3 = System.Tuple; tuple4 = System.Tuple; @@ -178,30 +546,30 @@ type tuple7 = System.Tuple; empty_list = class - class function operator implicit(x: empty_list): !list; + class function operator implicit(x: empty_list): list; begin - Result := new !list(); + Result := new list(); end; end; empty_set = class - class function operator implicit(x: empty_set): !set; + class function operator implicit(x: empty_set): &set; begin - Result := new !set; + Result := new &set(); end; end; empty_dict = class - class function operator implicit(x: empty_dict): !dict; + class function operator implicit(x: empty_dict): dict; begin - Result := new !dict(); + Result := new dict(); end; end; function !empty_list(): empty_list; function !empty_dict(): empty_dict; -function &set(): empty_set; + implementation @@ -246,8 +614,6 @@ begin Result := TypeName(obj) .Replace('<', '[') .Replace('>', ']') - .Replace('List', 'list') - .Replace('Dictionary', 'dict') .Replace('empty_list', 'list[anytype]') .Replace('empty_set', 'set[anytype]') .Replace('empty_dict', 'dict[anytype]') @@ -289,17 +655,17 @@ function abs(x: integer): integer := if x >= 0 then x else -x; function abs(x: real): real := PABCSystem.Abs(x); -function len(lst: PABCSystem.List): integer := lst.Count(); -function len(st: set of T): integer := st.Count(); -function len(dct: PABCSystem.Dictionary): integer := dct.Count(); -function len(arr: array of T): integer := arr.Count(); +function len(lst: list): integer := lst.!count; +function len(st: &set): integer := st.!count; +function len(dct: dict): integer := dct.!count; +function len(arr: array of T): integer := arr.Length; function len(s: string): integer := s.Length; -function sorted(lst: PABCSystem.List): PABCSystem.List; +function sorted(lst: list): list; begin - var new_list := new PABCSystem.List(lst); - new_list.sort(); - Result := new_list; + var newList := lst.copy(); + newList.sort(); + Result := newList; end; function sum(lst: sequence of integer): integer := lst.sum(); @@ -360,49 +726,32 @@ begin Result := x; end; -function !count(Self: PABCSystem.List; val: T): integer; extensionmethod; +function &set.isdisjoint(other : sequence of T) : boolean; begin - Result := 0; - for var i := 0 to Self.Count - 1 do - if val = Self[i] then - Result += 1; -end; - -function pop(Self: PABCSystem.List; ind: integer): T; extensionmethod; -begin - Result := Self[ind]; - Self.RemoveAt(ind); -end; - -procedure add(Self: set of T; val: T); extensionmethod; -begin - Self += val; -end; - -procedure remove(Self: set of T; val: T); extensionmethod; -begin - Self -= val; + if other = nil then + raise new System.ArgumentNullException('other', 'Null object is not iterable'); + + var c1 := wrappee.Count; + var c2 := other.Count(); + + if (c1 = 0) or (c2 = 0) then + Result := true + else + begin + if c1 >= c2 then + Result := other.All(elem -> not wrappee.Contains(elem)) + else + begin + var otherSet := new HashSet(other); + Result := wrappee.All(elem -> not otherSet.Contains(elem)); + end; + end; + end; function get_keys(dct: Dictionary):= dct.keys; function get_values(dct: Dictionary):= dct.values; -function copy(Self: set of T): set of T; extensionmethod; -begin - Result := Self; -end; - -procedure clear(var st: set of T); -begin - st := []; -end; - -function __NewSetCreatorInternal(params a: array of T): NewSet; -begin - //Result._hs := new HashSet; - Result._hs.UnionWith(a); -end; - // TUPLES BEGIN function CreateTuple( v1: T1; v2: T2 @@ -436,20 +785,10 @@ function CreateTuple( // TUPLES END -function Dict(params pairs: array of (TKey, TVal)): Dictionary; -begin - Result := new Dictionary(); - for var i := 0 to pairs.Length - 1 do - Result.Add(pairs[i][0], pairs[i][1]); -end; - -function &set(sq: sequence of T): set of T; -begin - foreach var e in sq do - Result.Add(e); -end; - -function &list(sq: sequence of T): PABCSystem.List := sq.ToList(); +//function &set(sq: sequence of T): &set; +//begin +// Result := new &set(sq); +//end; function all(s: sequence of boolean): boolean; begin @@ -473,14 +812,15 @@ begin end; end; -function ToDictionary(Self: sequence of System.tuple): Dictionary; extensionmethod; +///- +function ToDictionary(Self: sequence of System.Tuple): dict; extensionmethod; begin Result := Self.ToDictionary(x->x[0],x->x[1]); end; function !empty_list(): empty_list := new empty_list(); function !empty_dict(): empty_dict := new empty_dict(); -function &set(): empty_set := new empty_set; + function round(val: real): integer := PABCSystem.round(val); diff --git a/bin/Lib/SPythonSystemPys.pys b/bin/Lib/SPythonSystemPys.pys index 8e3a39431..7211115f9 100644 --- a/bin/Lib/SPythonSystemPys.pys +++ b/bin/Lib/SPythonSystemPys.pys @@ -4,9 +4,9 @@ from SPythonSystem import range, len def print(*args: obj, **kwargs: str): sep: str = ' ' end: str = '\n' - if 'sep' in kwargs.keys(): + if 'sep' in kwargs.get_keys(): sep = kwargs['sep'] - if 'end' in kwargs.keys(): + if 'end' in kwargs.get_keys(): end = kwargs['end'] for i in range(0, len(args) - 1): diff --git a/bin/Lib/itertools.pys b/bin/Lib/itertools.pys index 488fae2a9..d741c53a2 100644 --- a/bin/Lib/itertools.pys +++ b/bin/Lib/itertools.pys @@ -15,7 +15,7 @@ def chain(*args: list[int]) -> list[int]: # если вызвать как repeat(10, times=12) def repeat(val: int, **kwargs: int) -> list[int]: times = 1 - if 'times' in kwargs.keys(): + if 'times' in kwargs.get_keys(): times = kwargs['times'] return [val for i in range(times)]