Skip to content

Commit

Permalink
Moved syntax highlighter from GrammarExplorer to a separate project.
Browse files Browse the repository at this point in the history
  • Loading branch information
yallie committed Mar 11, 2018
1 parent f1a7ab0 commit 12b2f9c
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 53 deletions.
22 changes: 4 additions & 18 deletions Irony.GrammarExplorer/030.Irony.GrammarExplorer.2010.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
</Compile>
<Compile Include="GrammarItemList.cs" />
<Compile Include="GrammarLoader.cs" />
<Compile Include="Highlighter\EditorAdapter.cs" />
<Compile Include="Highlighter\EditorViewAdapter.cs" />
<Compile Include="Highlighter\FastColoredTextBoxHighlighter.cs" />
<Compile Include="Highlighter\WavyLineStyle.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="fmGrammarExplorer.resx">
Expand All @@ -107,10 +103,6 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="fmShowException.resx">
<SubType>Designer</SubType>
<DependentUpon>fmShowException.cs</DependentUpon>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
Expand All @@ -126,22 +118,16 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="fmShowException.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="fmShowException.Designer.cs">
<DependentUpon>fmShowException.cs</DependentUpon>
</Compile>
<Compile Include="Highlighter\RichTextBoxHighlighter.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Highlighter\AboutCodeHighlighter.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Irony.Interpreter\015.Irony.Interpreter.2010.csproj">
<Project>{321A7F5D-00C2-4095-9970-075CDEE8C139}</Project>
<Name>015.Irony.Interpreter.2010</Name>
</ProjectReference>
<ProjectReference Include="..\Irony.WinForms\035.Irony.WinForms.2010.csproj">
<Project>{70D319F3-3C0C-4EB5-A271-58ED22FB3070}</Project>
<Name>035.Irony.WinForms.2010</Name>
</ProjectReference>
<ProjectReference Include="..\Irony\010.Irony.2010.csproj">
<Project>{D81F5C91-D7DB-46E5-BC99-49488FB6814C}</Project>
<Name>010.Irony.2010</Name>
Expand Down
5 changes: 3 additions & 2 deletions Irony.GrammarExplorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright (c) Roman Ivantsov
* This source code is subject to terms and conditions of the MIT License
* for Irony. A copy of the license can be found in the License.txt file
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* MIT License.
* You must not remove this notice from this software.
* **********************************************************************************/
Expand All @@ -14,6 +14,7 @@
using System.Collections.Generic;
using System.Windows.Forms;
using System.Diagnostics;
using Irony.WinForms.Exceptions;

namespace Irony.GrammarExplorer {
class Program : MarshalByRefObject {
Expand Down
3 changes: 2 additions & 1 deletion Irony.GrammarExplorer/fmGrammarExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
using Irony.Ast;
using Irony.Parsing;
using Irony.GrammarExplorer.Properties;
using Irony.GrammarExplorer.Highlighter;
using Irony.WinForms.Exceptions;
using Irony.WinForms.Highlighter;

namespace Irony.GrammarExplorer {
using ScriptException = Irony.Interpreter.ScriptException; //that's the only place we use stuff from Irony.Interpreter
Expand Down
84 changes: 84 additions & 0 deletions Irony.WinForms/035.Irony.WinForms.2010.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{70D319F3-3C0C-4EB5-A271-58ED22FB3070}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Irony.WinForms</RootNamespace>
<AssemblyName>Irony.WinForms</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</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="FastColoredTextBox">
<HintPath>..\Libraries\FastColoredTextBox\FastColoredTextBox.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Exceptions\fmShowException.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Exceptions\fmShowException.Designer.cs">
<DependentUpon>fmShowException.cs</DependentUpon>
</Compile>
<Compile Include="Highlighter\EditorAdapter.cs" />
<Compile Include="Highlighter\EditorViewAdapter.cs" />
<Compile Include="Highlighter\FastColoredTextBoxHighlighter.cs" />
<Compile Include="Highlighter\RichTextBoxHighlighter.cs" />
<Compile Include="Highlighter\WavyLineStyle.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Highlighter\AboutCodeHighlighter.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Irony\010.Irony.2010.csproj">
<Project>{D81F5C91-D7DB-46E5-BC99-49488FB6814C}</Project>
<Name>010.Irony.2010</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Exceptions\fmShowException.resx">
<DependentUpon>fmShowException.cs</DependentUpon>
</EmbeddedResource>
</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>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright (c) Roman Ivantsov
* This source code is subject to terms and conditions of the MIT License
* for Irony. A copy of the license can be found in the License.txt file
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* MIT License.
* You must not remove this notice from this software.
* **********************************************************************************/
Expand All @@ -18,7 +18,7 @@
using System.Text;
using System.Windows.Forms;

namespace Irony.GrammarExplorer {
namespace Irony.WinForms.Exceptions {
public partial class fmShowException : Form {
public fmShowException() {
InitializeComponent();
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
using System.Runtime.InteropServices;
using System.Diagnostics;
using Irony.Parsing;
using Irony.WinForms.Exceptions;

namespace Irony.GrammarExplorer {
namespace Irony.WinForms.Highlighter {

public class EditorAdapter {
Parser _parser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using System.Threading;
using Irony.Parsing;

namespace Irony.GrammarExplorer {
namespace Irony.WinForms.Highlighter {
public delegate void ColorizeMethod();
public interface IUIThreadInvoker {
void InvokeOnUIThread(ColorizeMethod colorize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using System.Diagnostics;
using FastColoredTextBoxNS;

namespace Irony.GrammarExplorer.Highlighter {
namespace Irony.WinForms.Highlighter {

/// <summary>
/// Highlights text inside FastColoredTextBox control.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright (c) Roman Ivantsov
* This source code is subject to terms and conditions of the MIT License
* for Irony. A copy of the license can be found in the License.txt file
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* at the root of this distribution.
* By using this source code in any fashion, you are agreeing to be bound by the terms of the
* MIT License.
* You must not remove this notice from this software.
* **********************************************************************************/
Expand All @@ -26,14 +26,14 @@
using Irony.Parsing;
using System.Diagnostics;

namespace Irony.GrammarExplorer {
namespace Irony.WinForms.Highlighter {

public class TokenColorTable : Dictionary<TokenColor, Color> { }

public class RichTextBoxHighlighter : NativeWindow, IDisposable, IUIThreadInvoker {
public RichTextBox TextBox;
public readonly TokenColorTable TokenColors = new TokenColorTable();
public readonly EditorAdapter Adapter;
public readonly EditorAdapter Adapter;
public readonly EditorViewAdapter ViewAdapter;

private IntPtr _savedEventMask = IntPtr.Zero;
Expand All @@ -43,7 +43,7 @@ public class RichTextBoxHighlighter : NativeWindow, IDisposable, IUIThreadInvoke
#region constructor, initialization and disposing
public RichTextBoxHighlighter(RichTextBox textBox, LanguageData language) {
TextBox = textBox;
Adapter = new EditorAdapter(language);
Adapter = new EditorAdapter(language);
ViewAdapter = new EditorViewAdapter(Adapter, this);
InitColorTable();
Connect();
Expand Down Expand Up @@ -77,7 +77,7 @@ private void Disconnect() {

public void Dispose() {
Adapter.Stop();
_disposed = true;
_disposed = true;
Disconnect();
this.ReleaseHandle();
GC.SuppressFinalize(this);
Expand All @@ -88,7 +88,7 @@ private void InitColorTable() {
TokenColors[TokenColor.Identifier] = Color.Black;
TokenColors[TokenColor.Keyword] = Color.Blue;
TokenColors[TokenColor.Number] = Color.DarkRed;
TokenColors[TokenColor.String] = Color.DarkSlateGray;
TokenColors[TokenColor.String] = Color.DarkSlateGray;
TokenColors[TokenColor.Text] = Color.Black;

}
Expand All @@ -106,7 +106,7 @@ void TextBox_KeyDown(object sender, KeyEventArgs e) {

void TextBox_TextChanged(object sender, EventArgs e) {
//if we are here while colorizing, it means the "change" event is a result of our coloring action
if (_colorizing) return;
if (_colorizing) return;
ViewAdapter.SetNewText(TextBox.Text);
}
void TextBox_ScrollResize(object sender, EventArgs e) {
Expand Down Expand Up @@ -152,7 +152,7 @@ private void UpdateViewRange() {
private int HScrollPos {
get {
//sometimes explodes with null reference exception
return GetScrollPos((int)TextBox.Handle, SB_HORZ);
return GetScrollPos((int)TextBox.Handle, SB_HORZ);
}
set {
SetScrollPos((IntPtr)TextBox.Handle, SB_HORZ, value, true);
Expand All @@ -162,7 +162,7 @@ private int HScrollPos {

private int VScrollPos {
get {
return GetScrollPos((int)TextBox.Handle, SB_VERT);
return GetScrollPos((int)TextBox.Handle, SB_VERT);
}
set {
SetScrollPos((IntPtr)TextBox.Handle, SB_VERT, value, true);
Expand All @@ -173,25 +173,25 @@ private int VScrollPos {

#region Colorizing tokens
public void LockTextBox() {
// Stop redrawing:
// Stop redrawing:
SendMessage(TextBox.Handle, WM_SETREDRAW, 0, IntPtr.Zero );
// Stop sending of events:
// Stop sending of events:
_savedEventMask = SendMessage(TextBox.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
//SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, IntPtr.Zero);
}

public void UnlockTextBox() {
// turn on events
// turn on events
SendMessage(TextBox.Handle, EM_SETEVENTMASK, 0, _savedEventMask);
// turn on redrawing
// turn on redrawing
SendMessage(TextBox.Handle, WM_SETREDRAW, 1, IntPtr.Zero);
}

void Adapter_ColorizeTokens(object sender, ColorizeEventArgs args) {
if (_disposed) return;
if (_disposed) return;
//Debug.WriteLine("Coloring " + args.Tokens.Count + " tokens.");
_colorizing = true;

int hscroll = HScrollPos;
int vscroll = VScrollPos;
int selstart = TextBox.SelectionStart;
Expand All @@ -214,9 +214,9 @@ void Adapter_ColorizeTokens(object sender, ColorizeEventArgs args) {
}

private Color GetTokenColor(Token token) {
if (token.EditorInfo == null) return Color.Black;
if (token.EditorInfo == null) return Color.Black;
//Right now we scan source, not parse; initially all keywords are recognized as Identifiers; then they are "backpatched"
// by parser when it detects that it is in fact keyword from Grammar. So now this backpatching does not happen,
// by parser when it detects that it is in fact keyword from Grammar. So now this backpatching does not happen,
// so we have to detect keywords here
var colorIndex = token.EditorInfo.Color;
if (token.KeyTerm != null && token.KeyTerm.EditorInfo != null && token.KeyTerm.Flags.IsSet(TermFlags.IsKeyword)) {
Expand All @@ -232,10 +232,10 @@ private Color GetTokenColor(Token token) {
#region IUIThreadInvoker Members

public void InvokeOnUIThread(ColorizeMethod colorize) {
TextBox.BeginInvoke(new MethodInvoker(colorize));
TextBox.BeginInvoke(new MethodInvoker(colorize));
}

#endregion
}//class

}//namespace
}//namespace
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Drawing;
using FastColoredTextBoxNS;

namespace Irony.GrammarExplorer.Highlighter {
namespace Irony.WinForms.Highlighter {
/// <summary>
/// This style draws a wavy line below a given text range.
/// </summary>
Expand Down
Loading

0 comments on commit 12b2f9c

Please sign in to comment.