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..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 @@ -477,7 +477,12 @@ 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(), token.diagnostics()); + } + return token; } /** 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..5556cd4e9ac3 --- /dev/null +++ b/compiler/ballerina-parser/src/test/resources/expressions/xml-template/xml_template_assert_36.json @@ -0,0 +1,414 @@ +{ + "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" + } + ] + }, + { + "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" + } + ] + } + ] + } + ] + }, + { + "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..4f1edb48075f --- /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 ``; +} 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..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,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, 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 45f16af8752d..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 @@ -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 ``; +}