コード例 #1
0
ファイル: ReplWindow.cs プロジェクト: takeshik/YacqPlugin
 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(">>> ");
 }
コード例 #2
0
ファイル: VectorExpression.cs プロジェクト: takeshik/yacq
 internal VectorExpression(
     SymbolTable symbols,
     YacqList elements
 )
     : base(symbols, elements)
 {
 }
コード例 #3
0
ファイル: LambdaListExpression.cs プロジェクト: takeshik/yacq
 internal LambdaListExpression(
     SymbolTable symbols,
     YacqList elements
 )
     : base(symbols, elements)
 {
 }
コード例 #4
0
ファイル: IdentifierExpression.cs プロジェクト: takeshik/yacq
 internal IdentifierExpression(
     SymbolTable symbols,
     String name
 )
     : base(symbols)
 {
     this.Name = name;
 }
コード例 #5
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 internal SerializedExpression(
     SymbolTable symbols,
     Node node
 )
     : base(symbols)
 {
     this.Node = node;
 }
コード例 #6
0
 internal TypeCandidateExpression(
     SymbolTable symbols,
     IList<Type> candidates
 )
     : base(symbols)
 {
     this.Candidates = new ReadOnlyCollection<Type>(candidates ?? Type.EmptyTypes);
 }
コード例 #7
0
ファイル: Symbols.cs プロジェクト: takeshik/YacqPlugin
 public static Expression Clear(DispatchExpression e, SymbolTable s, Type t)
 {
     return YacqExpression.Dispatch(
         s,
         DispatchTypes.Method,
         s.Resolve("*textbox*"),
         "Clear"
     );
 }
コード例 #8
0
ファイル: NumberExpression.cs プロジェクト: takeshik/yacq
 internal NumberExpression(
     SymbolTable symbols,
     String text
 )
     : base(symbols)
 {
     this.SourceText = text;
     this.Value = this.Parse();
 }
コード例 #9
0
 internal AmbiguousParameterExpression(
     SymbolTable symbols,
     Type type,
     String name
 )
     : base(symbols)
 {
     this._type = type;
     this.Name = name;
 }
コード例 #10
0
ファイル: MacroExpression.cs プロジェクト: takeshik/yacq
 internal MacroExpression(SymbolTable symbols, Expression body, IList<AmbiguousParameterExpression> parameters)
     : base(symbols)
 {
     if (parameters.Any(p => p.Type(symbols) != null && !typeof(Expression).IsAppropriate(p.Type)))
     {
         throw new ArgumentException("All parameters of macro must be Expression", "parameters");
     }
     this.Parameters = new ReadOnlyCollection<AmbiguousParameterExpression>(parameters ?? Arrays.Empty<AmbiguousParameterExpression>());
     this.Body = body ?? Empty();
     this.SetPosition(this.Parameters.EndWith(this.Body));
 }
コード例 #11
0
ファイル: ContextfulExpression.cs プロジェクト: takeshik/yacq
 internal ContextfulExpression(
     SymbolTable symbols,
     Expression expression,
     ContextType contextType
 )
     : base(symbols)
 {
     this.Expression = expression;
     this.ContextType = contextType;
     this.SetPosition(expression);
 }
コード例 #12
0
ファイル: QuotedExpression.cs プロジェクト: takeshik/yacq
 internal QuotedExpression(
     SymbolTable symbols,
     QuoteType quoteType,
     Expression expression
 )
     : base(symbols)
 {
     this.QuoteType = quoteType;
     this.Expression = expression ?? Empty();
     this.SetPosition(this.Expression);
 }
コード例 #13
0
ファイル: TextExpression.cs プロジェクト: takeshik/yacq
 internal TextExpression(
     SymbolTable symbols,
     Char quoteChar,
     String sourceText
 )
     : base(symbols)
 {
     this._codes = new List<String>();
     this.QuoteChar = quoteChar;
     this.SourceText = sourceText ?? "";
     this.Value = this.Parse();
 }
コード例 #14
0
ファイル: Symbols.cs プロジェクト: takeshik/YacqPlugin
 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"
         )
     );
 }
コード例 #15
0
ファイル: IdentifierExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Reduces this node to a simpler expression with additional symbol tables.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <param name="expectedType">The type which is expected as the type of reduced expression.</param>
 /// <returns>The reduced expression.</returns>
 protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType)
 {
     if (symbols.ResolveMatch(DispatchTypes.Member, this.Name) != null
         || symbols.Missing != DispatchExpression.DefaultMissing
     )
     {
         return Variable(symbols, this.Name)
             .ReduceOnce(symbols, expectedType)
             .Let(e => (e as MacroExpression).Null(m => m.Evaluate(symbols)) ?? e);
     }
     else
     {
         throw new ParseException("Identifier evaluation failed: " + this, this);
     }
 }
