diff --git a/src/allocator.c b/src/allocator.c index 77f14ea..49794e4 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 #include #include diff --git a/src/allocator.h b/src/allocator.h index 3bc7ced..ddeb7ed 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 diff --git a/src/bitreader.c b/src/bitreader.c index d3553f0..43038df 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 #include #include "internal.h" diff --git a/src/hammer.c b/src/hammer.c index 09358d4..0e48b85 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; ilen; ++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 8986d3e..a353641 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 decd721..8a756c4 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 diff --git a/src/pprint.c b/src/pprint.c index cf39c0e..6832b30 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 #include @@ -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 9d0d9a2..016274c 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 47c5ac4..ea57ae9 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