diff --git a/src/allocator.c b/src/allocator.c index 77f14ea347d7a8f6c0f7da11a517e7b78ff25dab..49794e4a82297cf702689c75267398b46f45234b 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -1,3 +1,20 @@ +/* Arena allocator for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include <glib.h> #include <stdint.h> #include <sys/types.h> diff --git a/src/allocator.h b/src/allocator.h index 3bc7cedc44739424dd9ad7a9f9f7db6b5b0d51ad..ddeb7ed47acb863f4ce3402ed634d78ae9838ac2 100644 --- a/src/allocator.h +++ b/src/allocator.h @@ -1,3 +1,20 @@ +/* Arena allocator for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #ifndef HAMMER_ALLOCATOR__H__ #define HAMMER_ALLOCATOR__H__ #include <sys/types.h> diff --git a/src/bitreader.c b/src/bitreader.c index d3553f0155d6d8db250f4839a4894e5a3b4670c9..43038dfc90677d81061d3a1b2f5de7f5a2b073e0 100644 --- a/src/bitreader.c +++ b/src/bitreader.c @@ -1,3 +1,20 @@ +/* Bit-parsing operations for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include <stdint.h> #include <stdio.h> #include "internal.h" diff --git a/src/hammer.c b/src/hammer.c index 09358d4e239589481691b008710ecff12edb493b..0e48b85cafd27a3d345dd62c064ac74f2f5f3980 100644 --- a/src/hammer.c +++ b/src/hammer.c @@ -72,6 +72,7 @@ parse_result_t* do_parse(const parser_t* parser, parse_state_t *state) { parse_result_t* make_result(parse_state_t *state, parsed_token_t *tok) { parse_result_t *ret = a_new(parse_result_t, 1); ret->ast = tok; + ret->arena = state->arena; return ret; } @@ -80,6 +81,23 @@ typedef struct { uint8_t len; } token_t; +static parse_result_t* parse_unimplemented(void* env, parse_state_t *state) { + (void) env; + (void) state; + static parsed_token_t token = { + .token_type = TT_ERR + }; + static parse_result_t result = { + .ast = &token + }; + return &result; +} + +static parser_t unimplemented = { + .fn = parse_unimplemented, + .env = NULL +}; + static parse_result_t* parse_token(void *env, parse_state_t *state) { token_t *t = (token_t*)env; for (int i=0; i<t->len; ++i) { @@ -144,7 +162,7 @@ const parser_t* whitespace(const parser_t* p) { return ret; } -const parser_t* action(const parser_t* p, const action_t a) { return NULL; } +const parser_t* action(const parser_t* p, const action_t a) { return &unimplemented; } static parse_result_t* parse_charset(void *env, parse_state_t *state) { uint8_t in = read_bits(&state->input_stream, 8, false); @@ -440,35 +458,16 @@ const parser_t* xor(const parser_t* p1, const parser_t* p2) { return ret; } -const parser_t* repeat0(const parser_t* p) { return NULL; } -const parser_t* repeat1(const parser_t* p) { return NULL; } -const parser_t* repeat_n(const parser_t* p, const size_t n) { return NULL; } - -static parse_result_t* parse_optional(void *env, parse_state_t *state) { - return NULL; -} - -const parser_t* optional(const parser_t* p) { - parser_t *ret = g_new(parser_t, 1); - ret->fn = parse_optional; ret->env = NULL; - return ret; -} - -static parse_result_t* parse_ignore(void *env, parse_state_t *state) { - return NULL; -} - -const parser_t* ignore(const parser_t* p) { - parser_t *ret = g_new(parser_t, 1); - ret->fn = parse_ignore; ret->env = NULL; - return ret; -} - -const parser_t* list(const parser_t* p, const parser_t* sep) { return NULL; } -const parser_t* epsilon_p() { return NULL; } -const parser_t* attr_bool(const parser_t* p, attr_bool_t a) { return NULL; } -const parser_t* and(const parser_t* p) { return NULL; } -const parser_t* not(const parser_t* p) { return NULL; } +const parser_t* repeat0(const parser_t* p) { return &unimplemented; } +const parser_t* repeat1(const parser_t* p) { return &unimplemented; } +const parser_t* repeat_n(const parser_t* p, const size_t n) { return &unimplemented; } +const parser_t* optional(const parser_t* p) { return &unimplemented; } +const parser_t* ignore(const parser_t* p) { return &unimplemented; } +const parser_t* list(const parser_t* p, const parser_t* sep) { return &unimplemented; } +const parser_t* epsilon_p() { return &unimplemented; } +const parser_t* attr_bool(const parser_t* p, attr_bool_t a) { return &unimplemented; } +const parser_t* and(const parser_t* p) { return &unimplemented; } +const parser_t* not(const parser_t* p) { return &unimplemented; } static guint cache_key_hash(gconstpointer key) { return djbhash(key, sizeof(parser_cache_key_t)); diff --git a/src/hammer.h b/src/hammer.h index 8986d3e39dde2c5471c4fbc4d0e7de3a6fdee99d..a3536414cd8737b40a19db132ed6d7bc7f10dab2 100644 --- a/src/hammer.h +++ b/src/hammer.h @@ -57,6 +57,7 @@ typedef enum token_type { TT_SINT, TT_UINT, TT_SEQUENCE, + TT_ERR, TT_MAX } token_type_t; @@ -80,6 +81,7 @@ typedef struct parsed_token { */ typedef struct parse_result { const parsed_token_t *ast; + arena_t arena; } parse_result_t; /* Type of an action to apply to an AST, used in the action() parser. */ diff --git a/src/internal.h b/src/internal.h index decd7215c4265207781984e4a7e8ac28e625a53e..8a756c432c3b93fbdef2b7f93dd28f2e23feb4b0 100644 --- a/src/internal.h +++ b/src/internal.h @@ -1,3 +1,20 @@ +/* Internals for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #ifndef HAMMER_INTERNAL__H #define HAMMER_INTERNAL__H #include <glib.h> diff --git a/src/pprint.c b/src/pprint.c index cf39c0e9a1f0adafa73c03b92d45907dd11f130f..6832b30af1f790b68ed5b6be3fa40ef2b9a5a726 100644 --- a/src/pprint.c +++ b/src/pprint.c @@ -1,3 +1,20 @@ +/* Pretty-printer for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #define _GNU_SOURCE #include <stdio.h> #include <glib.h> @@ -102,6 +119,9 @@ static void unamb_sub(const parsed_token_t* tok, struct result_buf *buf) { len = asprintf(&tmpbuf, "s%#lx", tok->uint); append_buf(buf, tmpbuf, len); break; + case TT_ERR: + append_buf(buf, "ERR", 3); + break; case TT_SEQUENCE: { GSequenceIter *it; int at_begin = 1; diff --git a/src/test_suite.c b/src/test_suite.c index 9d0d9a2d90072e9e3c18fc623fa95dc395c5289e..016274c0013424f2ecf36cfdc7c2ad7084d992bc 100644 --- a/src/test_suite.c +++ b/src/test_suite.c @@ -1,3 +1,20 @@ +/* Test suite for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include "hammer.h" #include "test_suite.h" diff --git a/src/test_suite.h b/src/test_suite.h index 47c5ac401f4a368b7ceba0642030d9f3aaaa0457..ea57ae97b035474ec0d0e31e8f7d31ee0dc50923 100644 --- a/src/test_suite.h +++ b/src/test_suite.h @@ -1,3 +1,20 @@ +/* Test suite for Hammer. + * Copyright (C) 2012 Meredith L. Patterson, Dan "TQ" Hirsch + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #ifndef HAMMER_TEST_SUITE__H #define HAMMER_TEST_SUITE__H