Skip to content

Commit d57d31b

Browse files
committed
Significantly overhauled syntax highlighting logic. Made numerous breaking changes to existing syntax style guide interface.
Syntax highlighting in the console is nearling completion.
1 parent 1792bab commit d57d31b

33 files changed

+731
-366
lines changed

Code Grapher/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.20079.0")]
36-
[assembly: AssemblyFileVersion("1.0.20079.0")]
35+
[assembly: AssemblyVersion("1.0.20080.1")]
36+
[assembly: AssemblyFileVersion("1.0.20080.1")]

Common/Common.csproj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="Antlr4.Runtime, Version=4.6.0.0, Culture=neutral, PublicKeyToken=09abb75b9ed49849, processorArchitecture=MSIL">
35+
<HintPath>..\packages\Antlr4.Runtime.4.6.6\lib\net45\Antlr4.Runtime.dll</HintPath>
36+
</Reference>
37+
<Reference Include="JetBrains.Annotations, Version=2019.1.3.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
38+
<HintPath>..\packages\JetBrains.Annotations.2019.1.3\lib\net20\JetBrains.Annotations.dll</HintPath>
39+
</Reference>
3440
<Reference Include="System" />
3541
<Reference Include="System.Core" />
3642
<Reference Include="System.Drawing" />
@@ -42,9 +48,15 @@
4248
<Reference Include="System.Xml" />
4349
</ItemGroup>
4450
<ItemGroup>
45-
<Compile Include="Editor\ISyntaxGuide.cs" />
51+
<Compile Include="Syntax\ISyntaxHighlightingGuide.cs" />
52+
<Compile Include="Extensions\TokenInterfaceExtensionMethods.cs" />
53+
<Compile Include="Grammar\Place.cs" />
54+
<Compile Include="Grammar\SyntaxToken.cs" />
4655
<Compile Include="Properties\AssemblyInfo.cs" />
4756
</ItemGroup>
57+
<ItemGroup>
58+
<None Include="packages.config" />
59+
</ItemGroup>
4860
<ItemGroup />
4961
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5062
</Project>

TestRig/Extensions/TokenInterfaceExtensionMethods.cs renamed to Common/Extensions/TokenInterfaceExtensionMethods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040

4141
using JetBrains.Annotations;
4242

43-
using Org.Edgerunner.ANTLR4.Tools.Testing.Grammar;
43+
using Org.Edgerunner.ANTLR4.Tools.Common.Grammar;
4444

