-
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(biome_graphql_parser): parse input object definition
- Loading branch information
1 parent
ed7509c
commit 88f9435
Showing
8 changed files
with
1,502 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
crates/biome_graphql_parser/src/parser/definitions/input_object.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
use crate::parser::{ | ||
directive::DirectiveList, parse_description, parse_error::expected_name, parse_name, | ||
value::is_at_string, GraphqlParser, | ||
}; | ||
use biome_graphql_syntax::{ | ||
GraphqlSyntaxKind::{self, *}, | ||
T, | ||
}; | ||
use biome_parser::{ | ||
parse_lists::ParseNodeList, parse_recovery::ParseRecovery, parsed_syntax::ParsedSyntax, | ||
prelude::ParsedSyntax::*, Parser, | ||
}; | ||
|
||
use super::{ | ||
field::{is_at_input_value_definition, parse_input_value_definition}, | ||
is_at_definition, | ||
}; | ||
|
||
#[inline] | ||
pub(crate) fn parse_input_object_type_definition(p: &mut GraphqlParser) -> ParsedSyntax { | ||
if !is_at_input_object_type_definition(p) { | ||
return Absent; | ||
} | ||
let m = p.start(); | ||
|
||
// description is optional | ||
parse_description(p).ok(); | ||
|
||
p.bump(T![input]); | ||
|
||
parse_name(p).or_add_diagnostic(p, expected_name); | ||
|
||
DirectiveList.parse_list(p); | ||
|
||
// input fields are optional | ||
parse_input_fields_definition(p).ok(); | ||
|
||
Present(m.complete(p, GRAPHQL_INPUT_OBJECT_TYPE_DEFINITION)) | ||
} | ||
|
||
#[inline] | ||
fn parse_input_fields_definition(p: &mut GraphqlParser) -> ParsedSyntax { | ||
if !is_at_input_fields_definition(p) { | ||
return Absent; | ||
} | ||
let m = p.start(); | ||
p.expect(T!['{']); | ||
|
||
InputFieldList.parse_list(p); | ||
p.expect(T!['}']); | ||
|
||
Present(m.complete(p, GRAPHQL_INPUT_FIELDS_DEFINITION)) | ||
} | ||
|
||
#[derive(Default)] | ||
struct InputFieldList; | ||
|
||
impl ParseNodeList for InputFieldList { | ||
type Kind = GraphqlSyntaxKind; | ||
type Parser<'source> = GraphqlParser<'source>; | ||
|
||
const LIST_KIND: Self::Kind = GRAPHQL_INPUT_FIELD_LIST; | ||
|
||
fn parse_element(&mut self, p: &mut Self::Parser<'_>) -> ParsedSyntax { | ||
parse_input_value_definition(p) | ||
} | ||
|
||
fn is_at_list_end(&self, p: &mut Self::Parser<'_>) -> bool { | ||
is_input_fields_end(p) | ||
} | ||
|
||
fn recover( | ||
&mut self, | ||
p: &mut Self::Parser<'_>, | ||
parsed_element: ParsedSyntax, | ||
) -> biome_parser::parse_recovery::RecoveryResult { | ||
parsed_element.or_recover(p, &InputFieldListParseRecovery, expected_name) | ||
} | ||
} | ||
|
||
struct InputFieldListParseRecovery; | ||
|
||
impl ParseRecovery for InputFieldListParseRecovery { | ||
type Kind = GraphqlSyntaxKind; | ||
type Parser<'source> = GraphqlParser<'source>; | ||
const RECOVERED_KIND: Self::Kind = GRAPHQL_BOGUS; | ||
|
||
fn is_at_recovered(&self, p: &mut Self::Parser<'_>) -> bool { | ||
is_at_input_value_definition(p) || is_input_fields_end(p) | ||
} | ||
} | ||
|
||
#[inline] | ||
pub(crate) fn is_at_input_object_type_definition(p: &mut GraphqlParser) -> bool { | ||
p.at(T![input]) || (is_at_string(p) && p.nth_at(1, T![input])) | ||
} | ||
|
||
#[inline] | ||
fn is_at_input_fields_definition(p: &mut GraphqlParser) -> bool { | ||
p.at(T!['{']) | ||
// missing opening brace | ||
|| is_at_input_value_definition(p) | ||
} | ||
|
||
#[inline] | ||
fn is_input_fields_end(p: &mut GraphqlParser) -> bool { | ||
p.at(T!['}']) || is_at_definition(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
crates/biome_graphql_parser/tests/graphql_test_suite/err/definitions/input_object.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
input Point2D | ||
x: Float | ||
y: Float | ||
} | ||
|
||
input Point2D | ||
x: Float | ||
y: Float | ||
|
||
input Point2D { | ||
|
||
input Point2D @deprecated { | ||
x: Float | ||
} | ||
|
||
input Point2D { | ||
x: = 0 | ||
y: @deprecated | ||
} | ||
|
||
input Point2D { | ||
x = 0 | ||
y: @deprecated | ||
} | ||
|
||
input Point2D { | ||
= 0 | ||
: @ | ||
} | ||
|
||
input Point2D { | ||
x | ||
y | ||
} | ||
|
||
input Point2D { | ||
= | ||
: Float | ||
} | ||
|
||
iput Point2D { | ||
x: Float | ||
y: Float | ||
} |
Oops, something went wrong.