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