lr/lex.h

33 lines
842 B
C

#pragma once
#include<stdbool.h>
#include<stdint.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include"vec.h"
#include"str.h"
#include"tok.h"
#define vec_pushl(v,l) do{Tok x=l;vec_push(v,&x);}while(0)
enum LEXTYPE {LNONE=0, LIDENTIFIER, LINTEGER, LFLOAT, LSTRING, LOPERATOR, LKEYWORD, LCOMMENT, LMINUS, LFAKE, };
enum LEXSUBTYPE {LENDSTATEMENT=55, LASSIGN, LLPAREN, LRPAREN, LLCBRACE, LRCBRACE, LSMINUS, LADD, LSMUL, LSDIV, LSNOT, LSCOLON, LSCOMMA, LSREF, LSDEREF, };
extern const char*lextype_names[];
extern const char*lexsubtype_names[];
extern const char*lextype_colors[];
typedef struct Lexer
{
Vec tokens;
uint32_t mode;
bool escape_sequence;
} Lexer;
Lexer lex_new();
// size_t lex_strchrcount(char*str,char c);
void lex_free(Lexer*l);
void lex_print(Lexer*l);
void lex_string(Lexer*l,char*s);