Skip to content

Commit

Permalink
Merge pull request #187 from KennyOliver/issue-185
Browse files Browse the repository at this point in the history
Issue 185: (Fix) Minifier adds space after all keywords including `create`
  • Loading branch information
KennyOliver authored Jan 8, 2025
2 parents b376292 + 650f25e commit 8444ab2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ FlavorLang blends coding with culinary creativity! Write programs like recipes &
<!-- chmod +x install.sh -->

```bash
./install.sh
$ bash install.sh
```

##### 3. Handle macOS Security Prompt (If Any)
Expand All @@ -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
Expand All @@ -102,13 +102,13 @@ flavor --about
<!-- chmod +x install.sh -->

```bash
./install.sh
$ bash install.sh
```

##### 3. Verify Installation

```bash
flavor --about
$ flavor --about
```

#### Make it Yourself
Expand Down Expand Up @@ -190,22 +190,22 @@ $ 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

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 <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd> (or <kbd>&#8984;</kbd>+<kbd>&#8679;</kbd>+<kbd>P</kbd> on macOS) and select <kbd>Extensions: Install from VSIX…</kbd>.
- Press <kbd>&#8984;</kbd><kbd>&#8679;</kbd><kbd>P</kbd> (<kbd>Ctrl</kbd><kbd>Shift</kbd><kbd>P</kbd> on Windows) and select <kbd>Extensions: Install from VSIX…</kbd>.
- Select the generated `.vsix` file within the `vscode-extension` folder.
- Restart your extensions via the popup notification.

Expand Down
42 changes: 29 additions & 13 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 8444ab2

Please sign in to comment.