Skip to content

Commit

Permalink
Add getMaxTokenType for C# vocab object like antlr#1146
Browse files Browse the repository at this point in the history
  • Loading branch information
parrt committed Mar 29, 2016
1 parent d9272ed commit 90d753b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Vocabulary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public class Vocabulary : IVocabulary
[NotNull]
private readonly string[] displayNames;

private readonly int maxTokenType;

/// <summary>
/// Constructs a new instance of
/// <see cref="Vocabulary"/>
Expand Down Expand Up @@ -126,6 +128,19 @@ public Vocabulary(string[] literalNames, string[] symbolicNames, string[] displa
this.literalNames = literalNames != null ? literalNames : EmptyNames;
this.symbolicNames = symbolicNames != null ? symbolicNames : EmptyNames;
this.displayNames = displayNames != null ? displayNames : EmptyNames;
this.maxTokenType =
System.Math.Max(this.displayNames.Length,
System.Math.Max(this.literalNames.Length, this.symbolicNames.Length)) - 1;

}

/// <summary>
/// Returns the highest token type value. It can be used to iterate from
/// zero to that number, inclusively, thus querying all stored entries.
/// </summary>
public virtual int getMaxTokenType()
{
return maxTokenType;
}

[return: Nullable]
Expand Down

0 comments on commit 90d753b

Please sign in to comment.