Allow var token in match..with and require in 'is' expression

This commit is contained in:
Alexander Zakharenko 2018-05-22 21:30:38 +03:00
parent 8026b6b31c
commit 32f8b7adf2
7 changed files with 1991 additions and 1858 deletions

View file

@ -2,7 +2,7 @@
// This CSharp output file generated by Gardens Point LEX
// Version: 1.1.3.301
// Machine: ALEXANDER-PC
// DateTime: 17.05.2018 0:42:21
// DateTime: 22.05.2018 21:23:09
// UserName: Alexander
// GPLEX input file <ABCPascal.lex>
// GPLEX frame file <embedded resource>

View file

@ -173,8 +173,8 @@
%type <stn> full_lambda_fp_list lambda_simple_fp_sect lambda_function_body lambda_procedure_body optional_full_lambda_fp_list
%type <ob> field_in_unnamed_object list_fields_in_unnamed_object func_class_name_ident_list rem_lambda variable_list var_ident_list
%type <ti> tkAssignOrEqual
%type <stn> pattern match_with pattern_case pattern_cases pattern_out_param
%type <ob> pattern_out_param_list
%type <stn> pattern pattern_optional_var match_with pattern_case pattern_cases pattern_out_param pattern_out_param_optional_var
%type <ob> pattern_out_param_list pattern_out_param_list_optional_var
%%
parse_goal
@ -2557,11 +2557,11 @@ pattern_cases
pattern_case
:
{ $$ = new empty_statement(); }
| pattern tkWhen expr_l1 tkColon unlabelled_stmt
| pattern_optional_var tkWhen expr_l1 tkColon unlabelled_stmt
{
$$ = new pattern_case($1 as pattern_node, $5 as statement, $3, @$);
}
| pattern tkColon unlabelled_stmt
| pattern_optional_var tkColon unlabelled_stmt
{
$$ = new pattern_case($1 as pattern_node, $3 as statement, null, @$);
}
@ -3024,7 +3024,34 @@ pattern
$$ = new deconstructor_pattern($3 as List<pattern_deconstructor_parameter>, $1, @$);
}
;
pattern_optional_var
: simple_or_template_type_reference tkRoundOpen pattern_out_param_list_optional_var tkRoundClose
{
$$ = new deconstructor_pattern($3 as List<pattern_deconstructor_parameter>, $1, @$);
}
;
pattern_out_param_list_optional_var
: pattern_out_param_optional_var
{
$$ = new List<pattern_deconstructor_parameter>();
($$ as List<pattern_deconstructor_parameter>).Add($1 as pattern_deconstructor_parameter);
}
| pattern_out_param_list_optional_var tkSemiColon pattern_out_param_optional_var
{
var list = $1 as List<pattern_deconstructor_parameter>;
list.Add($3 as pattern_deconstructor_parameter);
$$ = list;
}
| pattern_out_param_list_optional_var tkComma pattern_out_param_optional_var
{
var list = $1 as List<pattern_deconstructor_parameter>;
list.Add($3 as pattern_deconstructor_parameter);
$$ = list;
}
;
pattern_out_param_list
: pattern_out_param
{
@ -3043,9 +3070,24 @@ pattern_out_param_list
list.Add($3 as pattern_deconstructor_parameter);
$$ = list;
}
;
;
pattern_out_param
: tkVar identifier tkColon type_ref
{
$$ = new var_deconstructor_parameter($2, $4, @$);
}
| tkVar identifier
{
$$ = new var_deconstructor_parameter($2, null, @$);
}
| pattern
{
$$ = new recursive_deconstructor_parameter($1 as pattern_node, @$);
}
;
pattern_out_param_optional_var
: identifier tkColon type_ref
{
$$ = new var_deconstructor_parameter($1, $3, @$);
@ -3054,7 +3096,15 @@ pattern_out_param
{
$$ = new var_deconstructor_parameter($1, null, @$);
}
| pattern
| tkVar identifier tkColon type_ref
{
$$ = new var_deconstructor_parameter($2, $4, @$);
}
| tkVar identifier
{
$$ = new var_deconstructor_parameter($2, null, @$);
}
| pattern_optional_var
{
$$ = new recursive_deconstructor_parameter($1 as pattern_node, @$);
}

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
begin
var res := Arr(object(new List<integer>), object('asd'), object(1), object(2.0)).First(x -> x is string(s));
var res := Arr(object(new List<integer>), object('asd'), object(1), object(2.0)).First(x -> x is string(var s));
Assert(res = 'asd');
end.

View file

@ -1,7 +1,7 @@
begin
var a:='asd';
if (a is string(s)) and (s is string(s1)) then
if (s1 is string(s2)) and (s2 is string(s3)) and (s3 = 'asd') then
if (a is string(var s)) and (s is string(var s1)) then
if (s1 is string(var s2)) and (s2 is string(var s3)) and (s3 = 'asd') then
Assert(s3 = 'asd')
else
Assert(false)

View file

@ -13,7 +13,7 @@ begin
var p := new Pair<integer, string>;
p._a := 1;
p._b := 'asd';
if p is Pair<integer, string>(integer(a), string(b)) then
if p is Pair<integer, string>(integer(var a), string(var b)) then
Assert((a = 1) and (b = 'asd'))
else
Assert(false);

View file

@ -1,6 +1,6 @@
function Y1(): sequence of integer;
begin
if 1 is integer(i) then
if 1 is integer(var i) then
yield i;
end;