コード例 #16
0
ファイル: ListExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Reduces this node to a simpler expression with additional symbol tables.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <param name="expectedType">The type which is expected as the type of reduced expression.</param>
 /// <returns>The reduced expression.</returns>
 protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType)
 {
     Expression value = null;
     if (this.Elements.IsEmpty())
     {
         return Empty();
     }
     if (!(this[0] is IdentifierExpression)
         || symbols.ResolveMatch(DispatchTypes.Member, this[0].Id()) != null
     )
     {
         value = this[0].TryReduce(symbols);
         if (value is MacroExpression)
         {
             return ((MacroExpression) value).Evaluate(symbols, this.Elements.Skip(1));
         }
         if (value != null && value.Type(symbols).GetDelegateSignature() != null)
         {
             return Invoke(value, this.Elements.Skip(1).ReduceAll(symbols));
         }
         if (value is TypeCandidateExpression)
         {
             return Dispatch(
                 symbols,
                 DispatchTypes.Constructor,
                 value,
                 null,
                 this.Elements.Skip(1)
             );
         }
     }
     if (this[0] is IdentifierExpression
         && symbols.ResolveMatch(DispatchTypes.Method, this[0].Id()) != null
         || symbols.Missing != DispatchExpression.DefaultMissing
     )
     {
         return Function(
             symbols,
             this[0].Id(),
             this.Elements.Skip(1)
         );
     }
     if (value != null && this.Length == 1)
     {
         return value;
     }
     throw new ParseException("List evaluation failed: " + this, this);
 }
コード例 #17
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);
 }
コード例 #18
0
ファイル: LambdaListExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Reduces this node to a simpler expression with additional symbol tables.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <param name="expectedType">The type which is expected as the type of reduced expression.</param>
 /// <returns>The reduced expression.</returns>
 protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType)
 {
     return Enumerable.Range(0, Math.Max(
         this.Elements
             .SelectMany(YacqExpressionVisitor.Traverse)
             .Max(e =>
             {
                 Int32 value = -1;
                 return e.Id().Null(s =>
                     s.StartsWithInvariant("$") && Int32.TryParse(s.Substring(1), out value)
                 )
                     ? value
                     : -1;
             }) + 1,
             expectedType.GetDelegateSignature().Null(m => m.GetParameters().Length, 0)
     ))
         .Select(i => AmbiguousParameter(symbols, "$" + i))
         .ToArray()
         .Let(ps => AmbiguousLambda(symbols, List(symbols, this.Elements), ps));
 }
コード例 #19
0
ファイル: Symbols.cs プロジェクト: takeshik/YacqPlugin
 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"
     );
 }
コード例 #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");
 }
コード例 #21
0
ファイル: VectorExpression.cs プロジェクト: takeshik/yacq
        /// <summary>
        /// Reduces this node to a simpler expression with additional symbol tables.
        /// </summary>
        /// <param name="symbols">The additional symbol table for reducing.</param>
        /// <param name="expectedType">The type which is expected as the type of reduced expression.</param>
        /// <returns>The reduced expression.</returns>
        protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType)
        {
            return this.Elements.Any()
                // TODO: Use expectedType?
                ? this.Elements.Select(e => e.List(":"))
                      .ToArray()
                      .If(ps => ps.All(p => p != null),
                          ps => ps.Select(p => p.First().Reduce(symbols)).ToArray().Let(ks =>
                              ps.Select(p => p.Last().Reduce(symbols)).ToArray().Let(vs =>
                                  ks.Select(k => k.Type).GetCommonType().Let(kt =>
                                      vs.Select(v => v.Type).GetCommonType().Let(vt =>
                                          Dispatch(symbols, DispatchTypes.Constructor,
                                              TypeCandidate(typeof(Dictionary<,>).MakeGenericType(kt, vt)),
                                              null
                                          ).Method(symbols, "has", ks
                                              .Select(k => ImplicitConvert(k, kt))
                                              .Zip(vs.Select(v => ImplicitConvert(v, vt)),
                                                  (k, v) => Vector(symbols, k, v)
                                              )
#if SILVERLIGHT
                                              .Cast<Expression>()
#endif
                                          )
                                      )
                                  )
                              )
                          ),
                          _ => (Expression) this.Elements.ReduceAll(symbols)
                              .ToArray()
                              .Let(es => es
                                  .Select(e => e.Type)
                                  .Distinct()
                                  .GetCommonType()
                                  .Let(t => NewArrayInit(t, es.Select(e => ImplicitConvert(e, t))))
                              )
                      )
                : NewArrayInit(expectedType.Null(t => t.GetElementType()) ?? typeof(Object));
        }
コード例 #22
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Loads the object graph as specified Data Contract binary data and creates a <see cref="SerializedExpression"/> which represents an expression.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="data">The Data Contract binary data to use as source.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the loaded object graph and represents an expression.</returns>
 public static SerializedExpression LoadBinary(SymbolTable symbols, Byte[] data)
 {
     return new MemoryStream(data, false)
         .Dispose(s => LoadBinary(symbols, s));
 }
コード例 #23
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Loads the object graph as Data Contract binary data from specified file and creates a <see cref="SerializedExpression"/> which represents an expression.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="file">The file to load and use as source.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the loaded object graph and represents an expression.</returns>
 public static SerializedExpression LoadBinary(SymbolTable symbols, FileInfo file)
 {
     return file.OpenRead()
         .Dispose(s => LoadBinary(symbols, s));
 }
コード例 #24
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Loads the object graph as Data Contract binary data into an output stream and creates a <see cref="SerializedExpression"/> which represents an expression.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="stream">The stream to load as input.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the loaded object graph and represents an expression.</returns>
 public static SerializedExpression LoadBinary(SymbolTable symbols, Stream stream)
 {
     return Load(
         symbols,
         XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max)
     );
 }
コード例 #25
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Loads the object graph as specified Data Contract XML data and creates a <see cref="SerializedExpression"/> which represents an expression.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="data">The Data Contract XML data to use as source.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the loaded object graph and represents an expression.</returns>
 public static SerializedExpression LoadText(SymbolTable symbols, String data)
 {
     return new MemoryStream(Encoding.UTF8.GetBytes(data), false)
         .Dispose(s => LoadText(symbols, s));
 }
コード例 #26
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Loads the object graph and creates a <see cref="SerializedExpression"/> which represents an expression using the specified <see cref="XmlDictionaryWriter"/>.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="reader">An <see cref="XmlDictionaryReader"/> used to read the object graph.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the loaded object graph and represents an expression.</returns>
 public static SerializedExpression Load(SymbolTable symbols, XmlDictionaryReader reader)
 {
     return new SerializedExpression(
         symbols,
         (Node) SerializedExpression.Serializer.ReadObject(reader)
     );
 }
コード例 #27
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Creates a <see cref="SerializedExpression"/> to get object graph which represents specified expression.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="expression">The expression to serialize.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has the object graph which represents specified expression.</returns>
 public static SerializedExpression Serialize(SymbolTable symbols, Expression expression)
 {
     return Serialize(symbols, Node.Serialize(expression));
 }
コード例 #28
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Creates a <see cref="SerializedExpression"/> with specified object graph.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="node">The <see cref="Node"/> which represents expression.</param>
 /// <returns>A <see cref="SerializedExpression"/> that has specified object graph.</returns>
 public static SerializedExpression Serialize(SymbolTable symbols, Node node)
 {
     return new SerializedExpression(symbols, node);
 }
コード例 #29
0
ファイル: SymbolEntry.cs プロジェクト: erisonliang/yacq
 /// <summary>
 /// Converts the string representation of a symbol entry to an equivalent <see cref="SymbolEntry"/> object.
 /// </summary>
 /// <param name="expression">An expression string that contains a symbol entry to convert.</param>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="isLiteral"><c>true</c> if the symbol entry indicates a literal; otherwise, <c>false</c>.</param>
 /// <returns>An object that is equivalent to the symbol entry specified in the <paramref name="expression"/> parameter.</returns>
 public static SymbolEntry Parse(String expression, SymbolTable symbols, Boolean isLiteral)
 {
     return(Parse(YacqServices.Read(expression), symbols, isLiteral));
 }
コード例 #30
0
ファイル: SymbolEntry.cs プロジェクト: erisonliang/yacq
 /// <summary>
 /// Converts the string representation of a symbol entry to an equivalent <see cref="SymbolEntry"/> object.
 /// </summary>
 /// <param name="expression">An expression string that contains a symbol entry to convert.</param>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <returns>An object that is equivalent to the symbol entry specified in the <paramref name="expression"/> parameter.</returns>
 public static SymbolEntry Parse(String expression, SymbolTable symbols)
 {
     return(Parse(expression, symbols, false));
 }
コード例 #31
0
ファイル: SerializedExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Reduces (means deserialize) this node to a simpler expression with additional symbol tables.
 /// </summary>
 /// <param name="symbols">The additional symbol table for reducing.</param>
 /// <param name="expectedType">The type which is expected as the type of reduced expression.</param>
 /// <returns>The reduced (or deserialized) expression.</returns>
 protected override Expression ReduceImpl(SymbolTable symbols, Type expectedType)
 {
     return this.Deserialize();
 }
コード例 #32
0
ファイル: VectorExpression.cs プロジェクト: takeshik/yacq
 /// <summary>
 /// Creates a <see cref="VectorExpression"/> that represents the vector.
 /// </summary>
 /// <param name="symbols">The symbol table for the expression.</param>
 /// <param name="elements">An array of <see cref="Expression"/> objects that represents the elements of the expression.</param>
 /// <returns>A <see cref="VectorExpression"/> that has specified elements.</returns>
 public static VectorExpression Vector(SymbolTable symbols, params Expression[] elements)
 {
     return Vector(symbols, (IEnumerable<Expression>) elements);
 }