Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

feature: initial commit

  • Loading branch information...
commit cdcf6370e4b920536f9ca3822a3574f2f1d9d7bf 0 parents
@jflam authored
Showing with 1,424 additions and 0 deletions.
  1. +2 −0  Console/.gitignore
  2. +8 −0 Console/App.xaml
  3. +9 −0 Console/App.xaml.cs
  4. +136 −0 Console/Console.csproj
  5. +9 −0 Console/MainWindow.xaml
  6. +9 −0 Console/MainWindow.xaml.cs
  7. +55 −0 Console/Properties/AssemblyInfo.cs
  8. +62 −0 Console/Properties/Resources.Designer.cs
  9. +117 −0 Console/Properties/Resources.resx
  10. +26 −0 Console/Properties/Settings.Designer.cs
  11. +7 −0 Console/Properties/Settings.settings
  12. +2 −0  Core/.gitignore
  13. +54 −0 Core/Colorizer.cs
  14. +135 −0 Core/Core.csproj
  15. +55 −0 Core/Properties/AssemblyInfo.cs
  16. +62 −0 Core/Properties/Resources.Designer.cs
  17. +117 −0 Core/Properties/Resources.resx
  18. +26 −0 Core/Properties/Settings.Designer.cs
  19. +7 −0 Core/Properties/Settings.settings
  20. +14 −0 Core/Repl.xaml
  21. +193 −0 Core/Repl.xaml.cs
  22. +49 −0 Core/ReplResources.xaml
  23. +19 −0 Core/Resources.cs
  24. +174 −0 Core/hosting.cs
  25. BIN  Libs/IronPython.Modules.dll
  26. BIN  Libs/IronPython.dll
  27. BIN  Libs/IronRuby.Libraries.dll
  28. BIN  Libs/IronRuby.dll
  29. BIN  Libs/Microsoft.Dynamic.dll
  30. BIN  Libs/Microsoft.Scripting.Core.dll
  31. BIN  Libs/Microsoft.Scripting.ExtensionAttribute.dll
  32. BIN  Libs/Microsoft.Scripting.dll
  33. +26 −0 Repl.sln
  34. +31 −0 Viewers/System.Windows.Media.Imaging.BitmapImage.viewer.rb
  35. +20 −0 Viewers/default.viewer.rb