45-
namespace Org.Edgerunner.ANTLR4.Tools.Testing.Extensions
45+
namespace Org.Edgerunner.ANTLR4.Tools.Common.Extensions
4646
{
4747
/// <summary>
4848
/// Class containing extension methods for the token interface.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
#endregion
3636

37-
namespace Org.Edgerunner.ANTLR4.Tools.Testing.Grammar
37+
namespace Org.Edgerunner.ANTLR4.Tools.Common.Grammar
3838
{
3939
/// <summary>
4040
/// Struct representing a placement within some source.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
using Antlr4.Runtime;
3838

39-
using Org.Edgerunner.ANTLR4.Tools.Testing.Extensions;
39+
using Org.Edgerunner.ANTLR4.Tools.Common.Extensions;
4040

41-
namespace Org.Edgerunner.ANTLR4.Tools.Testing.Grammar
41+
namespace Org.Edgerunner.ANTLR4.Tools.Common.Grammar
4242
{
4343
/// <summary>
4444
/// Struct that represents a lightweight view model for IToken instances

Common/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.20080.0")]
36-
[assembly: AssemblyFileVersion("1.0.20080.0")]
35+
[assembly: AssemblyVersion("1.0.20080.9")]
36+
[assembly: AssemblyFileVersion("1.0.20080.9")]
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#region BSD 3-Clause License
2-
// <copyright file="IEditorGuide.cs" company="Edgerunner.org">
2+
// <copyright file="ISyntaxHighlightingGuide.cs" company="Edgerunner.org">
33
// Copyright 2020
44
// </copyright>
55
//
@@ -36,9 +36,11 @@
3636

3737
using System.Drawing;
3838

39-
namespace Org.Edgerunner.ANTLR4.Tools.Common.Editor
39+
using Org.Edgerunner.ANTLR4.Tools.Common.Grammar;
40+
41+
namespace Org.Edgerunner.ANTLR4.Tools.Common.Syntax
4042
{
41-
public interface ISyntaxGuide
43+
public interface ISyntaxHighlightingGuide
4244
{
4345
/// <summary>
4446
/// Gets the name of the grammar.
@@ -47,30 +49,30 @@ public interface ISyntaxGuide
4749
string GrammarName { get; }
4850

4951
/// <summary>
50-
/// Gets the color to use for parsing errors.
52+
/// Gets the error indicator color.
5153
/// </summary>
52-
/// <value>The color of the error.</value>
53-
Color ErrorColor { get; }
54+
/// <returns>The <see cref="Color"/> to use.</returns>
55+
Color GetErrorIndicatorColor();
5456

5557
/// <summary>
56-
/// Gets the foreground brush to use for the token.
58+
/// Gets the foreground color to use for the token.
5759
/// </summary>
58-
/// <param name="tokenTypeName">Name of the token type.</param>
59-
/// <returns>The <see cref="Brush"/> to use.</returns>
60-
Brush GetTokenForegroundBrush(string tokenTypeName);
60+
/// <param name="token">The token.</param>
61+
/// <returns>The <see cref="Color"/> to use.</returns>
62+
Color GetTokenForegroundColor(SyntaxToken token);
6163

6264
/// <summary>
63-
/// Gets the background brush to use for the token.
65+
/// Gets the background color to use for the token.
6466
/// </summary>
65-
/// <param name="tokenTypeName">Name of the token type.</param>
66-
/// <returns>The <see cref="Brush"/> to use.</returns>
67-
Brush GetTokenBackgroundBrush(string tokenTypeName);
67+
/// <param name="token">The token.</param>
68+
/// <returns>The <see cref="Color"/> to use.</returns>
69+
Color GetTokenBackgroundColor(SyntaxToken token);
6870

6971
/// <summary>
7072
/// Gets the FontStyle to use for the token.
7173
/// </summary>
72-
/// <param name="tokenTypeName">Name of the token type.</param>
74+
/// <param name="token">The token.</param>
7375
/// <returns>The <see cref="FontStyle"/> to use.</returns>
74-
FontStyle GetTokenFontStyle(string tokenTypeName);
76+
FontStyle GetTokenFontStyle(SyntaxToken token);
7577
}
7678
}

Common/packages.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Antlr4.Runtime" version="4.6.6" targetFramework="net461" />
4+
<package id="JetBrains.Annotations" version="2019.1.3" targetFramework="net461" />
5+
</packages>

Grun/Grun.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -36,6 +36,9 @@
3636
<Reference Include="Antlr4.Runtime, Version=4.6.0.0, Culture=neutral, PublicKeyToken=09abb75b9ed49849, processorArchitecture=MSIL">
3737
<HintPath>..\packages\Antlr4.Runtime.4.6.6\lib\net45\Antlr4.Runtime.dll</HintPath>
3838
</Reference>
39+
<Reference Include="Colorful.Console, Version=1.2.10.0, Culture=neutral, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Colorful.Console.1.2.10\lib\net461\Colorful.Console.dll</HintPath>
41+
</Reference>
3942
<Reference Include="CommandLine, Version=2.7.82.0, Culture=neutral, PublicKeyToken=5a870481e358d379, processorArchitecture=MSIL">
4043
<HintPath>..\packages\CommandLineParser.2.7.82\lib\net461\CommandLine.dll</HintPath>
4144
</Reference>
@@ -61,6 +64,7 @@
6164
<Reference Include="System.Xml" />
6265
</ItemGroup>
6366
<ItemGroup>
67+
<Compile Include="HighlightingTokenCache.cs" />
6468
<Compile Include="Options.cs">
6569
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6670
</Compile>
@@ -85,6 +89,10 @@
8589
<Project>{ec6f674c-4d48-40c4-b28b-85627c1ea3ce}</Project>
8690
<Name>Code Grapher</Name>
8791
</ProjectReference>
92+
<ProjectReference Include="..\Common\Common.csproj">
93+
<Project>{8bd992fd-a3b3-4af9-9371-5aa14ddfda68}</Project>
94+
<Name>Common</Name>
95+
</ProjectReference>
8896
<ProjectReference Include="..\GunWin\GunWin.csproj">
8997
<Project>{a3568fa3-d6b3-4165-af95-cdb78d86f416}</Project>
9098
<Name>GunWin</Name>

Grun/HighlightingTokenCache.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#region BSD 3-Clause License
2+
// <copyright file="HighlightingTokenCache.cs" company="Edgerunner.org">
3+
// Copyright 2020
4+
// </copyright>
5+
//
6+
// BSD 3-Clause License
7+
//
8+
// Copyright (c) 2020,
9+
// All rights reserved.
10+
//
11+
// Redistribution and use in source and binary forms, with or without
12+
// modification, are permitted provided that the following conditions are met:
13+
//
14+
// 1. Redistributions of source code must retain the above copyright notice, this
15+
// list of conditions and the following disclaimer.
16+
//
17+
// 2. Redistributions in binary form must reproduce the above copyright notice,
18+
// this list of conditions and the following disclaimer in the documentation
19+
// and/or other materials provided with the distribution.
20+
//
21+
// 3. Neither the name of the copyright holder nor the names of its
22+
// contributors may be used to endorse or promote products derived from
23+
// this software without specific prior written permission.
24+
//
25+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29+
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33+
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35+
#endregion
36+
37+
using System.Collections.Generic;
38+
39+
using Org.Edgerunner.ANTLR4.Tools.Common.Grammar;
40+
41+
namespace Org.Edgerunner.ANTLR4.Tools.Testing.GrunDotNet
42+
{
43+
public class HighlightingTokenCache
44+
{
45+
private readonly Dictionary<int, Dictionary<int, int>> _KnownTokens;
46+
47+
public HighlightingTokenCache()
48+
{
49+
_KnownTokens = new Dictionary<int, Dictionary<int, int>>();
50+
}
51+
52+
public bool IsKnown(SyntaxToken token)
53+
{
54+
if (_KnownTokens.TryGetValue(token.LineNumber, out var lineCache))
55+
if (lineCache.TryGetValue(token.ColumnPosition, out var hash))
56+
if (hash == token.GetHashCode())
57+
return true;
58+
59+
return false;
60+
}
61+
62+
public void RegisterToken(SyntaxToken token)
63+
{
64+
if (_KnownTokens.TryGetValue(token.LineNumber, out var lineCache))
65+
lineCache[token.ColumnPosition] = token.GetHashCode();
66+
else
67+
_KnownTokens[token.LineNumber] = new Dictionary<int, int> { { token.ColumnPosition, token.GetHashCode() } };
68+
}
69+
70+
public void FlushTokensForLine(int lineNumber)
71+
{
72+
if (_KnownTokens.TryGetValue(lineNumber, out var lineCache))
73+
lineCache.Clear();
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)