Update
This commit is contained in:
parent
9f37123e46
commit
efb18f605c
8 changed files with 158 additions and 248 deletions
35
parser/include/parser/external_scanner_state.h
Normal file
35
parser/include/parser/external_scanner_state.h
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* external_scanner_state.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/08/24 13:56:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/08/24 14:00:11 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef EXTERNAL_SCANNER_STATE_H
|
||||
#define EXTERNAL_SCANNER_STATE_H
|
||||
|
||||
#include "me/types.h"
|
||||
|
||||
struct ExternalScannerState
|
||||
{
|
||||
char *long_data;
|
||||
t_u32 length;
|
||||
};
|
||||
typedef struct ExternalScannerState ExternalScannerState;
|
||||
typedef struct SubtreeHeapData SubtreeHeapData;
|
||||
typedef const SubtreeHeapData *Subtree;
|
||||
|
||||
void ts_external_scanner_state_init(ExternalScannerState *self, const t_u8 *data, t_u32 length);
|
||||
ExternalScannerState ts_external_scanner_state_copy(const ExternalScannerState *self);
|
||||
void ts_external_scanner_state_delete(ExternalScannerState *self);
|
||||
const t_u8 *ts_external_scanner_state_data(const ExternalScannerState *self);
|
||||
bool ts_external_scanner_state_eq(const ExternalScannerState *self, const t_u8 *buffer, t_u32 length);
|
||||
const ExternalScannerState *ts_subtree_external_scanner_state(Subtree self);
|
||||
bool ts_subtree_external_scanner_state_eq(Subtree self, Subtree other);
|
||||
|
||||
#endif /* EXTERNAL_SCANNER_STATE_H */
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
#include "me/types.h"
|
||||
#include "parser/api.h"
|
||||
#include "parser/array.h"
|
||||
#include "parser/external_scanner_state.h"
|
||||
#include "parser/length.h"
|
||||
#include "parser/parser.h"
|
||||
#include <limits.h>
|
||||
|
|
@ -15,26 +16,6 @@
|
|||
#define TS_TREE_STATE_NONE USHRT_MAX
|
||||
#define NULL_SUBTREE ((Subtree)NULL)
|
||||
|
||||
struct ExternalScannerState
|
||||
{
|
||||
union {
|
||||
char *long_data;
|
||||
};
|
||||
t_u32 length;
|
||||
};
|
||||
|
||||
// The serialized state of an external scanner.
|
||||
//
|
||||
// Every time an external token subtree is created after a call to an
|
||||
// external scanner, the scanner's `serialize` function is called to
|
||||
// retrieve a serialized copy of its state. The bytes are then copied
|
||||
// onto the subtree itself so that the scanner's state can later be
|
||||
// restored using its `deserialize` function.
|
||||
//
|
||||
// Small byte arrays are stored inline, and long ones are allocated
|
||||
// separately on the heap.
|
||||
typedef struct ExternalScannerState ExternalScannerState;
|
||||
|
||||
// A heap-allocated representation of a subtree.
|
||||
//
|
||||
// This representation is used for parent nodes, external tokens,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue