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