Created
November 27, 2013 11:50
-
-
Save tiffany352/7674449 to your computer and use it in GitHub Desktop.
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
data foo :: trait { | |
bar :: int -> int, | |
baz :: char array | |
} | |
data foobar :: struct { | |
val :: int | |
} | |
impl foo foobar { | |
bar x = val x +, | |
baz = "whee" | |
} | |
data barbaz :: enum { | |
State1, | |
State2 :: int, | |
State3 :: (int, char -> int) | |
} | |
let myfoobar = foobar {val = 4} | |
in myfoobar 4 bar | |
def hello :: () IO: | |
hello = "hello, world" print | |
def blocks :: () IO: | |
blocks = { | |
"foo" print | |
"bar" print | |
} | |
[1 2 3] :: list | |
[1 2 3] :: int array | |
true 4 5 if :: int | |
if true: | |
4 | |
5 | |
def fib :: int -> int: | |
fib 0 = 0 | |
fib 1 = 1 | |
fib n = n 1 - fib n 2 - fib + | |
/////////////// | |
program :: ws (stat sws)* [stat] | |
stat :: 'data' sws atom ws '::' ws typedesc | |
| 'impl' sws atom sws atom ws '{' ws (def ws ',' ws)* [def] ws '}' | |
| 'fn' sws (func = atom) ws '::' ws typedesc sws (func (ws pattern)* ws '=' (ws expr)+ ws)+ | |
| expr | |
typedesc :: 'int' | 'char' | 'uint' | 'float' | 'str' | |
| '[' ws typedesc ws ']' | |
| '(' (ws typedesc ws ',') ws [typedesc ws] ')' | |
| 'struct' ws '{' (ws typedecl ws ',')+ [typedecl ws] '}' | |
| 'trait' ws '{' (ws typedecl ws ',')+ [typedecl ws] '}' | |
typedecl :: atom '::' typedesc | |
expr :: seqexp | letexpr | atom | number | string | structliteral | block | def | |
seqexp :: atom sws expr ':' (ws expr)+ | |
letexpr :: 'let' (sws def)+ sws 'in' sws expr | |
ident :: (any unicode alphabetical character) | '_' | '!' | '@' | '?' | |
atom :: ident+ | |
number :: '0x' digit+ | |
| ('-' | '+')? digit* ('.' digit+)? (('e'|'E') digit+)? | |
string :: '"' (escape | [^"\])* '"' | |
escape :: '\n' | '\r' | '\t' | '\\' | '\'' | '\"' | |
structliteral :: atom ws '{' (ws binding ws ',')* ws [binding ws] '}' | |
def :: pattern ws '=' (ws expr)+ | |
binding :: atom ws '=' (ws expr)+ | |
pattern :: literal | structpattern | atom | |
literal :: number | string | |
structpattern :: atom ws '{' (ws pattern_def ws ',')* ws [pattern_def ws] '}' | |
pattern_def :: atom ws '=' ws pattern | |
block :: '{' (ws expr)* ws '}' | |
ws :: space* | |
sws :: space+ | |
space :: ' ' | '\t' | '\n' | '\r' | comment | |
comment :: '//' [^\n]* '\n' | |
| '/*' (comment | .)* '*/' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment