Add support for Ballerina language (#1196)

This commit is contained in:
Erik Schierboom 2024-11-18 11:16:59 +01:00 committed by GitHub
parent d2b30026a6
commit 06499611c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 0 deletions

View File

@ -133,6 +133,14 @@
"shebangs": ["#!/bin/awk -f"],
"extensions": ["awk"]
},
"Ballerina": {
"line_comment": ["//", "#"],
"quotes": [
["\\\"", "\\\""],
["`", "`"]
],
"extensions": ["bal"]
},
"Bash": {
"name": "BASH",
"shebangs": ["#!/bin/bash"],

40
tests/data/ballerina.bal Normal file
View File

@ -0,0 +1,40 @@
// 40 lines 29 code 6 comments 5 blanks
# Returns Bob's response to someone talking to him.
#
# + input - whatever is said to Bob
# + return - Bob's response
public function hey(string input) returns string {
string trimmed = input.trim();
boolean silent = isSilence(trimmed);
boolean asking = isQuestion(trimmed);
boolean yelling = isYelling(trimmed);
match [silent, yelling, asking] {
[true, _, _] => {
return "Fine. Be that way!";
}
[_, true, true] => {
return "Calm down, I know what I'm doing!";
}
[_, true, false] => {
return "Whoa, chill out!";
}
[_, false, true] => {
return "Sure.";
}
_ => {
return "Whatever.";
}
}
}
isolated function isSilence(string input) returns boolean => input.length() == 0;
isolated function isQuestion(string input) returns boolean => input.endsWith("?");
function isYelling(string input) returns boolean {
// contains an uppercase letter and does not contain a lowercase letter
return input.includesMatch(re `\p{Lu}`)
&& !input.includesMatch(re `\p{Ll}`);
}