/*! * Copyright 2016 The ANTLR Project. All rights reserved. * Licensed under the BSD-3-Clause license. See LICENSE file in the project root for license information. */ /** * This interface provides information about the vocabulary used by a * recognizer. * * @see Recognizer.vocabulary * @author Sam Harwell */ export interface Vocabulary { /** * Returns the highest token type value. It can be used to iterate from * zero to that number, inclusively, thus querying all stored entries. * @return the highest token type value */ readonly maxTokenType: number; /** * Gets the string literal associated with a token type. The string returned * by this method, when not {@code null}, can be used unaltered in a parser * grammar to represent this token type. * *
The following table shows examples of lexer rules and the literal * names assigned to the corresponding token types.
* *| Rule | *Literal Name | *Java String Literal | *
|---|---|---|
| {@code THIS : 'this';} | *{@code 'this'} | *{@code "'this'"} | *
| {@code SQUOTE : '\'';} | *{@code '\''} | *{@code "'\\''"} | *
| {@code ID : [A-Z]+;} | *n/a | *{@code null} | *
This method supports token types defined by any of the following * methods:
* *tokens{} block in a lexer or parser
* grammar.The following table shows examples of lexer rules and the literal * names assigned to the corresponding token types.
* *| Rule | *Symbolic Name | *
|---|---|
| {@code THIS : 'this';} | *{@code THIS} | *
| {@code SQUOTE : '\'';} | *{@code SQUOTE} | *
| {@code ID : [A-Z]+;} | *{@code ID} | *
ANTLR provides a default implementation of this method, but * applications are free to override the behavior in any manner which makes * sense for the application. The default implementation returns the first * result from the following list which produces a non-{@code null} * result.
* *