From: Brendan Hansen Date: Mon, 19 Feb 2024 03:13:38 +0000 (-0600) Subject: added: per-file flag for optional semicolons X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=c6da37402f97f5777021670605906b656674630a;p=onyx.git added: per-file flag for optional semicolons --- diff --git a/compiler/include/lex.h b/compiler/include/lex.h index 2e721c77..5e2981df 100644 --- a/compiler/include/lex.h +++ b/compiler/include/lex.h @@ -115,6 +115,7 @@ typedef struct OnyxTokenizer { bh_arr(OnyxToken) tokens; + b32 optional_semicolons : 1; b32 insert_semicolon: 1; } OnyxTokenizer; diff --git a/compiler/src/lex.c b/compiler/src/lex.c index 0efad284..00459736 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 && context.options->enable_optional_semicolons) { + if (tokenizer->insert_semicolon && tokenizer->optional_semicolons) { OnyxToken semicolon_token; semicolon_token.type = Token_Type_Inserted_Semicolon; semicolon_token.text = "; "; @@ -219,6 +219,11 @@ whitespace_skipped: } tk.length = tokenizer->curr - tk.text - 2; + + if (bh_arr_length(tokenizer->tokens) == 0 && bh_str_starts_with(tk.text, "+optional_semicolons")) { + tokenizer->optional_semicolons = 1; + } + goto token_parsed; } @@ -558,6 +563,7 @@ OnyxTokenizer onyx_tokenizer_create(bh_allocator allocator, bh_file_contents *fc .line_start = fc->data, .tokens = NULL, + .optional_semicolons = context.options->enable_optional_semicolons, .insert_semicolon = 0, };