Beispiel #1
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Macro(
                this.Body.Deserialize(),
                this.Parameters.SelectAll(p => p.Deserialize <AmbiguousParameterExpression>())
                ));
 }
Beispiel #2
0
        public ReplWindow()
        {
            this.Width   = 450;
            this.Height  = 350;
            this.Title   = "YACQ Console";
            this.Content = this.textBox;
            this.textBox.AcceptsReturn   = true;
            this.textBox.BorderThickness = new Thickness(0);
            this.textBox.FontFamily      = new FontFamily("Consolas");
            this.textBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
            this.textBox.VerticalScrollBarVisibility   = ScrollBarVisibility.Visible;
            this.textBox.TextWrapping = TextWrapping.Wrap;
            this.textBox.Text         = string.Format("YACQ {0} on Krile {1}\r\n", YacqServices.Version, typeof(App).Assembly.GetName().Version);
            this.textBox.Select(this.textBox.Text.Length, 0);
            this.textBox.PreviewKeyDown += this.textBox_PreviewKeyDown;
            this.symbolTable             = new SymbolTable(YacqFilter.FilterSymbols, typeof(Symbols))
            {
                { "*textbox*", YacqExpression.Constant(textBox) },
            };
            var rcPath = Path.Combine(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                "yacq_lib\\rc.yacq"
                );

            if (File.Exists(rcPath))
            {
                YacqServices.ParseAll(this.symbolTable, File.ReadAllText(rcPath))
                .ForEach(e => YacqExpression.Lambda(e).Compile().DynamicInvoke());
                this.textBox.AppendText("rc.yacq was loaded.\r\n");
            }
            this.textBox.AppendText(">>> ");
        }
Beispiel #3
0
 public override DynamicMetaObject FallbackSetIndex(DynamicMetaObject target, DynamicMetaObject[] indexes, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    YacqExpression.Function(this._symbols, "=",
                                            YacqExpression.Function(this._symbols, ".",
                                                                    target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType),
                                                                    YacqExpression.Vector(this._symbols,
                                                                                          indexes.SelectAll(o => o.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType))
                                                                                          )
                                                                    ),
                                            value.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                                            ).Reduce(this._symbols).TryConvert(typeof(Object)),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
Beispiel #4
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Text(
                this.QuoteChar,
                this.SourceText
                ));
 }
Beispiel #5
0
 public override Expression Deserialize()
 {
     return(YacqExpression.AmbiguousParameter(
                this.Type.Null(t => t.Deserialize()),
                this.Name
                ));
 }
Beispiel #6
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Contextful(
                this.Expression.Deserialize(),
                this.ContextType
                ));
 }
 public override DynamicMetaObject FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    (Static.GetTargetType(target.Value)
                     .Null(t => YacqExpression.TypeCandidate(this._symbols, t))
                     ?? target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                    )
                    .Method(this._symbols, this.Name,
                            args.SelectAll(o => o.Expression.Reduce(this._symbols).TryConvert(o.RuntimeType))
                            )
                    .Reduce(this._symbols)
                    .If(e => e.Type == typeof(void), e =>
                        Expression.Block(e, Expression.Default(typeof(Object)))
                        )
                    .If(e => e.Type.IsValueType, e =>
                        e.TryConvert(typeof(Object))
                        ),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
Beispiel #8
0
 public override Expression Deserialize()
 {
     return(YacqExpression.AmbiguousLambda(
                this.ReturnType.Null(t => t.Deserialize()),
                this.Bodies.Select(n => n.Deserialize()),
                this.Parameters.SelectAll(p => p.Deserialize <AmbiguousParameterExpression>())
                ));
 }
 public static Expression Clear(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.Dispatch(
                s,
                DispatchTypes.Method,
                s.Resolve("*textbox*"),
                "Clear"
                ));
 }
