aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 9a9dae401cc055d45e2c703a65584aeda7c2efc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>

#include "io/file.h"
#include "cli/args.h"
#include "lexer/lexer.h"

int main(int argc, char** argv)
{
	struct Args args;

	enum ParseResult result = parse_args(argc, argv, &args);
	if (result == PARSE_EXIT)
		return 0;
	if (result == PARSE_ERROR)
		return 1;

	struct File source;
	if (!read_file(args.input_path, &source))
		return 1;

	struct Lexer lexer = create_lexer(source.data);

	for (;;)
	{
		struct Token token = scan_token(&lexer);
		printf("%4u  %-14s  %.*s\n", token.line, token_type_name(token.type), (int)token.length, token.start);
		if (token.type == TOKEN_EOF)
			break;
	}

	free_file(&source);
	return 0;
}