Updated scanner to be a bit more normed, didn't yet do the big ass functions
This commit is contained in:
parent
7e1e51e90b
commit
00546417ff
6 changed files with 108 additions and 94 deletions
|
|
@ -6,42 +6,44 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/09/01 19:33:04 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/09/01 19:55:50 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/09/01 20:02:49 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "me/char/char.h"
|
||||
#include "me/str/str.h"
|
||||
#include "me/types.h"
|
||||
#include "me/vec/vec_heredoc.h"
|
||||
#include "parser/inner/heredoc.h"
|
||||
#include "parser/inner/scanner.h"
|
||||
#include "parser/parser.h"
|
||||
|
||||
bool scan_heredoc_start(t_heredoc *heredoc, TSLexer *lexer)
|
||||
bool scan_heredoc_start(t_heredoc *heredoc, TSLexer *lexer)
|
||||
{
|
||||
bool found_delimiter;
|
||||
bool found_delimiter;
|
||||
|
||||
while (me_isspace(lexer->lookahead))
|
||||
lexer->advance(lexer, true);
|
||||
lexer->result_symbol = HEREDOC_START;
|
||||
heredoc->is_raw = lexer->lookahead == '\'' || lexer->lookahead == '"' || lexer->lookahead == '\\';
|
||||
heredoc->is_raw = lexer->lookahead == '\'' || lexer->lookahead == '"'
|
||||
|| lexer->lookahead == '\\';
|
||||
found_delimiter = advance_word(lexer, &heredoc->delimiter);
|
||||
if (!found_delimiter)
|
||||
return (string_clear(&heredoc->delimiter), false);
|
||||
return (found_delimiter);
|
||||
}
|
||||
|
||||
bool scan_heredoc_end_identifier(t_heredoc *heredoc, TSLexer *lexer)
|
||||
bool scan_heredoc_end_identifier(t_heredoc *heredoc, TSLexer *lexer)
|
||||
{
|
||||
t_i32 size;
|
||||
t_i32 size;
|
||||
|
||||
size = 0;
|
||||
string_clear(&heredoc->current_leading_word);
|
||||
if (heredoc->delimiter.len > 0)
|
||||
{
|
||||
while (lexer->lookahead != '\0' && lexer->lookahead != '\n' && (t_i32)heredoc->delimiter.buf[size] == lexer->lookahead &&
|
||||
heredoc->current_leading_word.len < heredoc->delimiter.len)
|
||||
while (lexer->lookahead != '\0' && lexer->lookahead != '\n'
|
||||
&& (t_i32)heredoc->delimiter.buf[size] == lexer->lookahead
|
||||
&& heredoc->current_leading_word.len < heredoc->delimiter.len)
|
||||
{
|
||||
string_push_char(&heredoc->current_leading_word, lexer->lookahead);
|
||||
lexer->advance(lexer, false);
|
||||
|
|
@ -50,28 +52,26 @@ bool scan_heredoc_end_identifier(t_heredoc *heredoc, TSLexer *lexer)
|
|||
}
|
||||
if (heredoc->delimiter.len == 0)
|
||||
return (false);
|
||||
return (str_compare(heredoc->current_leading_word.buf, heredoc->delimiter.buf));
|
||||
return (str_compare(heredoc->current_leading_word.buf,
|
||||
heredoc->delimiter.buf));
|
||||
}
|
||||
|
||||
bool scan_heredoc_content_nullbyte(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_backslash(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_dollar(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_newline(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_other(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_nullbyte(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_backslash(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_dollar(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_newline(struct s_heredoc_scan_state *state);
|
||||
bool scan_heredoc_content_other(struct s_heredoc_scan_state *state);
|
||||
|
||||
bool scan_heredoc_content(t_scanner *scanner, TSLexer *lexer, enum e_token_type middle_type, enum e_token_type end_type)
|
||||
bool scan_heredoc_content(t_scanner *scanner, TSLexer *lexer,
|
||||
enum e_token_type middle_type, enum e_token_type end_type)
|
||||
{
|
||||
struct s_heredoc_scan_state state;
|
||||
bool (*func)(struct s_heredoc_scan_state *state);
|
||||
|
||||
state.did_advance = false;
|
||||
state.lexer = lexer;
|
||||
state.heredoc = vec_heredoc_last(&scanner->heredocs);
|
||||
state.scanner = scanner;
|
||||
state.middle_type = middle_type;
|
||||
state.end_type = end_type;
|
||||
state.return_value = false;
|
||||
struct s_heredoc_scan_state state;
|
||||
t_heredoc_content_func func;
|
||||
|
||||
state = (struct s_heredoc_scan_state){.did_advance = false, \
|
||||
.lexer = lexer, .heredoc = vec_heredoc_last(&scanner->heredocs), \
|
||||
.scanner = scanner, .middle_type = middle_type, .end_type = end_type, \
|
||||
.return_value = false};
|
||||
while (true)
|
||||
{
|
||||
if (lexer->lookahead == '\0')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue