mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 09:40:21 +00:00
Add Ballerina language (#3818)
* Add Ballerina language * Add missing file * Update color * Update with required changes * Update sub-module
This commit is contained in:
committed by
Colin Seymour
parent
78c58f956e
commit
c2d558b71d
16
samples/Ballerina/hello-world-service.bal
Normal file
16
samples/Ballerina/hello-world-service.bal
Normal file
@@ -0,0 +1,16 @@
|
||||
import ballerina.lang.messages;
|
||||
import ballerina.net.http;
|
||||
import ballerina.doc;
|
||||
|
||||
@doc:Description {value:"By default Ballerina assumes that the service is to be exposed via HTTP/1.1 using the system default port and that all requests coming to the HTTP server will be delivered to this service."}
|
||||
service<http> helloWorld {
|
||||
@doc:Description {value:"All resources are invoked with an argument of type message, the built-in reference type representing a network invocation."}
|
||||
resource sayHello (message m) {
|
||||
// Creates an empty message.
|
||||
message response = {};
|
||||
// A util method that can be used to set string payload.
|
||||
messages:setStringPayload(response, "Hello, World!");
|
||||
// Reply keyword sends the response back to the client.
|
||||
reply response;
|
||||
}
|
||||
}
|
||||
6
samples/Ballerina/hello-world.bal
Normal file
6
samples/Ballerina/hello-world.bal
Normal file
@@ -0,0 +1,6 @@
|
||||
import ballerina.lang.system;
|
||||
|
||||
function main (string[] args) {
|
||||
system:println("Hello, World!");
|
||||
}
|
||||
|
||||
31
samples/Ballerina/json.bal
Normal file
31
samples/Ballerina/json.bal
Normal file
@@ -0,0 +1,31 @@
|
||||
import ballerina.lang.system;
|
||||
|
||||
function main (string[] args) {
|
||||
// JSON string value.
|
||||
json j1 = "Apple";
|
||||
system:println(j1);
|
||||
|
||||
// JSON number value.
|
||||
json j2 = 5.36;
|
||||
system:println(j2);
|
||||
|
||||
// JSON true value.
|
||||
json j3 = true;
|
||||
system:println(j3);
|
||||
|
||||
// JSON false value.
|
||||
json j4 = false;
|
||||
system:println(j4);
|
||||
|
||||
// JSON null value.
|
||||
json j5 = null;
|
||||
|
||||
//JSON Objects.
|
||||
json j6 = {name:"apple", color:"red", price:j2};
|
||||
system:println(j6);
|
||||
|
||||
//JSON Arrays. They are arrays of any JSON value.
|
||||
json j7 = [1, false, null, "foo",
|
||||
{first:"John", last:"Pala"}];
|
||||
system:println(j7);
|
||||
}
|
||||
28
samples/Ballerina/var.bal
Normal file
28
samples/Ballerina/var.bal
Normal file
@@ -0,0 +1,28 @@
|
||||
import ballerina.lang.system;
|
||||
|
||||
function divideBy10 (int d) (int, int) {
|
||||
return d / 10, d % 10;
|
||||
}
|
||||
|
||||
function main (string[] args) {
|
||||
//Here the variable type is inferred type from the initial value. This is same as "int k = 5";
|
||||
var k = 5;
|
||||
system:println(10 + k);
|
||||
|
||||
//Here the type of the 'strVar' is 'string'.
|
||||
var strVar = "Hello!";
|
||||
system:println(strVar);
|
||||
|
||||
//Multiple assignment with 'var' allows you to define the variable then and there.
|
||||
//Variable type is inferred from the right-hand side.
|
||||
var q, r = divideBy10(6);
|
||||
system:println("06/10: " + "quotient=" + q + " " +
|
||||
"remainder=" + r);
|
||||
|
||||
//To ignore a particular return value in a multiple assignment statement, use '_'.
|
||||
var q1, _ = divideBy10(57);
|
||||
system:println("57/10: " + "quotient=" + q1);
|
||||
|
||||
var _, r1 = divideBy10(9);
|
||||
system:println("09/10: " + "remainder=" + r1);
|
||||
}
|
||||
26
samples/Ballerina/xml.bal
Normal file
26
samples/Ballerina/xml.bal
Normal file
@@ -0,0 +1,26 @@
|
||||
import ballerina.lang.system;
|
||||
|
||||
function main (string[] args) {
|
||||
|
||||
// XML element. Can only have one root element.
|
||||
xml x1 = xml `<book>The Lost World</book>`;
|
||||
system:println(x1);
|
||||
|
||||
// XML text
|
||||
xml x2 = xml `Hello, world!`;
|
||||
system:println(x2);
|
||||
|
||||
// XML comment
|
||||
xml x3 = xml `<!--I am a comment-->`;
|
||||
system:println(x3);
|
||||
|
||||
// XML processing instruction
|
||||
xml x4 = xml `<?target data?>`;
|
||||
system:println(x4);
|
||||
|
||||
// Multiple XML items can be combined to form a sequence of XML. The resulting sequence is again an XML on its own.
|
||||
xml x5 = x1 + x2 + x3 + x4;
|
||||
system:println("\nResulting XML sequence:");
|
||||
system:println(x5);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user