From d02f8255ddab60edb531eb7ef2c27628ed31db1b Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Tue, 4 Mar 2025 11:58:12 +0530 Subject: [PATCH] Remove Char usage --- ballerina/modules/parser/char_reader.bal | 10 +++--- ballerina/modules/parser/lexer.bal | 36 +++++++++---------- .../parser/tests/char_reader_tests.bal | 6 ++-- ballerina/modules/parser/types.bal | 2 +- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/ballerina/modules/parser/char_reader.bal b/ballerina/modules/parser/char_reader.bal index b3854d852..61cbc1e6a 100644 --- a/ballerina/modules/parser/char_reader.bal +++ b/ballerina/modules/parser/char_reader.bal @@ -16,33 +16,33 @@ public class CharReader { private CharIterator iterator; - private string:Char?[] buffer; + private string?[] buffer; public isolated function init(string document) { self.iterator = document.iterator(); self.buffer = []; } - public isolated function peek(int into = 0) returns string:Char? { + public isolated function peek(int into = 0) returns string? { if self.buffer.length() > into { return self.buffer[into]; } int startIndex = self.buffer.length(); foreach int i in startIndex ... into { - string:Char? char = self.next(); + string? char = self.next(); self.buffer.push(char); } return self.buffer[into]; } - public isolated function read() returns string:Char? { + public isolated function read() returns string? { if self.buffer.length() > 0 { return self.buffer.shift(); } return self.next(); } - isolated function next() returns string:Char? { + isolated function next() returns string? { CharIteratorNode? next = self.iterator.next(); if next is () { return; diff --git a/ballerina/modules/parser/lexer.bal b/ballerina/modules/parser/lexer.bal index b3af1d727..a60ca762b 100644 --- a/ballerina/modules/parser/lexer.bal +++ b/ballerina/modules/parser/lexer.bal @@ -50,7 +50,7 @@ public class Lexer { } isolated function readNextToken() returns Token|SyntaxError { - string:Char? char = self.charReader.peek(); + string? char = self.charReader.peek(); if char == () { return { kind: T_EOF, @@ -77,14 +77,14 @@ public class Lexer { } } - isolated function readSeparatorToken(string:Char char) returns Token? { + isolated function readSeparatorToken(string char) returns Token? { Location location = self.currentLocation; _ = self.readNextChar(); int kind = getTokenType(char); return getToken(char, kind, location); } - isolated function readSpecialCharacterToken(string:Char char) returns Token { + isolated function readSpecialCharacterToken(string char) returns Token { Location location = self.currentLocation; _ = self.readNextChar(); int kind = getTokenType(char); @@ -104,7 +104,7 @@ public class Lexer { Location location = self.currentLocation; _ = self.readNextChar(); // Consume first double quote character - string:Char? char = self.charReader.peek(); + string? char = self.charReader.peek(); boolean isEscaped = false; int tokenTag = -1; while char != () { @@ -138,7 +138,7 @@ public class Lexer { string line = ""; self.consumeIgnoreChars(3); // Consume first three double quote characters int tokenTag = -1; - string:Char? currentChar = self.charReader.peek(); + string? currentChar = self.charReader.peek(); boolean isEscaped = false; while currentChar != () { @@ -217,7 +217,7 @@ public class Lexer { int tokenTag = -1; while next is CharIteratorNode { - string:Char value = next.value; + string value = next.value; if (symbolTable.hasKey(value)) { tokenTag = symbolTable.get(value); } else { @@ -233,11 +233,11 @@ public class Lexer { return i; } - isolated function readNumericLiteral(string:Char firstChar) returns Token|SyntaxError { + isolated function readNumericLiteral(string firstChar) returns Token|SyntaxError { Location location = self.currentLocation; string numeral = firstChar; // Passing first char to handle negative numbers. _ = self.readNextChar(); // Consume first char - string:Char? character = self.charReader.peek(); + string? character = self.charReader.peek(); int tokenTag = -1; while character != () { if (symbolTable.hasKey(character)) { @@ -263,7 +263,7 @@ public class Lexer { return getToken(number, T_INT, location); } - isolated function readFloatLiteral(string initialNumber, string:Char separator, Location location) + isolated function readFloatLiteral(string initialNumber, string separator, Location location) returns Token|SyntaxError { _ = self.readNextChar(); // Consume the separator character boolean isExpExpected = separator == DOT; @@ -271,7 +271,7 @@ public class Lexer { boolean isDigitExpected = true; string numeral = initialNumber + separator; - string:Char? value = self.charReader.peek(); + string? value = self.charReader.peek(); int tokenTag = -1; while value != () { if (symbolTable.hasKey(value)) { @@ -308,7 +308,7 @@ public class Lexer { isolated function readCommentToken() returns Token|SyntaxError { Location location = self.currentLocation; _ = self.readNextChar(); // Ignore first hash character - string:Char? character = self.charReader.peek(); + string? character = self.charReader.peek(); string word = "#"; int tokenTag = -1; while character != () { @@ -334,7 +334,7 @@ public class Lexer { int i = 0; while i < 3 { i += 1; - string:Char? c = self.readNextChar(); + string? c = self.readNextChar(); if c == DOT { ellipsis += c; continue; @@ -351,12 +351,12 @@ public class Lexer { return getToken(ELLIPSIS, T_ELLIPSIS, location); } - isolated function readIdentifierToken(string:Char firstChar) returns Token|SyntaxError { + isolated function readIdentifierToken(string firstChar) returns Token|SyntaxError { Location location = self.currentLocation; _ = self.readNextChar(); check validateFirstChar(firstChar, self.currentLocation); string word = firstChar; - string:Char? char = self.charReader.peek(); + string? char = self.charReader.peek(); int tokenTag = -1; while char != () { if (symbolTable.hasKey(char)) { @@ -391,7 +391,7 @@ public class Lexer { }; } - isolated function updateLocation(string:Char? char) { + isolated function updateLocation(string? char) { if (char == ()) { self.currentLocation.column += 1; return; @@ -409,14 +409,14 @@ public class Lexer { } } - isolated function readNextChar() returns string:Char? { - string:Char? char = self.charReader.read(); + isolated function readNextChar() returns string? { + string? char = self.charReader.read(); self.updateLocation(char); return char; } } -isolated function getTokenType(string:Char? value) returns int { +isolated function getTokenType(string? value) returns int { if value == () { return T_EOF; } diff --git a/ballerina/modules/parser/tests/char_reader_tests.bal b/ballerina/modules/parser/tests/char_reader_tests.bal index b2d03fa70..87326986e 100644 --- a/ballerina/modules/parser/tests/char_reader_tests.bal +++ b/ballerina/modules/parser/tests/char_reader_tests.bal @@ -22,7 +22,7 @@ import ballerina/test; isolated function testCharReaderForSimpleString() { string s = "Hello"; CharReader reader = new (s); - string:Char? c = reader.read(); + string? c = reader.read(); string expectedChar = "H"; test:assertEquals(c, expectedChar); @@ -52,7 +52,7 @@ isolated function testCharReaderForSimpleString() { isolated function testCharReaderForEof() { string s = ""; CharReader reader = new (s); - string:Char? c = reader.read(); + string? c = reader.read(); test:assertEquals(c, ()); } @@ -62,7 +62,7 @@ isolated function testCharReaderForEof() { isolated function testCharReaderForNewLine() { string s = "\n\n\n"; CharReader reader = new (s); - string:Char? c = reader.read(); + string? c = reader.read(); c = reader.read(); string expectedChar = "\n"; test:assertEquals(c, expectedChar); diff --git a/ballerina/modules/parser/types.bal b/ballerina/modules/parser/types.bal index 97e86f5b6..fe63c30a6 100644 --- a/ballerina/modules/parser/types.bal +++ b/ballerina/modules/parser/types.bal @@ -17,7 +17,7 @@ public type Scalar int|float|decimal|string|boolean; type CharIteratorNode record { - string:Char value; + string value; }; type CharIterator object {