Cthulhu  0.2.10
Cthulhu compiler collection
Flex/Bison interop utils

Flex/Bison interop utils for easier integration. More...

Collaboration diagram for Flex/Bison interop utils:

Modules

 Helpers for flex and bison driver frontends
 

Data Structures

struct  scan_callbacks_t
 scanner function callbacks for flex and bison More...
 
struct  parse_result_t
 

Macros

#define CT_CALLBACKS(id, prefix)
 callback boilerplate macro More...
 

Enumerations

enum  parse_error_t {
  eParseOk , eParseInitError , eParseScanError , eParseReject ,
  eParseCount
}
 

Functions

CT_INTEROP_API parse_result_t scan_buffer (scan_t *scan, const scan_callbacks_t *callbacks)
 parse the contents of a scanner into a language specific ast More...
 

Detailed Description

Flex/Bison interop utils for easier integration.

Macro Definition Documentation

◆ CT_CALLBACKS

#define CT_CALLBACKS (   id,
  prefix 
)
Value:
static int prefix##_##id##_##init(scan_t *extra, void *scanner) \
{ \
return prefix##lex_init_extra(extra, (yyscan_t *)scanner); \
} \
static int prefix##_##id##_parse(void *scanner, scan_t *extra) \
{ \
return prefix##parse(scanner, (scan_t *)extra); \
} \
static void *prefix##_##id##_scan(const char *text, size_t size, void *scanner) \
{ \
CTASSERTF(size <= INT_MAX, #prefix "_scan (size = %zu > %d, name = %s)", size, INT_MAX, \
scan_path((scan_t *)scanner)); \
return prefix##_scan_bytes(text, (int)size, scanner); \
} \
static void prefix##_##id##_destroy_buffer(void *buffer, void *scanner) \
{ \
prefix##_delete_buffer((YY_BUFFER_STATE)buffer, scanner); \
} \
static void prefix##_##id##_destroy(void *scanner) \
{ \
prefix##lex_destroy(scanner); \
} \
static const scan_callbacks_t id = { \
.init = prefix##_##id##_##init, \
.parse = prefix##_##id##_parse, \
.scan = prefix##_##id##_scan, \
.destroy_buffer = prefix##_##id##_destroy_buffer, \
.destroy = prefix##_##id##_destroy, \
}
CT_NODISCARD CT_PUREFN CT_SCAN_API const char * scan_path(const scan_t *scan)
get the path of a scanner
Definition: scan.c:56
CT_NODISCARD size_t size
Definition: scan.h:128
scanner function callbacks for flex and bison
Definition: compile.h:26
int(* init)(scan_t *extra, void *scanner)
yylex_init_extra
Definition: compile.h:27
a source file scanner
Definition: scan.h:24

callback boilerplate macro

generate callback boilerplate for scan_buffer

Parameters
idthe name of the generated callback object
prefixthe prefix assigned to flex and bison functions

Definition at line 42 of file compile.h.

Enumeration Type Documentation

◆ parse_error_t

Enumerator
eParseOk 

parse was successful

eParseInitError 

error initializing the scanner internals (our fault)

eParseScanError 

entered invalid state during scanning (our fault)

eParseReject 

failed due to invalid input (users fault)

eParseCount 

Definition at line 73 of file compile.h.

Function Documentation

◆ scan_buffer()

CT_INTEROP_API parse_result_t scan_buffer ( scan_t scan,
const scan_callbacks_t callbacks 
)

parse the contents of a scanner into a language specific ast

Note
callbacks should be generated via CT_CALLBACKS
Parameters
scanthe sanner being used
callbacksthe flex/bison callbacks
Returns
the parse result

Definition at line 26 of file compile.c.