protobuf-c-text
Library to generate & parse text format protobufs in C.
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups
Data Structures | Macros | Enumerations | Functions | Variables
parse.re File Reference

Routines to parse text format protobufs. More...

Go to the source code of this file.

Data Structures

struct  Token
 A token and its value. More...
 
struct  Scanner
 Maintains state for successive calls to scan() . More...
 
struct  State
 Maintain state for the FSM. More...
 

Macros

#define CHUNK   4096
 Amount of data to read from a file each time. More...
 
#define RETURN(tt)   { t.id = tt; return t; }
 Return the token. More...
 
#define YYFILL(n)
 Retrieves more input if available. More...
 
#define STATE_ERROR_STR_MAX   160
 Max size of an error message. More...
 

Enumerations

enum  TokenId {
  TOK_EOF, TOK_BAREWORD, TOK_OBRACE, TOK_CBRACE,
  TOK_COLON, TOK_QUOTED, TOK_NUMBER, TOK_BOOLEAN,
  TOK_MALLOC_ERR
}
 Token types. More...
 
enum  StateId { STATE_OPEN, STATE_ASSIGNMENT, STATE_VALUE, STATE_DONE }
 StateId enumeration. More...
 

Functions

static void * local_realloc (void *ptr, size_t old_size, size_t size, ProtobufCAllocator *allocator)
 A realloc implementation using ProtobufCAllocator functions. More...
 
static const char * token2txt (Token *t)
 Converts a Token to a string based on its type. More...
 
static void token_free (Token *t, ProtobufCAllocator *allocator)
 Frees memory allocated in a Token instance. More...
 
static void scanner_init_file (Scanner *scanner, FILE *f)
 Initialise a Scanner from a FILE. More...
 
static void scanner_init_string (Scanner *scanner, char *buf)
 Initialise a Scanner from a string. More...
 
static void scanner_free (Scanner *scanner, ProtobufCAllocator *allocator)
 Free data internal to the Scanner instance. More...
 
static ProtobufCBinaryData * unesc_str (unsigned char *src, int len, ProtobufCAllocator *allocator)
 Unescape string. More...
 
static int fill (Scanner *scanner, ProtobufCAllocator *allocator)
 Function to request more data from input source in Scanner. More...
 
static Token scan (Scanner *scanner, ProtobufCAllocator *allocator)
 Generated lexer. More...
 
static int state_init (State *state, Scanner *scanner, const ProtobufCMessageDescriptor *descriptor, ProtobufCAllocator *allocator)
 Initialise a State struct. More...
 
static void state_free (State *state)
 Free internal data in a State struct. More...
 
static StateId state_error (State *state, Token *t, char *error_fmt,...) __attribute__((format(printf
 Handle an error in the FSM. More...
 
static StateId state_open (State *state, Token *t)
 Expect an element name (bareword) or a closing brace. More...
 
static StateId state_assignment (State *state, Token *t)
 Expect a colon or opening brace. More...
 
static StateId state_value (State *state, Token *t)
 Expect a quoted string, enum (bareword) or boolean. More...
 
static ProtobufCMessage * protobuf_c_text_parse (const ProtobufCMessageDescriptor *descriptor, Scanner *scanner, ProtobufCTextError *result, ProtobufCAllocator *allocator)
 Base function for the API functions. More...
 
ProtobufCMessage * protobuf_c_text_from_file (const ProtobufCMessageDescriptor *descriptor, FILE *msg_file, ProtobufCTextError *result, ProtobufCAllocator *allocator)
 Import a text format protobuf from a FILE into a ProtobufCMessage. More...
 
ProtobufCMessage * protobuf_c_text_from_string (const ProtobufCMessageDescriptor *descriptor, char *msg, ProtobufCTextError *result, ProtobufCAllocator *allocator)
 Import a text format protobuf from a string into a ProtobufCMessage. More...
 

Variables

static StateId(* states [])(State *, Token *)
 Table of states and actions. More...
 

Detailed Description

Routines to parse text format protobufs.

This file contains the internal support functions as well as the exported functions which are used to parse text format protobufs into C protobuf data types.

Note that this file must first be pre-processed with re2c. The build system does this for you, but the manual step is as follows:

re2c -s -o protobuf-c-text/parse.c protobuf-c-text/parse.re
Author
Kevin Lyda kevin.nosp@m.@ie..nosp@m.suber.nosp@m.ic.n.nosp@m.et
Date
March 2014

Definition in file parse.re.