enum sexp_mode mode;
enum sexp_token expected;
+#if 0
struct sexp_compound_token token;
-
+#endif
/* Nesting level of lists. Transport encoding counts as one
* level of nesting. */
unsigned level;
parser->mode = mode;
parser->expected = 0;
+#if 0
sexp_compound_token_init(&parser->token);
+#endif
+
/* Start counting with 1 for the top level, to make comparisons
* between transport and level simpler.
*
/* Get next token, and check that it is of the expected kind. */
static void
sexp_check_token(struct sexp_parser *parser,
- enum sexp_token token)
+ enum sexp_token token,
+ struct nettle_buffer *string)
{
sexp_get_token(parser->input,
parser->transport ? SEXP_CANONICAL : parser->mode,
- &parser->token.string);
+ string);
if (token && parser->input->token != token)
die("Syntax error.\n");
* expression. We check at the end of strings and list whether or not
* we should expect a SEXP_CODING_END as the next token. */
static void
-sexp_parse(struct sexp_parser *parser)
+sexp_parse(struct sexp_parser *parser,
+ struct sexp_compound_token *token)
{
for (;;)
{
- sexp_check_token(parser, parser->expected);
+ sexp_get_token(parser->input,
+ parser->transport ? SEXP_CANONICAL : parser->mode,
+ &token->string);
+#if 0
+ sexp_check_token(parser, parser->expected,
+ &token->string);
if (parser->expected)
{
parser->expected = 0;
if (parser->input->token == SEXP_STRING)
- /* Nothing special */
+ /* XXX */
+ token->type = SEXP_DISPLAY
;
else
{
continue;
}
}
-
+#endif
switch(parser->input->token)
{
case SEXP_LIST_END:
if (!parser->level)
die("Unmatched end of list.\n");
-
+
+ token->type = SEXP_LIST_END;
+
+ check_transport_end:
if (parser->level == parser->transport)
- parser->expected = SEXP_CODING_END;
+ {
+ sexp_check_token(parser, SEXP_CODING_END, &token->string);
+ assert(parser->transport);
+ assert(parser->level == parser->transport);
+
+ parser->level--;
+ parser->transport = 0;
+ }
return;
case SEXP_EOF:
if (parser->level > 1)
die("Unexpected end of file.\n");
+
+ token->type = SEXP_EOF;
return;
case SEXP_LIST_START:
parser->level++;
+ token->type = SEXP_LIST_START;
return;
case SEXP_DISPLAY_START:
- sexp_check_token(parser, SEXP_STRING);
- sexp_check_token(parser, SEXP_DISPLAY_END);
- parser->input->token = SEXP_DISPLAY;
- parser->expected = SEXP_STRING;
- return;
+ sexp_check_token(parser, SEXP_STRING, &token->display);
+ sexp_check_token(parser, SEXP_DISPLAY_END, &token->display);
+ sexp_check_token(parser, SEXP_STRING, &token->string);
+
+ token->type = SEXP_DISPLAY;
+ goto check_transport_end;
case SEXP_STRING:
- if (parser->level == parser->transport)
- parser->expected = SEXP_CODING_END;
- return;
+ token->type = SEXP_STRING;
+ goto check_transport_end;
case SEXP_TRANSPORT_START:
if (parser->mode == SEXP_CANONICAL)
static void
-sexp_convert_list(struct sexp_input *input, struct sexp_parser *parser,
+sexp_convert_list(struct sexp_parser *parser,
+ struct sexp_compound_token *token,
struct sexp_output *output, enum sexp_mode mode_out,
unsigned indent);
* expression, to be converted, and return with input->token being the
* last token of the expression. */
static void
-sexp_convert_item(struct sexp_input *input, struct sexp_parser *parser,
+sexp_convert_item(struct sexp_parser *parser,
+ struct sexp_compound_token *token,
struct sexp_output *output, enum sexp_mode mode_out,
unsigned indent)
{
{
sexp_put_char(output, '{');
sexp_put_code_start(output, &nettle_base64);
- sexp_convert_item(input, parser, output, SEXP_CANONICAL, 0);
+ sexp_convert_item(parser, token, output, SEXP_CANONICAL, 0);
sexp_put_code_end(output);
sexp_put_char(output, '}');
}
- else switch(input->token)
+ else switch(token->type)
{
case SEXP_LIST_END:
die("Unmatched end of list.\n");
die("Unexpected end of coding.\n");
case SEXP_LIST_START:
- sexp_convert_list(input, parser, output, mode_out, indent);
+ sexp_convert_list(parser, token, output, mode_out, indent);
break;
case SEXP_STRING:
- sexp_put_string(output, mode_out, &parser->token.string);
+ sexp_put_string(output, mode_out, &token->string);
break;
case SEXP_DISPLAY:
sexp_put_char(output, '[');
- sexp_put_string(output, mode_out, &parser->token.string);
+ sexp_put_string(output, mode_out, &token->display);
sexp_put_char(output, ']');
- sexp_parse(parser);
- assert(input->token == SEXP_STRING);
- sexp_put_string(output, mode_out, &parser->token.string);
+ sexp_put_string(output, mode_out, &token->string);
break;
default:
}
static void
-sexp_convert_list(struct sexp_input *input, struct sexp_parser *parser,
+sexp_convert_list(struct sexp_parser *parser,
+ struct sexp_compound_token *token,
struct sexp_output *output, enum sexp_mode mode_out,
unsigned indent)
{
for (item = 0;; item++)
{
- sexp_parse(parser);
+ sexp_parse(parser, token);
- if (input->token == SEXP_LIST_END)
+ if (token->type == SEXP_LIST_END)
{
sexp_put_char(output, ')');
return;
sexp_put_newline(output, indent);
}
- sexp_convert_item(input, parser, output, mode_out, indent);
+ sexp_convert_item(parser, token, output, mode_out, indent);
}
}
struct conv_options options;
struct sexp_input input;
struct sexp_parser parser;
+ struct sexp_compound_token token;
struct sexp_output output;
parse_options(&options, argc, argv);
sexp_input_init(&input, stdin);
sexp_parse_init(&parser, &input, SEXP_ADVANCED);
+ sexp_compound_token_init(&token);
sexp_output_init(&output, stdout,
options.width, options.prefer_hex);
sexp_get_char(&input);
- sexp_parse(&parser);
+ sexp_parse(&parser, &token);
- if (input.token == SEXP_EOF)
+ if (token.type == SEXP_EOF)
{
if (options.once)
die("sexp-conv: No input expression.\n");
do
{
- sexp_convert_item(&input, &parser, &output, options.mode, 0);
+ sexp_convert_item(&parser, &token, &output, options.mode, 0);
if (options.hash)
sexp_put_digest(&output);
else if (options.mode != SEXP_CANONICAL)
sexp_put_newline(&output, 0);
- sexp_parse(&parser);
+ sexp_parse(&parser, &token);
}
- while (!options.once && input.token != SEXP_EOF);
+ while (!options.once && token.type != SEXP_EOF);
if (fflush(output.f) < 0)
die("Final fflush failed: %s.\n", strerror(errno));