aboutsummaryrefslogtreecommitdiff
path: root/src/include/lexer.h
blob: 200be5d18f8bbdec1fa7939dabab60f837c0001d (plain) (blame)
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
34
35
36
37
38
#ifndef LEXER_H
#define LEXER_H


#include "token.h"


#define LEXER_VALID (lexer->c != '\0' && lexer->i < strlen(lexer->content))


typedef struct LEXER_STRUC {
   char c;           // current character in content
   unsigned int i;   // index of c
   char* content;    // the code itself
} lexer_t;


// constructor/destroyer
extern lexer_t*   lexer_init                 (char* content);
extern void       lexer_destroy              (lexer_t* lexer);

// advance the lexer
extern void       lexer_next                 (lexer_t* lexer);
extern void       lexer_pass                 (lexer_t* lexer);
extern token_t*   lexer_get_next_token       (lexer_t* lexer);    // chars -> tokens
extern token_t*   lexer_next_token           (lexer_t* lexer, int token_type);
extern char*      lexer_get_c_as_string      (lexer_t* lexer);

// collectors
extern token_t*   lexer_get_arr              (lexer_t* lexer);
extern token_t*   lexer_collect              (lexer_t* lexer, int (*end_char)(char), int fskip, int lskip, int type);

// special def collectors
extern token_t*   lexer_get_directive        (lexer_t* lexer);
extern token_t*   lexer_get_keyword          (lexer_t* lexer);


#endif