示例#1
0
文件: parser_test.c 项目: jbmikk/pars
static void _parse_parent_child_nonterminal(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_child_rule_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
示例#2
0
文件: parser_test.c 项目: jbmikk/pars
void _parser_basic_parse(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_simple_ab_fsm(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
示例#3
0
文件: parser_test.c 项目: jbmikk/pars
static void _parse_sibling_with_children_test(){

	ParserContext context;
	Ast ast;
	AstBuilder builder;

	_build_siblings_with_children(&fix.parser.fsm);

	ast_init(&ast, NULL, &fix.parser.table);

	ast_builder_init(&builder, &ast);
	ast_builder_append_follow(&builder, &(Token){1, 1, 'a'});
	ast_builder_append(&builder, &(Token){2, 1, 'b'});
	ast_builder_append(&builder, &(Token){3, 1, 'c'});
	ast_builder_parent(&builder);
	ast_builder_append_follow(&builder, &(Token){4, 1, 'd'});
	ast_builder_append(&builder, &(Token){5, 1, 'e'});
	ast_builder_append(&builder, &(Token){6, 1, 'f'});
	ast_builder_done(&builder);
	ast_builder_dispose(&builder);

	parser_context_init(&context, &fix.parser);

	parser_context_set_source_ast(&context, &ast);

	int error = parser_context_execute(&context);

	t_assert(!error);

	parser_context_dispose(&context);
	ast_dispose(&ast);
}
示例#4
0
void t_teardown(){
	ast_dispose(&fix.ast);
	symbol_table_dispose(&fix.table);
	input_dispose(&fix.input);
}