2013-08-27 13:23:37 -04:00
|
|
|
Goal = translation_unit ;
|
2016-04-18 22:56:29 -04:00
|
|
|
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
2015-04-04 01:32:40 -04:00
|
|
|
translation_unit = WS unorderd_list_part WS ;
|
2016-04-30 16:52:56 -04:00
|
|
|
unorderd_list_part = import WS unorderd_list_part | function WS unorderd_list_part | type_def line_end WS unorderd_list_part | adt_def line_end WS unorderd_list_part | if_comp WS unorderd_list_part | simple_passthrough WS unorderd_list_part | declaration_statement line_end WS unorderd_list_part | compiler_intrinsic line_end WS unorderd_list_part | import | function | type_def line_end | adt_def line_end | if_comp | simple_passthrough | declaration_statement line_end | compiler_intrinsic line_end ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2015-07-14 19:32:54 -04:00
|
|
|
type = "ref" WS pre_reffed | pre_reffed ;
|
2016-04-29 16:19:23 -04:00
|
|
|
pre_reffed = "\*" WS pre_reffed | "void" | "char" | "uchar" | "short" | "ushort" | "int" | "uint" | "long" | "ulong" | "float" | "double" | scoped_identifier | scoped_identifier WS template_inst | function_type ;
|
2015-05-22 22:30:25 -04:00
|
|
|
function_type = "fun" WS "\(" WS opt_type_list WS "\)" WS ":" WS type ;
|
2015-04-14 16:08:36 -04:00
|
|
|
dec_type = ":" WS type ;
|
2014-06-17 00:10:57 -07:00
|
|
|
|
2015-05-22 22:30:25 -04:00
|
|
|
opt_type_list = type_list | ;
|
2014-06-17 00:10:57 -07:00
|
|
|
template_inst = "<" WS type_list WS ">" ;
|
|
|
|
|
type_list = type_list WS "," WS type | type ;
|
|
|
|
|
|
2015-04-14 16:08:36 -04:00
|
|
|
template_dec = "<" WS template_param_list WS ">" ;
|
2014-07-18 08:52:15 -07:00
|
|
|
template_param_list = template_param_list WS "," WS template_param | template_param ;
|
|
|
|
|
template_param = identifier WS traits | identifier ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2015-08-29 21:45:55 -04:00
|
|
|
import = "import" WS identifier line_end | "import" WS identifier WS ":" WS "\*" line_end | "import" WS identifier WS ":" WS identifier_list line_end ;
|
2015-11-06 03:23:55 -05:00
|
|
|
identifier_list = identifier | identifier WS "," WS identifier_list ;
|
2014-06-17 00:10:57 -07:00
|
|
|
|
2015-04-10 00:37:31 -04:00
|
|
|
# all for optional semicolons
|
2015-03-22 22:43:33 -04:00
|
|
|
line_break = "
|
|
|
|
|
+" ;
|
2015-05-09 03:13:40 -04:00
|
|
|
# why use line_white here but not below? who knows. It's wayy faster this way. Or maybe when I changed it there was a typing mistake. Noone knows.
|
|
|
|
|
line_white = "( | )+" ;
|
|
|
|
|
actual_white = line_white | line_break | line_break actual_white | line_white actual_white ;
|
2015-03-25 15:59:49 -04:00
|
|
|
# Why is WS comment necessary? The null case SHOULD handle it, I think. I'm just a tad worred......
|
|
|
|
|
WS = actual_white | WS comment WS | WS comment | ;
|
|
|
|
|
# cpp_comment lets us do stuff like ending a statement with a cpp comment - c comments already work as they don't eat the return
|
2015-05-09 03:13:40 -04:00
|
|
|
|
2015-06-19 19:36:34 -04:00
|
|
|
maybe_line_white = "( | )+" | c_comment | maybe_line_white c_comment | maybe_line_white "( | )+" | ;
|
|
|
|
|
line_end = maybe_line_white ";" | maybe_line_white line_break | maybe_line_white cpp_comment ;
|
|
|
|
|
#line_end = maybe_line_white ";" | maybe_line_white line_break | maybe_line_white cpp_comment | WS c_comment line_end ;
|
2015-05-09 03:13:40 -04:00
|
|
|
|
|
|
|
|
# line_end = "( | )+" ";" | "( | )+" line_break | "( | )+" cpp_comment | ";" | line_break | cpp_comment ;
|
|
|
|
|
# line_end = WS ";" | WS line_break | WS cpp_comment ;
|
|
|
|
|
# line_end = "( | )+" ending | ending ;
|
|
|
|
|
# ending = ";" | line_break | cpp_comment ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2016-01-03 23:50:07 -05:00
|
|
|
if_comp = "__if_comp__" WS identifier WS statement ;
|
|
|
|
|
#if_comp = "__if_comp__" WS identifier WS if_comp_pred ;
|
|
|
|
|
#if_comp_pred = code_block | simple_passthrough ;
|
|
|
|
|
|
2015-04-04 01:32:40 -04:00
|
|
|
simple_passthrough = "simple_passthrough" WS passthrough_params WS triple_quoted_string ;
|
2015-04-10 00:37:31 -04:00
|
|
|
passthrough_params = "\(" WS in_passthrough_params WS ":" WS out_passthrough_params WS ":" WS opt_string WS "\)" | ;
|
|
|
|
|
in_passthrough_params = opt_param_assign_list ;
|
|
|
|
|
out_passthrough_params = opt_param_assign_list ;
|
2015-04-04 01:32:40 -04:00
|
|
|
opt_param_assign_list = param_assign_list | ;
|
2015-04-10 00:37:31 -04:00
|
|
|
param_assign_list = param_assign WS "," WS param_assign_list | param_assign ;
|
2015-06-19 13:28:02 -04:00
|
|
|
param_assign = identifier WS "=" WS identifier | identifier ;
|
2015-04-04 01:32:40 -04:00
|
|
|
opt_string = string | ;
|
2014-01-07 13:14:58 -05:00
|
|
|
|
2016-05-05 04:51:10 -04:00
|
|
|
triple_quoted_string = "\"\"\"((\"\"(`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+)|(\"(`|[0-9]|-|=| |[a-z]|\[|]|\\|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+))*(`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )*(((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+\")|((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+\"\")|((`|[0-9]|-|=| |[a-z]|\[|]|\\|;|'|
|
|
|
|
|
|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|<|>|\?| )+))*\"\"\"" ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2015-05-16 12:05:23 -04:00
|
|
|
#identifier = alpha_alphanumeric ;
|
|
|
|
|
identifier = augmented_alpha_alphanumeric ;
|
2015-04-04 01:32:40 -04:00
|
|
|
scope_op = ":" ":" ;
|
|
|
|
|
scoped_identifier = scoped_identifier WS scope_op WS identifier | identifier ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2015-08-05 03:43:34 -04:00
|
|
|
#Note that to prevent confilct with nested templates (T<A<B>>) right_shift is a nonterminal contructed as follows
|
2014-07-18 08:52:15 -07:00
|
|
|
right_shift = ">" ">" ;
|
2016-05-05 04:51:10 -04:00
|
|
|
overloadable_operator = "\+" | "-" | "\*" | "/" | "%" | "^" | "&" | "\|" | "~" | "!" | "," | "=" | "\+\+" | "--" | "<<" | right_shift | "==" | "!=" | "&&" | "\|\|" | "\+=" | "-=" | "/=" | "%=" | "^=" | "&=" | "\|=" | "\*=" | "<<=" | ">>=" | "->" | "\(" "\)" | "\[]" | "\[]=" ;
|
2014-03-14 15:55:45 -04:00
|
|
|
func_identifier = identifier | identifier overloadable_operator ;
|
2015-06-19 11:27:37 -04:00
|
|
|
# allow omitting of return type (automatic void)
|
2015-07-13 12:16:30 -04:00
|
|
|
|
|
|
|
|
# HACKY - typed_return has it's own internal whitespace as to not make WS typed_return-reduces to null WS ambigious
|
|
|
|
|
typed_return = WS dec_type | ;
|
2016-04-29 01:14:26 -04:00
|
|
|
function = "ext" WS "fun" WS func_identifier WS "\(" WS opt_typed_parameter_list WS "\)" typed_return | "fun" WS func_identifier WS template_dec WS "\(" WS opt_typed_parameter_list WS "\)" typed_return WS statement | "fun" WS func_identifier WS "\(" WS opt_typed_parameter_list WS "\)" typed_return WS statement ;
|
2015-07-13 12:16:30 -04:00
|
|
|
lambda = "fun" WS "\(" WS opt_typed_parameter_list WS "\)" typed_return WS statement ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2016-05-19 23:17:32 -07:00
|
|
|
opt_typed_parameter_list = typed_parameter_list | typed_parameter_list WS "," WS "..." | ;
|
2013-11-01 02:52:18 -04:00
|
|
|
typed_parameter_list = typed_parameter_list WS "," WS typed_parameter | typed_parameter ;
|
2015-04-14 16:08:36 -04:00
|
|
|
typed_parameter = identifier WS dec_type ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
|
|
|
|
opt_parameter_list = parameter_list | ;
|
2013-12-18 18:05:21 -06:00
|
|
|
parameter_list = parameter_list WS "," WS parameter | parameter ;
|
2013-11-07 22:19:33 -05:00
|
|
|
parameter = boolean_expression ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2015-05-16 12:05:23 -04:00
|
|
|
def_nonterm = "def" ;
|
|
|
|
|
obj_nonterm = "obj" ;
|
|
|
|
|
type_def = def_nonterm WS identifier WS type | obj_nonterm WS identifier WS template_dec WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS template_dec WS traits WS "{" WS declaration_block WS "}" | obj_nonterm WS identifier WS traits WS "{" WS declaration_block WS "}" ;
|
2014-07-18 08:52:15 -07:00
|
|
|
|
2015-05-09 03:13:40 -04:00
|
|
|
declaration_block = declaration_statement line_end WS declaration_block | function WS declaration_block | declaration_statement line_end | function | ;
|
2014-07-18 08:52:15 -07:00
|
|
|
traits = "\(" WS trait_list WS "\)" ;
|
2014-12-19 18:29:33 -05:00
|
|
|
trait_list = trait_list WS "," WS scoped_identifier | scoped_identifier ;
|
2014-07-18 08:52:15 -07:00
|
|
|
|
2015-08-29 21:45:55 -04:00
|
|
|
adt_nonterm = "adt" ;
|
2015-11-06 03:23:55 -05:00
|
|
|
adt_def = adt_nonterm WS identifier WS "{" WS adt_option_list WS "}" ;
|
|
|
|
|
adt_option_list = adt_option | adt_option WS "," WS adt_option_list ;
|
|
|
|
|
adt_option = identifier | identifier WS dec_type ;
|
2015-08-29 21:45:55 -04:00
|
|
|
|
2014-07-03 01:52:44 -07:00
|
|
|
if_statement = "if" WS "\(" WS boolean_expression WS "\)" WS statement | "if" WS "\(" WS boolean_expression WS "\)" WS statement WS "else" WS statement ;
|
2013-12-18 18:05:21 -06:00
|
|
|
|
2015-11-14 19:05:28 -05:00
|
|
|
match_statement = "match" WS "\(" WS boolean_expression WS "\)" WS "{" WS case_statement_list WS "}" ;
|
|
|
|
|
case_statement_list = case_statement WS case_statement_list | case_statement ;
|
|
|
|
|
case_statement = scoped_identifier WS "\(" WS identifier WS "\)" WS statement | scoped_identifier WS "\(" WS "\)" WS statement ;
|
|
|
|
|
|
2013-12-18 18:05:21 -06:00
|
|
|
while_loop = "while" WS boolean_expression WS statement ;
|
|
|
|
|
|
2015-05-09 03:13:40 -04:00
|
|
|
for_loop = "for" WS "\(" WS statement WS boolean_expression line_end WS statement WS "\)" WS statement ;
|
2013-12-18 18:05:21 -06:00
|
|
|
|
2013-12-22 01:34:59 -06:00
|
|
|
return_statement = "return" | "return" WS boolean_expression ;
|
2013-12-18 18:05:21 -06:00
|
|
|
|
2014-06-28 08:31:33 -07:00
|
|
|
code_block = "{" WS statement_list WS "}" | "{" WS "}" ;
|
2013-12-18 18:05:21 -06:00
|
|
|
|
2013-08-27 13:23:37 -04:00
|
|
|
statement_list = statement_list WS statement | statement ;
|
2015-11-14 19:05:28 -05:00
|
|
|
statement = if_statement | match_statement | while_loop | for_loop | return_statement line_end | boolean_expression line_end | assignment_statement line_end | declaration_statement line_end | code_block | if_comp | simple_passthrough | break_statement | continue_statement | defer_statement ;
|
2015-05-15 15:19:55 -04:00
|
|
|
break_statement = "break" ;
|
|
|
|
|
continue_statement = "continue" ;
|
|
|
|
|
defer_statement = "defer" WS statement ;
|
2015-06-19 19:36:34 -04:00
|
|
|
function_call = unarad WS "\(" WS opt_parameter_list WS "\)" ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2016-04-28 18:47:53 -04:00
|
|
|
compiler_intrinsic = "#" identifier WS "\(" WS intrinsic_parameter_list WS "\)" | "#" identifier WS "<" WS type_list WS ">" ;
|
|
|
|
|
intrinsic_parameter_list = intrinsic_parameter_list WS "," WS intrinsic_parameter | intrinsic_parameter ;
|
|
|
|
|
intrinsic_parameter = identifier ;
|
|
|
|
|
|
2013-08-27 13:23:37 -04:00
|
|
|
boolean_expression = boolean_expression WS "\|\|" WS and_boolean_expression | and_boolean_expression ;
|
2016-04-19 18:39:01 -04:00
|
|
|
and_boolean_expression = and_boolean_expression WS "&&" WS bitwise_or | bitwise_or ;
|
|
|
|
|
bitwise_or = bitwise_or WS "\|" WS bitwise_xor | bitwise_xor ;
|
|
|
|
|
bitwise_xor = bitwise_xor WS "^" WS bitwise_and | bitwise_and ;
|
|
|
|
|
bitwise_and = bitwise_and WS "&" WS bool_exp | bool_exp ;
|
2014-07-23 02:23:21 -07:00
|
|
|
bool_exp = expression WS comparator WS expression | expression ;
|
2013-12-18 18:05:21 -06:00
|
|
|
comparator = "==" | "<=" | ">=" | "!=" | "<" | ">" ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2014-07-18 08:52:15 -07:00
|
|
|
expression = expression WS "<<" WS term | expression WS right_shift WS shiftand | shiftand ;
|
2013-12-18 18:05:21 -06:00
|
|
|
shiftand = shiftand WS "-" WS term | shiftand WS "\+" WS term | term ;
|
2015-04-04 01:32:40 -04:00
|
|
|
term = term WS "/" WS factor | term WS "\*" WS factor | term WS "%" WS factor | factor ;
|
2016-01-19 03:16:16 -05:00
|
|
|
factor = "\+\+" WS unarad | unarad WS "\+\+" | "--" WS unarad | unarad WS "--" | "\+" WS unarad | "-" WS unarad | "!" WS unarad | "~" WS unarad | "\*" WS unarad | "&" WS unarad | unarad ;
|
2016-05-05 04:51:10 -04:00
|
|
|
unarad = number | scoped_identifier | scoped_identifier WS template_inst | access_operation | function_call | compiler_intrinsic | bool | string | character | "\(" WS boolean_expression WS "\)" | unarad WS "\[" WS expression WS "]" | lambda | cast_expression ;
|
2016-04-18 22:56:29 -04:00
|
|
|
cast_expression = "\(" WS boolean_expression WS "\)" WS "cast" WS type ;
|
2014-07-18 08:52:15 -07:00
|
|
|
number = integer | floating_literal ;
|
2015-06-28 20:25:27 -04:00
|
|
|
access_operation = unarad WS "." WS identifier | unarad WS "->" WS identifier | unarad WS "." WS identifier WS template_inst | unarad WS "->" WS identifier WS template_inst ;
|
2013-08-27 13:23:37 -04:00
|
|
|
|
2014-01-19 18:20:52 -05:00
|
|
|
assignment_statement = factor WS "=" WS boolean_expression | factor WS "\+=" WS boolean_expression | factor WS "-=" WS boolean_expression | factor WS "\*=" WS boolean_expression | factor WS "/=" WS boolean_expression ;
|
2015-05-10 02:18:59 -04:00
|
|
|
# if it's being assigned to, we allow type inferencing
|
|
|
|
|
declaration_statement = "var" WS identifier WS "=" WS boolean_expression | "var" WS identifier WS dec_type WS "=" WS boolean_expression | "var" WS identifier WS dec_type | "var" WS identifier WS "." WS identifier WS "\(" WS opt_parameter_list WS "\)" WS dec_type ;
|
2016-05-05 04:51:10 -04:00
|
|
|
hexadecimal = "0x([0-9]|[a-f])+" ;
|
2015-04-04 01:32:40 -04:00
|
|
|
integer = numeric | hexadecimal ;
|
2015-06-28 20:50:07 -04:00
|
|
|
floating_literal = numeric "." float_end ;
|
2016-05-05 04:51:10 -04:00
|
|
|
float_end = "[0-9]+" | "[0-9]+f" | "[0-9]+d" ;
|
2015-04-04 01:32:40 -04:00
|
|
|
bool = "true" | "false" ;
|
2016-05-05 04:51:10 -04:00
|
|
|
character = "'(`|[0-9]|-|=|(\\t)|[a-z]|\[|]|(\\\\)|;|(\\')|(\\n)|,|.|/|~|!|@|#|$|%|^|&|\*|\(|\)|_|\+|[A-Z]|{|}|\||:|\"|<|>|\?| |(\\0))'" ;
|
2015-05-16 12:05:23 -04:00
|
|
|
|
2016-04-18 22:56:29 -04:00
|
|
|
keywords_also_identifiers = "obj" | "def" | "fun" | "var" | "ref" | "adt" | "cast" | "import" | "simple_passthrough" ;
|
2016-05-05 04:51:10 -04:00
|
|
|
alpha_alphanumeric = "([a-z]|[A-Z]|_)([a-z]|[A-Z]|_|[0-9])*" ;
|
2015-05-16 12:05:23 -04:00
|
|
|
augmented_alpha_alphanumeric = alpha_alphanumeric augmented_alpha_alphanumeric | keywords_also_identifiers augmented_alpha_alphanumeric | alpha_alphanumeric | keywords_also_identifiers ;
|
|
|
|
|
|
2016-05-05 04:51:10 -04:00
|
|
|
numeric = "[0-9]+" ;
|
2016-02-07 16:22:55 -05:00
|
|
|
# note the hacks around \things. Hmm, I feel like it actually shouldn't be like this. Added \\\* because I want to come back later
|
2016-05-10 01:23:37 -04:00
|
|
|
string = triple_quoted_string | "\"([#-[]| |[]-~]|(\\\\)|(\\n)|(\\t)|(\\\*)|(\\0)|
|
|
|
|
|
|[ -!]|(\\\"))*\"" ;
|
2015-03-25 15:59:49 -04:00
|
|
|
comment = cpp_comment | c_comment ;
|
2016-05-10 00:40:46 -04:00
|
|
|
cpp_comment = "//[ -~]*
|
2015-03-25 15:59:49 -04:00
|
|
|
" ;
|
2016-05-10 00:40:46 -04:00
|
|
|
c_comment = "(/\*/*\**(([ -)]|[0-~]|[+-.]| |
|
|
|
|
|
)/*\**)+\*/)|(/\*\*/)" ;
|