@PublicApi public class Parser extends java.lang.Object
Document
You should not generally need to call this class as the GraphQL
code sets this up for you
but if you are doing specific graphql utilities this class is essential.
Graphql syntax has a series of characters, such as spaces, new lines and commas that are not considered relevant
to the syntax. However they can be captured and associated with the AST elements they belong to.
This costs more memory but for certain use cases (like editors) this maybe be useful. We have chosen to no capture
ignored characters by default but you can turn this on, either per parse or statically for the whole JVM
via setCaptureIgnoredChars(boolean)
IgnoredChar
Constructor and Description |
---|
Parser() |
Modifier and Type | Method and Description |
---|---|
protected GraphqlAntlrToLanguage |
getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens,
MultiSourceReader multiSourceReader)
Deprecated.
- really should use
getAntlrToLanguage(CommonTokenStream, MultiSourceReader, Boolean) |
protected GraphqlAntlrToLanguage |
getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens,
MultiSourceReader multiSourceReader,
java.lang.Boolean captureIgnoredChars)
Allows you to override the ANTLR to AST code.
|
static boolean |
getCaptureIgnoredChars()
By default the Parser will not capture ignored characters.
|
static Document |
parse(java.lang.String input)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.io.Reader reader)
Parses reader input into a graphql AST
Document |
Document |
parseDocument(java.io.Reader reader,
boolean captureIgnoredChars)
Parses reader input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input,
boolean captureIgnoredChars)
Parses a string input into a graphql AST
Document |
Document |
parseDocument(java.lang.String input,
java.lang.String sourceName)
Parses a string input into a graphql AST
Document |
static Value<?> |
parseValue(java.lang.String input)
Parses a string input into a graphql AST
Value |
static void |
setCaptureIgnoredChars(boolean flag)
By default the Parser will not capture ignored characters.
|
public static boolean getCaptureIgnoredChars()
IgnoredChar
public static void setCaptureIgnoredChars(boolean flag)
flag
- - whether to capture ignored characters in AST elements or notIgnoredChar
public static Document parse(java.lang.String input) throws InvalidSyntaxException
Document
input
- the input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic static Value<?> parseValue(java.lang.String input) throws InvalidSyntaxException
Value
input
- the input to parseValue
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.lang.String input) throws InvalidSyntaxException
Document
input
- the input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.lang.String input, java.lang.String sourceName) throws InvalidSyntaxException
Document
input
- the input to parsesourceName
- - the name to attribute to the input text in SourceLocation.getSourceName()
Document
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.lang.String input, boolean captureIgnoredChars) throws InvalidSyntaxException
Document
input
- the input to parsecaptureIgnoredChars
- whether to capture characters that are otherwise ignored in graphql syntax against
each AST elementDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.io.Reader reader) throws InvalidSyntaxException
Document
reader
- the reader input to parseDocument
InvalidSyntaxException
- if the input is not valid graphql syntaxpublic Document parseDocument(java.io.Reader reader, boolean captureIgnoredChars) throws InvalidSyntaxException
Document
reader
- the reader input to parsecaptureIgnoredChars
- whether to capture characters that are otherwise ignored in graphql syntax against
each AST elementDocument
InvalidSyntaxException
- if the input is not valid graphql syntax@Deprecated protected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader)
getAntlrToLanguage(CommonTokenStream, MultiSourceReader, Boolean)
tokens
- the token streammultiSourceReader
- the source of the query documentprotected GraphqlAntlrToLanguage getAntlrToLanguage(org.antlr.v4.runtime.CommonTokenStream tokens, MultiSourceReader multiSourceReader, java.lang.Boolean captureIgnoredChars)
tokens
- the token streammultiSourceReader
- the source of the query documentcaptureIgnoredChars
- - whether ignored characters should be captured in the AST elements