Skip to content

Commit

Permalink
trying to get the graphql schema to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
burner committed Jul 22, 2024
1 parent cc7483f commit 0fbbb62
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 64 deletions.
8 changes: 7 additions & 1 deletion graphql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ListType:
Values:
Val: [Value#val]
Vals: [Value#val, comma, Values#follow]
ValsNoComma: [Value#val, Values#follow]

Array:
Empty: [lbrack, rbrack]
Expand Down Expand Up @@ -224,12 +225,15 @@ NamedTypes:

ArgumentsDefinition:
A: [lparen, InputValueDefinitions, rparen]
DA: [lparen, Description#des, InputValueDefinitions, rparen]
NA: [lparen, rparen]

InputValueDefinitions:
I: [InputValueDefinition#iv]
ICF: [InputValueDefinition#iv, comma, InputValueDefinitions#follow]
IF: [InputValueDefinition#iv, InputValueDefinitions#follow]
DI: [Description#des, InputValueDefinition#iv]
DICF: [Description#des, InputValueDefinition#iv, comma, InputValueDefinitions#follow]
DIF: [Description#des, InputValueDefinition#iv, InputValueDefinitions#follow]

InputValueDefinition:
TVD: [name#name, colon, Type#type, DefaultValue#df, Directives#dirs]
Expand Down Expand Up @@ -264,6 +268,8 @@ EnumValueDefinitions:
EnumValueDefinition:
ED: [name#name, Directives#dirs]
E: [name#name]
DED: [Description#des, name#name, Directives#dirs]
DE: [Description#des, name#name]

InputTypeDefinition:
NDE: [input, name#name, Directives#dir, lcurly,
Expand Down
42 changes: 35 additions & 7 deletions source/graphql/ast.d
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ class ListType : Node {
enum ValuesEnum {
Val,
Vals,
ValsNoComma,
}

class Values : Node {
Expand Down Expand Up @@ -1927,24 +1928,18 @@ class NamedTypes : Node {

enum ArgumentsDefinitionEnum {
A,
DA,
NA,
}

class ArgumentsDefinition : Node {
@safe :

ArgumentsDefinitionEnum ruleSelection;
Description des;

this(ArgumentsDefinitionEnum ruleSelection) {
this.ruleSelection = ruleSelection;
}

this(ArgumentsDefinitionEnum ruleSelection, Description des) {
this.ruleSelection = ruleSelection;
this.des = des;
}

void visit(Visitor vis) {
vis.accept(this);
}
Expand All @@ -1966,6 +1961,9 @@ enum InputValueDefinitionsEnum {
I,
ICF,
IF,
DI,
DICF,
DIF,
}

class InputValueDefinitions : Node {
Expand All @@ -1974,6 +1972,7 @@ class InputValueDefinitions : Node {
InputValueDefinitionsEnum ruleSelection;
InputValueDefinitions follow;
InputValueDefinition iv;
Description des;

this(InputValueDefinitionsEnum ruleSelection, InputValueDefinition iv) {
this.ruleSelection = ruleSelection;
Expand All @@ -1986,6 +1985,19 @@ class InputValueDefinitions : Node {
this.follow = follow;
}

this(InputValueDefinitionsEnum ruleSelection, Description des, InputValueDefinition iv) {
this.ruleSelection = ruleSelection;
this.des = des;
this.iv = iv;
}

this(InputValueDefinitionsEnum ruleSelection, Description des, InputValueDefinition iv, InputValueDefinitions follow) {
this.ruleSelection = ruleSelection;
this.des = des;
this.iv = iv;
this.follow = follow;
}

void visit(Visitor vis) {
vis.accept(this);
}
Expand Down Expand Up @@ -2278,12 +2290,15 @@ class EnumValueDefinitions : Node {
enum EnumValueDefinitionEnum {
ED,
E,
DED,
DE,
}

class EnumValueDefinition : Node {
@safe :

EnumValueDefinitionEnum ruleSelection;
Description des;
Directives dirs;
Token name;

Expand All @@ -2298,6 +2313,19 @@ class EnumValueDefinition : Node {
this.name = name;
}

this(EnumValueDefinitionEnum ruleSelection, Description des, Token name, Directives dirs) {
this.ruleSelection = ruleSelection;
this.des = des;
this.name = name;
this.dirs = dirs;
}

this(EnumValueDefinitionEnum ruleSelection, Description des, Token name) {
this.ruleSelection = ruleSelection;
this.des = des;
this.name = name;
}

void visit(Visitor vis) {
vis.accept(this);
}
Expand Down
87 changes: 85 additions & 2 deletions source/graphql/lexer.d
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,10 @@ struct Lexer {
++this.stringPos;
++e;
}
this.cur = Token(TokenType.stringValue, this.input[b + 3
.. e - 3], this.line, this.column);
this.cur = Token(TokenType.stringValue
, this.input[b + 3 .. e - 3], this.line
, this.column
);
} else {
while(this.stringPos < this.input.length
&& (this.input[this.stringPos] != '"'
Expand Down Expand Up @@ -777,3 +779,84 @@ unittest {
l.popFront();
assert(l.empty);
}

unittest {
import std.string : indexOf;

string f = `
"""
Defines what type of global IDs are accepted for a mutation argument of type ID.
"""
directive @possibleTypes(
"""
Abstract type of accepted global ID
"""
abstractType: String
"""
Accepted types of global IDs.
"""
concreteTypes: [String!]!
) on INPUT_FIELD_DEFINITION
`;

auto l = Lexer(f, QueryParser.no);
assert(!l.empty);
assert(l.front.type == TokenType.stringValue, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.directive, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.at, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.name, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.lparen, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.stringValue, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.name, l.front.toString());
l.popFront();
assert(!l.empty);
assert(l.front.type == TokenType.colon, l.front.toString());
l.popFront();
}

unittest {
string f = `
"""
Optional comment for approving deployments
"""
comment: String = ""
`;

auto l = Lexer(f, QueryParser.no);
assert(!l.empty);
assert(l.front.type == TokenType.stringValue, l.front.toString());
l.popFront();

assert(!l.empty);
assert(l.front.type == TokenType.name, l.front.toString());
l.popFront();

assert(!l.empty);
assert(l.front.type == TokenType.colon, l.front.toString());
l.popFront();

assert(!l.empty);
assert(l.front.type == TokenType.name, l.front.toString());
l.popFront();

assert(!l.empty);
assert(l.front.type == TokenType.equal, l.front.toString());
l.popFront();

assert(!l.empty);
assert(l.front.type == TokenType.stringValue, l.front.toString());
l.popFront();
}
Loading

0 comments on commit 0fbbb62

Please sign in to comment.