Beispiel #10
0
 /// <summary>
 /// Defines a new auto-implemented property to the type.
 /// </summary>
 /// <param name="name">The name of the property. <paramref name="name"/> cannot contain embedded nulls.</param>
 /// <param name="type">The type of the property.</param>
 /// <param name="methodAttributes">A bitwise combination of the accessor method attributes.</param>
 /// <param name="initializer">The expression which is not reduced to be <see cref="LambdaExpression"/> for the initializer of the backing field, with a parameter for "this" instance, returns <paramref name="type"/> value.</param>
 /// <returns>The defined property.</returns>
 public PropertyBuilder DefineProperty(
     String name,
     Type type,
     MethodAttributes methodAttributes,
     Expression initializer
     )
 {
     return(this.DefineProperty(name, type, methodAttributes, initializer, YacqExpression.List(), YacqExpression.List()));
 }
Beispiel #11
0
 public static Expression DumpObject(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(JsonConvert))
            .Method(s, "SerializeObject",
                    e.Left,
                    Expression.Constant(Formatting.None),
                    SerializerSettings
                    ));
 }
Beispiel #12
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Dispatch(
                this.DispatchType,
                this.Left.Null(n => Deserialize()),
                this.Name,
                this.TypeArguments.SelectAll(t => t.Deserialize()),
                this.Arguments.SelectAll(n => n.Deserialize())
                ));
 }
 public static Expression Write(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.Dispatch(
                s,
                DispatchTypes.Method,
                s.Resolve("*textbox*"),
                "AppendText",
                YacqExpression.Dispatch(
                    s,
                    DispatchTypes.Method,
                    e.Left,
                    "ToString"
                    )
                ));
 }
Beispiel #14
0
 internal static SymbolTable CreatePathSymbols(SymbolTable symbols, IEnumerable <String> fragments)
 {
     return(((SymbolTableExpression)EnumerableEx.Generate(
                 Tuple.Create(fragments, symbols.ResolveModule()),
                 _ => _.Item1.Any(),
                 _ => Tuple.Create(_.Item1.Skip(1), _.Item1.First()
                                   .Let(f => _.Item2.ExistsKey(f) && _.Item2.Resolve(f) is SymbolTableExpression
                 ? ((SymbolTableExpression)_.Item2.Resolve(f)).Symbols
                 : new SymbolTable().Apply(
                                            s => s.MarkAsModule(),
                                            s => _.Item2[f] = YacqExpression.SymbolTable(s)
                                            )
                                        )),
                 _ => _.Item2
                 ).Last().Resolve(fragments.Last())).Symbols);
 }
Beispiel #15
0
 public void Run()
 {
     this.Output = "";
     Observable.Start(() =>
     {
         try
         {
             this.WriteOutput("Started.");
             var expr = YacqServices.Parse(
                 new SymbolTable()
             {
                 { DispatchTypes.Method, typeof(Object), "print", (e, s, t) =>
                   YacqExpression.Dispatch(
                       s,
                       DispatchTypes.Method,
                       Expression.Constant(this),
                       "Print",
                       e.Left
                       ) },
             },
                 this.Body
                 );
             this.WriteOutput("Parsed.\nGenerated Expression:\n" + expr);
             var func = Expression.Lambda(expr).Compile();
             this.WriteOutput("Compiled.");
             var ret = func.DynamicInvoke();
             this.WriteOutput("Finished.\nReturned Type: " + (ret != null ? ret.GetType().Name : "null"));
             if (ret != null)
             {
                 this.Output += "Returned Value:\n" + (ret is IEnumerable && !(ret is String)
                     ? String.Join(", ", ((IEnumerable)ret).OfType <Object>().Select(e => e.ToString()))
                     : ret
                                                       );
             }
         }
         catch (Exception ex)
         {
             this.WriteOutput(ex.ToString());
         }
     }).Subscribe(_ =>
     {
     });
 }
Beispiel #16
0
            public static Expression Missing(DispatchExpression e, SymbolTable s, Type t)
            {
                Type type;

                if (e.DispatchType == DispatchTypes.Method &&
                    !s.ExistsKey(DispatchTypes.Method, e.Name) &&
                    (type = FilterRegistrant.GetFilter(e.Name).FirstOrDefault()) != null
                    )
                {
                    return(YacqExpression.Dispatch(
                               s,
                               DispatchTypes.Constructor,
                               YacqExpression.TypeCandidate(type),
                               null,
                               e.Arguments
                               )
                           .Method(s, "Filter", YacqExpression.Identifier(s, "it")));
                }
                return(DispatchExpression.DefaultMissing(e, s, t));
            }
Beispiel #17
0
 public override DynamicMetaObject FallbackUnaryOperation(DynamicMetaObject target, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    YacqExpression.Function(this._symbols, GetSymbolName(this.Operation),
                                            target.Expression.Reduce(_symbols).TryConvert(target.RuntimeType)
                                            ).Reduce(this._symbols).TryConvert(typeof(Object)),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
 public static Expression WriteLine(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.Dispatch(
                s,
                DispatchTypes.Method,
                YacqExpression.Dispatch(
                    s,
                    DispatchTypes.Method,
                    "+",
                    YacqExpression.Dispatch(
                        s,
                        DispatchTypes.Method,
                        e.Left,
                        "ToString"
                        ),
                    Expression.Constant("\n")
                    ),
                "printn"
                ));
 }
Beispiel #19
0
 public override DynamicMetaObject FallbackInvoke(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    YacqExpression.List(this._symbols,
                                        args.SelectAll(o => o.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType))
                                        .StartWith(target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType))
                                        ).Reduce(this._symbols).TryConvert(typeof(Object)),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
Beispiel #20
0
 public static Expression Tab(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(Setting))
            .Member(s, "Instance")
            .Member(s, "StateProperty")
            .Member(s, "TabInformations")
            .Method(s, "SelectMany",
                    YacqExpression.Function(s, "\\",
                                            YacqExpression.Vector(s, YacqExpression.Identifier(s, "e")),
                                            YacqExpression.Identifier(s, "e")
                                            )
                    )
            .Method(s, "First",
                    YacqExpression.LambdaList(s,
                                              YacqExpression.Identifier(s, "=="),
                                              YacqExpression.Identifier(s, "$0").Member(s, "Name"),
                                              e.Arguments[0]
                                              )
                    )
            .Member(s, "TweetSources")
            .Method(s, "Single"));
 }
Beispiel #21
0
 /// <summary>
 /// Creates a <see cref="Type"/> object for the type. After defining members on the type, this method is called in order to load its Type object.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <returns>The new Type object for this type.</returns>
 public Type Create(SymbolTable symbols = null)
 {
     if (this.IsCreated)
     {
         return(this._type.CreateType());
     }
     if (this.GetConstructors().IsEmpty())
     {
         this.DefineConstructor(null);
     }
     if (this._cctor != null)
     {
         this._cctor.Null(c => c.GetILGenerator().Emit(OpCodes.Ret));
     }
     return(this._type.CreateType()
            .Apply(
                t => this._initializers.ForEach(_ =>
                                                new SymbolTable(symbols)
     {
         { "this", YacqExpression.TypeCandidate(t) },
     }
                                                .Let(s => _.Item2.Reduce(s, _.Item3.ReplaceGenericArguments(
                                                                             new Dictionary <Type, Type>()
     {
         { this._type, t },
     }
                                                                             ))
                                                     .Apply(e => (e != null
                         ? (LambdaExpression)e
                         : Expression.Lambda(_.Item2.Reduce(s))
                                                                  ).CompileToMethod(_.Item1))
                                                     )
                                                ),
                t => this._prologue.GetILGenerator().Emit(OpCodes.Ret),
                t => this._implType.CreateType(),
                t => this.IsCreated = true
                ));
 }
Beispiel #22
0
 public override DynamicMetaObject FallbackSetMember(DynamicMetaObject target, DynamicMetaObject value, DynamicMetaObject errorSuggestion)
 {
     try
     {
         return(new DynamicMetaObject(
                    YacqExpression.Function(this._symbols, "=",
                                            (Static.GetTargetType(target.Value)
                                             .Null(t => YacqExpression.TypeCandidate(this._symbols, t))
                                             ?? target.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                                            ).Member(this._symbols, this.Name),
                                            value.Expression.Reduce(this._symbols).TryConvert(target.RuntimeType)
                                            ).Reduce(this._symbols).TryConvert(typeof(Object)),
                    target.Restrictions
                    ));
     }
     catch (Exception ex)
     {
         return(errorSuggestion
                ?? new DynamicMetaObject(
                    Expression.Throw(Expression.Constant(ex), typeof(Object)),
                    BindingRestrictions.Empty
                    ));
     }
 }
