161 lines
3.8 KiB
C
Raw Normal View History

2025-12-02 06:54:32 +01:00
#ifndef RAVA_LEXER_H
#define RAVA_LEXER_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
typedef enum {
RAVA_TOKEN_EOF,
RAVA_TOKEN_KEYWORD_ABSTRACT,
RAVA_TOKEN_KEYWORD_ASSERT,
RAVA_TOKEN_KEYWORD_BOOLEAN,
RAVA_TOKEN_KEYWORD_BREAK,
RAVA_TOKEN_KEYWORD_BYTE,
RAVA_TOKEN_KEYWORD_CASE,
RAVA_TOKEN_KEYWORD_CATCH,
RAVA_TOKEN_KEYWORD_CHAR,
RAVA_TOKEN_KEYWORD_CLASS,
RAVA_TOKEN_KEYWORD_CONST,
RAVA_TOKEN_KEYWORD_CONTINUE,
RAVA_TOKEN_KEYWORD_DEFAULT,
RAVA_TOKEN_KEYWORD_DO,
RAVA_TOKEN_KEYWORD_DOUBLE,
RAVA_TOKEN_KEYWORD_ELSE,
RAVA_TOKEN_KEYWORD_ENUM,
RAVA_TOKEN_KEYWORD_EXTENDS,
RAVA_TOKEN_KEYWORD_FINAL,
RAVA_TOKEN_KEYWORD_FINALLY,
RAVA_TOKEN_KEYWORD_FLOAT,
RAVA_TOKEN_KEYWORD_FOR,
RAVA_TOKEN_KEYWORD_GOTO,
RAVA_TOKEN_KEYWORD_IF,
RAVA_TOKEN_KEYWORD_IMPLEMENTS,
RAVA_TOKEN_KEYWORD_IMPORT,
RAVA_TOKEN_KEYWORD_INSTANCEOF,
RAVA_TOKEN_KEYWORD_INT,
RAVA_TOKEN_KEYWORD_INTERFACE,
RAVA_TOKEN_KEYWORD_LONG,
RAVA_TOKEN_KEYWORD_NATIVE,
RAVA_TOKEN_KEYWORD_NEW,
RAVA_TOKEN_KEYWORD_PACKAGE,
RAVA_TOKEN_KEYWORD_PRIVATE,
RAVA_TOKEN_KEYWORD_PROTECTED,
RAVA_TOKEN_KEYWORD_PUBLIC,
RAVA_TOKEN_KEYWORD_RETURN,
RAVA_T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EN_INC,
RAVA_TOKEN_DEC,
RAVA_TOKEN_PLUS,
RAVA_TOKEN_MINUS,
RAVA_TOKEN_STAR,
RAVA_TOKEN_SLASH,
RAVA_TOKEN_AMP,
RAVA_TOKEN_PIPE,
RAVA_TOKEN_CARET,
RAVA_TOKEN_PERCENT,
RAVA_TOKEN_LSHIFT,
RAVA_TOKEN_RSHIFT,
RAVA_TOKEN_URSHIFT,
RAVA_TOKEN_PLUSASSIGN,
RAVA_TOKEN_MINUSASSIGN,
RAVA_TOKEN_STARASSIGN,
RAVA_TOKEN_SLASHASSIGN,
RAVA_TOKEN_ANDASSIGN,
RAVA_TOKEN_ORASSIGN,
RAVA_TOKEN_CARETASSIGN,
RAVA_TOKEN_PERCENTASSIGN,
RAVA_TOKEN_LSHIFTASSIGN,
RAVA_TOKEN_RSHIFTASSIGN,
RAVA_TOKEN_URSHIFTASSIGN,
RAVA_TOKEN_ERROR
} RavaTokenType_e;
typedef union {
int64_t int_value;
double float_value;
char *string_value;
char char_value;
} RavaLiteralValue_u;
typedef struct {
RavaTokenType_e type;
char *lexeme;
int line;
int column;
RavaLiteralValue_u value;
} RavaToken_t;
typedef struct {
const char *source;
size_t source_length;
size_t current;
size_t start;
int line;
int column;
int start_column;
char *error_message;
} RavaLexer_t;
RavaLexer_t* rava_lexer_create(const char *source);
void rava_lexer_destroy(RavaLexer_t *lexer);
RavaToken_t* rava_lexer_next_token(RavaLexer_t *lexer);
void rava_token_destroy(RavaToken_t *token);
#endif