Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public void Accept(MatchExpression match)
 {
     match.VisitChildren (functionCompiler);
 }
Exemplo n.º 3
0
		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);
		}
Exemplo n.º 4
0
		public override void Accept (MatchExpression match)
		{
			errorLog.AddError (ErrorType.ParserError, match.Location,
				"match expression can not exist inside pattern!");
		}
Exemplo n.º 5
0
 public virtual void Accept(MatchExpression match)
 {
 }
Exemplo n.º 6
0
 public void Accept(MatchExpression match)
 {
     match.VisitChildren (this);
 }
Exemplo n.º 7
0
 public void Accept(MatchExpression match)
 {
     FunctionAnalyser visitor = new FunctionAnalyser (errorLog, symbolTable);
     match.Visit (visitor);
 }
Exemplo n.º 8
0
 public void Accept(MatchExpression match)
 {
 }