Add pattern examples & fix desugaring
This commit is contained in:
parent
3f93bfa24b
commit
ef82825afe
8
Patterns/patterns-switch.pas
Normal file
8
Patterns/patterns-switch.pas
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
begin
|
||||
var a := new List<integer>(arr(1, 2));
|
||||
match a with
|
||||
integer(var c): write(1);
|
||||
boolean(var s): write(2);
|
||||
List<integer>(var l):write(3)
|
||||
end;
|
||||
end.
|
||||
26
Patterns/patterns.pas
Normal file
26
Patterns/patterns.pas
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
type
|
||||
Person = auto class
|
||||
name: string;
|
||||
age: integer;
|
||||
end;
|
||||
|
||||
type
|
||||
Student = class(Person);
|
||||
|
||||
begin
|
||||
var b1 := new Student('asd', 30) is Person(var c);
|
||||
writeln(c);
|
||||
|
||||
var b2 := 1 is integer(var d);
|
||||
writeln(d);
|
||||
|
||||
var arr := Arr(1, 3, 5, 7, 9);
|
||||
|
||||
var l := new List<integer>(arr);
|
||||
var b4 := l is List<integer>(var f);
|
||||
writeln(f);
|
||||
|
||||
var delegate: Func<word, char> := PABCSystem.ChrUnicode;
|
||||
var b5 := delegate is Func<word, char>(var g);
|
||||
writeln(g);
|
||||
end.
|
||||
|
|
@ -42,6 +42,9 @@ namespace PascalABCCompiler.SyntaxTreeConverters
|
|||
// double_question_desugar_visitor
|
||||
DoubleQuestionDesugarVisitor.New.ProcessNode(root);
|
||||
|
||||
// pattern matching
|
||||
MatchWithVisitor.New.ProcessNode(root);
|
||||
IsPatternVisitor.New.ProcessNode(root);
|
||||
|
||||
// Всё, связанное с yield
|
||||
MarkMethodHasYieldAndCheckSomeErrorsVisitor.New.ProcessNode(root);
|
||||
|
|
|
|||
Loading…
Reference in a new issue