Add getMaxTokenType for C# vocab object like https://github.com/antlr/antlr4/pull/1146

This commit is contained in:
parrt 2016-03-29 16:14:53 -07:00
parent d9272ed979
commit 90d753b08a
1 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,8 @@ namespace Antlr4.Runtime
[NotNull]
private readonly string[] displayNames;
private readonly int maxTokenType;
/// <summary>
/// Constructs a new instance of
/// <see cref="Vocabulary"/>
@ -126,6 +128,19 @@ namespace Antlr4.Runtime
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]