Created
October 23, 2021 12:29
-
-
Save Rexagon/bfea6fc0d5f29c5f38977dc5f510e32d to your computer and use it in GitHub Desktop.
TL pest grammar
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
WHITESPACE = _{ " " | NEWLINE } | |
COMMENT = _{ | |
("//" ~ ANY* ~ (NEWLINE | EOI) ) | | |
("/*" ~ (!"*/" ~ ANY)* ~ "*/") | |
} | |
ident_char = @{ ASCII_ALPHANUMERIC | "_" } | |
lc_ident = @{ ASCII_ALPHA_LOWER ~ ident_char* } | |
uc_ident = @{ ASCII_ALPHA_UPPER ~ ident_char* } | |
namespace_ident = @{ lc_ident } | |
lc_ident_ns = @{ (namespace_ident ~ ".")* ~ lc_ident } | |
uc_ident_ns = @{ (namespace_ident ~ ".")* ~ uc_ident } | |
lc_ident_full = @{ lc_ident_ns ~ ("#" ~ ASCII_HEX_DIGIT{8})? } | |
nat_const = @{ ASCII_DIGIT+ } | |
tl_program = { | |
SOI ~ constr_declarations ~ ( | |
("---" ~ "functions" ~ "---" ~ fun_declarations) | | |
("---" ~ "types" ~ "---" ~ constr_declarations) | |
)* ~ EOI | |
} | |
constr_declarations = { declaration* } | |
fun_declarations = { declaration* } | |
declaration = { combinator_decl | builtin_combinator_decl | partial_app_decl | final_decl } | |
type_expr = { expr } | |
nat_expr = { expr } | |
expr = { | |
( "(" ~ expr* ~ ")" ) | | |
type_ident | | |
var_ident | | |
nat_const | | |
( "%" ~ expr ) | | |
( type_ident ~ "<" ~ expr ~ ("," ~ expr)* ~ ">" ) | |
} | |
type_ident = { boxed_type_ident | lc_ident_ns | "#" } | |
boxed_type_ident = { uc_ident_ns } | |
var_ident = { lc_ident | uc_ident } | |
type_term = { expr } | |
nat_term = { expr } | |
combinator_decl = { full_combinator_id ~ opt_args* ~ args* ~ "=" ~ result_type ~ ";" } | |
full_combinator_id = { lc_ident_full | "_" } | |
combinator_id = { lc_ident_ns | "_" } | |
opt_args = { "{" ~ var_ident+ ~ ":" ~ "!"? ~ type_expr ~ "}" } | |
args = { | |
( var_ident_opt ~ ":" ~ conditional_def? ~ "!"? ~ type_expr ) | | |
( (var_ident_opt ~ ":")? ~ (multiplicity ~ "*")? ~ "[" ~ args* ~ "]" ) | | |
( "(" ~ var_ident_opt+ ~ ":" ~ "!"? ~ type_term ~ ")" ) | | |
( "!"? ~ type_term ) | |
} | |
multiplicity = { nat_term } | |
var_ident_opt = { var_ident | "_" } | |
conditional_def = { var_ident ~ ("." ~ nat_const)? ~ "?" } | |
result_type = { | |
( boxed_type_ident ~ expr* ) | | |
( boxed_type_ident ~ "<" ~ expr ~ ("," ~ expr)* ~ ">" ) | |
} | |
builtin_combinator_decl = { full_combinator_id ~ "?" ~ "=" ~ boxed_type_ident ~ ";" } | |
partial_app_decl = { partial_type_app_decl | partial_comb_app_decl } | |
partial_type_app_decl = { | |
(boxed_type_ident ~ expr+ ~ ";") | | |
(boxed_type_ident ~ "<" ~ expr ~ ("," ~ expr)* ~ ">" ~ ";") | |
} | |
partial_comb_app_decl = { combinator_id ~ expr+ ~ ";" } | |
final_decl = { | |
("New" ~ boxed_type_ident ~ ";") | | |
("Final" ~ boxed_type_ident ~ ";") | | |
("Empty" ~ boxed_type_ident ~ ";") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment