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(">>> "); }
internal VectorExpression( SymbolTable symbols, YacqList elements ) : base(symbols, elements) { }
internal LambdaListExpression( SymbolTable symbols, YacqList elements ) : base(symbols, elements) { }
internal IdentifierExpression( SymbolTable symbols, String name ) : base(symbols) { this.Name = name; }
internal SerializedExpression( SymbolTable symbols, Node node ) : base(symbols) { this.Node = node; }
internal TypeCandidateExpression( SymbolTable symbols, IList<Type> candidates ) : base(symbols) { this.Candidates = new ReadOnlyCollection<Type>(candidates ?? Type.EmptyTypes); }
public static Expression Clear(DispatchExpression e, SymbolTable s, Type t) { return YacqExpression.Dispatch( s, DispatchTypes.Method, s.Resolve("*textbox*"), "Clear" ); }
internal NumberExpression( SymbolTable symbols, String text ) : base(symbols) { this.SourceText = text; this.Value = this.Parse(); }
internal AmbiguousParameterExpression( SymbolTable symbols, Type type, String name ) : base(symbols) { this._type = type; this.Name = name; }
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)); }
internal ContextfulExpression( SymbolTable symbols, Expression expression, ContextType contextType ) : base(symbols) { this.Expression = expression; this.ContextType = contextType; this.SetPosition(expression); }
internal QuotedExpression( SymbolTable symbols, QuoteType quoteType, Expression expression ) : base(symbols) { this.QuoteType = quoteType; this.Expression = expression ?? Empty(); this.SetPosition(this.Expression); }
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(); }
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" ) ); }
/// <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); } }
/// <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); }
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); }
/// <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)); }
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" ); }
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"); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <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) ); }
/// <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)); }
/// <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) ); }
/// <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)); }
/// <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); }
/// <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)); }
/// <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)); }
/// <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(); }
/// <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); }