diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-14 21:04:18 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-14 21:04:18 +0200 |
commit | b4d3c6b5685024efc651e31e2308b0d76bbc3c06 (patch) | |
tree | 63fef1a04052cd185c07f2119593f0d3e23a3d4c /src/lexer.h | |
parent | e0f96e02d6277f92b24ea3afaa49d6c0a7a6731c (diff) |
lexer: Extract lexer.c and lexer.h from pipa.c
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/lexer.h')
-rw-r--r-- | src/lexer.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/lexer.h b/src/lexer.h new file mode 100644 index 0000000..29cfc11 --- /dev/null +++ b/src/lexer.h @@ -0,0 +1,68 @@ +/* +* Copyright (C) 2023 Johnny Richard +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ +#ifndef LEXER_H +#define LEXER_H + +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> + +typedef enum { + TOKEN_NAME, + TOKEN_OPAREN, + TOKEN_CPAREN, + TOKEN_COLON, + TOKEN_SEMICOLON, + TOKEN_OCURLY, + TOKEN_CCURLY, + TOKEN_NUMBER, + TOKEN_EOF +} token_kind_t; + +typedef struct token_t { + token_kind_t kind; + char *value; + uint32_t row; + uint32_t col; +} token_t; + + +typedef struct lexer_t { + char *filepath; + char *src; + size_t srclen; + uint32_t cur; + uint32_t row; + uint32_t bol; +} lexer_t; + +void lexer_init(lexer_t *lexer, char *filepath); + +void lexer_next_token(lexer_t *lexer, token_t *token); + +void lexer_load_file_contents(lexer_t *lexer); + +char lexer_current_char(lexer_t *lexer); + +bool lexer_is_eof(lexer_t *lexer); + +bool lexer_is_not_eof(lexer_t *lexer); + +void lexer_drop_char(lexer_t *lexer); + +#endif /* LEXER_H */ + |