-
-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Ballerina language (#1196)
- Loading branch information
1 parent
d2b3002
commit 0649961
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} |