Skip to content

Commit 29931be

Browse files
committed
Added the AllGrammarNames property to the ISyntaxHighlightingGuide to allow a guide to support many grammars. Also added the missing ENDTRY token to the Heuristic highlighter.
1 parent bc7bf73 commit 29931be

File tree

4 files changed

+12
-3
lines changed

4 files changed

+12
-3
lines changed

Common/Syntax/ISyntaxHighlightingGuide.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3535
#endregion
3636

37+
using System.Collections.Generic;
3738
using System.Drawing;
3839

3940
using Org.Edgerunner.ANTLR4.Tools.Common.Grammar;
@@ -48,6 +49,11 @@ public interface ISyntaxHighlightingGuide
4849
/// <value>The name of the grammar.</value>
4950
string GrammarName { get; }
5051

52+
/// <summary>Gets all grammar names this syntax highlighting guide supports.</summary>
53+
/// <value>All grammar names.</value>
54+
/// <remarks>Usually used for a cluster of grammar variants that share structure.</remarks>
55+
IList<string> AllGrammarNames { get; }
56+
5157
/// <summary>
5258
/// Gets the error indicator color.
5359
/// </summary>

Grun.Net.sln

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio 15
43
VisualStudioVersion = 15.0.28307.1022

GunWin/Editor/SyntaxHighlighting/HeuristicSyntaxHighlightingGuide.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class HeuristicSyntaxHighlightingGuide : ISyntaxHighlightingGuide
6464
/// <param name="settings">The settings.</param>
6565
public HeuristicSyntaxHighlightingGuide(Settings settings)
6666
{
67+
AllGrammarNames = new List<string>();
6768
_Settings = settings;
6869
_ForegroundColors = new Dictionary<string, Color>();
6970
_BackgroundColors = new Dictionary<string, Color>();
@@ -151,6 +152,7 @@ private bool IsKeyword(SyntaxToken token)
151152
case "EXCEPT":
152153
case "CATCH":
153154
case "FINALLY":
155+
case "ENDTRY":
154156
case "THROW":
155157
case "RAISE":
156158

@@ -308,6 +310,7 @@ private bool IsComment(SyntaxToken token)
308310
}
309311

310312
public string GrammarName { get; set; }
313+
public IList<string> AllGrammarNames { get; }
311314

312315
public Color GetErrorIndicatorColor()
313316
{

Utilities/Syntax/SyntaxHighlighting.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
#endregion
3838

3939
using System;
40-
40+
using System.Collections;
41+
using System.Collections.Generic;
4142
using JetBrains.Annotations;
4243

4344
using Org.Edgerunner.ANTLR4.Tools.Common.Syntax;
@@ -89,7 +90,7 @@ public static Tuple<SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide>
8990
foreach (var reference in guideReferences)
9091
{
9192
var guide = loader.LoadSyntaxGuide(reference);
92-
if (guide != null && guide.GrammarName == grammar.GrammarName)
93+
if (guide != null && (guide.GrammarName == grammar.GrammarName || guide.AllGrammarNames.Contains(grammar.GrammarName)))
9394
return new Tuple<SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide>(reference, guide);
9495
}
9596

0 commit comments

Comments
 (0)