From 0f4f106863386b22ebe72e39318a63fe17f02551 Mon Sep 17 00:00:00 2001 From: luooooob Date: Sat, 18 Jan 2025 20:10:44 +0800 Subject: [PATCH] add support for MoonBit --- README.md | 1 + Unix/t/00_C.t | 6 +++++ cloc | 6 +++++ tests/inputs/moonbit.mbt | 54 ++++++++++++++++++++++++++++++++++++++ tests/inputs/moonbit.mbti | 14 ++++++++++ tests/outputs/moonbit.yaml | 21 +++++++++++++++ 6 files changed, 102 insertions(+) create mode 100644 tests/inputs/moonbit.mbt create mode 100644 tests/inputs/moonbit.mbti create mode 100644 tests/outputs/moonbit.yaml diff --git a/README.md b/README.md index eb7c289a..7b981f37 100644 --- a/README.md +++ b/README.md @@ -1214,6 +1214,7 @@ Modelica (mo) Modula3 (i3, ig, m3, mg) Mojo (mojo, 🔥) Mojom (mojom) +MoonBit (mbt, mbti, mbtx, mbty) MSBuild script (btproj, csproj, msbuild, vcproj, wdproj, wixproj) MUMPS (mps, m) Mustache (mustache) diff --git a/Unix/t/00_C.t b/Unix/t/00_C.t index bc87d62b..915e0319 100755 --- a/Unix/t/00_C.t +++ b/Unix/t/00_C.t @@ -766,6 +766,12 @@ my @Tests = ( 'ref' => '../tests/outputs/hi.mojo.yaml', 'args' => '../tests/inputs/hi.mojo', }, + { + 'name' => 'MoonBit', + 'ref' => '../tests/outputs/moonbit.yaml', + 'args' => '../tests/inputs/moonbit.mbt ' . + '../tests/inputs/moonbit.mbti ', + }, { 'name' => 'Mumps', 'ref' => '../tests/outputs/Mumps.mps.yaml', diff --git a/cloc b/cloc index d706d31b..581d692f 100755 --- a/cloc +++ b/cloc @@ -9025,6 +9025,10 @@ sub set_constants { # {{{1 'mojom' => 'Mojom' , 'mojo' => 'Mojo' , '🔥' => 'Mojo' , + 'mbt' => 'MoonBit' , + 'mbti' => 'MoonBit' , + 'mbtx' => 'MoonBit' , + 'mbty' => 'MoonBit' , 'meson.build' => 'Meson' , 'metal' => 'Metal' , 'mk' => 'make' , @@ -10510,6 +10514,7 @@ sub set_constants { # {{{1 [ 'call_regexp_common' , 'C' ], [ 'remove_inline' , '#.*$' ], ], + 'MoonBit' => [ [ 'remove_matches' , '^\s*//' ], ], 'Nemerle' => [ [ 'rm_comments_in_strings', '"', '/*', '*/' ], [ 'rm_comments_in_strings', '"', '//', '' ], @@ -11746,6 +11751,7 @@ sub set_constants { # {{{1 'Modelica' => 2.00, 'MUMPS' => 4.21, 'Mustache' => 1.75, + 'MoonBit' => 2.50, 'Nastran' => 1.13, 'Nemerle' => 2.50, 'NetLogo' => 4.00, diff --git a/tests/inputs/moonbit.mbt b/tests/inputs/moonbit.mbt new file mode 100644 index 00000000..dfeb2fd0 --- /dev/null +++ b/tests/inputs/moonbit.mbt @@ -0,0 +1,54 @@ +///| +///without spaces +/// 返回一个新数组,其中元素被反转。 +/// +/// # 示例 +/// +/// ``` +/// reverse([1,2,3,4]) |> println() +/// ``` +fn reverse[T](xs : Array[T]) -> Array[T] { + Array::rev(xs) +} + +test { + assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) // pass + assert_eq!(reverse([1,2,3,4]), [4, 3, 2, 1]) //pass + let _ = "https://github.com" +} + +fn main { + let greeting = + #| + #| (\(\ + #| ( -.-) + #| o_(")(") + #| __ __ ____ __ ___ ____ _ __ + #| / / / /__ / / /___ / |/ /___ ____ ____ / __ )(_) /_ + #| / /_/ / _ \/ / / __ \ / /|_/ / __ \/ __ \/ __ \/ __ / / __/ + #| / __ / __/ / / /_/ / / / / / /_/ / /_/ / / / / /_/ / / /_ + #| /_/ /_/\___/_/_/\____/ /_/ /_/\____/\____/_/ /_/_____/_/\__/ + #| + println(greeting) + + // Define two array of Int. + let arr1 : Array[Int] = [1, 2, 3, 4, 5] + + // Let compiler infer the type. + let arr2 = [6, 7, 8, 9, 10] + + // Get the length of the array. + println(arr1.length()) + + // Access the element of the array. + println(arr1[1]) + + // We change the elements inside the array. + // The binding of arr1 is immutable, it still points to the same array. + // The internal mutability of the array is defined by the standard library and + // is not affected by the binding. + arr1.push(6) + arr1[1] = 10 + println("push and change element:") + println(arr1) +} diff --git a/tests/inputs/moonbit.mbti b/tests/inputs/moonbit.mbti new file mode 100644 index 00000000..00ed44a2 --- /dev/null +++ b/tests/inputs/moonbit.mbti @@ -0,0 +1,14 @@ +package moonbitlang/core/array + +alias @moonbitlang/core/quickcheck as @quickcheck + +// Values + +// Types and methods +impl FixedArray { + all[T](Self[T], (T) -> Bool) -> Bool +} + +// Type aliases + +// Traits diff --git a/tests/outputs/moonbit.yaml b/tests/outputs/moonbit.yaml new file mode 100644 index 00000000..b02b0b1d --- /dev/null +++ b/tests/outputs/moonbit.yaml @@ -0,0 +1,21 @@ +--- +# github.com/AlDanial/cloc +header : + cloc_url : github.com/AlDanial/cloc + cloc_version : 2.02 + elapsed_seconds : 0.0278570652008057 + n_files : 2 + n_lines : 27 + files_per_second : 35.8975359676826 + lines_per_second : 969.23347112743 + report_file : ./tests/outputs/moonbit.yaml +'MoonBit' : + nFiles: 2 + blank: 12 + comment: 21 + code: 35 +SUM: + blank: 12 + comment: 21 + code: 35 + nFiles: 2