diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2023-04-26 00:40:44 +0200 |
---|---|---|
committer | Carlos Maniero <carlosmaniero@gmail.com> | 2023-04-25 23:19:13 -0300 |
commit | 127dae1c3b48c3a4dceddb9000309bfeaa8d0a01 (patch) | |
tree | 4d92b3a7b4c29f0ace3a5ff699e4789f60b0aa46 /src/lexer.h | |
parent | c1a1bd2320b4c1508c4ab20d23b7c193a94d8026 (diff) |
style: Use clang-format as formatter and linter tool
We want to keep the code style consistent, this first commit adds a
.clang-format in order to "document" our style code.
This patch also adds a target *linter* to Makefile which will complain
if we have any style issue on test and src dirs.
I have run the follow command to create the .clang-format file:
$ clang-format -style=mozilla -dump-config > .clang-format
And I also made some adjusts to .clang-format changing the following
properties:
PointerAlignment: Right
ColumnLimit: 120
Commands executed to fix the current styling:
$ find . -name *.h | xargs clang-format -i
$ find . -name *.c | xargs clang-format -i
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/lexer.h')
-rw-r--r-- | src/lexer.h | 116 |
1 files changed, 63 insertions, 53 deletions
diff --git a/src/lexer.h b/src/lexer.h index 9f45910..8c84745 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1,77 +1,87 @@ /* -* 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/>. -*/ + * 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 "string_view.h" +#include <stdbool.h> #include <stdint.h> #include <stdlib.h> -#include <stdbool.h> -#include "string_view.h" -typedef enum { - TOKEN_NAME, - TOKEN_OPAREN, - TOKEN_CPAREN, - TOKEN_COLON, - TOKEN_SEMICOLON, - TOKEN_OCURLY, - TOKEN_CCURLY, - TOKEN_NUMBER, - TOKEN_OP, - TOKEN_EOF, - TOKEN_UNKNOWN +typedef enum +{ + TOKEN_NAME, + TOKEN_OPAREN, + TOKEN_CPAREN, + TOKEN_COLON, + TOKEN_SEMICOLON, + TOKEN_OCURLY, + TOKEN_CCURLY, + TOKEN_NUMBER, + TOKEN_OP, + TOKEN_EOF, + TOKEN_UNKNOWN } token_kind_t; -typedef struct token_t { - token_kind_t kind; +typedef struct token_t +{ + token_kind_t kind; string_view_t value; - char *filepath; - uint32_t row; - uint32_t col; - uint32_t bol; + char *filepath; + uint32_t row; + uint32_t col; + uint32_t bol; } token_t; - -typedef struct lexer_t { - char *filepath; - char *src; - size_t srclen; - uint32_t cur; - uint32_t row; - uint32_t bol; +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_init(lexer_t *lexer, char *filepath); -void lexer_next_token(lexer_t *lexer, token_t *token); +void +lexer_next_token(lexer_t *lexer, token_t *token); -void lexer_load_file_contents(lexer_t *lexer); +void +lexer_load_file_contents(lexer_t *lexer); -char lexer_current_char(lexer_t *lexer); +char +lexer_current_char(lexer_t *lexer); -bool lexer_is_eof(lexer_t *lexer); +bool +lexer_is_eof(lexer_t *lexer); -bool lexer_is_not_eof(lexer_t *lexer); +bool +lexer_is_not_eof(lexer_t *lexer); -void lexer_drop_char(lexer_t *lexer); +void +lexer_drop_char(lexer_t *lexer); -void lexer_step_back_to(lexer_t *lexer, token_t *token); +void +lexer_step_back_to(lexer_t *lexer, token_t *token); -char * token_kind_to_str(token_kind_t kind); +char * +token_kind_to_str(token_kind_t kind); #endif /* LEXER_H */ - |