Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ballerina – Where is Span defined?

I am trying to assign the return value of regexp:findAll to a variable, and I cannot seem to figure it out. The documentation at that previous link says that the return type is Span[] but the compiler doesn’t seem to know anything about that type. Here is a code fragment:

    string:RegExp word_char = re `\w`;
    Span[] spans = word_char.findAll("test string");

And I get these errors:

| error: unknown type 'Span'
|   Span[] spans = word_char.findAll("test string");
|   ^--^
| error: incompatible types: expected 'other[]', found 'ballerina/lang.regexp:0.0.0:Span[]'
|   Span[] spans = word_char.findAll("test string");
|                  ^------------------------------^
| Compilation aborted due to errors.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Span is defined in the same module as the findAll function (lang.regexp). So it requires importing the ballerina/lang.regexp module and using a qualified identifier (with the regexp prefix).

import ballerina/lang.regexp;

public function main() {
    string:RegExp word_char = re `\w`;
    regexp:Span[] findAll = word_char.findAll("test string");
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading