Esempio n. 1
0
        static FluentParser()
        {
            /*
             * Grammar:
             * expression     => factor ( ( "-" | "+" ) factor )* ;
             * factor         => unary ( ( "/" | "*" ) unary )* ;
             * unary          => ( "-" ) unary
             *                 | primary ;
             * primary        => NUMBER
             *                  | "(" expression ")" ;
             */

            // The Deferred helper creates a parser that can be referenced by others before it is defined
            var expression = Deferred <Expression>();

            var number = Terms.Decimal()
                         .Then <Expression>(static d => new Number(d))
        public IEnumerable <Parser <IAssetParserFragment> > GetParsers()
        {
            var propType = Between(Terms.Char('<'),
                                   Terms.Identifier().Then <IAssetParserFragment>(id => new PropertyValueFragment
            {
                PropertyType = id.ToString()
            }),
                                   Terms.Char('>'));
            var propValue = Between(Terms.Char('<'), Terms.Identifier().AndSkip(Terms.Char('=')).And(TemplateParser.ValueInputParser.Or(Terms.Char('*').Then(c => c.ToString())))
                                    .Then <IAssetParserFragment>(x =>
                                                                 new PropertyValueFragment
            {
                PropertyType = x.Item1.ToString(), PropertyValue = x.Item2.ToString()
            }), Terms.Char('>'));

            var numberPropValue = Between(Terms.Char('<'),
                                          Terms.Identifier().AndSkip(Terms.Char('=')).And(
                                              Separated(Terms.Char('|'), Terms.Integer().Then(Convert.ToDouble).Or(Terms.Decimal().Then(Convert.ToDouble)))), Terms.Char('>'))
                                  .Then <IAssetParserFragment>(result => new NumberCollectionValueFragment(result.Item1.ToString())
            {
                AllowedValues = result.Item2
            });

            return(new List <Parser <IAssetParserFragment> > {
                propType, propValue, numberPropValue
            });
        }