Subversion Repositories spk

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
#include "bod_parser.h"
2
#include "bod_text_parser.h"
3
#include "token_stream.h"
4
#include "bod_cut_parser.h"
114 cycrow 5
 
6
#include <assert.h>
1 cycrow 7
//---------------------------------------------------------------------------------
8
bob_dom_document * bod_parser::parseBuffer(char *pszBuffer, size_t size, fileType type)
9
{
10
	bod_text_parser parser;
11
	token_stream is;
12
	bob_dom_document *doc=NULL;
13
	bob_dom_cut *cut=NULL;
14
	bob_dom_bob *bob=NULL;
15
	bod_parser_base *errorObj;
16
	bool bRes=false;
17
 
18
	is.rdbuffer(pszBuffer, size);
19
 
20
	if(type==bobFile){
21
		bod_bob_parser *bp=new bod_bob_parser(m_settings);
22
		errorObj=bp;
23
		bob=bp->loadBOB(is, false);
24
		bRes=bob!=NULL;
25
	}
26
	else if(type==cutFile){
27
		bod_cut_parser *cp=new bod_cut_parser(m_settings);
28
		cut=cp->loadCUT(is);
29
		errorObj=cp;
30
		bRes=cut!=NULL;
31
	}
32
 
33
	for(iterator &it=errorObj->errors.begin(); it!=errorObj->errors.end(); ++it){
34
		error(it);
35
	}
36
 
37
	if(bRes){
38
		doc=new bob_dom_document(m_settings);
39
		doc->bob=bob;
40
		doc->cut=cut;
41
	}
42
	return doc;
43
}
44
//---------------------------------------------------------------------------------
114 cycrow 45
bool bod_parser::compile(char *pszBuffer, size_t size, fileType type, obinaryfilestream& os)
1 cycrow 46
{
47
	token_stream is;
48
	bod_parser_base *errorObj;
49
	bool bRes=false;
50
 
114 cycrow 51
	is.parseFlags((bod_text_parser::ParseFlags)bod_text_parser::parseBODComments);
1 cycrow 52
	is.rdbuffer(pszBuffer, size);
53
 
54
	if(type==bobFile){
55
		bod_bob_parser *bp=new bod_bob_parser(m_settings);
56
		errorObj=bp;
57
		bRes=bp->compile(is, os, false);
58
	}
59
	else if(type==cutFile){
60
		bod_cut_parser *cp=new bod_cut_parser(m_settings);
61
		bRes=cp->compile(is, os);
62
		errorObj=cp;
63
	}
114 cycrow 64
	else
65
		assert(0); // invalid fileType
1 cycrow 66
 
67
	for(iterator &it=errorObj->errors.begin(); it!=errorObj->errors.end(); ++it){
68
		error(it);
69
	}
114 cycrow 70
 
71
	delete errorObj;
72
 
1 cycrow 73
	return bRes;
74
}
75
//---------------------------------------------------------------------------------
76
void bod_parser::error(iterator& it)
77
{
78
	Error *e=new Error();
79
 
80
	e->code=it->code;
81
	e->col=it->col;
82
	e->line=it->line;
83
	memcpy(e->text, it->text, sizeof(e->text));
84
	errors.push_back(e);
85
}
86
//---------------------------------------------------------------------------------