libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
lexer.h
Go to the documentation of this file.
1
8#pragma once
9
10#include "def.h"
11#include "loc.h"
12#include "util/io.h"
13
14#ifndef _PS_PUBLIC_SRC
15 #include <stdbool.h>
16
17 #include "token.h"
18 #include "util/dynarrs.h"
19 #ifndef PS_LEXER_MAX_ERRORS
22 #define PS_LEXER_MAX_ERRORS 5
23 #endif
24
29 struct ps_loc loc;
31
33
36
37 // Handling strings & interpolations
44};
45
47static bool _A(unused) ps_lexer_is_eof(void);
48
51 #define ps_lexer_next_are(next, n) _ps_lexer_next_are(next, n)
52
56 #define ps_lexer_next_are_lit(next) \
57 _ps_lexer_next_are(next, sizeof(next) - 1)
58
61static void _A(unused) ps_lexer_advance(void);
62
67static void _A(unused) ps_lexer_advance_n(usize n);
68
71static void _A(unused) ps_add_token(enum ps_token_type type, usize length);
72
75static void _A(unused) ps_add_token_with_loc(enum ps_token_type type,
77#endif
78
84struct ps_token_arr* ps_lex(const struct ps_file_ctx* file_ctx);
Base definitions.
#define _A(attr)
Definition def.h:56
#define STR
Definition def.h:40
#define usize
Definition def.h:50
Defines safe file I/O functions.
void ps_add_token(enum ps_token_type type, usize length)
Definition lexer.c:477
bool ps_lexer_is_eof(void)
Checks whether the lexer is at the end of input.
Definition lexer.c:55
void ps_lexer_advance(void)
Advances past one character in the lexer.
Definition lexer.c:230
void ps_add_token_with_loc(enum ps_token_type type, usize length, struct ps_loc loc)
Definition lexer.c:482
void ps_lexer_advance_n(usize n)
Advances past the next n characters in the lexer, updating internal state as necessary.
Definition lexer.c:272
static void usize struct ps_loc loc
Definition lexer.h:76
struct ps_token_arr * ps_lex(const struct ps_file_ctx *file_ctx)
Lexes the given source code into tokens.
Definition lexer.c:559
static void usize length
Definition lexer.h:71
File location structure.
Information captured in a file necessary for effective info/error reporting.
Definition io.h:15
Represents lexer state for a single file.
Definition lexer.h:26
struct ps_loc loc
The current location of the lexer.
Definition lexer.h:29
usize length
The length of the file.
Definition lexer.h:28
usize par_nesting
Nesting level of parentheses.
Definition lexer.h:35
STR code
The source code of the file.
Definition lexer.h:27
bool is_string_escaped
Whether the next character in the string should be escaped.
Definition lexer.h:38
usize interp_par_nesting
The nesting of parentheses at the start of string interpolation.
Definition lexer.h:42
bool in_comment
Whether the lexer is currently in a comment.
Definition lexer.h:34
bool interp_string
Whether the lexer is currrently in an interpolated string.
Definition lexer.h:40
struct ps_token_arr * tokens
The token array.
Definition lexer.h:30
struct ps_string_arr * defines
Definition lexer.h:32
Represents a token location.
Definition loc.h:16
Defines a token.
ps_token_type
The type of a token.
Definition token.h:18