private static AstNode ParseMatch(TokenStream stream) { MatchExpression expr = new MatchExpression (stream.Location); stream.Expect (TokenClass.Keyword, "match"); expr.Add (ParseExpression (stream)); stream.Expect (TokenClass.OpenBrace); while (stream.Accept (TokenClass.Keyword, "case")) { AstNode condition = null; AstNode pattern = ParsePattern (stream); if (stream.Accept (TokenClass.Keyword, "when")) { condition = ParseExpression (stream); } stream.Expect (TokenClass.Operator, "=>"); AstNode value = ParseExpression (stream); expr.Children.Add (new CaseExpression (pattern.Location, pattern, condition, value)); } stream.Expect (TokenClass.CloseBrace); return expr; }
public void Accept(MatchExpression match) { match.VisitChildren (functionCompiler); }
public override void Accept (MatchExpression match) { AstNode value = match.Children [0]; value.Visit (this); int temporary = methodBuilder.CreateTemporary (); methodBuilder.EmitInstruction (match.Location, Opcode.StoreLocal, temporary); PatternCompiler compiler = new PatternCompiler (symbolTable, methodBuilder, temporary, this); IodineLabel nextLabel = methodBuilder.CreateLabel (); IodineLabel endLabel = methodBuilder.CreateLabel (); for (int i = 1; i < match.Children.Count; i++) { if (i > 1) { methodBuilder.MarkLabelPosition (nextLabel); nextLabel = methodBuilder.CreateLabel (); } CaseExpression clause = match.Children [i] as CaseExpression; clause.Pattern.Visit (compiler); methodBuilder.EmitInstruction (match.Location, Opcode.JumpIfFalse, nextLabel); if (clause.Condition != null) { clause.Condition.Visit (this); methodBuilder.EmitInstruction (match.Location, Opcode.JumpIfFalse, nextLabel); } clause.Value.Visit (this); methodBuilder.EmitInstruction (match.Location, Opcode.Jump, endLabel); } methodBuilder.MarkLabelPosition (endLabel); }
public override void Accept (MatchExpression match) { errorLog.AddError (ErrorType.ParserError, match.Location, "match expression can not exist inside pattern!"); }
public virtual void Accept(MatchExpression match) { }
public void Accept(MatchExpression match) { match.VisitChildren (this); }
public void Accept(MatchExpression match) { FunctionAnalyser visitor = new FunctionAnalyser (errorLog, symbolTable); match.Visit (visitor); }
public void Accept(MatchExpression match) { }