Exemplo n.º 1
0
        public override Verb CreateVerb(string[] tokens)
        {
            var functionName = tokens[2];

            Color(position, tokens[1].Length, Whitespaces);
            Color(functionName.Length, IsClassName(functionName) ? Types : Invokeables);
            Color(tokens[3].Length, Structures);
            Color(tokens[4].Length, Whitespaces);

            if (GetExpression(source, NextPosition, CloseParenthesis()) is Some <(Block, int)> some)
            {
                (var block, var index) = some.Value;
                var arguments           = new Arguments(block);
                var blockOrLambdaParser = new BlockOrLambdaParser();
                if (blockOrLambdaParser.Scan(source, index))
                {
                    index = blockOrLambdaParser.Position;
                    var value = blockOrLambdaParser.Value;
                    arguments.AddArgument(value);
                }
                overridePosition = index;
                return(new FunctionInvoke(functionName, arguments));
            }

            return(null);
        }
Exemplo n.º 2
0
        public override Verb CreateVerb(string[] tokens)
        {
            var message = tokens[2];

            Color(position, tokens[1].Length, Structures);
            Color(message.Length, Messaging);

            Block      actualArguments;
            Block      executable = null;
            Parameters parameters = null;
            var        index      = position + length;
            var        bracket    = tokens[3];
            Lambda     lambda     = null;

            if (bracket == "(")
            {
                Color(1, Structures);
                if (GetExpression(source, index, CloseParenthesis()).If(out actualArguments, out var newIndex))
                {
                    index = newIndex;
                }
                else
                {
                    actualArguments = new Block();
                }
            }
            else
            {
                actualArguments = new Block();
            }

            if (blockOrLambdaParser.Scan(source, index))
            {
                overridePosition = blockOrLambdaParser.Result.Position;
                if (blockOrLambdaParser.Result.Verb is IExecutable e)
                {
                    parameters = e.Parameters;
                    executable = e.Action;
                    MessagingState.RegisterMessageCall(message);
                    var arguments = new Arguments(actualArguments, executable, parameters);
                    if (lambda != null)
                    {
                        arguments.AddArgument(lambda);
                    }

                    result.Value = new Message(message, arguments);
                }
            }

            return(new NullOp());
        }
Exemplo n.º 3
0
        public IMaybe <(int, string, Lambda)> Parse(string source, int index)
        {
            if (matcher.IsMatch(source.Substring(index), @"^ /(':') /('while' | 'until')"))
            {
                Color(index, matcher[0, 1].Length, Structures);
                var word = matcher[0, 2];
                Color(word.Length, Messaging);
                if (blockParser.Scan(source, index + matcher[0].Length))
                {
                    var result = blockParser.Result;
                    var value  = result.Value;
                    if (!(value is Lambda lambda))
                    {
                        lambda = new Lambda(new Region(), (Block)value, new Parameters(), false);
                    }
                    index = result.Position;
                    word  = word.ToTitleCase();
                    return((index, word, lambda).Some());
                }
            }

            return(none <(int, string, Lambda)>());
        }