libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
token.c
Go to the documentation of this file.
1// Copyright (C) 2023 Ethan Uppal. All rights reserved.
2
3#include <stdio.h>
4#include "token.h"
5#include "enum/make.h"
6
7static STR token_type_strs[] = {
8#define ENUM TO_STRING
9#include "token_type.h"
10#undef ENUM
11};
12
14 return token_type_strs[type];
15}
16
18 switch (self->type) {
19 case PS_TOKEN_NL: {
20 printf("\\n");
21 break;
22 }
23 case PS_TOKEN_LIT_STR: {
24 printf("\"%.*s\"", (int)self->length, self->start);
25 break;
26 }
27 case PS_TOKEN_LIT_STR_INTERP: {
28 printf("\"%.*s\"", (int)self->length, self->start);
29 break;
30 }
31 default: {
32 printf("%.*s", (int)self->length, self->start);
33 break;
34 }
35 }
36 printf(" (%s) at ", ps_token_type_to_string(self->type));
37 ps_loc_print(&self->loc, 0);
38})
#define STR
Definition def.h:40
Retrieval of associated data from custom enum (see enum.h).
#define PS_PRINT_IMPL(T,...)
Definition print.h:10
Represents a token.
Definition token.h:34
STR ps_token_type_to_string(enum ps_token_type type)
Returns: the string representation of the given token type type.
Definition token.c:13
Defines a token.
ps_token_type
The type of a token.
Definition token.h:18
All token types.