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