Skip to content

Commit e9d5726

Browse files
Add initial improvement
1 parent 8d2374b commit e9d5726

12 files changed

+231
-151
lines changed

ballerina/common_utils.bal

+3-3
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ isolated function getOutputObject(Data data, ErrorDetail[] errors) returns Outpu
140140
}
141141

142142
isolated function getTypeName(parser:ArgumentNode argumentNode) returns string {
143-
parser:ArgumentType kind = argumentNode.getKind();
143+
int kind = argumentNode.getKind();
144144
if kind == parser:T_INT {
145145
return INT;
146146
} else if kind == parser:T_FLOAT {
@@ -158,7 +158,7 @@ isolated function getTypeName(parser:ArgumentNode argumentNode) returns string {
158158
}
159159
}
160160

161-
isolated function getArgumentTypeKind(string argType) returns parser:ArgumentType {
161+
isolated function getArgumentTypeKind(string argType) returns int {
162162
if argType == INT {
163163
return parser:T_INT;
164164
} else if argType == STRING {
@@ -232,7 +232,7 @@ isolated function getErrorDetailRecord(string message, Location|Location[] locat
232232
};
233233
}
234234

235-
isolated function getArgumentTypeIdentifierFromType(__Type argType) returns parser:ArgumentType {
235+
isolated function getArgumentTypeIdentifierFromType(__Type argType) returns int {
236236
if argType.kind == NON_NULL {
237237
return getArgumentTypeIdentifierFromType(<__Type> argType?.ofType);
238238
} else if argType.kind == LIST {

ballerina/field_validator_visitor.bal

+13-13
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class FieldValidatorVisitor {
124124
isolated function visistAnyValue(parser:ArgumentNode argumentNode, __InputValue schemaArg) {
125125
parser:ArgumentNode modifiedArgNode = self.nodeModifierContext.getModifiedArgumentNode(argumentNode);
126126
parser:ArgumentValue|parser:ArgumentValue[] value = modifiedArgNode.getValue();
127-
if value is () && schemaArg.'type.kind == NON_NULL {
127+
if value == () && schemaArg.'type.kind == NON_NULL {
128128
string expectedTypeName = getTypeNameFromType(schemaArg.'type);
129129
string message = string `${expectedTypeName} cannot represent non ${expectedTypeName} value: null`;
130130
ErrorDetail errorDetail = getErrorDetailRecord(message, modifiedArgNode.getValueLocation());
@@ -188,7 +188,7 @@ class FieldValidatorVisitor {
188188
}
189189
self.modifyArgumentNode(argNode, value = value);
190190
if !isProvidedField {
191-
if subInputValue.'type.kind == NON_NULL && subInputValue.defaultValue is () {
191+
if subInputValue.'type.kind == NON_NULL && subInputValue.defaultValue == () {
192192
string inputFieldName = getInputObjectFieldFormPath(self.argumentPath, subInputValue.name);
193193
string message = string `Field "${inputFieldName}" of required type ` +
194194
string `"${getTypeNameFromType(subInputValue.'type)}" was not provided.`;
@@ -264,7 +264,7 @@ class FieldValidatorVisitor {
264264
fieldName);
265265
self.modifyArgumentNode(argumentNode, variableValue = clonedVariableValue);
266266
self.removePath();
267-
} else if variableValue is () {
267+
} else if variableValue == () {
268268
self.validateArgumentValue(variableValue, modifiedArgNode.getValueLocation(), getTypeName(modifiedArgNode),
269269
schemaArg);
270270
} else {
@@ -273,7 +273,7 @@ class FieldValidatorVisitor {
273273
expectedTypeName = getTypeNameFromType(schemaArg.'type);
274274
}
275275
string listError = getListElementError(self.argumentPath);
276-
string value = variableValue is () ? "null" : variableValue.toString();
276+
string value = variableValue == () ? "null" : variableValue.toString();
277277
string message = string `${listError}${expectedTypeName} cannot represent non ${expectedTypeName} value:` +
278278
string ` ${value}`;
279279
ErrorDetail errorDetail = getErrorDetailRecord(message, modifiedArgNode.getValueLocation());
@@ -283,7 +283,7 @@ class FieldValidatorVisitor {
283283

284284
isolated function validateArgumentValue(parser:ArgumentValue value, Location valueLocation, string actualTypeName,
285285
__InputValue schemaArg) {
286-
if value is () {
286+
if value == () {
287287
if schemaArg.'type.kind == NON_NULL {
288288
string listError = getListElementError(self.argumentPath);
289289
string message = string `${listError}Expected value of type "${getTypeNameFromType(schemaArg.'type)}"` +
@@ -360,12 +360,12 @@ class FieldValidatorVisitor {
360360
self.validateListVariableValue(fieldValueClone, subInputValue, location, fieldName);
361361
variableValues[subInputValue.name] = fieldValueClone;
362362
self.removePath();
363-
} else if fieldValue is () {
363+
} else if fieldValue == () {
364364
string expectedTypeName = getOfTypeName(inputValue.'type);
365365
self.validateArgumentValue(fieldValue, location, expectedTypeName, subInputValue);
366366
}
367367
} else {
368-
if subInputValue.'type.kind == NON_NULL && inputValue?.defaultValue is () {
368+
if subInputValue.'type.kind == NON_NULL && inputValue?.defaultValue == () {
369369
string inputField = getInputObjectFieldFormPath(self.argumentPath, subInputValue.name);
370370
string message = string `Field "${inputField}" of required type ` +
371371
string `"${getTypeNameFromType(subInputValue.'type)}" was not provided.`;
@@ -400,7 +400,7 @@ class FieldValidatorVisitor {
400400
foreach int i in 0 ..< variableValues.length() {
401401
self.updatePath(i);
402402
json listItemValue = variableValues[i];
403-
if listItemValue is () {
403+
if listItemValue == () {
404404
string expectedTypeName = getOfTypeName(listItemInputValue.'type);
405405
self.validateArgumentValue(listItemValue, location, expectedTypeName, listItemInputValue);
406406
} else if getOfTypeName(listItemInputValue.'type) == subgraph:ANY {
@@ -545,7 +545,7 @@ class FieldValidatorVisitor {
545545
}
546546

547547
foreach __InputValue inputValue in notFoundInputValues {
548-
if inputValue.'type.kind == NON_NULL && inputValue?.defaultValue is ()
548+
if inputValue.'type.kind == NON_NULL && inputValue?.defaultValue == ()
549549
&& getOfType(inputValue.'type).name != UPLOAD {
550550
string message = getMissingRequiredArgError(fieldNode, inputValue);
551551
self.errors.push(getErrorDetailRecord(message, fieldNode.getLocation()));
@@ -560,7 +560,7 @@ class FieldValidatorVisitor {
560560
}
561561
string fragmentOnTypeName = fragmentNode.getOnType();
562562
__Type? fragmentOnType = getTypeFromTypeArray(self.schema.types, fragmentOnTypeName);
563-
if fragmentOnType is () {
563+
if fragmentOnType == () {
564564
string message = string `Unknown type "${fragmentOnTypeName}".`;
565565
ErrorDetail errorDetail = getErrorDetailRecord(message, fragmentNode.getLocation());
566566
self.errors.push(errorDetail);
@@ -592,7 +592,7 @@ class FieldValidatorVisitor {
592592
foreach parser:ArgumentValue 'field in inputObjectFields {
593593
if 'field is parser:ArgumentNode {
594594
int? index = definedFields.indexOf('field.getName());
595-
if index is () {
595+
if index == () {
596596
string message = string `Field "${'field.getName()}" is not defined by type ` +
597597
string `"${node.getName()}".`;
598598
self.errors.push(getErrorDetailRecord(message, 'field.getLocation()));
@@ -665,7 +665,7 @@ class FieldValidatorVisitor {
665665
return self.errors.length() > 0 ? self.errors : ();
666666
}
667667

668-
private isolated function modifyArgumentNode(parser:ArgumentNode originalNode, parser:ArgumentType? kind = (),
668+
private isolated function modifyArgumentNode(parser:ArgumentNode originalNode, int? kind = (),
669669
parser:ArgumentValue|parser:ArgumentValue[] value = (),
670670
json variableValue = ()) {
671671
parser:ArgumentNode previouslyModifiedNode = self.nodeModifierContext.getModifiedArgumentNode(originalNode);
@@ -699,7 +699,7 @@ isolated function getRequierdFieldFromType(__Type parentType, __Type[] typeArray
699699
parser:FieldNode fieldNode) returns __Field? {
700700
__Field[] fields = getFieldsArrayFromType(parentType);
701701
__Field? requiredField = getFieldFromFieldArray(fields, fieldNode.getName());
702-
if requiredField is () {
702+
if requiredField == () {
703703
if fieldNode.getName() == SCHEMA_FIELD && parentType.name == QUERY_TYPE_NAME {
704704
__Type fieldType = <__Type>getTypeFromTypeArray(typeArray, SCHEMA_TYPE_NAME);
705705
requiredField = createField(SCHEMA_FIELD, fieldType);

ballerina/modules/parser/argument_node.bal

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ public readonly class ArgumentNode {
2121
private Location location;
2222
private ArgumentValue|ArgumentValue[] value;
2323
private Location valueLocation;
24-
private ArgumentType kind;
24+
private int kind;
2525
private string? variableName;
2626
private json variableValue;
2727
private boolean variableDefinition;
2828
private boolean containsInvalidValue;
2929

30-
public isolated function init(string name, Location location, ArgumentType kind,
30+
public isolated function init(string name, Location location, int kind,
3131
boolean isVarDef = false, Location? valueLocation = (),
3232
ArgumentValue|ArgumentValue[] value = (), string? variableName = (),
3333
boolean containsInvalidValue = false, json variableValue = ()) {
@@ -54,7 +54,7 @@ public readonly class ArgumentNode {
5454
return self.location;
5555
}
5656

57-
public isolated function getKind() returns ArgumentType {
57+
public isolated function getKind() returns int {
5858
return self.kind;
5959
}
6060

@@ -82,12 +82,12 @@ public readonly class ArgumentNode {
8282
return self.containsInvalidValue;
8383
}
8484

85-
public isolated function modifyWith(ArgumentType? kind = (), ArgumentValue|ArgumentValue[] value = (),
85+
public isolated function modifyWith(int? kind = (), ArgumentValue|ArgumentValue[] value = (),
8686
Location? valueLocation = (), boolean? isVarDef = (),
87-
json variableValue = (), boolean? containsInvalidValue = ())
87+
json variableValue = (), boolean? containsInvalidValue = ())
8888
returns ArgumentNode {
8989

90-
ArgumentType kindParam = kind is () ? self.kind : kind;
90+
int kindParam = kind is () ? self.kind : kind;
9191
boolean isVarDefParam = isVarDef is () ? self.variableDefinition : isVarDef;
9292
Location? valueLocationParam = valueLocation is () ? self.valueLocation : valueLocation;
9393
ArgumentValue|ArgumentValue[] valueParam = value is () ? self.value : value;

ballerina/modules/parser/constants.bal

+25-48
Original file line numberDiff line numberDiff line change
@@ -42,62 +42,39 @@ const FRAGMENT = "fragment";
4242
const ON = "on";
4343
public const NULL = "null";
4444

45-
enum Digit {
46-
ZERO = "0",
47-
ONE = "1",
48-
TWO = "2",
49-
THREE = "3",
50-
FOUR = "4",
51-
FIVE = "5",
52-
SIX = "6",
53-
SEVEN = "7",
54-
EIGHT = "8",
55-
NINE = "9"
56-
}
57-
58-
enum Exp {
59-
EXP_SIMPLE = "e",
60-
EXP_CAPITAL = "E"
61-
}
62-
63-
enum WhiteSpace {
64-
SPACE = " ",
65-
TAB = "\t"
66-
}
67-
68-
enum LineTerminator {
69-
NEW_LINE = "\n",
70-
LINE_RETURN = "\r",
71-
EOF = ""
72-
}
73-
7445
const TRUE = "true";
7546
const FALSE = "false";
47+
const EOF = "";
7648

7749
// Parser Types
78-
const T_EOF = 0;
50+
7951
public const T_IDENTIFIER = 1;
8052
public const T_STRING = 2;
8153
public const T_INT = 3;
8254
public const T_FLOAT = 4;
8355
public const T_BOOLEAN = 5;
84-
public const T_COMMENT = 6;
85-
public const T_OPEN_BRACE = 7;
86-
public const T_CLOSE_BRACE = 8;
87-
public const T_OPEN_PARENTHESES = 9;
88-
public const T_CLOSE_PARENTHESES = 10;
89-
public const T_COLON = 11;
90-
public const T_COMMA = 12;
91-
public const T_NEW_LINE = 13;
92-
public const T_WHITE_SPACE = 14;
93-
public const T_ELLIPSIS = 15;
94-
public const T_DOLLAR = 16;
95-
public const T_EQUAL = 17;
96-
public const T_EXCLAMATION = 18;
97-
public const T_OPEN_BRACKET = 19;
98-
public const T_CLOSE_BRACKET = 20;
99-
public const T_AT = 21;
100-
public const T_INPUT_OBJECT = 22;
101-
public const T_LIST = 23;
56+
public const T_INPUT_OBJECT = 6;
57+
public const T_LIST = 7;
58+
59+
public const T_OPEN_BRACE = 8;
60+
public const T_CLOSE_BRACE = 9;
61+
public const T_OPEN_PARENTHESES = 10;
62+
public const T_CLOSE_PARENTHESES = 11;
63+
public const T_OPEN_BRACKET = 12;
64+
public const T_CLOSE_BRACKET = 13;
65+
66+
public const T_COLON = 14;
67+
public const T_DOLLAR = 15;
68+
public const T_EQUAL = 16;
69+
public const T_EXCLAMATION = 17;
70+
public const T_AT = 18;
71+
72+
public const T_COMMENT = 19;
73+
public const T_COMMA = 20;
74+
public const T_NEW_LINE = 21;
75+
public const T_WHITE_SPACE = 22;
76+
77+
public const T_EOF = 23;
10278

79+
public const T_ELLIPSIS = 24;
10380
public const ANONYMOUS_OPERATION = "<anonymous>";

0 commit comments

Comments
 (0)