Skip to content

Commit

Permalink
grammar: Move each grammar construct's parsing code it its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Aug 12, 2024
1 parent c6c4872 commit 3bbeee1
Show file tree
Hide file tree
Showing 19 changed files with 551 additions and 435 deletions.
8 changes: 6 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ set -e

mkdir -p bin

cc_flags="-std=c11 -g -Wall -Wextra -Werror -Iflamingo/runtime -Wno-unused-parameter"
cc_flags="-std=c11 -g -Wall -Wextra -Werror -Iflamingo/runtime -Iflamingo -Wno-unused-parameter"

cc $cc_flags -c flamingo/flamingo.c -o bin/flamingo.o
# XXX With the default error limit, clangd tells us that there are too many errors and it's stopping here.
# When the error limit is disabled like I'm doing here, it says there are no errors.
# Could this be a clangd bug?

cc $cc_flags -ferror-limit=0 -c flamingo/flamingo.c -o bin/flamingo.o
cc $cc_flags -c main.c -o bin/main.o

cc $(find bin -name "*.o") $cc_flags -o bin/flamingo
Expand Down
41 changes: 41 additions & 0 deletions compile_commands.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[
{
"arguments": [
"cc",
"-c",
"-std=c11",
"-g",
"-Wall",
"-Wextra",
"-Werror",
"-Iflamingo/runtime",
"-Iflamingo",
"-Wno-unused-parameter",
"-ferror-limit=0",
"-o",
"bin/flamingo.o",
"flamingo/flamingo.c"
],
"directory": "/home/obiwac/flamingo/flamingo",
"file": "flamingo/flamingo.c"
},
{
"arguments": [
"cc",
"-c",
"-std=c11",
"-g",
"-Wall",
"-Wextra",
"-Werror",
"-Iflamingo/runtime",
"-Iflamingo",
"-Wno-unused-parameter",
"-o",
"bin/main.o",
"main.c"
],
"directory": "/home/obiwac/flamingo/flamingo",
"file": "main.c"
}
]
13 changes: 12 additions & 1 deletion flamingo/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,18 @@
#include <stdlib.h>
#include <string.h>

__attribute__((format(printf, 2, 3))) static int error(flamingo_t* flamingo, char const* fmt, ...) {
static inline int parse_expr(flamingo_t* flamingo, TSNode node, flamingo_val_t** val);
static inline int parse_statement(flamingo_t* flamingo, TSNode node);
static inline int parse_block(flamingo_t* flamingo, TSNode node);
static inline int parse_print(flamingo_t* flamingo, TSNode node);
static inline int parse_literal(flamingo_t* flamingo, TSNode node, flamingo_val_t** val);
static inline int parse_identifier(flamingo_t* flamingo, TSNode node, flamingo_val_t** val);
static inline int parse_call(flamingo_t* flamingo, TSNode node, flamingo_val_t** val);
static inline int parse_assignment(flamingo_t* flamingo, TSNode node);
static inline int parse_import(flamingo_t* flamingo, TSNode node);
static inline int parse_function_declaration(flamingo_t* flamingo, TSNode node);

__attribute__((format(printf, 2, 3))) static inline int error(flamingo_t* flamingo, char const* fmt, ...) {
va_list args;
va_start(args, fmt);

Expand Down
Loading

0 comments on commit 3bbeee1

Please sign in to comment.