diff --git a/CodeCompletion/CodeFormatter.cs b/CodeCompletion/CodeFormatter.cs index 1c8c3d21b..767d89240 100644 --- a/CodeCompletion/CodeFormatter.cs +++ b/CodeCompletion/CodeFormatter.cs @@ -3193,6 +3193,68 @@ namespace CodeFormatters add_space_after = false; } + public override void visit(const_pattern_parameter _const_parameter) + { + visit_node(_const_parameter.const_param); + add_space_after = false; + } + + public override void visit(wild_card_deconstructor_parameter _wild_card_deconstructor_parameter) + { + add_space_after = false; + } + + public override void visit(tuple_pattern_var_parameter _tuple_pattern_var_parameter) + { + sb.Append("var"); + SetKeywordOffset("var"); + read_from_beg_pos = true; + visit_node(_tuple_pattern_var_parameter.identifier); + } + + public override void visit(tuple_pattern_wild_card _tuple_pattern_wild_card) + { + add_space_after = false; + } + + public override void visit(tuple_pattern _tuple_pattern) + { + foreach (var parameter in _tuple_pattern.parameters) + { + visit_node(parameter); + add_space_after = true; + } + add_space_after = false; + } + + public override void visit(collection_pattern _collection_pattern) + { + foreach (var parameter in _collection_pattern.parameters) + { + visit_node(parameter); + add_space_after = true; + } + add_space_after = false; + } + + public override void visit(collection_pattern_gap_parameter _collection_pattern_gap_parameter) + { + add_space_after = false; + } + + public override void visit(collection_pattern_var_parameter _collection_pattern_var_parameter) + { + sb.Append("var"); + SetKeywordOffset("var"); + read_from_beg_pos = true; + visit_node(_collection_pattern_var_parameter.identifier); + } + + public override void visit(collection_pattern_wild_card _collection_pattern_wild_card) + { + add_space_after = false; + } + public override void visit(deconstructor_pattern _deconstructor_pattern) { visit_node(_deconstructor_pattern.type); @@ -3206,18 +3268,34 @@ namespace CodeFormatters public override void visit(var_deconstructor_parameter _var_deconstructor_parameter) { - sb.Append("var"); - SetKeywordOffset("var"); - read_from_beg_pos = true; + if (_var_deconstructor_parameter.var_keyword_used) + { + sb.Append("var"); + SetKeywordOffset("var"); + read_from_beg_pos = true; + } visit_node(_var_deconstructor_parameter.identifier); if (_var_deconstructor_parameter.type != null) visit_node(_var_deconstructor_parameter.type); } + public override void visit(recursive_pattern_parameter _recursive_pattern_parameter) + { + visit_node(_recursive_pattern_parameter.pattern); + } + public override void visit(recursive_deconstructor_parameter _recursive_deconstructor_parameter) { visit_node(_recursive_deconstructor_parameter.pattern); } + public override void visit(recursive_tuple_parameter _recursive_tuple_parameter) + { + visit_node(_recursive_tuple_parameter.pattern); + } + public override void visit(recursive_collection_parameter _recursive_collection_parameter) + { + visit_node(_recursive_collection_parameter.pattern); + } public override void visit(var_tuple_def_statement _var_tuple_def_statement) { diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs index 0a80aa470..7f63587c2 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.cs @@ -2,7 +2,7 @@ // This CSharp output file generated by Gardens Point LEX // Version: 1.1.3.301 // Machine: DESKTOP-IF20NRO -// DateTime: 4/25/2019 5:35:11 PM +// DateTime: 5/20/2019 1:17:15 PM // UserName: FatCow // GPLEX input file // GPLEX frame file diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y index ae52436ca..7d7f97420 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascal.y +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascal.y @@ -3497,11 +3497,11 @@ pattern_out_param } | tkVar identifier tkColon type_ref { - $$ = new var_deconstructor_parameter($2, $4, @$); + $$ = new var_deconstructor_parameter($2, $4, true, @$); } | tkVar identifier { - $$ = new var_deconstructor_parameter($2, null, @$); + $$ = new var_deconstructor_parameter($2, null, true, @$); } | pattern { @@ -3528,19 +3528,19 @@ pattern_out_param_optional_var } | identifier tkColon type_ref { - $$ = new var_deconstructor_parameter($1, $3, @$); + $$ = new var_deconstructor_parameter($1, $3, false, @$); } | identifier { - $$ = new var_deconstructor_parameter($1, null, @$); + $$ = new var_deconstructor_parameter($1, null, false, @$); } | tkVar identifier tkColon type_ref { - $$ = new var_deconstructor_parameter($2, $4, @$); + $$ = new var_deconstructor_parameter($2, $4, true, @$); } | tkVar identifier { - $$ = new var_deconstructor_parameter($2, null, @$); + $$ = new var_deconstructor_parameter($2, null, true, @$); } | pattern_optional_var { diff --git a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs index 5c9be98eb..14acc5b5f 100644 --- a/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs +++ b/Parsers/PascalABCParserNewSaushkin/ABCPascalYacc.cs @@ -2,7 +2,7 @@ // GPPG version 1.3.6 // Machine: DESKTOP-IF20NRO -// DateTime: 4/25/2019 5:35:12 PM +// DateTime: 5/20/2019 1:17:16 PM // UserName: FatCow // Input file @@ -5796,12 +5796,12 @@ public partial class GPPGParser: ShiftReduceParser tkVar, identifier, tkColon, type_ref { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, true, CurrentLocationSpan); } break; case 648: // pattern_out_param -> tkVar, identifier { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, true, CurrentLocationSpan); } break; case 649: // pattern_out_param -> pattern @@ -5831,22 +5831,22 @@ public partial class GPPGParser: ShiftReduceParser identifier, tkColon, type_ref { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, false, CurrentLocationSpan); } break; case 655: // pattern_out_param_optional_var -> identifier { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, false, CurrentLocationSpan); } break; case 656: // pattern_out_param_optional_var -> tkVar, identifier, tkColon, type_ref { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-3].id, ValueStack[ValueStack.Depth-1].td, true, CurrentLocationSpan); } break; case 657: // pattern_out_param_optional_var -> tkVar, identifier { - CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, CurrentLocationSpan); + CurrentSemanticValue.stn = new var_deconstructor_parameter(ValueStack[ValueStack.Depth-1].id, null, true, CurrentLocationSpan); } break; case 658: // pattern_out_param_optional_var -> pattern_optional_var diff --git a/SyntaxTree/tree/SyntaxTreeStreamReader.cs b/SyntaxTree/tree/SyntaxTreeStreamReader.cs index ce4ed17c6..d1083b345 100644 --- a/SyntaxTree/tree/SyntaxTreeStreamReader.cs +++ b/SyntaxTree/tree/SyntaxTreeStreamReader.cs @@ -4130,6 +4130,7 @@ namespace PascalABCCompiler.SyntaxTree read_pattern_parameter(_var_deconstructor_parameter); _var_deconstructor_parameter.identifier = _read_node() as ident; _var_deconstructor_parameter.type = _read_node() as type_definition; + _var_deconstructor_parameter.var_keyword_used = br.ReadBoolean(); } diff --git a/SyntaxTree/tree/SyntaxTreeStreamWriter.cs b/SyntaxTree/tree/SyntaxTreeStreamWriter.cs index 62fc4f3c9..8aca836e1 100644 --- a/SyntaxTree/tree/SyntaxTreeStreamWriter.cs +++ b/SyntaxTree/tree/SyntaxTreeStreamWriter.cs @@ -6481,6 +6481,7 @@ namespace PascalABCCompiler.SyntaxTree bw.Write((byte)1); _var_deconstructor_parameter.type.visit(this); } + bw.Write(_var_deconstructor_parameter.var_keyword_used); } diff --git a/SyntaxTree/tree/Tree.cs b/SyntaxTree/tree/Tree.cs index 793782fdf..bce9648ef 100644 --- a/SyntaxTree/tree/Tree.cs +++ b/SyntaxTree/tree/Tree.cs @@ -50181,25 +50181,28 @@ namespace PascalABCCompiler.SyntaxTree /// ///Конструктор с параметрами. /// - public var_deconstructor_parameter(ident _identifier,type_definition _type) + public var_deconstructor_parameter(ident _identifier,type_definition _type,bool _var_keyword_used) { this._identifier=_identifier; this._type=_type; + this._var_keyword_used=_var_keyword_used; FillParentsInDirectChilds(); } /// ///Конструктор с параметрами. /// - public var_deconstructor_parameter(ident _identifier,type_definition _type,SourceContext sc) + public var_deconstructor_parameter(ident _identifier,type_definition _type,bool _var_keyword_used,SourceContext sc) { this._identifier=_identifier; this._type=_type; + this._var_keyword_used=_var_keyword_used; source_context = sc; FillParentsInDirectChilds(); } protected ident _identifier; protected type_definition _type; + protected bool _var_keyword_used; /// /// @@ -50235,6 +50238,21 @@ namespace PascalABCCompiler.SyntaxTree } } + /// + /// + /// + public bool var_keyword_used + { + get + { + return _var_keyword_used; + } + set + { + _var_keyword_used=value; + } + } + /// Создает копию узла public override syntax_tree_node Clone() @@ -50253,6 +50271,7 @@ namespace PascalABCCompiler.SyntaxTree copy.type = (type_definition)type.Clone(); copy.type.Parent = copy; } + copy.var_keyword_used = var_keyword_used; return copy; } diff --git a/SyntaxTree/tree/tree.xml b/SyntaxTree/tree/tree.xml index 079004e23..9d436c1d7 100644 --- a/SyntaxTree/tree/tree.xml +++ b/SyntaxTree/tree/tree.xml @@ -2999,6 +2999,7 @@ + @@ -4652,6 +4653,7 @@ + diff --git a/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs b/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs index 23719d176..ab50b45d9 100644 --- a/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs +++ b/SyntaxVisitors/SugarVisitors/PatternsDesugaringVisitor.cs @@ -249,6 +249,7 @@ namespace SyntaxVisitors.SugarVisitors pattern.parameters[i] = new var_deconstructor_parameter( constParamIdent, GetTypeDefinitionForConstParam(constPattern.const_param), + false, pattern.parameters[i].source_context); paramCheckExpr = paramCheckExpr == null ? (expression)constParamCheck : bin_expr.LogicalAnd(paramCheckExpr, constParamCheck); @@ -260,6 +261,7 @@ namespace SyntaxVisitors.SugarVisitors pattern.parameters[i] = new var_deconstructor_parameter( wildCardGeneratedParamIdent, null, + false, pattern.parameters[i].source_context); } @@ -651,7 +653,7 @@ namespace SyntaxVisitors.SugarVisitors pattern_parameter varParameter = null; if (pattern is deconstructor_pattern) { - varParameter = new var_deconstructor_parameter(newName, null); + varParameter = new var_deconstructor_parameter(newName, null, false); } else if (pattern is collection_pattern) { @@ -671,6 +673,7 @@ namespace SyntaxVisitors.SugarVisitors private void DesugarIsExpressionInAssignment(is_pattern_expr isExpression) { + // Кинуть тут эксепшн Debug.Assert(isExpression.right is deconstructor_pattern, "Only deconstructor patterns can be used in assignment"); var statementsToAdd = ProcessDesugaringForDeconstructorPattern(isExpression); AddDefinitionsInUpperStatementList(isExpression, statementsToAdd);