コード例 #1
0
        //this is the constructor used when function is an override
        public AnonymousFunction(string value, List <IBaseFunction> predefined) : this()
        {
            Override = true;
            Name     = value.Split('.')[1].Split('(')[0];

            var b = predefined.FirstOrDefault(f => f.Name == Name);

            if (b == null)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException, $"Unexpected error. Function failed to override: {Name}.", value));
            }
            if (b.Sealed == true)
            {
                Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                      $"Invalid Operation. Cannot override Sealed function: {Name}.", value));
            }
            Base = b;
            //get top level anonymous functions before everything else
            var anonRegex        = new Regex(Compiler.ScopeRegex(@"=>"), RegexOptions.IgnorePatternWhitespace);
            var anonRegexMatches = anonRegex.Matches(value);

            foreach (var a in anonRegexMatches)
            {
                var func = new AnonymousFunction(a.ToString(), true, _base);
                FunctionStack.Add(func);
                value = value.Replace(a.ToString(), $"\"{func.Name}\"");
            }
            //
            Value        = value;
            ExpectedArgs = value.Split('(')[1].Split(')')[0].Split(',');
            ParseDirectives(value);
        }
コード例 #2
0
        //standard constructor
        public AnonymousFunction(string value) : this()
        {
            Name = value.Split('.')[1].Split('(')[0];
            var b = Compiler.PredefinedList.FirstOrDefault(f => f.Name == Name);

            if (b != null)
            {
                if (b.Sealed == true)
                {
                    Compiler.ExceptionListener.Throw(new ExceptionHandler(ExceptionType.CompilerException,
                                                                          $"Invalid Operation. Cannot create a new instance of a Sealed function: {Name}.", value));
                }
            }
            //get top level anonymous functions before everything else
            var anonRegex        = new Regex(Compiler.ScopeRegex(@"=>"), RegexOptions.IgnorePatternWhitespace);
            var anonRegexMatches = anonRegex.Matches(value);

            foreach (var a in anonRegexMatches)
            {
                var func = new AnonymousFunction(a.ToString(), true, _base);
                func.Base = Base;
                FunctionStack.Add(func);
                value = value.Replace(a.ToString(), $"\"{func.Name}\"");
            }
            //
            Value        = value;
            ExpectedArgs = value.Split('(')[1].Split(')')[0].Split(',');
            ParseDirectives(value);
        }
コード例 #3
0
        //this constructor is when function is anonomysly named
        public AnonymousFunction(string value, bool anon, IBaseFunction callerBase) : this()
        {
            Base        = callerBase;
            IsAnonymous = true;
            //get top level anonymous functions before everything else
            value = value.Substring(1);
            var anonRegex        = new Regex(Compiler.ScopeRegex(@"=>"), RegexOptions.IgnorePatternWhitespace);
            var anonRegexMatches = anonRegex.Matches(value);

            foreach (var a in anonRegexMatches)
            {
                var func = new AnonymousFunction(a.ToString(), true, _base);
                FunctionStack.Add(func);
                value = value.Replace(a.ToString(), $"\"{func.Name}\"");
            }
            Value        = value;
            Name         = "AnonymousFunction" + Compiler.AnonymousFunctionIndex;
            ExpectedArgs = value.Split('(')[1].Split(')')[0].Split(',');
            ParseDirectives(value);
            //Name = value.Split('.')[1].Split('(')[0];
        }
コード例 #4
0
        //the construction for custom extensions
        public AnonymousFunction(string value, CustomExtension parent) : this()
        {
            Name = value.Split('.')[1].Split('(')[0];

            //get top level anonymous functions before everything else
            var anonRegex        = new Regex(Compiler.ScopeRegex(@"=>"), RegexOptions.IgnorePatternWhitespace);
            var anonRegexMatches = anonRegex.Matches(value);

            foreach (var a in anonRegexMatches)
            {
                var func = new AnonymousFunction(a.ToString(), true, _base);
                func.Base = Base;
                FunctionStack.Add(func);
                value = value.Replace(a.ToString(), $"\"{func.Name}\"");
            }
            //
            Value        = value;
            ExpectedArgs = value.Split('(')[1].Split(')')[0].Split(',');
            var type = ExpectedArgs.ElementAtOrDefault(0);

            if (type != null && type == "this variable")
            {
                parent.SetProperties(Name, new string[] { }, false, false, true, new string[] { });
            }
            else if (type != null && type == "this function")
            {
                parent.SetProperties(Name, new string[] { }, false, false, false, new string[] { });
            }
            else
            {
                Compiler.ExceptionListener.Throw("[287]Custom extension must have input parameter of `this variable` or `this function`");
            }
            //replace this from the parameter, so it can be called by just `function` or `variable` at runtime
            //the `this` is only there for definition, to direct the extension parser to look for this extension
            //in the variable lot or not.
            ExpectedArgs[0] = ExpectedArgs[0].Replace("this ", "");
            ParseDirectives(value);
        }