mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 17:58:18 +00:00
ex_getln: Make use of new parser to color expressions
Retires g:Nvim_color_expr callback.
This commit is contained in:
13
src/nvim/viml/parser/parser.c
Normal file
13
src/nvim/viml/parser/parser.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "nvim/viml/parser/parser.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "viml/parser/parser.c.generated.h"
|
||||
#endif
|
||||
|
||||
|
||||
void parser_simple_get_line(void *cookie, ParserLine *ret_pline)
|
||||
{
|
||||
ParserLine **plines_p = (ParserLine **)cookie;
|
||||
*ret_pline = **plines_p;
|
||||
(*plines_p)++;
|
||||
}
|
@@ -8,6 +8,7 @@
|
||||
#include "nvim/lib/kvec.h"
|
||||
#include "nvim/func_attr.h"
|
||||
#include "nvim/mbyte.h"
|
||||
#include "nvim/memory.h"
|
||||
|
||||
/// One parsed line
|
||||
typedef struct {
|
||||
@@ -80,6 +81,56 @@ typedef struct {
|
||||
bool can_continuate;
|
||||
} ParserState;
|
||||
|
||||
static inline void viml_parser_init(
|
||||
ParserState *const ret_pstate,
|
||||
const ParserLineGetter get_line, void *const cookie,
|
||||
ParserHighlight *const colors)
|
||||
REAL_FATTR_ALWAYS_INLINE REAL_FATTR_NONNULL_ARG(1, 2);
|
||||
|
||||
/// Initialize a new parser state instance
|
||||
///
|
||||
/// @param[out] ret_pstate Parser state to initialize.
|
||||
/// @param[in] get_line Line getter function.
|
||||
/// @param[in] cookie Argument for the get_line function.
|
||||
/// @param[in] colors Where to save highlighting. May be NULL if it is not
|
||||
/// needed.
|
||||
static inline void viml_parser_init(
|
||||
ParserState *const ret_pstate,
|
||||
const ParserLineGetter get_line, void *const cookie,
|
||||
ParserHighlight *const colors)
|
||||
{
|
||||
*ret_pstate = (ParserState) {
|
||||
.reader = {
|
||||
.get_line = get_line,
|
||||
.cookie = cookie,
|
||||
.conv = MBYTE_NONE_CONV,
|
||||
},
|
||||
.pos = { 0, 0 },
|
||||
.colors = colors,
|
||||
.can_continuate = false,
|
||||
};
|
||||
kvi_init(ret_pstate->reader.lines);
|
||||
kvi_init(ret_pstate->stack);
|
||||
}
|
||||
|
||||
static inline void viml_parser_destroy(ParserState *const pstate)
|
||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_ALWAYS_INLINE;
|
||||
|
||||
/// Free all memory allocated by the parser on heap
|
||||
///
|
||||
/// @param pstate Parser state to free.
|
||||
static inline void viml_parser_destroy(ParserState *const pstate)
|
||||
{
|
||||
for (size_t i = 0; i < kv_size(pstate->reader.lines); i++) {
|
||||
ParserLine pline = kv_A(pstate->reader.lines, i);
|
||||
if (pline.allocated) {
|
||||
xfree((void *)pline.data);
|
||||
}
|
||||
}
|
||||
kvi_destroy(pstate->reader.lines);
|
||||
kvi_destroy(pstate->stack);
|
||||
}
|
||||
|
||||
static inline void viml_preader_get_line(ParserInputReader *const preader,
|
||||
ParserLine *const ret_pline)
|
||||
REAL_FATTR_NONNULL_ALL;
|
||||
@@ -186,4 +237,8 @@ static inline void viml_parser_highlight(ParserState *const pstate,
|
||||
}));
|
||||
}
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "viml/parser/parser.h.generated.h"
|
||||
#endif
|
||||
|
||||
#endif // NVIM_VIML_PARSER_PARSER_H
|
||||
|
Reference in New Issue
Block a user