Skip to content

Commit 5ab0931

Browse files
committed
1 parent a089f07 commit 5ab0931

38 files changed

+5815
-1206
lines changed

src/main/c/yarp/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ FUZZ_OUTPUT_DIR = $(shell pwd)/fuzz/output
1010

1111
SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
1212

13-
CPPFLAGS := -Iinclude
13+
CPPFLAGS := -Iinclude $(CPPFLAGS)
1414
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
1515
CC := cc
1616
WASI_SDK_PATH := /opt/wasi-sdk
@@ -94,6 +94,9 @@ all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
9494
all-no-debug: OPTFLAGS := -O3
9595
all-no-debug: all
9696

97+
minimal: CFLAGS := $(CFLAGS) -DPRISM_BUILD_MINIMAL
98+
minimal: all
99+
97100
run: Makefile $(STATIC_OBJECTS) $(HEADERS) test.c
98101
$(ECHO) "compiling test.c"
99102
$(Q) $(CC) $(CPPFLAGS) $(CFLAGS) $(STATIC_OBJECTS) test.c

src/main/c/yarp/include/prism.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,41 @@ PRISM_EXPORTED_FUNCTION void pm_parser_free(pm_parser_t *parser);
7979
*/
8080
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse(pm_parser_t *parser);
8181

82+
/**
83+
* This function is used in pm_parse_stream to retrieve a line of input from a
84+
* stream. It closely mirrors that of fgets so that fgets can be used as the
85+
* default implementation.
86+
*/
87+
typedef char * (pm_parse_stream_fgets_t)(char *string, int size, void *stream);
88+
89+
/**
90+
* Parse a stream of Ruby source and return the tree.
91+
*
92+
* @param parser The parser to use.
93+
* @param buffer The buffer to use.
94+
* @param stream The stream to parse.
95+
* @param fgets The function to use to read from the stream.
96+
* @param options The optional options to use when parsing.
97+
* @return The AST representing the source.
98+
*/
99+
PRISM_EXPORTED_FUNCTION pm_node_t * pm_parse_stream(pm_parser_t *parser, pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *fgets, const pm_options_t *options);
100+
101+
// We optionally support serializing to a binary string. For systems that don't
102+
// want or need this functionality, it can be turned off with the
103+
// PRISM_EXCLUDE_SERIALIZATION define.
104+
#ifndef PRISM_EXCLUDE_SERIALIZATION
105+
106+
/**
107+
* Parse and serialize the AST represented by the source that is read out of the
108+
* given stream into to the given buffer.
109+
*
110+
* @param buffer The buffer to serialize to.
111+
* @param stream The stream to parse.
112+
* @param fgets The function to use to read from the stream.
113+
* @param data The optional data to pass to the parser.
114+
*/
115+
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_stream(pm_buffer_t *buffer, void *stream, pm_parse_stream_fgets_t *fgets, const char *data);
116+
82117
/**
83118
* Serialize the given list of comments to the given buffer.
84119
*
@@ -155,6 +190,8 @@ PRISM_EXPORTED_FUNCTION void pm_serialize_lex(pm_buffer_t *buffer, const uint8_t
155190
*/
156191
PRISM_EXPORTED_FUNCTION void pm_serialize_parse_lex(pm_buffer_t *buffer, const uint8_t *source, size_t size, const char *data);
157192

193+
#endif
194+
158195
/**
159196
* Parse the source and return true if it parses without errors or warnings.
160197
*
@@ -190,6 +227,10 @@ const char * pm_token_type_human(pm_token_type_t token_type);
190227
*/
191228
PRISM_EXPORTED_FUNCTION void pm_parser_errors_format(const pm_parser_t *parser, pm_buffer_t *buffer, bool colorize);
192229

230+
// We optionally support dumping to JSON. For systems that don't want or need
231+
// this functionality, it can be turned off with the PRISM_EXCLUDE_JSON define.
232+
#ifndef PRISM_EXCLUDE_JSON
233+
193234
/**
194235
* Dump JSON to the given buffer.
195236
*
@@ -199,6 +240,8 @@ PRISM_EXPORTED_FUNCTION void pm_parser_errors_format(const pm_parser_t *parser,
199240
*/
200241
PRISM_EXPORTED_FUNCTION void pm_dump_json(pm_buffer_t *buffer, const pm_parser_t *parser, const pm_node_t *node);
201242

243+
#endif
244+
202245
/**
203246
* @mainpage
204247
*

0 commit comments

Comments
 (0)