From: Brendan Hansen Date: Tue, 6 Feb 2024 03:10:41 +0000 (-0600) Subject: changed: optional semicolons are behind a feature flag X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=85705ba69561cf84e0df051090fa4364c1fdccce;p=onyx.git changed: optional semicolons are behind a feature flag --- diff --git a/compiler/include/astnodes.h b/compiler/include/astnodes.h index 1968cd2b..f72f20d7 100644 --- a/compiler/include/astnodes.h +++ b/compiler/include/astnodes.h @@ -1843,6 +1843,8 @@ struct CompileOptions { b32 no_stale_code : 1; b32 show_all_errors : 1; + b32 enable_optional_semicolons : 1; + b32 generate_tag_file : 1; b32 generate_symbol_info_file : 1; b32 generate_lsp_info_file : 1; diff --git a/compiler/src/lex.c b/compiler/src/lex.c index e4c23663..0efad284 100644 --- a/compiler/src/lex.c +++ b/compiler/src/lex.c @@ -158,7 +158,7 @@ OnyxToken* onyx_get_token(OnyxTokenizer* tokenizer) { switch (*tokenizer->curr) { case '\n': - if (tokenizer->insert_semicolon) { + if (tokenizer->insert_semicolon && context.options->enable_optional_semicolons) { OnyxToken semicolon_token; semicolon_token.type = Token_Type_Inserted_Semicolon; semicolon_token.text = "; "; diff --git a/compiler/src/onyx.c b/compiler/src/onyx.c index 1808f859..f22ead80 100644 --- a/compiler/src/onyx.c +++ b/compiler/src/onyx.c @@ -94,6 +94,7 @@ static const char *build_docstring = DOCSTRING_HEADER "\t Can drastically increase binary size.\n" "\t--generate-foreign-info Generate information for foreign blocks. Rarely needed, so disabled by default.\n" "\t--wasm-mvp Use only WebAssembly MVP features.\n" + "\t--feature Enable an experimental language feature.\n" "\n" "Developer options:\n" "\t--no-colors Disables colors in the error message.\n" @@ -123,6 +124,8 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg .no_stale_code = 0, .show_all_errors = 0, + .enable_optional_semicolons = 0, + .runtime = Runtime_Onyx, .files = NULL, @@ -280,6 +283,12 @@ static CompileOptions compile_opts_parse(bh_allocator alloc, int argc, char *arg else if (!strcmp(argv[i], "--show-all-errors")) { options.show_all_errors = 1; } + else if (!strcmp(argv[i], "--feature")) { + char *next_arg = argv[++i]; + if (!strcmp(next_arg, "optional-semicolons")) { + options.enable_optional_semicolons = 1; + } + } else if (!strcmp(argv[i], "-I")) { bh_arr_push(options.included_folders, argv[++i]); } diff --git a/compiler/src/parser.c b/compiler/src/parser.c index a60f522a..bec7ef9e 100644 --- a/compiler/src/parser.c +++ b/compiler/src/parser.c @@ -3068,6 +3068,16 @@ static b32 parse_possible_function_definition_no_consume(OnyxParser* parser) { // :LinearTokenDependent OnyxToken* token_after_paren = matching_paren + 1; + + // Allow for: + // foo :: () + // -> i32 {} + // + // bar :: () + // { } + if (token_after_paren->type == Token_Type_Inserted_Semicolon) + token_after_paren += 1; + if (token_after_paren->type != Token_Type_Right_Arrow && token_after_paren->type != '{' && token_after_paren->type != Token_Type_Keyword_Do