Пример #1
0
        private static AstNode ParseBlock(TokenStream stream)
        {
            CodeBlock ret = new CodeBlock (stream.Location);
            stream.Expect (TokenClass.OpenBrace);

            while (!stream.Match (TokenClass.CloseBrace)) {
                ret.Add (ParseStatement (stream));
            }

            stream.Expect (TokenClass.CloseBrace);
            return ret;
        }
Пример #2
0
        private static AstNode ParseFunction(TokenStream stream, bool prototype = false,
			ClassDeclaration cdecl = null)
        {
            if (stream.Accept (TokenClass.Operator, "@")) {
                /*
                 * Function decorators in the form of
                 * @myDecorator
                 * func foo () {
                 * }
                 * are merely syntatic sugar for
                 * func foo () {
                 * }
                 * foo = myDecorator (foo)
                 */
                AstNode expr = ParseExpression (stream); // Decorator expression
                /* This is the original function which is to be decorated */
                FunctionDeclaration idecl = ParseFunction (stream, prototype, cdecl) as FunctionDeclaration;
                /* We must construct an arglist which will be passed to the decorator */
                ArgumentList args = new ArgumentList (stream.Location);
                args.Add (new NameExpression (stream.Location, idecl.Name));
                /*
                 * Since two values can not be returned, we must return a single node containing both
                 * the function declaration and call to the decorator
                 */
                AstRoot nodes = new AstRoot (stream.Location);
                nodes.Add (idecl);
                nodes.Add (new Expression (stream.Location, new BinaryExpression (stream.Location,
                    BinaryOperation.Assign,
                    new NameExpression (stream.Location, idecl.Name),
                    new CallExpression (stream.Location, expr, args))));
                return nodes;
            }
            stream.Expect (TokenClass.Keyword, "func");
            bool isInstanceMethod;
            bool isVariadic;
            bool hasKeywordArgs;
            Token ident = stream.Expect (TokenClass.Identifier);
            List<string> parameters = ParseFuncParameters (stream,
                out isInstanceMethod,
                out isVariadic,
                out hasKeywordArgs);

            FunctionDeclaration decl = new FunctionDeclaration (stream.Location, ident != null ?
                ident.Value : "",
                isInstanceMethod,
                isVariadic,
                hasKeywordArgs,
                parameters);

            if (!prototype) {

                if (stream.Accept (TokenClass.Operator, "=>")) {
                    decl.Add (new ReturnStatement (stream.Location, ParseExpression (stream)));
                } else {
                    stream.Expect (TokenClass.OpenBrace);
                    CodeBlock scope = new CodeBlock (stream.Location);

                    if (stream.Match (TokenClass.Keyword, "super")) {
                        scope.Add (ParseSuperCall (stream, cdecl));
                    }

                    while (!stream.Match (TokenClass.CloseBrace)) {
                        scope.Add (ParseStatement (stream));
                    }

                    decl.Add (scope);
                    stream.Expect (TokenClass.CloseBrace);
                }
            }
            return decl;
        }
Пример #3
0
 public void Accept(CodeBlock scope)
 {
     scope.Visit (functionCompiler);
 }
Пример #4
0
		public override void Accept (CodeBlock scope)
		{
			symbolTable.NextScope ();

			FunctionCompiler scopeCompiler = new FunctionCompiler (symbolTable, methodBuilder,
				                                 breakLabels, continueLabels);
			foreach (AstNode node in scope) {
				node.Visit (scopeCompiler);
			}
			symbolTable.LeaveScope ();
		}
Пример #5
0
		public override void Accept (CodeBlock scope)
		{
			errorLog.AddError (ErrorType.ParserError, scope.Location,
				"statement can not exist inside pattern!");
		}
Пример #6
0
 public virtual void Accept(CodeBlock scope)
 {
 }
Пример #7
0
 public void Accept(CodeBlock scope)
 {
     symbolTable.BeginScope ();
     scope.VisitChildren (this);
     symbolTable.EndScope ();
 }
Пример #8
0
 public void Accept(CodeBlock scope)
 {
     scope.VisitChildren (this);
 }
Пример #9
0
 public void Accept(CodeBlock scope)
 {
 }