1 mike 1.9 //%/////////////////////////////////////////////////////////////////////////////
2 //
|
3 kumpf 1.12 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM,
4 // The Open Group, Tivoli Systems
|
5 mike 1.9 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 kumpf 1.12 // of this software and associated documentation files (the "Software"), to
8 // deal in the Software without restriction, including without limitation the
9 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10 mike 1.9 // sell copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
|
13 kumpf 1.12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
14 mike 1.9 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
15 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
16 kumpf 1.12 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
18 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19 mike 1.9 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 //
22 //==============================================================================
23 //
24 // Author: Bob Blair (bblair@bmc.com)
25 //
26 // Modified By:
27 //
28 //%/////////////////////////////////////////////////////////////////////////////
29
30
31 //
32 // implementation of valueFactory
33 //
34 //
35 //
36 // implementation of those methods of class parser which are not pure
37 // virtual
38 //
39
40 mike 1.9 #include "parser.h"
41 //#include <sstream>
42 #include "parserExceptions.h"
43
44 //---------------------------------------------------------------------
45 // Take a YY_BUFFERSTATE off the stack of saved contexts
46 //---------------------------------------------------------------------
47 bufstate *
48 parser::pop_statebuff() {
49 bufstate *v = 0;
50 if (!_include_stack.isEmpty()) {
51 v = _include_stack.top();
52 _include_stack.pop();
53 }
54 return v;
55 }
56
57 //-------------------------------------------------------------------
58 // Create a flex input buffer from a String containing the file name
59 //-------------------------------------------------------------------
60 int
61 mike 1.9 parser::setInputBufferFromName(const String &filename) {
|
62 chuck 1.13 #ifdef PEGASUS_PLATFORM_OS400_ISERIES_IBM
63 // 't' not supported on OS/400
|
64 kumpf 1.14 FILE *f = fopen(filename.getCString(),"r");
|
65 chuck 1.13 #else
|
66 kumpf 1.14 FILE *f = fopen(filename.getCString(),"rt");
|
67 chuck 1.13 #endif
|
68 mike 1.9 if (f) {
69 set_current_filename(filename);
70 set_lineno(1);
71 return setInputBuffer(f);
72 } else {
73 return 1;
74 }
75 }
76
77 //-----------------------------------------------------------------
78 // Handle the end of an input buffer. Either there is saved context
79 // or there isn't. If there is, restore the saved particulars
80 // of that context so we can keep on parsing
81 //-----------------------------------------------------------------
82 int
83 parser::wrap() {
84 bufstate *v = pop_statebuff();
85 if (v) {
86 setInputBuffer(v->buffer_state);
87 set_current_filename(v->filename);
88 set_lineno(v->lineno);
89 mike 1.9 delete v;
90 return 0; // more data available
91 } else {
92 return 1; // end of it all
93 }
94 }
95
96 #ifdef PEGASUS_HAVE_NAMESPACES
97 using namespace ParserExceptions;
98 #endif /* PEGASUS_HAVE_NAMESPACES */
99
100 //----------------------------------------------------------------
|
101 karl 1.10 // ATTN: P2 BB 2001 Log where an error occured. This is lame, so it needs work
102 //
|
103 mike 1.9 //----------------------------------------------------------------
104 void
|
105 kumpf 1.11 parser::log_parse_error(char *token, const char *errmsg) const {
|
106 mike 1.9 char buf[40];
107 sprintf(buf, "%d", _lineno);
108 String s = _current_filename + ":" + buf + ": " + errmsg + " before `"
109 + token + "'\n";
|
110 kumpf 1.14 throw ParserLexException(s);
|
111 mike 1.9 }
|