Package graphql.parser
Class SafeTokenSource
java.lang.Object
graphql.parser.SafeTokenSource
- All Implemented Interfaces:
org.antlr.v4.runtime.TokenSource
This token source can wrap a lexer and if it asks for more than a maximum number of tokens
the user can take some action, typically throw an exception to stop lexing.
It tracks the maximum number per token channel, so we have 3 at the moment, and they will all be tracked.
This is used to protect us from evil input. The lexer will eagerly try to find all tokens
at times and certain inputs (directives butted together for example) will cause the lexer
to keep doing work even though before the tokens are presented back to the parser
and hence before it has a chance to stop work once too much as been done.
-
Constructor Summary
ConstructorsConstructorDescriptionSafeTokenSource
(org.antlr.v4.runtime.TokenSource lexer, int maxTokens, int maxWhitespaceTokens, BiConsumer<Integer, org.antlr.v4.runtime.Token> whenMaxTokensExceeded) -
Method Summary
Modifier and TypeMethodDescriptionint
org.antlr.v4.runtime.CharStream
int
getLine()
org.antlr.v4.runtime.TokenFactory
<?> org.antlr.v4.runtime.Token
void
setTokenFactory
(org.antlr.v4.runtime.TokenFactory<?> factory)
-
Constructor Details
-
SafeTokenSource
public SafeTokenSource(org.antlr.v4.runtime.TokenSource lexer, int maxTokens, int maxWhitespaceTokens, BiConsumer<Integer, org.antlr.v4.runtime.Token> whenMaxTokensExceeded)
-
-
Method Details
-
nextToken
public org.antlr.v4.runtime.Token nextToken()- Specified by:
nextToken
in interfaceorg.antlr.v4.runtime.TokenSource
-
getLine
public int getLine()- Specified by:
getLine
in interfaceorg.antlr.v4.runtime.TokenSource
-
getCharPositionInLine
public int getCharPositionInLine()- Specified by:
getCharPositionInLine
in interfaceorg.antlr.v4.runtime.TokenSource
-
getInputStream
public org.antlr.v4.runtime.CharStream getInputStream()- Specified by:
getInputStream
in interfaceorg.antlr.v4.runtime.TokenSource
-
getSourceName
- Specified by:
getSourceName
in interfaceorg.antlr.v4.runtime.TokenSource
-
setTokenFactory
public void setTokenFactory(org.antlr.v4.runtime.TokenFactory<?> factory) - Specified by:
setTokenFactory
in interfaceorg.antlr.v4.runtime.TokenSource
-
getTokenFactory
public org.antlr.v4.runtime.TokenFactory<?> getTokenFactory()- Specified by:
getTokenFactory
in interfaceorg.antlr.v4.runtime.TokenSource
-