Skip to content

Commit

Permalink
Add support for Ballerina language (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikSchierboom authored Nov 18, 2024
1 parent d2b3002 commit 0649961
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
"shebangs": ["#!/bin/awk -f"],
"extensions": ["awk"]
},
"Ballerina": {
"line_comment": ["//", "#"],
"quotes": [
["\\\"", "\\\""],
["`", "`"]
],
"extensions": ["bal"]
},
"Bash": {
"name": "BASH",
"shebangs": ["#!/bin/bash"],
Expand Down
40 changes: 40 additions & 0 deletions tests/data/ballerina.bal
Original file line number Diff line number Diff line change
@@ -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}`);
}

0 comments on commit 0649961

Please sign in to comment.