diff --git a/README.md b/README.md index 9aee901..00e5814 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ FlavorLang blends coding with culinary creativity! Write programs like recipes & ```bash -./install.sh +$ bash install.sh ``` ##### 3. Handle macOS Security Prompt (If Any) @@ -88,7 +88,7 @@ FlavorLang blends coding with culinary creativity! Write programs like recipes & ##### 4. Verify Installation ```bash -flavor --about +$ flavor --about ``` #### For Ubuntu Users @@ -102,13 +102,13 @@ flavor --about ```bash -./install.sh +$ bash install.sh ``` ##### 3. Verify Installation ```bash -flavor --about +$ flavor --about ``` #### Make it Yourself @@ -190,8 +190,8 @@ $ flavor --about # About FlavorLang Navigate to the `vscode-extension` folder and install dependencies: ```bash -cd vscode-extension -npm install +$ cd vscode-extension +$ npm install ``` #### 2. Package the Extension @@ -199,13 +199,13 @@ npm install Use vsce (Visual Studio Code Extension Manager) to build the `.vsix` package: ```bash -npx vsce package +$ npx vsce package ``` #### 3. Install in VS Code - Open VS Code. -- Press Ctrl+Shift+P (or ++P on macOS) and select Extensions: Install from VSIX…. +- Press P (CtrlShiftP on Windows) and select Extensions: Install from VSIX…. - Select the generated `.vsix` file within the `vscode-extension` folder. - Restart your extensions via the popup notification. diff --git a/src/main.c b/src/main.c index 1d76b0e..6c76605 100644 --- a/src/main.c +++ b/src/main.c @@ -143,13 +143,13 @@ void minify_tokens(Token *tokens, const char *output_file) { Token *next = tokens + 1; while (current->type != TOKEN_EOF) { + // Handle the current token switch (current->type) { case TOKEN_STRING: - fputc('"', output); // Opening quote + fputc('"', output); fputs(current->lexeme, output); - fputc('"', output); // Closing quote + fputc('"', output); break; - default: fputs(current->lexeme, output); break; @@ -159,20 +159,36 @@ void minify_tokens(Token *tokens, const char *output_file) { if (next->type != TOKEN_EOF) { bool add_space = false; - if (current->type == TOKEN_KEYWORD && - next->type == TOKEN_IDENTIFIER) { + // Always add space after keywords + if (current->type == TOKEN_KEYWORD) { + add_space = true; + } + // Space between identifiers/literals + else if ((current->type == TOKEN_IDENTIFIER || + current->type == TOKEN_STRING || + current->type == TOKEN_INTEGER || + current->type == TOKEN_FLOAT || + current->type == TOKEN_BOOLEAN) && + (next->type == TOKEN_IDENTIFIER || + next->type == TOKEN_STRING || + next->type == TOKEN_INTEGER || + next->type == TOKEN_FLOAT || + next->type == TOKEN_BOOLEAN)) { add_space = true; - } else if ((current->type == TOKEN_IDENTIFIER || - current->type == TOKEN_STRING || - current->type == TOKEN_INTEGER || - current->type == TOKEN_FLOAT || - current->type == TOKEN_BOOLEAN) && + } + // Handle operator spacing + else if ((current->type == TOKEN_IDENTIFIER || + current->type == TOKEN_STRING || + current->type == TOKEN_INTEGER || + current->type == TOKEN_FLOAT) && + next->type == TOKEN_OPERATOR) { + add_space = false; + } else if (current->type == TOKEN_OPERATOR && (next->type == TOKEN_IDENTIFIER || next->type == TOKEN_STRING || next->type == TOKEN_INTEGER || - next->type == TOKEN_FLOAT || - next->type == TOKEN_BOOLEAN)) { - add_space = true; + next->type == TOKEN_FLOAT)) { + add_space = false; } if (add_space) {