Package graphql.parser
Class SafeTokenSource
- java.lang.Object
-
- graphql.parser.SafeTokenSource
-
- All Implemented Interfaces:
org.antlr.v4.runtime.TokenSource
public class SafeTokenSource extends java.lang.Object implements org.antlr.v4.runtime.TokenSourceThis 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.
-
-
Field Summary
Fields Modifier and Type Field Description private int[]channelCountsprivate org.antlr.v4.runtime.TokenSourcelexerprivate intmaxTokensprivate intmaxWhitespaceTokensprivate java.util.function.BiConsumer<java.lang.Integer,org.antlr.v4.runtime.Token>whenMaxTokensExceeded
-
Constructor Summary
Constructors Constructor Description SafeTokenSource(org.antlr.v4.runtime.TokenSource lexer, int maxTokens, int maxWhitespaceTokens, java.util.function.BiConsumer<java.lang.Integer,org.antlr.v4.runtime.Token> whenMaxTokensExceeded)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcallbackIfMaxExceeded(int maxCount, int currentCount, org.antlr.v4.runtime.Token token)intgetCharPositionInLine()org.antlr.v4.runtime.CharStreamgetInputStream()intgetLine()java.lang.StringgetSourceName()org.antlr.v4.runtime.TokenFactory<?>getTokenFactory()org.antlr.v4.runtime.TokennextToken()voidsetTokenFactory(org.antlr.v4.runtime.TokenFactory<?> factory)
-
-
-
Field Detail
-
lexer
private final org.antlr.v4.runtime.TokenSource lexer
-
maxTokens
private final int maxTokens
-
maxWhitespaceTokens
private final int maxWhitespaceTokens
-
whenMaxTokensExceeded
private final java.util.function.BiConsumer<java.lang.Integer,org.antlr.v4.runtime.Token> whenMaxTokensExceeded
-
channelCounts
private final int[] channelCounts
-
-
Method Detail
-
nextToken
public org.antlr.v4.runtime.Token nextToken()
- Specified by:
nextTokenin interfaceorg.antlr.v4.runtime.TokenSource
-
callbackIfMaxExceeded
private void callbackIfMaxExceeded(int maxCount, int currentCount, org.antlr.v4.runtime.Token token)
-
getLine
public int getLine()
- Specified by:
getLinein interfaceorg.antlr.v4.runtime.TokenSource
-
getCharPositionInLine
public int getCharPositionInLine()
- Specified by:
getCharPositionInLinein interfaceorg.antlr.v4.runtime.TokenSource
-
getInputStream
public org.antlr.v4.runtime.CharStream getInputStream()
- Specified by:
getInputStreamin interfaceorg.antlr.v4.runtime.TokenSource
-
getSourceName
public java.lang.String getSourceName()
- Specified by:
getSourceNamein interfaceorg.antlr.v4.runtime.TokenSource
-
setTokenFactory
public void setTokenFactory(org.antlr.v4.runtime.TokenFactory<?> factory)
- Specified by:
setTokenFactoryin interfaceorg.antlr.v4.runtime.TokenSource
-
getTokenFactory
public org.antlr.v4.runtime.TokenFactory<?> getTokenFactory()
- Specified by:
getTokenFactoryin interfaceorg.antlr.v4.runtime.TokenSource
-
-