-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Cuneiform programming language #4157
Closed
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
da50bea
Add Cuneiform to languages.yml and add samples
joergen7 c7b73e2
Remove unused language extensions
joergen7 8ac72d4
Delete repeating examples
joergen7 9536af3
Improve on tests
joergen7 7271975
Automatically assign lang id, all tests but two pass
joergen7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,39 @@ | ||
|
||
|
||
def inc( x : Str ) -> Str { | ||
|
||
def inc( x : Str ) -> <y : Str> in Python *{ | ||
y = int( x )+1 | ||
}* | ||
|
||
( inc( x = x )|y ) | ||
} | ||
|
||
def dec( x : Str ) -> Str { | ||
|
||
def dec( x : Str ) -> <y : Str> in Python *{ | ||
y = int( x )-1 | ||
}* | ||
|
||
( dec( x = x )|y ) | ||
} | ||
|
||
def ackermann( m : Str, n : Str ) -> Str { | ||
if( m == 0 ) | ||
then | ||
inc( x = n ) | ||
else | ||
if( n == 0 ) | ||
then | ||
ackermann( | ||
m = dec( x = m ), | ||
n = 1 ) | ||
else | ||
ackermann( | ||
m = dec( x = m ), | ||
n = ackermann( m = m, n = dec( x = n ) ) ) | ||
end | ||
end | ||
} | ||
|
||
ackermann( m = 2, n = 2 ); |
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,191 @@ | ||
def forall( l : [Bool] ) -> Bool { | ||
fold acc = true, x <- l do | ||
(acc and x) | ||
end | ||
} | ||
|
||
def boolean_list_eq( l1 : [Bool], l2 : [Bool] ) -> Bool { | ||
|
||
def boolean_list_compare( l1 : [Bool], l2 : [Bool] ) -> [Bool] { | ||
for x1 <- l1, x2 <- l2 do | ||
( ( x1 and x2 ) or not( x1 or x2 ) ) : Bool | ||
end | ||
} | ||
|
||
let cmp : [Bool] = boolean_list_compare( l1 = l1, l2 = l2 ); | ||
forall( l = cmp ) | ||
} | ||
|
||
|
||
def string_list_eq( l1 : [Str], l2 : [Str] ) -> Bool { | ||
|
||
def string_list_compare( l1 : [Str], l2 : [Str] ) -> [Bool] { | ||
for x1 <- l1, x2 <- l2 do | ||
( x1 == x2 ) : Bool | ||
end | ||
} | ||
|
||
let cmp : [Bool] = string_list_compare( l1 = l1, l2 = l2 ); | ||
forall( l = cmp ) | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
def output_bool() -> <out1 : Bool, out2 : Bool> | ||
in Bash *{ | ||
out1=true | ||
out2=false | ||
}* | ||
|
||
let <out1 = c1 : Bool, out2 = d1 : Bool> = | ||
output_bool(); | ||
|
||
let output_bool_test : Str = | ||
if( not c1 or d1 ) | ||
then | ||
error "output_bool" : Str | ||
else | ||
"ok" | ||
end; | ||
|
||
|
||
|
||
|
||
def input_bool( a : Bool, b : Bool ) -> <out : Str> | ||
in Bash *{ | ||
if [ $a == 'true' ] | ||
then | ||
if [ $b == 'false' ] | ||
then | ||
out='ok' | ||
else | ||
exit -1 | ||
fi | ||
else | ||
exit -1 | ||
fi | ||
}* | ||
|
||
let <out = input_bool_test : Str> = | ||
input_bool( a = true, b = false ); | ||
|
||
|
||
|
||
|
||
|
||
def output_string() -> <out : Str> | ||
in Bash *{ | ||
out='blub' | ||
}* | ||
|
||
let <out = c2 : Str> = output_string(); | ||
|
||
let output_string_test : Str = | ||
if( c2 == "blub" ) | ||
then | ||
"ok" | ||
else | ||
error "output_string" : Str | ||
end; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
def input_string( a : Str ) -> <out : Str> | ||
in Bash *{ | ||
if [ $a == 'blub' ] | ||
then | ||
out='ok' | ||
else | ||
exit -1 | ||
fi | ||
}* | ||
|
||
let <out = input_string_test : Str> = | ||
input_string( a = "blub" ); | ||
|
||
|
||
|
||
def output_boolean_list() -> <out : [Bool]> | ||
in Bash *{ | ||
out=('true' 'false' 'true') | ||
}* | ||
|
||
let <out = c3 : [Bool]> = output_boolean_list(); | ||
|
||
let d3 : [Bool] = [true, false, true : Bool]; | ||
|
||
let output_boolean_list_test : Str = | ||
if boolean_list_eq( l1 = c3, l2 = d3 ) | ||
then | ||
"ok" | ||
else | ||
error "output_boolean_list" : Str | ||
end; | ||
|
||
|
||
|
||
|
||
|
||
def output_string_list() -> <out : [Str]> | ||
in Bash *{ | ||
out=('a' 'b' 'c') | ||
}* | ||
|
||
let <out = c4 : [Str]> = output_string_list(); | ||
|
||
let d4 : [Str] = ["a", "b", "c" : Str]; | ||
|
||
let output_string_list_test : Str = | ||
if string_list_eq( l1 = c4, l2 = d4 ) | ||
then | ||
"ok" | ||
else | ||
error "output_string_list" : Str | ||
end; | ||
|
||
|
||
|
||
|
||
def write_file( inp : Str ) -> <file : File> | ||
in Bash *{ | ||
file='out.txt' | ||
echo $inp >> $file | ||
}* | ||
|
||
def read_file( file : File ) -> <out : Str> | ||
in Bash *{ | ||
out=`cat $file` | ||
}* | ||
|
||
let c5 : Str = "blub"; | ||
|
||
let <out = d5 : Str> = | ||
read_file( file = ( write_file( inp = c5 )|file ) ); | ||
|
||
let file_test : Str = | ||
if( c5 == d5 ) | ||
then | ||
"ok" | ||
else | ||
error "file_test" : Str | ||
end; | ||
|
||
|
||
|
||
|
||
[output_bool_test, | ||
input_bool_test, | ||
output_string_test, | ||
input_string_test, | ||
output_boolean_list_test, | ||
output_string_list_test, | ||
file_test : Str]; | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though it's a different language, you can use Ruby's grammar for Cuneiform highlighting. The results look decent enough.
If that isn't good enough, just give me the formal language specification, and I'll write a grammar for you. 😉