From 3b173b29667174b791d31301dbb637c3bea13fe6 Mon Sep 17 00:00:00 2001 From: Vitaly Kuprin Date: Wed, 4 Dec 2024 22:52:50 +0100 Subject: [PATCH] feat: add c3 support Signed-off-by: Vitaly Kuprin --- lib/linguist/languages.yml | 14 ++++++ samples/C3/example.c3 | 95 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 samples/C3/example.c3 diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index b5eebfe28..e22cde43e 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -824,6 +824,20 @@ C2hs Haskell: codemirror_mode: haskell codemirror_mime_type: text/x-haskell language_id: 45 +C3: + type: programming + color: "#555555" + extensions: + - ".c3" + - ".c3i" + - ".c3l" + - ".c3d" + tm_scope: source.c3 + ace_mode: c_cpp + language_id: 1000000 + aliases: + - c3lang + group: C3 CAP CDS: type: programming tm_scope: source.cds diff --git a/samples/C3/example.c3 b/samples/C3/example.c3 new file mode 100644 index 000000000..6c43d0850 --- /dev/null +++ b/samples/C3/example.c3 @@ -0,0 +1,95 @@ +module example; + +import std::io; +import std::math; + +def Callback = fn int(char* text); + +enum Status : int +{ + IDLE, + BUSY, + DONE, +} + +struct MyData +{ + char* name; + Callback open; + Status status; + + struct other + { + int value; + int status; + } + + union + { + int* number; + char* text; + } +} + +fault MathError +{ + DIVISION_BY_ZERO +} + +fn double! divide(int a, int b) +{ + if (b == 0) return MathError.DIVISION_BY_ZERO?; + return (double)a / (double)b; +} + +<* + @param foo "the number of foos" + @require foo > 0, foo < 1000 + @return "number of foos x 10" + @ensure return < 10000, return > 0 +*> +fn int testFoo(int foo) +{ + return foo * 10; +} + +fn void example_foreach(float[] values) +{ + foreach (index, value : values) + { + io::printfn("%d: %f", index, value); + } +} + +fn void demo_switch(Status s) +{ + switch (s) + { + case IDLE: + io::printn("Idle"); + case BUSY: + io::printn("Busy"); + nextcase; + case DONE: + io::printn("Done"); + } +} + +fn void test_defer(int x) +{ + defer io::printn(); + defer io::print("A"); + if (x == 1) return; + { + defer io::print("B"); + if (x == 0) return; + } + io::print("!"); +} + +fn int main() +{ + MyData data = { .name = "test", .status = Status.IDLE }; + test_defer(1); + return 0; +}