FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
graphql-java/src/main/java/graphql/parser/Parser.java at master · emeraldjava/graphql-java · GitHub
emeraldjava
/
graphql-java
Public
forked from
graphql-java/graphql-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
graphql-java
/
src
/
main
/
java
/
graphql
/
parser
/
Parser.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (41 loc) · 1.97 KB
Breadcrumbs
graphql-java
/
src
/
main
/
java
/
graphql
/
parser
/
Parser.java
Copy path
File metadata and controls
51 lines (41 loc) · 1.97 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package
graphql
.
parser
;
import
graphql
.
Internal
;
import
graphql
.
language
.
Document
;
import
graphql
.
parser
.
antlr
.
GraphqlLexer
;
import
graphql
.
parser
.
antlr
.
GraphqlParser
;
import
org
.
antlr
.
v4
.
runtime
.
ANTLRInputStream
;
import
org
.
antlr
.
v4
.
runtime
.
BailErrorStrategy
;
import
org
.
antlr
.
v4
.
runtime
.
CommonTokenStream
;
import
org
.
antlr
.
v4
.
runtime
.
Token
;
import
org
.
antlr
.
v4
.
runtime
.
atn
.
PredictionMode
;
import
org
.
antlr
.
v4
.
runtime
.
misc
.
ParseCancellationException
;
import
java
.
util
.
List
;
@
Internal
public
class
Parser
{
public
Document
parseDocument
(
String
input
) {
GraphqlLexer
lexer
=
new
GraphqlLexer
(
new
ANTLRInputStream
(
input
));
CommonTokenStream
tokens
=
new
CommonTokenStream
(
lexer
);
GraphqlParser
parser
=
new
GraphqlParser
(
tokens
);
parser
.
removeErrorListeners
();
parser
.
getInterpreter
().
setPredictionMode
(
PredictionMode
.
SLL
);
parser
.
setErrorHandler
(
new
BailErrorStrategy
());
GraphqlParser
.
DocumentContext
document
=
parser
.
document
();
GraphqlAntlrToLanguage
antlrToLanguage
=
new
GraphqlAntlrToLanguage
(
tokens
);
antlrToLanguage
.
visitDocument
(
document
);
Token
stop
=
document
.
getStop
();
List
<
Token
>
allTokens
=
tokens
.
getTokens
();
if
(
stop
!=
null
&&
allTokens
!=
null
&& !
allTokens
.
isEmpty
()) {
Token
last
=
allTokens
.
get
(
allTokens
.
size
() -
1
);
//
// do we have more tokens in the stream than we consumed in the parse?
// if yes then its invalid. We make sure its the same channel
boolean
notEOF
=
last
.
getType
() !=
Token
.
EOF
;
boolean
lastGreaterThanDocument
=
last
.
getTokenIndex
() >
stop
.
getTokenIndex
();
boolean
sameChannel
=
last
.
getChannel
() ==
stop
.
getChannel
();
if
(
notEOF
&&
lastGreaterThanDocument
&&
sameChannel
) {
throw
new
ParseCancellationException
(
"There are more tokens in the query that have not been consumed"
);
}
}
return
antlrToLanguage
.
result
;
}
}
Back
|
FazBrowse Home
|
New Git URL