2  Console/.gitignore
@@ -0,0 +1,2 @@
+bin
+obj
8 Console/App.xaml
@@ -0,0 +1,8 @@
+<Application x:Class="Console.App"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ StartupUri="MainWindow.xaml">
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
9 Console/App.xaml.cs
@@ -0,0 +1,9 @@
+using System.Windows;
+
+namespace Console {
+ /// <summary>
+ /// Interaction logic for App.xaml
+ /// </summary>
+ public partial class App : Application {
+ }
+}
136 Console/Console.csproj
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{68758A4D-D8C0-4466-9320-5E21C1FE3467}</ProjectGuid>
+ <OutputType>WinExe</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Console</RootNamespace>
+ <AssemblyName>Console</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="IronPython, Version=2.6.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronPython.dll</HintPath>
+ </Reference>
+ <Reference Include="IronPython.Modules, Version=2.6.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronPython.Modules.dll</HintPath>
+ </Reference>
+ <Reference Include="IronRuby, Version=0.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronRuby.dll</HintPath>
+ </Reference>
+ <Reference Include="IronRuby.Libraries, Version=0.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronRuby.Libraries.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Dynamic, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Dynamic.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting.Core, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting.ExtensionAttribute, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.ExtensionAttribute.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="WindowsBase">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationCore">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationFramework">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <ApplicationDefinition Include="App.xaml">
+ <Generator>MSBuild:Compile</Generator>
+ <SubType>Designer</SubType>
+ </ApplicationDefinition>
+ <Compile Include="App.xaml.cs">
+ <DependentUpon>App.xaml</DependentUpon>
+ <SubType>Code</SubType>
+ </Compile>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="MainWindow.xaml.cs">
+ <DependentUpon>MainWindow.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <AppDesigner Include="Properties\" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\Core\Core.csproj">
+ <Project>{0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}</Project>
+ <Name>Core</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <Page Include="MainWindow.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
9 Console/MainWindow.xaml
@@ -0,0 +1,9 @@
+<Window x:Class="Console.MainWindow"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:core="clr-namespace:Core;assembly=Core"
+ Title="MainWindow" Height="700" Width="900">
+ <Grid>
+ <core:Repl Name="MainRepl"/>
+ </Grid>
+</Window>
9 Console/MainWindow.xaml.cs
@@ -0,0 +1,9 @@
+using System.Windows;
+
+namespace Console {
+ public partial class MainWindow : Window {
+ public MainWindow() {
+ InitializeComponent();
+ }
+ }
+}
55 Console/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Console")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("MSIT")]
+[assembly: AssemblyProduct("Console")]
+[assembly: AssemblyCopyright("Copyright © MSIT 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
+//inside a <PropertyGroup>. For example, if you are using US english
+//in your source files, set the <UICulture> to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
62 Console/Properties/Resources.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Console.Properties {
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if ((resourceMan == null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Console.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
117 Console/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
26 Console/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Console.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
7 Console/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile>
2  Core/.gitignore
@@ -0,0 +1,2 @@
+bin
+obj
54 Core/Colorizer.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Windows;
+using System.Windows.Documents;
+using Microsoft.Scripting;
+
+namespace Core {
+ public static class Colorizer {
+ private static Dictionary<TokenCategory, string> _colorizationStyles = new Dictionary<TokenCategory, string>() {
+ { TokenCategory.NumericLiteral, "NumericLiteral" },
+ { TokenCategory.Keyword, "Keyword" },
+ { TokenCategory.Identifier, "Identifier" },
+ { TokenCategory.StringLiteral, "StringLiteral" },
+ { TokenCategory.Comment, "Comment" },
+ { TokenCategory.Error, "Error" },
+ { TokenCategory.None, "None" },
+ };
+
+ private static Run CreateTextRun(string code, TokenInfo token) {
+ var text = code.Substring(token.SourceSpan.Start.Index, token.SourceSpan.Length);
+ var result = new Run(text);
+ var style = _colorizationStyles.ContainsKey(token.Category) ? _colorizationStyles[token.Category] : _colorizationStyles[TokenCategory.None];
+ result.Style = Application.Current.FindResource(style) as Style;
+ return result;
+ }
+
+ private static Run CreateLeadingWhitespaceRun(string code, int position, TokenInfo token) {
+ var text = code.Substring(position, token.SourceSpan.Start.Index - position);
+ return new Run(text);
+ }
+
+ public static List<Run> Colorize(DlrEngine engine, string code, Action<Run, TokenInfo> proc) {
+ var result = new List<Run>();
+ int position = 0;
+ foreach (TokenInfo token in engine.GetTokenInfos(code)) {
+ result.Add(CreateLeadingWhitespaceRun(code, position, token));
+ var run = CreateTextRun(code, token);
+ if (proc != null)
+ proc(run, token);
+ result.Add(run);
+ position = token.SourceSpan.Start.Index + token.SourceSpan.Length;
+ }
+ return result;
+ }
+
+ public static List<Run> ColorizeErrors(string error) {
+ var result = new List<Run>();
+ var run = new Run(error);
+ run.Style = Application.Current.FindResource("Error") as Style;
+ result.Add(run);
+ return result;
+ }
+ }
+}
135 Core/Core.csproj
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}</ProjectGuid>
+ <OutputType>library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>Core</RootNamespace>
+ <AssemblyName>Core</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="IronPython, Version=2.6.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronPython.dll</HintPath>
+ </Reference>
+ <Reference Include="IronPython.Modules, Version=2.6.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronPython.Modules.dll</HintPath>
+ </Reference>
+ <Reference Include="IronRuby, Version=0.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronRuby.dll</HintPath>
+ </Reference>
+ <Reference Include="IronRuby.Libraries, Version=0.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\IronRuby.Libraries.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Dynamic, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Dynamic.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting.Core, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.Core.dll</HintPath>
+ </Reference>
+ <Reference Include="Microsoft.Scripting.ExtensionAttribute, Version=0.9.5.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\Libs\Microsoft.Scripting.ExtensionAttribute.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.Xml.Linq">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="System.Xml" />
+ <Reference Include="UIAutomationProvider">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="WindowsBase">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationCore">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationFramework">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="Colorizer.cs" />
+ <Compile Include="hosting.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\Resources.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DesignTime>True</DesignTime>
+ <DependentUpon>Resources.resx</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\Settings.Designer.cs">
+ <AutoGen>True</AutoGen>
+ <DependentUpon>Settings.settings</DependentUpon>
+ <DesignTimeSharedInput>True</DesignTimeSharedInput>
+ </Compile>
+ <Compile Include="Repl.xaml.cs">
+ <DependentUpon>Repl.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Resources.cs" />
+ <EmbeddedResource Include="Properties\Resources.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <None Include="Properties\Settings.settings">
+ <Generator>SettingsSingleFileGenerator</Generator>
+ <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+ </None>
+ <AppDesigner Include="Properties\" />
+ </ItemGroup>
+ <ItemGroup>
+ <Page Include="Repl.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
+ <None Include="ReplResources.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
55 Core/Properties/AssemblyInfo.cs
@@ -0,0 +1,55 @@
+using System.Reflection;
+using System.Resources;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Windows;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Core")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("MSIT")]
+[assembly: AssemblyProduct("Core")]
+[assembly: AssemblyCopyright("Copyright © MSIT 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+//In order to begin building localizable applications, set
+//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
+//inside a <PropertyGroup>. For example, if you are using US english
+//in your source files, set the <UICulture> to en-US. Then uncomment
+//the NeutralResourceLanguage attribute below. Update the "en-US" in
+//the line below to match the UICulture setting in the project file.
+
+//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
+
+
+[assembly: ThemeInfo(
+ ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
+ //(used if a resource is not found in the page,
+ // or application resource dictionaries)
+ ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
+ //(used if a resource is not found in the page,
+ // app, or any theme specific resource dictionaries)
+)]
+
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
62 Core/Properties/Resources.Designer.cs
@@ -0,0 +1,62 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Core.Properties {
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if ((resourceMan == null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Core.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+ }
+}
117 Core/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+</root>
26 Core/Properties/Settings.Designer.cs
@@ -0,0 +1,26 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:2.0.50727.4918
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace Core.Properties {
+
+
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0")]
+ internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+
+ private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+
+ public static Settings Default {
+ get {
+ return defaultInstance;
+ }
+ }
+ }
+}
7 Core/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
+ <Profiles>
+ <Profile Name="(Default)" />
+ </Profiles>
+ <Settings />
+</SettingsFile>
14 Core/Repl.xaml
@@ -0,0 +1,14 @@
+<UserControl x:Class="Core.Repl"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
+ <Grid>
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="*" />
+ </Grid.RowDefinitions>
+
+ <RichTextBox Name="MainRepl" Style="{DynamicResource TextStyle}" PreviewKeyDown="MainRepl_PreviewKeyDown" Grid.Row="0" />
+ </Grid>
+</UserControl>
193 Core/Repl.xaml.cs
@@ -0,0 +1,193 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Markup;
+using System.Xml;
+using IronRuby.Builtins;
+
+namespace Core {
+ public partial class Repl : UserControl {
+ private Dictionary<string, DlrEngine> _languageMap = new Dictionary<string, DlrEngine>();
+ private string _currentEngine;
+ private DlrEngine _rubyEngine; // always need a reference to this for our output rendering extensions
+
+ public DlrEngine CurrentEngine {
+ get { return _languageMap[_currentEngine]; }
+ }
+
+ public Repl() {
+ InitializeComponent();
+ LoadResources();
+ InitializeScriptEngines();
+ InitializePlugins();
+ }
+
+ private void LoadResources() {
+ // TODO: load embedded ReplResources.xaml and write to disk if we don't have one in our current dir
+ var resourceDictionary = (ResourceDictionary)XamlReader.Load(XmlReader.Create("ReplResources.xaml"));
+ Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
+ }
+
+ private void InitializePlugins() {
+ // TODO: remove hard-coded path
+ CurrentEngine.Require(@"c:\teched\repl\Viewers\default.viewer.rb");
+ }
+
+ private void InitializeScriptEngines() {
+ DlrEngine engine = new RubyEngine();
+ _languageMap[engine.Name] = engine;
+ _rubyEngine = engine;
+ engine = new PythonEngine();
+ _languageMap[engine.Name] = engine;
+ _currentEngine = "ruby";
+ }
+
+ private void InsertTextBlock(List<Run> runs) {
+ var block = new TextBlock();
+ block.Inlines.AddRange(runs);
+
+ var pos = MainRepl.CaretPosition.Paragraph;
+ pos.Inlines.Add(new LineBreak());
+ pos.Inlines.AddRange(runs);
+ }
+
+ private void InsertColorizedCode(string code) {
+ InsertTextBlock(Colorizer.Colorize(CurrentEngine, code, null));
+ }
+
+ private void RenderError(string error) {
+ InsertTextBlock(Colorizer.ColorizeErrors(error));
+ }
+
+ private void RenderInput(string code) {
+ var pos = MainRepl.CaretPosition.Paragraph;
+ var selected_text = MainRepl.Selection.Text;
+ MainRepl.Selection.Text = String.Empty;
+ var blocks = Colorizer.Colorize(CurrentEngine, code, null);
+ pos.Inlines.AddRange(blocks);
+ }
+
+ private Dictionary<Type, bool> _viewers = new Dictionary<Type, bool>();
+
+ private void LoadInspector(object obj) {
+ if (obj != null) {
+ var type = obj.GetType();
+ if (!_viewers.ContainsKey(type)) {
+ string className = obj.GetType().FullName;
+
+ // TODO: exclusions and config
+ foreach (var extension in CurrentEngine.GetFileExtensions()) {
+ string viewerPath = String.Format(@"c:\dev\repl\Viewers\{0}.viewer{1}", className, extension);
+ if (File.Exists(viewerPath)) {
+ CurrentEngine.Require(viewerPath);
+ }
+ }
+ }
+ }
+ }
+
+ public void InsertInspectedResult(object obj) {
+ LoadInspector(obj);
+ object result = _rubyEngine.InvokeMember(obj, "as_xaml");
+ if (result is MutableString) {
+ InsertColorizedCode(result.ToString());
+ } else {
+ MainRepl.CaretPosition.Paragraph.Inlines.Add((UIElement)result);
+ }
+ }
+
+ public void AddExternalObject(string name, object obj) {
+ CurrentEngine.SetVariable(name, obj);
+ }
+
+ private void RenderOutput(object result) {
+ var output = CurrentEngine.ReadStandardOutput();
+ if (output != null)
+ InsertColorizedCode(output.TrimEnd());
+ InsertInspectedResult(result);
+ }
+
+ private void RenderCode(TextRange selection, string code) {
+ }
+
+ private object Execute(string code) {
+ if (code.StartsWith("%")) {
+ var pos = code.IndexOf('%');
+ var language = code.Substring(pos + 1).Trim();
+ if (_languageMap.ContainsKey(language)) {
+ _currentEngine = language;
+ } else {
+ RenderOutput("uh oh - don't know that language");
+ }
+ return null;
+ } else {
+ return CurrentEngine.Execute(code);
+ }
+ }
+
+ private void MainRepl_PreviewKeyDown(object sender, KeyEventArgs args) {
+ if (args.IsCtrl(Key.E)) {
+ try {
+ var code = MainRepl.Selection.Text;
+ RenderInput(code);
+ RenderOutput(Execute(code));
+ args.Handled = true;
+ } catch (Exception e) {
+ RenderError(e.Message);
+ }
+ } else if (Keyboard.Modifiers == ModifierKeys.None && args.Key == Key.Return) {
+ if (!MainRepl.CaretPosition.IsAtLineStartPosition) {
+ var pos = MainRepl.CaretPosition.InsertLineBreak();
+ MainRepl.CaretPosition = pos.GetNextContextPosition(LogicalDirection.Forward);
+ args.Handled = true;
+ } else {
+ // remove the last line break in the paragraph's inlines collection
+ var current_run = MainRepl.CaretPosition.Parent as Run;
+ if (current_run != null) {
+ var last_line_break = ((Run)current_run).PreviousInline;
+ MainRepl.CaretPosition.Paragraph.Inlines.Remove(last_line_break);
+ }
+ MainRepl.CaretPosition.InsertParagraphBreak();
+ }
+ } else if (Keyboard.Modifiers == ModifierKeys.Control && args.Key == Key.S) {
+ using (var stream = File.OpenWrite(@"c:\temp\output.xml")) {
+ XamlWriter.Save(MainRepl.Document, stream);
+ }
+ } else if (Keyboard.Modifiers == ModifierKeys.Control && args.Key == Key.Return) {
+ var selection = new TextRange(MainRepl.CaretPosition.GetLineStartPosition(0), MainRepl.CaretPosition);
+ var code = selection.Text;
+ // TODO: replace the selection with formatted code
+ RenderOutput(Execute(code));
+ } else if (Keyboard.Modifiers == ModifierKeys.Control && args.Key == Key.Space) {
+ // change the style of the current Run that we are under to be the default text style
+ var pos = MainRepl.CaretPosition;
+ var run = pos.Parent as Run;
+ var style = (Style)Application.Current.FindResource("None");
+ if (run != null) {
+ run.Style = style;
+ }
+ }
+ }
+ }
+
+ #region Extension Methods
+
+ public static class ExtensionMethods {
+ public static bool IsCtrl(this KeyEventArgs keyEvent, Key value) {
+ return keyEvent.KeyboardDevice.Modifiers == ModifierKeys.Control
+ && keyEvent.Key == value;
+ }
+
+ public static bool IsCtrlShift(this KeyEventArgs keyEvent, Key value) {
+ return keyEvent.KeyboardDevice.Modifiers == ModifierKeys.Control
+ && keyEvent.KeyboardDevice.Modifiers == ModifierKeys.Shift
+ && keyEvent.Key == value;
+ }
+ }
+
+ #endregion
+}
49 Core/ReplResources.xaml
@@ -0,0 +1,49 @@
+<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
+ <Style x:Key="NumericLiteral">
+ <Setter Property="Control.Foreground" Value="#FFEE98" />
+ </Style>
+ <Style x:Key="Keyword">
+ <Setter Property="Control.Foreground" Value="#FF6600" />
+ </Style>
+ <Style x:Key="Identifier">
+ <Setter Property="Control.Foreground" Value="#FFCC00" />
+ </Style>
+ <Style x:Key="StringLiteral">
+ <Setter Property="Control.Foreground" Value="#66FF00" />
+ </Style>
+ <Style x:Key="Comment">
+ <Setter Property="Control.Foreground" Value="#9933CC" />
+ </Style>
+ <Style x:Key="Error">
+ <Setter Property="Control.Foreground" Value="#FF0000" />
+ </Style>
+ <Style x:Key="None">
+ <Setter Property="Control.Foreground" Value="#FFFFFF" />
+ </Style>
+ <Style x:Key="TextStyle">
+ <Setter Property="Control.FontFamily" Value="Consolas" />
+ <Setter Property="Control.Foreground" Value="White" />
+ <Setter Property="Control.Background" Value="Black" />
+ <Setter Property="Control.FontSize" Value="20" />
+ </Style>
+ <Style x:Key="WindowStyle">
+ <Setter Property="Control.Background" Value="Black" />
+ <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
+ </Style>
+ <Style TargetType="{x:Type ListBoxItem}">
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="{x:Type ListBoxItem}">
+ <TextBlock Name="TheBGControl"><ContentPresenter /></TextBlock>
+ <ControlTemplate.Triggers>
+ <Trigger Property="IsSelected" Value="True">
+ <Setter Property="Foreground" Value="Black" TargetName="TheBGControl" />
+ <Setter Property="Background" Value="Yellow" TargetName="TheBGControl" />
+ </Trigger>
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+</ResourceDictionary>
19 Core/Resources.cs
@@ -0,0 +1,19 @@
+using System.Windows;
+using System.Windows.Markup;
+using System.Xml;
+
+namespace Core {
+ public static class Core {
+ private static ResourceDictionary _resourceDictionary;
+
+ private static void LoadResources() {
+ _resourceDictionary = (ResourceDictionary)XamlReader.Load(XmlReader.Create("ReplResources.xaml"));
+ }
+
+ public static object FindResource(string key) {
+ if (_resourceDictionary == null)
+ LoadResources();
+ return _resourceDictionary[key];
+ }
+ }
+}
174 Core/hosting.cs
@@ -0,0 +1,174 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using IronPython.Runtime;
+using IronRuby;
+using IronRuby.Builtins;
+using IronRuby.Compiler;
+using IronRuby.Runtime;
+using Microsoft.Scripting;
+using Microsoft.Scripting.Hosting;
+using Microsoft.Scripting.Hosting.Providers;
+
+namespace Core {
+
+ #region Abstract class for targeting DLR hosting interfaces
+
+ public abstract class DlrEngine {
+ protected ScriptEngine _engine;
+ protected ScriptScope _scope;
+ protected MemoryStream _outputStream;
+ protected CompilerOptions _compilerOptions;
+
+ protected virtual void ResetOutputStream() {
+ _outputStream = new MemoryStream();
+ _engine.Runtime.IO.SetOutput(_outputStream, Encoding.UTF8);
+ }
+
+ protected ScriptSource CreateScriptSourceFromString(string code) {
+ return _engine.CreateScriptSourceFromString(code, SourceCodeKind.InteractiveCode);
+ }
+
+ protected SourceUnit CreateSourceUnit(string code) {
+ var context = HostingHelpers.GetLanguageContext(_engine);
+ return context.CreateSnippet(code, SourceCodeKind.InteractiveCode);
+ }
+
+ public virtual ScriptScope CreateScriptScope() {
+ return _engine.Runtime.CreateScope();
+ }
+
+ public abstract void Reset(ScriptScope scope);
+
+ public virtual object Execute(string code) {
+ var scriptSource = CreateScriptSourceFromString(code);
+ var compiledCode = scriptSource.Compile();
+
+ if (_scope == null) {
+ return compiledCode.Execute();
+ } else {
+ var result = compiledCode.Execute(_scope);
+ _scope.SetVariable("_", result);
+ return result;
+ }
+ }
+
+ public abstract object InvokeMember(object target, string method);
+
+ public virtual List<TokenInfo> GetTokenInfos(string code) {
+ var tokenizer = new Tokenizer(true);
+ tokenizer.Initialize(CreateSourceUnit(code));
+ return new List<TokenInfo>(tokenizer.ReadTokens(code.Length));
+ }
+
+ public abstract bool Require(string module);
+
+ public virtual string ReadStandardOutput() {
+ if (_outputStream.Position == 0)
+ return null;
+
+ _outputStream.Seek(0, SeekOrigin.Begin);
+ StreamReader reader = new StreamReader(_outputStream, Encoding.UTF8);
+ var result = reader.ReadToEnd();
+ ResetOutputStream();
+ return result;
+ }
+
+ public virtual string GetFileExtension() {
+ return _engine.Runtime.Setup.LanguageSetups[0].FileExtensions[0];
+ }
+
+ public virtual IList<string> GetFileExtensions() {
+ // HACK
+ return _engine.Runtime.Setup.LanguageSetups[0].FileExtensions;
+ }
+
+ public virtual void SetVariable(string name, object value) {
+ _scope.SetVariable(name, value);
+ }
+
+ public abstract string Name { get; }
+ }
+
+ #endregion
+
+ #region Concrete classes for targeting specific DLR languages
+
+ public class PythonEngine : DlrEngine {
+ public PythonEngine() : this(null) { }
+
+ public PythonEngine(ScriptScope scriptScope) {
+ Reset(scriptScope);
+ ResetOutputStream();
+ }
+
+ public override void Reset(ScriptScope scope) {
+ var setup = new ScriptRuntimeSetup();
+ var ls = new LanguageSetup(typeof(PythonContext).AssemblyQualifiedName, "Python", new[] { "py" }, new[] { ".py" });
+ setup.LanguageSetups.Add(ls);
+ var runtime = new ScriptRuntime(setup);
+ _engine = runtime.GetEngine("py");
+ _scope = scope == null ? _engine.Runtime.CreateScope() : scope;
+ }
+
+ public override bool Require(string module) {
+ throw new NotImplementedException();
+ }
+
+ public override object InvokeMember(object target, string method) {
+ throw new NotImplementedException();
+ }
+
+ public override string Name {
+ get { return "python"; }
+ }
+ }
+
+ // TODO: redesign this to accept config via a delegate
+ public class RubyEngine : DlrEngine {
+ private const string BasePath = @"C:\dev\ironruby\Merlin\External.LCA_RESTRICTED\Languages\Ruby\redist-libs";
+ private const string MerlinPath = @"c:\dev\ironruby\merlin\main\languages\ruby";
+ private IronRuby.Builtins.Binding _topLevelBinding;
+
+ public RubyEngine() : this(null) { }
+
+ public RubyEngine(ScriptScope scriptScope) {
+ Reset(scriptScope);
+ ResetOutputStream();
+ }
+
+ public override void Reset(ScriptScope scope) {
+ _engine = Ruby.CreateEngine((setup) =>
+ {
+ setup.Options["InterpretedMode"] = true;
+ setup.Options["SearchPaths"] = new[] { MerlinPath + @"\libs", BasePath + @"\ruby\site_ruby\1.8", BasePath + @"\ruby\site_ruby", BasePath + @"\ruby\1.8" };
+ });
+
+ _scope = scope == null ? _engine.Runtime.CreateScope() : scope;
+ _topLevelBinding = (IronRuby.Builtins.Binding)_engine.Execute("binding", _scope);
+ }
+
+ public override object Execute(string code) {
+ return RubyUtils.Evaluate(MutableString.Create(code), _topLevelBinding.LocalScope, _topLevelBinding.LocalScope.SelfObject, null, null, 0);
+ }
+
+ public override object InvokeMember(object target, string method) {
+ return _engine.Operations.InvokeMember(target, method);
+ }
+
+ public override bool Require(string module) {
+ return _engine.RequireRubyFile(module);
+ }
+
+ public override void SetVariable(string name, object value) {
+ _engine.Runtime.Globals.SetVariable(name, value);
+ }
+
+ public override string Name {
+ get { return "ruby"; }
+ }
+ }
+
+ #endregion
+}
BIN  Libs/IronPython.Modules.dll
Binary file not shown
BIN  Libs/IronPython.dll
Binary file not shown
BIN  Libs/IronRuby.Libraries.dll
Binary file not shown
BIN  Libs/IronRuby.dll
Binary file not shown
BIN  Libs/Microsoft.Dynamic.dll
Binary file not shown
BIN  Libs/Microsoft.Scripting.Core.dll
Binary file not shown
BIN  Libs/Microsoft.Scripting.ExtensionAttribute.dll
Binary file not shown
BIN  Libs/Microsoft.Scripting.dll
Binary file not shown
26 Repl.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "Console\Console.csproj", "{68758A4D-D8C0-4466-9320-5E21C1FE3467}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0B50DAA3-3B19-466E-A55C-2ADC7ECBA2DD}.Release|Any CPU.Build.0 = Release|Any CPU
+ {68758A4D-D8C0-4466-9320-5E21C1FE3467}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {68758A4D-D8C0-4466-9320-5E21C1FE3467}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {68758A4D-D8C0-4466-9320-5E21C1FE3467}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {68758A4D-D8C0-4466-9320-5E21C1FE3467}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
31 Viewers/System.Windows.Media.Imaging.BitmapImage.viewer.rb
@@ -0,0 +1,31 @@
+# System.Windows.Media.Imaging.BitmapImage viewer
+
+# TODO: eliminate most of the boilerplate here. The tricky part is mapping from the fully qualified type name
+# to the assembly that we need to require at the top of the file. Once that's done, we should be able to
+# module_eval just the as_xaml method in this file.
+
+require 'PresentationCore'
+require 'PresentationFramework'
+
+include System::Windows::Controls
+include System::Windows::Documents
+
+module System
+ module Windows
+ module Media
+ module Imaging
+ class BitmapImage
+ def as_xaml
+ image = Image.new
+ image.width = 400
+ image.source = self
+
+ b = Border.new
+ b.child = image
+ b
+ end
+ end
+ end
+ end
+ end
+end
20 Viewers/default.viewer.rb
@@ -0,0 +1,20 @@
+
+# Default visualizer
+
+class Object
+ def as_xaml
+ "=> #{self}"
+ end
+end
+
+class NilClass
+ def as_xaml
+ "=> nil"
+ end
+end
+
+class Array
+ def as_xaml
+ "=> #{self.inspect}"
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.