diff options
-rw-r--r-- | src/buildparser.cpp | 16 | ||||
-rw-r--r-- | src/buildparser.h | 7 | ||||
-rw-r--r-- | src/parser.cpp | 27 | ||||
-rw-r--r-- | src/parser.h | 40 |
4 files changed, 69 insertions, 21 deletions
diff --git a/src/buildparser.cpp b/src/buildparser.cpp index cb285d4..7903e04 100644 --- a/src/buildparser.cpp +++ b/src/buildparser.cpp | |||
@@ -31,22 +31,6 @@ Build *BuildParser::load( const std::string &sFile ) | |||
31 | return genBuild(); | 31 | return genBuild(); |
32 | } | 32 | } |
33 | 33 | ||
34 | void BuildParser::error( YYLTYPE *locp, const char *msg ) | ||
35 | { | ||
36 | fflush( stdout ); | ||
37 | throw BuildException("%s: %d.%d-%d.%d: %s", | ||
38 | file.c_str(), | ||
39 | locp->first_line, locp->first_column, | ||
40 | locp->last_line, locp->last_column, | ||
41 | msg ); | ||
42 | } | ||
43 | |||
44 | void BuildParser::error( const std::string &msg ) | ||
45 | { | ||
46 | fflush( stdout ); | ||
47 | throw BuildException("%s", msg.c_str() ); | ||
48 | } | ||
49 | |||
50 | // | 34 | // |
51 | // Target functions | 35 | // Target functions |
52 | // | 36 | // |
diff --git a/src/buildparser.h b/src/buildparser.h index 642cc73..2e1924c 100644 --- a/src/buildparser.h +++ b/src/buildparser.h | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <list> | 6 | #include <list> |
7 | #include <utility> | 7 | #include <utility> |
8 | #include "build.tab.h" | 8 | #include "build.tab.h" |
9 | #include "parser.h" | ||
9 | 10 | ||
10 | class Build; | 11 | class Build; |
11 | class BuildParser; | 12 | class BuildParser; |
@@ -46,7 +47,7 @@ enum eSetHow | |||
46 | setAdd | 47 | setAdd |
47 | }; | 48 | }; |
48 | 49 | ||
49 | class BuildParser | 50 | class BuildParser : public Parser |
50 | { | 51 | { |
51 | typedef std::pair<std::string, Function *> BuildListItem; | 52 | typedef std::pair<std::string, Function *> BuildListItem; |
52 | typedef std::list<BuildListItem> BuildList; | 53 | typedef std::list<BuildListItem> BuildList; |
@@ -56,13 +57,9 @@ public: | |||
56 | BuildParser(); | 57 | BuildParser(); |
57 | virtual ~BuildParser(); | 58 | virtual ~BuildParser(); |
58 | 59 | ||
59 | void error( YYLTYPE *locp, const char *msg ); | ||
60 | void error( const std::string &msg ); | ||
61 | |||
62 | Build *load( const std::string &sFile ); | 60 | Build *load( const std::string &sFile ); |
63 | 61 | ||
64 | private: | 62 | private: |
65 | std::string file; | ||
66 | void scanBegin(); | 63 | void scanBegin(); |
67 | void scanEnd(); | 64 | void scanEnd(); |
68 | 65 | ||
diff --git a/src/parser.cpp b/src/parser.cpp new file mode 100644 index 0000000..d9fd2d0 --- /dev/null +++ b/src/parser.cpp | |||
@@ -0,0 +1,27 @@ | |||
1 | #include "parser.h" | ||
2 | #include "build.h" | ||
3 | |||
4 | Parser::Parser() | ||
5 | { | ||
6 | } | ||
7 | |||
8 | Parser::~Parser() | ||
9 | { | ||
10 | } | ||
11 | |||
12 | void Parser::error( YYLTYPE *locp, const char *msg ) | ||
13 | { | ||
14 | fflush( stdout ); | ||
15 | throw BuildException("%s: %d.%d-%d.%d: %s", | ||
16 | file.c_str(), | ||
17 | locp->first_line, locp->first_column, | ||
18 | locp->last_line, locp->last_column, | ||
19 | msg ); | ||
20 | } | ||
21 | |||
22 | void Parser::error( const std::string &msg ) | ||
23 | { | ||
24 | fflush( stdout ); | ||
25 | throw BuildException("%s", msg.c_str() ); | ||
26 | } | ||
27 | |||
diff --git a/src/parser.h b/src/parser.h new file mode 100644 index 0000000..675e28b --- /dev/null +++ b/src/parser.h | |||
@@ -0,0 +1,40 @@ | |||
1 | #ifndef PARSER_H | ||
2 | #define PARSER_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | #include <string> | ||
6 | |||
7 | class Build; | ||
8 | |||
9 | #if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) | ||
10 | typedef struct YYLTYPE | ||
11 | { | ||
12 | int first_line; | ||
13 | int first_column; | ||
14 | int last_line; | ||
15 | int last_column; | ||
16 | } YYLTYPE; | ||
17 | # define yyltype YYLTYPE /* obsolescent; will be withdrawn */ | ||
18 | # define YYLTYPE_IS_DECLARED 1 | ||
19 | # define YYLTYPE_IS_TRIVIAL 1 | ||
20 | #endif | ||
21 | |||
22 | class Parser | ||
23 | { | ||
24 | public: | ||
25 | Parser(); | ||
26 | virtual ~Parser(); | ||
27 | |||
28 | virtual void error( YYLTYPE *locp, const char *msg ); | ||
29 | virtual void error( const std::string &msg ); | ||
30 | |||
31 | virtual Build *load( const std::string &sFile ) = 0; | ||
32 | |||
33 | protected: | ||
34 | std::string file; | ||
35 | |||
36 | private: | ||
37 | |||
38 | }; | ||
39 | |||
40 | #endif | ||