Renamed all the public functions

This commit is contained in:
Dan Hirsch 2012-05-26 14:06:52 +02:00
parent d7ba53b3b1
commit 0284c99f12
9 changed files with 237 additions and 227 deletions

View file

@ -19,6 +19,7 @@
#define HAMMER_HAMMER__H
#include <glib.h>
#include <stdint.h>
#include <stdio.h>
#include "allocator.h"
#define BYTE_BIG_ENDIAN 0x1
@ -106,14 +107,14 @@ typedef struct HParser_ {
* Top-level function to call a parser that has been built over some
* piece of input (of known size).
*/
HParseResult* parse(const HParser* parser, const uint8_t* input, size_t length);
HParseResult* h_parse(const HParser* parser, const uint8_t* input, size_t length);
/**
* Given a string, returns a parser that parses that string value.
*
* Result token type: TT_BYTES
*/
const HParser* token(const uint8_t *str, const size_t len);
const HParser* h_token(const uint8_t *str, const size_t len);
/**
* Given a single character, returns a parser that parses that
@ -121,7 +122,7 @@ const HParser* token(const uint8_t *str, const size_t len);
*
* Result token type: TT_UINT
*/
const HParser* ch(const uint8_t c);
const HParser* h_ch(const uint8_t c);
/**
* Given two single-character bounds, lower and upper, returns a parser
@ -130,14 +131,14 @@ const HParser* ch(const uint8_t c);
*
* Result token type: TT_UINT
*/
const HParser* ch_range(const uint8_t lower, const uint8_t upper);
const HParser* h_ch_range(const uint8_t lower, const uint8_t upper);
/**
* Given an integer parser, p, and two integer bounds, lower and upper,
* returns a parser that parses an integral value within the range
* [lower, upper] (inclusive).
*/
const HParser* int_range(const HParser *p, const int64_t lower, const int64_t upper);
const HParser* h_int_range(const HParser *p, const int64_t lower, const int64_t upper);
/**
* Returns a parser that parses the specified number of bits. sign ==
@ -145,63 +146,63 @@ const HParser* int_range(const HParser *p, const int64_t lower, const int64_t up
*
* Result token type: TT_SINT if sign == true, TT_UINT if sign == false
*/
const HParser* bits(size_t len, bool sign);
const HParser* h_bits(size_t len, bool sign);
/**
* Returns a parser that parses a signed 8-byte integer value.
*
* Result token type: TT_SINT
*/
const HParser* int64();
const HParser* h_int64();
/**
* Returns a parser that parses a signed 4-byte integer value.
*
* Result token type: TT_SINT
*/
const HParser* int32();
const HParser* h_int32();
/**
* Returns a parser that parses a signed 2-byte integer value.
*
* Result token type: TT_SINT
*/
const HParser* int16();
const HParser* h_int16();
/**
* Returns a parser that parses a signed 1-byte integer value.
*
* Result token type: TT_SINT
*/
const HParser* int8();
const HParser* h_int8();
/**
* Returns a parser that parses an unsigned 8-byte integer value.
*
* Result token type: TT_UINT
*/
const HParser* uint64();
const HParser* h_uint64();
/**
* Returns a parser that parses an unsigned 4-byte integer value.
*
* Result token type: TT_UINT
*/
const HParser* uint32();
const HParser* h_uint32();
/**
* Returns a parser that parses an unsigned 2-byte integer value.
*
* Result token type: TT_UINT
*/
const HParser* uint16();
const HParser* h_uint16();
/**
* Returns a parser that parses an unsigned 1-byte integer value.
*
* Result token type: TT_UINT
*/
const HParser* uint8();
const HParser* h_uint8();
/**
* Given another parser, p, returns a parser that skips any whitespace
@ -209,7 +210,7 @@ const HParser* uint8();
*
* Result token type: p's result type
*/
const HParser* whitespace(const HParser* p);
const HParser* h_whitespace(const HParser* p);
/**
* Given another parser, p, and a function f, returns a parser that
@ -217,14 +218,14 @@ const HParser* whitespace(const HParser* p);
*
* Result token type: any
*/
const HParser* action(const HParser* p, const HAction a);
const HParser* h_action(const HParser* p, const HAction a);
/**
* Parse a single character *NOT* in the given charset.
*
* Result token type: TT_UINT
*/
const HParser* not_in(const uint8_t *charset, int length);
const HParser* h_not_in(const uint8_t *charset, int length);
/**
* A no-argument parser that succeeds if there is no more input to
@ -232,14 +233,14 @@ const HParser* not_in(const uint8_t *charset, int length);
*
* Result token type: None. The HParseResult exists but its AST is NULL.
*/
const HParser* end_p();
const HParser* h_end_p();
/**
* This parser always fails.
*
* Result token type: NULL. Always.
*/
const HParser* nothing_p();
const HParser* h_nothing_p();
/**
* Given a null-terminated list of parsers, apply each parser in order.
@ -247,7 +248,7 @@ const HParser* nothing_p();
*
* Result token type: TT_SEQUENCE
*/
const HParser* sequence(const HParser* p, ...) __attribute__((sentinel));
const HParser* h_sequence(const HParser* p, ...) __attribute__((sentinel));
/**
* Given an array of parsers, p_array, apply each parser in order. The
@ -256,7 +257,7 @@ const HParser* sequence(const HParser* p, ...) __attribute__((sentinel));
*
* Result token type: The type of the first successful parser's result.
*/
const HParser* choice(const HParser* p, ...) __attribute__((sentinel));
const HParser* h_choice(const HParser* p, ...) __attribute__((sentinel));
/**
* Given two parsers, p1 and p2, this parser succeeds in the following
@ -266,7 +267,7 @@ const HParser* choice(const HParser* p, ...) __attribute__((sentinel));
*
* Result token type: p1's result type.
*/
const HParser* butnot(const HParser* p1, const HParser* p2);
const HParser* h_butnot(const HParser* p1, const HParser* p2);
/**
* Given two parsers, p1 and p2, this parser succeeds in the following
@ -276,7 +277,7 @@ const HParser* butnot(const HParser* p1, const HParser* p2);
*
* Result token type: p1's result type.
*/
const HParser* difference(const HParser* p1, const HParser* p2);
const HParser* h_difference(const HParser* p1, const HParser* p2);
/**
* Given two parsers, p1 and p2, this parser succeeds if *either* p1 or
@ -284,7 +285,7 @@ const HParser* difference(const HParser* p1, const HParser* p2);
*
* Result token type: The type of the result of whichever parser succeeded.
*/
const HParser* xor(const HParser* p1, const HParser* p2);
const HParser* h_xor(const HParser* p1, const HParser* p2);
/**
* Given a parser, p, this parser succeeds for zero or more repetitions
@ -292,7 +293,7 @@ const HParser* xor(const HParser* p1, const HParser* p2);
*
* Result token type: TT_SEQUENCE
*/
const HParser* many(const HParser* p);
const HParser* h_many(const HParser* p);
/**
* Given a parser, p, this parser succeeds for one or more repetitions
@ -300,7 +301,7 @@ const HParser* many(const HParser* p);
*
* Result token type: TT_SEQUENCE
*/
const HParser* many1(const HParser* p);
const HParser* h_many1(const HParser* p);
/**
* Given a parser, p, this parser succeeds for exactly N repetitions
@ -308,7 +309,7 @@ const HParser* many1(const HParser* p);
*
* Result token type: TT_SEQUENCE
*/
const HParser* repeat_n(const HParser* p, const size_t n);
const HParser* h_repeat_n(const HParser* p, const size_t n);
/**
* Given a parser, p, this parser succeeds with the value p parsed or
@ -316,7 +317,7 @@ const HParser* repeat_n(const HParser* p, const size_t n);
*
* Result token type: If p succeeded, the type of its result; if not, TT_NONE.
*/
const HParser* optional(const HParser* p);
const HParser* h_optional(const HParser* p);
/**
* Given a parser, p, this parser succeeds if p succeeds, but doesn't
@ -324,7 +325,7 @@ const HParser* optional(const HParser* p);
*
* Result token type: None. The HParseResult exists but its AST is NULL.
*/
const HParser* ignore(const HParser* p);
const HParser* h_ignore(const HParser* p);
/**
* Given a parser, p, and a parser for a separator, sep, this parser
@ -335,7 +336,7 @@ const HParser* ignore(const HParser* p);
*
* Result token type: TT_SEQUENCE
*/
const HParser* sepBy(const HParser* p, const HParser* sep);
const HParser* h_sepBy(const HParser* p, const HParser* sep);
/**
* Given a parser, p, and a parser for a separator, sep, this parser matches a list of things that p can parse, separated by sep. Unlike sepBy, this ensures that the result has at least one element.
@ -343,14 +344,14 @@ const HParser* sepBy(const HParser* p, const HParser* sep);
*
* Result token type: TT_SEQUENCE
*/
const HParser* sepBy1(const HParser* p, const HParser* sep);
const HParser* h_sepBy1(const HParser* p, const HParser* sep);
/**
* This parser always returns a zero length match, i.e., empty string.
*
* Result token type: None. The HParseResult exists but its AST is NULL.
*/
const HParser* epsilon_p();
const HParser* h_epsilon_p();
/**
* This parser applies its first argument to read an unsigned integer
@ -361,7 +362,7 @@ const HParser* epsilon_p();
*
* Result token type: TT_SEQUENCE
*/
const HParser* length_value(const HParser* length, const HParser* value);
const HParser* h_length_value(const HParser* length, const HParser* value);
/**
* This parser attaches a predicate function, which returns true or
@ -376,7 +377,7 @@ const HParser* length_value(const HParser* length, const HParser* value);
*
* Result token type: p's result type if pred succeeded, NULL otherwise.
*/
const HParser* attr_bool(const HParser* p, HPredicate pred);
const HParser* h_attr_bool(const HParser* p, HPredicate pred);
/**
* The 'and' parser asserts that a conditional syntax is satisfied,
@ -393,7 +394,7 @@ const HParser* attr_bool(const HParser* p, HPredicate pred);
*
* Result token type: None. The HParseResult exists but its AST is NULL.
*/
const HParser* and(const HParser* p);
const HParser* h_and(const HParser* p);
/**
* The 'not' parser asserts that a conditional syntax is *not*
@ -413,7 +414,7 @@ const HParser* and(const HParser* p);
*
* Result token type: None. The HParseResult exists but its AST is NULL.
*/
const HParser* not(const HParser* p);
const HParser* h_not(const HParser* p);
/**
* Create a parser that just calls out to another, as yet unknown,
@ -424,12 +425,24 @@ const HParser* not(const HParser* p);
* Result token type: the type of whatever parser is bound to it with
* bind_indirect().
*/
HParser *indirect();
HParser *h_indirect();
/**
* Set the inner parser of an indirect. See comments on indirect for
* details.
*/
void bind_indirect(HParser* indirect, HParser* inner);
void h_bind_indirect(HParser* indirect, HParser* inner);
// Some debugging aids
/**
* Format token into a compact unambiguous form. Useful for parser test cases.
* Caller is responsible for freeing the result.
*/
char* h_write_result_unamb(const HParsedToken* tok);
/**
* Format token to the given output stream. Indent starting at
* [indent] spaces, with [delta] spaces between levels.
*/
void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta);
#endif // #ifndef HAMMER_HAMMER__H