Beispiel #23
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Identifier(
                this.Name
                ));
 }
Beispiel #24
0
 public override Expression Deserialize()
 {
     return(YacqExpression.TypeCandidate(
                this.Candidates.Select(t => t.Deserialize())
                ));
 }
Beispiel #25
0
        internal StandardGrammar()
        {
            this._isReadOnly = false;
            var newline = Combinator.Choice(
                Chars.Sequence("\r\n"),
                Chars.OneOf('\r', '\n', '\x85', '\u2028', '\u2029')
                .Select(EnumerableEx.Return)
                ).Select(_ => Environment.NewLine);

            var punctuation = Chars.OneOf('"', '\'', '(', ')', ',', '.', ':', ';', '[', ']', '`', '{', '}');

            Parser <Char, YacqExpression> expressionRef = null;
            var expression = new Lazy <Parser <Char, YacqExpression> >(
                () => stream => expressionRef(stream)
                );

            this.Add("yacq", "expression", g => expression.Value);

            // Comments
            {
                this.Add("comment", "eol", g => Prims.Pipe(
                             ';'.Satisfy(),
                             newline.Not().Right(Chars.Any()).Many(),
                             newline.Ignore().Or(Chars.Eof()),
                             (p, r, s) => (YacqExpression)YacqExpression.Ignore()
                             ));

                Parser <Char, YacqExpression> blockCommentRef     = null;
                Parser <Char, YacqExpression> blockCommentRestRef = null;
                var blockComment = new Lazy <Parser <Char, YacqExpression> >(
                    () => stream => blockCommentRef(stream)
                    );
                var blockCommentRest = new Lazy <Parser <Char, YacqExpression> >(
                    () => stream => blockCommentRestRef(stream)
                    );
                var blockCommentPrefix = Chars.Sequence("#|");
                var blockCommentSuffix = Chars.Sequence("|#");
                blockCommentRef = blockCommentPrefix
                                  .Right(blockCommentRest.Value.Many())
                                  .Left(blockCommentSuffix)
                                  .Select(_ => (YacqExpression)YacqExpression.Ignore());
                blockCommentRestRef = blockCommentPrefix.Not()
                                      .Right(blockCommentSuffix.Not())
                                      .Right(Chars.Any())
                                      .Select(_ => (YacqExpression)YacqExpression.Ignore())
                                      .Or(blockComment.Value);
                this.Add("comment", "block", g => blockComment.Value);

                this.Add("comment", "expression", g => Prims.Pipe(
                             Chars.Sequence("#;"),
                             g["yacq", "expression"],
                             (p, r) => (YacqExpression)YacqExpression.Ignore()
                             ));

                this.Add("yacq", "comment", g => Combinator.Choice(g["comment"]));
            }

            this.Add("yacq", "ignore", g => Combinator.Choice(
                         this.Get["yacq", "comment"].Ignore(),
                         Chars.Space().Ignore(),
                         newline.Ignore()
                         ).Many().Select(_ => (YacqExpression)YacqExpression.Ignore()));

            // Texts
            this.Add("term", "text", g => SetPosition(
                         Chars.OneOf('\'', '\"', '`')
                         .SelectMany(q => q.Satisfy()
                                     .Not()
                                     .Right('\\'.Satisfy()
                                            .Right(q.Satisfy())
                                            .Or(Chars.Any())
                                            )
                                     .Many()
                                     .Left(q.Satisfy())
                                     .Select(cs => cs.StartWith(q).EndWith(q))
                                     )
                         .Select(cs => (YacqExpression)YacqExpression.Text(new String(cs.ToArray())))
                         ));

            // Numbers
            {
                var numberPrefix = Chars.OneOf('+', '-');
                var numberSuffix = Combinator.Choice(
                    Chars.Sequence("ul"),
                    Chars.Sequence("UL"),
                    Chars.OneOf('D', 'F', 'L', 'M', 'U', 'd', 'f', 'l', 'm', 'u')
                    .Select(EnumerableEx.Return)
                    );
                var digit     = '_'.Satisfy().Many().Right(Chars.Digit());
                var hexPrefix = Chars.Sequence("0x");
                var hex       = '_'.Satisfy().Many().Right(Chars.Hex());
                var octPrefix = Chars.Sequence("0o");
                var oct       = '_'.Satisfy().Many().Right(Chars.Oct());
                var binPrefix = Chars.Sequence("0b");
                var bin       = '_'.Satisfy().Many().Right(Chars.OneOf('0', '1'));
                var fraction  = Prims.Pipe(
                    '.'.Satisfy(),
                    digit.Many(1),
                    (d, ds) => ds.StartWith(d)
                    );
                var exponent = Prims.Pipe(
                    Chars.OneOf('E', 'e'),
                    Chars.OneOf('+', '-').Maybe(),
                    digit.Many(1),
                    (e, s, ds) => ds
                    .If(_ => s.Exists(), _ => _.StartWith(s.Perform()))
                    .StartWith(e)
                    );

                this.Add("term", "number", g => Combinator.Choice(
                             SetPosition(Prims.Pipe(
                                             binPrefix,
                                             bin.Many(1),
                                             numberSuffix.Maybe(),
                                             (p, n, s) => (YacqExpression)YacqExpression.Number(
                                                 new String(p.Concat(n).If(
                                                                _ => s.Exists(),
                                                                cs => cs.Concat(s.Perform())
                                                                ).ToArray())
                                                 )
                                             )),
                             SetPosition(Prims.Pipe(
                                             octPrefix,
                                             oct.Many(1),
                                             numberSuffix.Maybe(),
                                             (p, n, s) => (YacqExpression)YacqExpression.Number(
                                                 new String(p.Concat(n).If(
                                                                _ => s.Exists(),
                                                                cs => cs.Concat(s.Perform())
                                                                ).ToArray())
                                                 )
                                             )),
                             SetPosition(Prims.Pipe(
                                             hexPrefix,
                                             hex.Many(1),
                                             numberSuffix.Maybe(),
                                             (p, n, s) => (YacqExpression)YacqExpression.Number(
                                                 new String(p.Concat(n).If(
                                                                _ => s.Exists(),
                                                                cs => cs.Concat(s.Perform())
                                                                ).ToArray())
                                                 )
                                             )),
                             SetPosition(
                                 numberPrefix.Maybe().SelectMany(p =>
                                                                 digit.Many(1).SelectMany(i =>
                                                                                          fraction.Maybe().SelectMany(f =>
                                                                                                                      exponent.Maybe().SelectMany(e =>
                                                                                                                                                  numberSuffix.Maybe().Select(s =>
                                                                                                                                                                              (YacqExpression)YacqExpression.Number(new String(EnumerableEx.Concat(
                                                                                                                                                                                                                                   i.If(_ => p.Exists(), _ => _.StartWith(p.Perform())),
                                                                                                                                                                                                                                   f.Otherwise(Enumerable.Empty <Char>),
                                                                                                                                                                                                                                   e.Otherwise(Enumerable.Empty <Char>),
                                                                                                                                                                                                                                   s.Otherwise(Enumerable.Empty <Char>)
                                                                                                                                                                                                                                   ).ToArray()))
                                                                                                                                                                              )
                                                                                                                                                  )
                                                                                                                      )
                                                                                          )
                                                                 )
                                 )
                             ));
            }

            // Lists
            this.Add("term", "list", g => SetPosition(
                         g["yacq", "expression"]
                         .Between(g["yacq", "ignore"], g["yacq", "ignore"])
                         .Many()
                         .Between('('.Satisfy(), ')'.Satisfy())
                         .Select(es => (YacqExpression)YacqExpression.List(es))
                         ));

            // Vectors
            this.Add("term", "vector", g => SetPosition(
                         g["yacq", "expression"]
                         .Between(g["yacq", "ignore"], g["yacq", "ignore"])
                         .Many()
                         .Between('['.Satisfy(), ']'.Satisfy())
                         .Select(es => (YacqExpression)YacqExpression.Vector(es))
                         ));

            // Lambda Lists
            this.Add("term", "lambdaList", g => SetPosition(
                         g["yacq", "expression"]
                         .Between(g["yacq", "ignore"], g["yacq", "ignore"])
                         .Many()
                         .Between('{'.Satisfy(), '}'.Satisfy())
                         .Select(es => (YacqExpression)YacqExpression.LambdaList(es))
                         ));

            // Quotes
            this.Add("term", "quote", g => SetPosition(
                         Prims.Pipe(
                             Chars.Sequence("#'"),
                             g["yacq", "expression"],
                             (p, e) => (YacqExpression)YacqExpression.List(YacqExpression.Identifier("quote"), e)
                             )
                         ));

            // Quasiquotes
            this.Add("term", "quasiquote", g => SetPosition(
                         Prims.Pipe(
                             Chars.Sequence("#`"),
                             g["yacq", "expression"],
                             (p, e) => (YacqExpression)YacqExpression.List(YacqExpression.Identifier("quasiquote"), e)
                             )
                         ));

            // Unquote-Splicings
            this.Add("term", "unquoteSplicing", g => SetPosition(
                         Prims.Pipe(
                             Chars.Sequence("#,@"),
                             g["yacq", "expression"],
                             (p, e) => (YacqExpression)YacqExpression.List(YacqExpression.Identifier("unquote-splicing"), e)
                             )
                         ));

            // Unquotes
            this.Add("term", "unquote", g => SetPosition(
                         Prims.Pipe(
                             Chars.Sequence("#,"),
                             g["yacq", "expression"],
                             (p, e) => (YacqExpression)YacqExpression.List(YacqExpression.Identifier("unquote"), e)
                             )
                         ));

            // Identifiers
            this.Add("term", "identifier", g => Combinator.Choice(
                         SetPosition('.'.Satisfy()
                                     .Many(1)
                                     .Select(cs => (YacqExpression)YacqExpression.Identifier(new String(cs.ToArray())))
                                     ),
                         SetPosition(':'.Satisfy()
                                     .Many(1)
                                     .Select(cs => (YacqExpression)YacqExpression.Identifier(new String(cs.ToArray())))
                                     ),
                         SetPosition(Chars.Digit()
                                     .Not()
                                     .Right(Chars.Space()
                                            .Or(punctuation)
                                            .Not()
                                            .Right(Chars.Any())
                                            .Many(1)
                                            )
                                     .Select(cs => (YacqExpression)YacqExpression.Identifier(new String(cs.ToArray())))
                                     )
                         ));

            // Terms
            this.Add("yacq", "term", g => Combinator.Choice(g["term"])
                     .Between(g["yacq", "ignore"], g["yacq", "ignore"])
                     );

            // Infix Dots
            this.Add("infix", "dot", g => Prims.Pipe(
                         g["yacq", "term"],
                         '.'.Satisfy()
                         .Right(g["yacq", "term"])
                         .Many(),
                         (h, t) => t.Aggregate(h, (l, r) =>
                                               (YacqExpression)YacqExpression.List(YacqExpression.Identifier("."), l, r)
                                               )
                         ));

            // Infix Colons
            this.Add("infix", "colon", g => Prims.Pipe(
                         g["infix", "dot"],
                         ':'.Satisfy()
                         .Right(g["infix", "dot"])
                         .Many(),
                         (h, t) => t.Aggregate(h, (l, r) =>
                                               (YacqExpression)YacqExpression.List(YacqExpression.Identifier(":"), l, r)
                                               )
                         ));

            expressionRef = this.Get["infix"].Last();

            this.Set.Default = g => g["yacq", "expression"];

            this._isReadOnly = true;
        }
Beispiel #26
0
 public static Expression RangeFromTo(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(LongRange))
            .Method(s, "FromBetweenValues", e.Left, e.Arguments[0]));
 }
Beispiel #27
0
 public static Expression RangeExact(DispatchExpression e, SymbolTable s, Type t)
 {
     return(YacqExpression.TypeCandidate(typeof(LongRange))
            .Method(s, "FromPivotValue", e.Arguments[0]));
 }
Beispiel #28
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Quote(
                this.Expression.Deserialize()
                ));
 }
Beispiel #29
0
 public override Expression Deserialize()
 {
     return(YacqExpression.LambdaList(
                this.Elements.Null(_ => _.Select(n => n.Deserialize()))
                ));
 }
Beispiel #30
0
 public override Expression Deserialize()
 {
     return(YacqExpression.Ignore());
 }