Пример #1
0
                public static FTL.AST.INode Parse(CharStream cs)
                {
                    FTL.AST.INode expression = Expresson.Parse(cs);

                    int bufferPos = cs.Position;

                    WhiteSpace.Parse(cs);

                    if (cs.PeekNext() != SEPERATOR[0])
                    {
                        // it's not a select expression, so let's return early
                        cs.Rewind(bufferPos);
                        return(expression);
                    }

                    // it must be a select expression

                    cs.SkipString(SEPERATOR);

                    WhiteSpace.Parse(cs);

                    // we expect now a memberList (REQUIRED)
                    FTL.AST.MemberList memberList = MemberList.Parse(cs);

                    // skip extra new-line in case one is available
                    if (CharStream.IsNL(cs.PeekNext()))
                    {
                        NewLine.Parse(cs);
                    }

                    // return it all
                    return(new FTL.AST.SelectExpression(expression, memberList));
                }
Пример #2
0
                public static FTL.AST.INode Parse(CharStream cs)
                {
                    FTL.AST.INode result;

                    // if it's an identifier, it could be either simply be an identifier,
                    // or it could actually be a keyword-argument
                    if (Identifier.PeekAndParse(cs, out result))
                    {
                        int bufferPos = cs.Position;
                        // ignore any whitespace
                        WhiteSpace.Parse(cs);

                        // if we now encounter a `=` char, we'll assume it's a keyword-argument,
                        // and finish the parsing of that element,
                        // otherwise we'll assume it's simply an identifier and return early
                        if (cs.PeekNext() != '=')
                        {
                            cs.Rewind(bufferPos);
                            return(Expresson.ParseWithIdentifier(cs, result as FTL.AST.StringPrimitive));
                        }

                        cs.SkipNext();
                        WhiteSpace.Parse(cs);

                        FTL.AST.Pattern pattern = Pattern.ParseQuoted(cs);
                        return(new FTL.AST.KeywordArgument(
                                   result as L20n.FTL.AST.StringPrimitive,
                                   pattern));
                    }

                    // it's not an identifier, so is must be any non-identifier expression
                    return(Expresson.ParseNoneIdentifier(cs));
                }
Пример #3
0
        private void checkValidExpression <T>(string input, string rest = "")
        {
            var cs         = NCS(input);
            var expression = Expresson.Parse(cs);

            Assert.IsNotNull(expression);
            Assert.AreEqual(rest, cs.ReadUntilEnd());
            Assert.AreEqual(typeof(T), expression.GetType());
        }