commit e6fc1320c98f84ce121f25ac8e40ec46ffa76ee4
parent ac3570c8478f52b875d79afb958b23b2543efa12
Author: citbl <citbl@citbl.org>
Date: Sun, 10 May 2026 17:19:32 +1000
reeeeeeformat
Diffstat:
5 files changed, 75 insertions(+), 89 deletions(-)
diff --git a/.clang-format b/.clang-format
@@ -1,28 +1,15 @@
-BasedOnStyle: Webkit
+UseTab: Never
IndentWidth: 4
-ContinuationIndentWidth: 4
-UseTab: AlignWithSpaces
-
+TabWidth: 4
+ColumnLimit: 0
+SpacesBeforeTrailingComments: 2
PointerAlignment: Right
-
-AlignTrailingComments: true
-SpacesBeforeTrailingComments: 1
-KeepEmptyLinesAtTheStartOfBlocks: false
-AllowShortBlocksOnASingleLine: false
+AlignArrayOfStructures: Right
AllowShortIfStatementsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: false
-AlignConsecutiveDeclarations: false
-AlignConsecutiveAssignments: false
-AlignConsecutiveMacros: false
SortIncludes: false
-
-IndentCaseLabels: false
-ColumnLimit: 110 # gives about two column on screen at 20px
+BreakBeforeBraces: Stroustrup
PenaltyBreakBeforeFirstCallParameter: 1
-AlignAfterOpenBracket: DontAlign
-BinPackArguments: false
-BinPackParameters: false
-
-#BreakAfterReturnType: TopLevelDefinitions
+#AlignConsecutiveAssignments: Consecutive
diff --git a/src/common.h b/src/common.h
@@ -1,9 +1,9 @@
#pragma once
-#include <stdlib.h>
-#include <stdio.h>
#include <stdbool.h>
#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
typedef enum Token_Type {
NOTYETSET = 9,
@@ -65,10 +65,10 @@ typedef struct String {
typedef struct Token {
Token_Type type;
union Value {
- String as_string;
- char as_char;
- size_t as_int;
- bool as_bool;
+ String as_string;
+ char as_char;
+ size_t as_int;
+ bool as_bool;
} value;
const char *path;
const char *filename;
diff --git a/src/lexer.c b/src/lexer.c
@@ -5,8 +5,8 @@
static void add_token(Lexer *l, Token t)
{
if (l->len >= l->cap) {
- l->cap = l->cap == 0 ? 256 : l->cap * 2;
- l->tokens = realloc(l->tokens, l->cap * sizeof(Token));
+ l->cap = l->cap == 0 ? 256 : l->cap * 2;
+ l->tokens = realloc(l->tokens, l->cap * sizeof(Token));
}
l->tokens[l->len++] = t;
@@ -19,17 +19,17 @@ void print_tokens(Lexer *l)
size_t i;
for (i = 0; i < l->len; i++) {
- t = l->tokens[i];
- typ = t.type;
-
- switch (typ) {
- case LIT_STRING:
- printf("STRING LITERAL: %s\n", l->tokens[i].value.as_string.value);
- break;
- default:
- printf("print_tokens: unhandled token %i", typ);
- break;
- }
+ t = l->tokens[i];
+ typ = t.type;
+
+ switch (typ) {
+ case LIT_STRING:
+ printf("STRING LITERAL: %s\n", l->tokens[i].value.as_string.value);
+ break;
+ default:
+ printf("print_tokens: unhandled token %i", typ);
+ break;
+ }
}
}
@@ -39,8 +39,8 @@ static void add_to_string(Token *t, char c)
char *new_value;
if (str->len >= str->cap) {
- str->cap = str->cap == 0 ? 256 : str->cap * 2;
- str->value = realloc(str->value, str->cap * sizeof(char));
+ str->cap = str->cap == 0 ? 256 : str->cap * 2;
+ str->value = realloc(str->value, str->cap * sizeof(char));
}
str->value[str->len++] = c;
@@ -52,7 +52,7 @@ static char peek(Lexer *l)
size_t next = l->state.pos + 1;
if (next >= l->code_len) {
- return '\0';
+ return '\0';
}
return l->code[next];
@@ -66,8 +66,8 @@ static char consume(Lexer *l)
static void run_until_char(Lexer *l, char c)
{
do {
- // printf("%zu", l->state.pos);
- l->state.pos++;
+ // printf("%zu", l->state.pos);
+ l->state.pos++;
} while (peek(l) != c);
}
@@ -76,8 +76,7 @@ Lexer *lexer_lex(Lexer *l)
char c = '\0';
size_t len = strlen(l->code);
Token t = {
- .filename = l->filename, .path = l->path, .col = -1, .line = -1, .type = NOTYETSET, .value = { 0 }
- };
+ .filename = l->filename, .path = l->path, .col = -1, .line = -1, .type = NOTYETSET, .value = {0}};
l->tokens = calloc(250, sizeof(Token));
l->state.pos = 0;
@@ -85,42 +84,42 @@ Lexer *lexer_lex(Lexer *l)
// longest valid token first
while (l->state.pos <= len) {
- c = l->code[l->state.pos];
-
- if (c == '/' && peek(l) == '/') {
- // continue until the end of the line
- run_until_char(l, '\n');
- l->state.pos++;
- continue;
- }
-
- switch (c) {
- case '\"':
- l->state.in_string = true;
- t.type = LIT_STRING;
- c = l->code[++l->state.pos];
-
- while (l->code[l->state.pos] != '\"') {
- add_to_string(&t, c);
- c = l->code[++l->state.pos];
- }
-
- l->state.pos++;
- l->state.in_string = false;
- add_token(l, t);
- continue;
- case EOF:
- return l;
- case '\n':
- case '\r':
- l->state.pos++;
- continue;
- break;
- }
-
- // printf("%zu", l->state.pos);
- printf("unhandled: %c\n", c);
- l->state.pos++;
+ c = l->code[l->state.pos];
+
+ if (c == '/' && peek(l) == '/') {
+ // continue until the end of the line
+ run_until_char(l, '\n');
+ l->state.pos++;
+ continue;
+ }
+
+ switch (c) {
+ case '\"':
+ l->state.in_string = true;
+ t.type = LIT_STRING;
+ c = l->code[++l->state.pos];
+
+ while (l->code[l->state.pos] != '\"') {
+ add_to_string(&t, c);
+ c = l->code[++l->state.pos];
+ }
+
+ l->state.pos++;
+ l->state.in_string = false;
+ add_token(l, t);
+ continue;
+ case EOF:
+ return l;
+ case '\n':
+ case '\r':
+ l->state.pos++;
+ continue;
+ break;
+ }
+
+ // printf("%zu", l->state.pos);
+ printf("unhandled: %c\n", c);
+ l->state.pos++;
}
return l;
diff --git a/src/main.c b/src/main.c
@@ -8,7 +8,7 @@ int main(int argc, char **args)
{
char *filename;
char *contents;
- Lexer lexer = { 0 };
+ Lexer lexer = {0};
if (argc < 1) return 1;
diff --git a/src/utils.c b/src/utils.c
@@ -1,8 +1,8 @@
+#include "utils.h"
+#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "utils.h"
-#include "common.h"
char *read_file(const char *filename)
{
@@ -10,8 +10,8 @@ char *read_file(const char *filename)
char *source;
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
- fprintf(stderr, "file not found\n");
- return NULL;
+ fprintf(stderr, "file not found\n");
+ return NULL;
}
fseek(fp, 0, SEEK_END);
@@ -32,8 +32,8 @@ void separate_file_from_path(const char *fullpath, char **out_path, char **out_f
char *filename = strrchr(path, '/');
if (filename == NULL) {
- printf("No path found\n");
- exit(1);
+ printf("No path found\n");
+ exit(1);
}
*filename = '\0';