Esempio n. 1
0
        public List <Expr> Parse(ParserContext context)
        {
            // Create the resulting argument list.
            List <Expr> arguments = new List <Expr>();

            // Parse the next value.
            Expr value = new ExprParser().Parse(context);

            // Append value to the argument list.
            arguments.Add(value);

            // Capture the current token.
            Token token = context.Stream.Current;

            // Expect either a comma or pipe symbol.
            if (token.Type != SyntaxAnalysis.TokenType.OperatorPipe && token.Type != SyntaxAnalysis.TokenType.SymbolComma)
            {
                throw new Exception($"Expected next token to be of type either comma symbol or pipe operator, but got '{token.Type}'");
            }
            // There is another value.
            else if (token.Type == SyntaxAnalysis.TokenType.SymbolComma)
            {
                // Skip comma token.
                context.Stream.Skip();

                // Recursively invoke a new pipe args parser instance.
                List <Expr> nextArguments = new PipeArgsParser().Parse(context);

                // Append resulting arguments.
                arguments.AddRange(nextArguments);
            }

            // Return the resulting argument list.
            return(arguments);
        }
Esempio n. 2
0
        public Pipe Parse(ParserContext context)
        {
            // Expect current token to be symbol colon.
            context.Stream.EnsureCurrent(TokenType.SymbolColon);

            // Skip colon symbol.
            context.Stream.Skip();

            // Invoke the pipe arguments parser.
            List <Expr> arguments = new PipeArgsParser().Parse(context);

            // Expect current token to be pipe operator.
            context.Stream.EnsureCurrent(TokenType.OperatorPipe);

            // Capture the target identifier.
            string identifier = context.Stream.Next(TokenType.Identifier).Value;

            // Skip identifier onto semi-colon.
            context.Stream.Skip(TokenType.SymbolSemiColon);

            // Create the resulting pipe entity.
            Pipe pipe = new Pipe(arguments.ToArray(), identifier);

            // Return the resulting pipe entity.
            return(pipe);
        }