From 945e74d89ce9a827c2eeff4cc7c103826c49ec3d Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 14 Nov 2023 12:02:59 +0530 Subject: [PATCH 1/4] Fix missing closing gt token --- .../io/ballerina/compiler/internal/parser/XMLParser.java | 8 +++++++- .../org/ballerinalang/test/types/xml/XMLLiteralTest.java | 3 ++- .../test-src/types/xml/xml-literals-negative.bal | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java index a3d90242cd2c..ca27688c4704 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java @@ -477,7 +477,13 @@ private STNode parseXMLText() { * @return XML char-data token */ private STNode parseCharData() { - return consume(); + STToken token = consume(); + if (token.kind != SyntaxKind.XML_TEXT_CONTENT) { + return STNodeFactory.createLiteralValueToken(SyntaxKind.XML_TEXT_CONTENT, token.text(), + token.leadingMinutiae(), token.trailingMinutiae()); + } + + return token; } /** diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java index 033b40ceadb4..aea1d277e26e 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java @@ -211,7 +211,8 @@ public void testXMLNegativeSemantics() { "'(xml|xml:Text)', found 'xml'", 149, 39); BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + "'(xml>|xml>)', found 'xml'", 150, 54); - + BAssertUtil.validateError(negativeResult, index++, "missing gt token", 154, 23); + BAssertUtil.validateError(negativeResult, index++, "missing gt token", 155, 29); Assert.assertEquals(index, negativeResult.getErrorCount()); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal index 45f16af8752d..71cb91000ec6 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal @@ -149,3 +149,8 @@ function textInvalidXmlSequence() { xml<'xml:Element>|'xml:Text x39 = xml `33`; xml>|xml> x40 = xml `text1`; } + +function testMissingClosingGTToken() { + xml x1 = xml ``; + xml x2 = xml ``; +} From 3cbf21bafbb252d4c744fd6ecb40c406a7c747d3 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 14 Nov 2023 13:33:20 +0530 Subject: [PATCH 2/4] Pass diagnostics when creating new node --- .../java/io/ballerina/compiler/internal/parser/XMLParser.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java index ca27688c4704..456fa126af8e 100644 --- a/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java +++ b/compiler/ballerina-parser/src/main/java/io/ballerina/compiler/internal/parser/XMLParser.java @@ -480,9 +480,8 @@ private STNode parseCharData() { STToken token = consume(); if (token.kind != SyntaxKind.XML_TEXT_CONTENT) { return STNodeFactory.createLiteralValueToken(SyntaxKind.XML_TEXT_CONTENT, token.text(), - token.leadingMinutiae(), token.trailingMinutiae()); + token.leadingMinutiae(), token.trailingMinutiae(), token.diagnostics()); } - return token; } From 1fb2f854c6d3365664791321fc89bd95489f2acc Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 14 Nov 2023 14:31:06 +0530 Subject: [PATCH 3/4] Add parser level test --- .../XMLTemplateExpressionTest.java | 4 + .../xml-template/xml_template_assert_36.json | 426 ++++++++++++++++++ .../xml-template/xml_template_source_36.bal | 4 + 3 files changed, 434 insertions(+) create mode 100644 compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json create mode 100644 compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal diff --git a/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/expressions/XMLTemplateExpressionTest.java b/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/expressions/XMLTemplateExpressionTest.java index 8e218b51e85e..c84420df7568 100644 --- a/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/expressions/XMLTemplateExpressionTest.java +++ b/compiler/ballerina-parser/src/test/java/io/ballerinalang/compiler/parser/test/syntax/expressions/XMLTemplateExpressionTest.java @@ -204,4 +204,8 @@ public void testMissingNameInXMLEndTag() { public void testMissingQuoteInXMLAttributeValue() { testFile("xml-template/xml_template_source_35.bal", "xml-template/xml_template_assert_35.json"); } + + public void testMissingClosingAndNextStartingAngleBracket() { + testFile("xml-template/xml_template_source_36.bal", "xml-template/xml_template_assert_36.json"); + } } diff --git a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json new file mode 100644 index 000000000000..94e9a7752634 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json @@ -0,0 +1,426 @@ +{ + "kind": "FUNCTION_DEFINITION", + "hasDiagnostics": true, + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "IDENTIFIER_TOKEN", + "value": "foo" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "FUNCTION_SIGNATURE", + "children": [ + { + "kind": "OPEN_PAREN_TOKEN" + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "CLOSE_PAREN_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "FUNCTION_BODY_BLOCK", + "hasDiagnostics": true, + "children": [ + { + "kind": "OPEN_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + }, + { + "kind": "LIST", + "hasDiagnostics": true, + "children": [ + { + "kind": "LOCAL_VAR_DECL", + "hasDiagnostics": true, + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "XML_TYPE_DESC", + "children": [ + { + "kind": "XML_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "x1", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "XML_TEMPLATE_EXPRESSION", + "hasDiagnostics": true, + "children": [ + { + "kind": "XML_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BACKTICK_TOKEN" + }, + { + "kind": "LIST", + "hasDiagnostics": true, + "children": [ + { + "kind": "XML_EMPTY_ELEMENT", + "hasDiagnostics": true, + "children": [ + { + "kind": "LT_TOKEN" + }, + { + "kind": "XML_SIMPLE_NAME", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "a", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [] + }, + { + "kind": "SLASH_TOKEN" + }, + { + "kind": "GT_TOKEN", + "isMissing": true, + "hasDiagnostics": true, + "diagnostics": [ + "ERROR_MISSING_GT_TOKEN" + ] + } + ] + }, + { + "kind": "XML_TEXT", + "children": [ + { + "kind": "XML_TEXT_CONTENT", + "value": "a" + } + ] + }, + { + "kind": "XML_TEXT", + "children": [ + { + "kind": "XML_TEXT_CONTENT", + "value": "\u003e" + } + ] + } + ] + }, + { + "kind": "BACKTICK_TOKEN" + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + }, + { + "kind": "LOCAL_VAR_DECL", + "hasDiagnostics": true, + "children": [ + { + "kind": "LIST", + "children": [] + }, + { + "kind": "TYPED_BINDING_PATTERN", + "children": [ + { + "kind": "XML_TYPE_DESC", + "children": [ + { + "kind": "XML_KEYWORD", + "leadingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ], + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "CAPTURE_BINDING_PATTERN", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "x2", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + }, + { + "kind": "EQUAL_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "XML_TEMPLATE_EXPRESSION", + "hasDiagnostics": true, + "children": [ + { + "kind": "XML_KEYWORD", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + }, + { + "kind": "BACKTICK_TOKEN" + }, + { + "kind": "LIST", + "hasDiagnostics": true, + "children": [ + { + "kind": "XML_EMPTY_ELEMENT", + "hasDiagnostics": true, + "children": [ + { + "kind": "LT_TOKEN" + }, + { + "kind": "XML_SIMPLE_NAME", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "a", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + }, + { + "kind": "LIST", + "children": [ + { + "kind": "XML_ATTRIBUTE", + "children": [ + { + "kind": "XML_SIMPLE_NAME", + "children": [ + { + "kind": "IDENTIFIER_TOKEN", + "value": "n" + } + ] + }, + { + "kind": "EQUAL_TOKEN" + }, + { + "kind": "XML_ATTRIBUTE_VALUE", + "children": [ + { + "kind": "DOUBLE_QUOTE_TOKEN" + }, + { + "kind": "LIST", + "children": [ + { + "kind": "XML_TEXT_CONTENT", + "value": "a" + } + ] + }, + { + "kind": "DOUBLE_QUOTE_TOKEN", + "trailingMinutiae": [ + { + "kind": "WHITESPACE_MINUTIAE", + "value": " " + } + ] + } + ] + } + ] + } + ] + }, + { + "kind": "SLASH_TOKEN" + }, + { + "kind": "GT_TOKEN", + "isMissing": true, + "hasDiagnostics": true, + "diagnostics": [ + "ERROR_MISSING_GT_TOKEN" + ] + } + ] + }, + { + "kind": "XML_TEXT", + "children": [ + { + "kind": "XML_TEXT_CONTENT", + "value": "a" + } + ] + }, + { + "kind": "XML_TEXT", + "children": [ + { + "kind": "XML_TEXT_CONTENT", + "value": "\u003e" + } + ] + } + ] + }, + { + "kind": "BACKTICK_TOKEN" + } + ] + }, + { + "kind": "SEMICOLON_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] + }, + { + "kind": "CLOSE_BRACE_TOKEN", + "trailingMinutiae": [ + { + "kind": "END_OF_LINE_MINUTIAE", + "value": "\n" + } + ] + } + ] + } + ] +} diff --git a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal new file mode 100644 index 000000000000..bdb1b521e3fb --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal @@ -0,0 +1,4 @@ +function foo() { + xml x1 = xml ``; + xml x2 = xml ``; +} From f95c5fba2b0b13db79ad5c1a478e6ee1203920e4 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Mon, 20 Nov 2023 10:38:44 +0530 Subject: [PATCH 4/4] Fix failing formatter test --- .../xml-template/xml_template_assert_36.json | 16 ++-------------- .../xml-template/xml_template_source_36.bal | 4 ++-- .../test/types/xml/XMLLiteralTest.java | 4 ++-- .../test-src/types/xml/xml-literals-negative.bal | 4 ++-- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json index 94e9a7752634..5556cd4e9ac3 100644 --- a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json +++ b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json @@ -150,13 +150,7 @@ "children": [ { "kind": "IDENTIFIER_TOKEN", - "value": "a", - "trailingMinutiae": [ - { - "kind": "WHITESPACE_MINUTIAE", - "value": " " - } - ] + "value": "a" } ] }, @@ -346,13 +340,7 @@ ] }, { - "kind": "DOUBLE_QUOTE_TOKEN", - "trailingMinutiae": [ - { - "kind": "WHITESPACE_MINUTIAE", - "value": " " - } - ] + "kind": "DOUBLE_QUOTE_TOKEN" } ] } diff --git a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal index bdb1b521e3fb..4f1edb48075f 100644 --- a/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal +++ b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_source_36.bal @@ -1,4 +1,4 @@ function foo() { - xml x1 = xml ``; - xml x2 = xml ``; + xml x1 = xml ``; + xml x2 = xml ``; } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java index aea1d277e26e..67b2a38df455 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralTest.java @@ -211,8 +211,8 @@ public void testXMLNegativeSemantics() { "'(xml|xml:Text)', found 'xml'", 149, 39); BAssertUtil.validateError(negativeResult, index++, "incompatible types: expected " + "'(xml>|xml>)', found 'xml'", 150, 54); - BAssertUtil.validateError(negativeResult, index++, "missing gt token", 154, 23); - BAssertUtil.validateError(negativeResult, index++, "missing gt token", 155, 29); + BAssertUtil.validateError(negativeResult, index++, "missing gt token", 154, 22); + BAssertUtil.validateError(negativeResult, index++, "missing gt token", 155, 28); Assert.assertEquals(index, negativeResult.getErrorCount()); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal index 71cb91000ec6..3952bce53638 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-negative.bal @@ -151,6 +151,6 @@ function textInvalidXmlSequence() { } function testMissingClosingGTToken() { - xml x1 = xml ``; - xml x2 = xml ``; + xml x1 = xml ``; + xml x2 = xml ``; }