wacc/lexer.h
2023-02-13 14:42:46 +01:00

101 lines
1.9 KiB
C

#ifndef LEXER_H
#define LEXER_H
#include <stddef.h>
typedef enum {
TokenTypeEof,
TokenTypeInvalidChar,
TokenTypeMalformedMultilineComment,
TokenTypeMalformedChar,
TokenTypeMalformedString,
TokenTypeId,
TokenTypeInt,
TokenTypeHex,
TokenTypeBinary,
TokenTypeFloat,
TokenTypeChar,
TokenTypeString,
TokenTypeIf,
TokenTypeElse,
TokenTypeLoop,
TokenTypeWhile,
TokenTypeFor,
TokenTypeIn,
TokenTypeBreak,
TokenTypeLet,
TokenTypeMatch,
TokenTypeFalse,
TokenTypeTrue,
TokenTypeNot,
TokenTypeAnd,
TokenTypeOr,
TokenTypeFn,
TokenTypeReturn,
TokenTypeLParen,
TokenTypeRParen,
TokenTypeLBrace,
TokenTypeRBrace,
TokenTypeLBracket,
TokenTypeRBracket,
TokenTypeDot,
TokenTypeComma,
TokenTypeColon,
TokenTypeSemicolon,
TokenTypeDoubleMatch,
TokenTypeAmpersand,
TokenTypeUnderscore,
TokenTypePlusEqual,
TokenTypeMinusEqual,
TokenTypeAsteriskEqual,
TokenTypeSlashEqual,
TokenTypePercentEqual,
TokenTypeDoubleEqual,
TokenTypeExclamationEqual,
TokenTypeLtEqual,
TokenTypeGtEqual,
TokenTypePlus,
TokenTypeMinus,
TokenTypeAsterisk,
TokenTypeSlash,
TokenTypePercent,
TokenTypeEqual,
TokenTypeExclamation,
TokenTypeLt,
TokenTypeGt,
} TokenType;
const char* token_type_to_string(TokenType type);
typedef struct {
size_t index;
int line, column;
} Position;
typedef struct {
TokenType type;
Position position;
size_t length;
} Token;
char* token_string(const Token* token, const char* text);
char* token_to_string(const Token* token, const char* text);
typedef struct {
const char* text;
size_t index, length;
int line, column;
} Lexer;
void lexer_create(Lexer* lexer, const char* text, size_t text_length);
Token lexer_next(Lexer* lexer);
char* lexer_token_string(const Lexer* lexer, const Token* token);
#endif