Skip to content

Commit

Permalink
add support for MoonBit
Browse files Browse the repository at this point in the history
  • Loading branch information
luooooob committed Jan 18, 2025
1 parent dee134f commit 0f4f106
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions Unix/t/00_C.t
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 6 additions & 0 deletions cloc
Original file line number Diff line number Diff line change
Expand Up @@ -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' ,
Expand Down Expand Up @@ -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', '"', '//', '' ],
Expand Down Expand Up @@ -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,
Expand Down
54 changes: 54 additions & 0 deletions tests/inputs/moonbit.mbt
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 14 additions & 0 deletions tests/inputs/moonbit.mbti
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions tests/outputs/moonbit.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0f4f106

Please sign in to comment.