lib Library API Documentation

koscript_parser.cc

00001 /* This file is part of the KDE project 00002 Copyright (C) 1998, 1999, 2000 Torben Weis <weis@kde.org> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00017 Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #include <iostream> 00021 00022 #include <qstring.h> 00023 00024 #include <klocale.h> 00025 00026 #include "koscript_parser.h" 00027 #include "koscript_parsenode.h" 00028 00029 extern FILE* yyin; 00030 extern char* yytext; 00031 extern int yylex(); 00032 00033 KSParser *theParser; 00034 00035 QString idl_lexFile; 00036 QString toplevelFile; 00037 int idl_line_no; 00038 00039 // Imported from yacc.yy 00040 extern void kscriptParse( const char *_code, int extension, KLocale* locale ); 00041 extern void kscriptParse( int extension, KLocale* locale ); 00042 00043 KSParser::KSParser() 00044 { 00045 rootNode = 0; 00046 } 00047 00048 KSParser::~KSParser() 00049 { 00050 if ( rootNode ) 00051 delete rootNode; 00052 } 00053 00054 bool KSParser::parse( FILE *inp_file, const char *filename, int extension, KLocale* locale ) 00055 { 00056 idl_lexFile = toplevelFile = const_cast<char *>(filename); 00057 yyin = inp_file; 00058 00059 m_errorMessage = ""; 00060 theParser = this; 00061 idl_line_no = 1; 00062 kscriptParse( extension, locale ); 00063 00064 return m_errorMessage.isEmpty(); 00065 } 00066 00067 bool KSParser::parse( const char* code, int extension, KLocale* locale ) 00068 { 00069 m_errorMessage = ""; 00070 theParser = this; 00071 idl_line_no = 1; 00072 kscriptParse( code, extension, locale ); 00073 00074 return m_errorMessage.isEmpty(); 00075 } 00076 00077 void KSParser::setRootNode( KSParseNode *node ) 00078 { 00079 rootNode = node; 00080 } 00081 00082 00083 KSParseNode *KSParser::getRootNode() 00084 { 00085 return rootNode; 00086 } 00087 00088 00089 void KSParser::parse_error( const char *file, const char *err, int line ) 00090 { 00091 m_errorMessage = "%1:%2: %3 before '%4'"; 00092 m_errorMessage = m_errorMessage.arg( file ).arg( line ).arg( err ).arg( yytext ); 00093 } 00094 00095 void KSParser::print( bool detailed ) 00096 { 00097 if ( rootNode ) 00098 rootNode->print( detailed ); 00099 } 00100 00101 bool KSParser::eval( KSContext& context ) 00102 { 00103 if ( !rootNode ) 00104 return FALSE; 00105 00106 return rootNode->eval( context ); 00107 } 00108 00109 KSParseNode* KSParser::donateParseTree() 00110 { 00111 KSParseNode* n = rootNode; 00112 rootNode = 0; 00113 return n; 00114 }
KDE Logo
This file is part of the documentation for lib Library Version 1.3.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Sep 24 18:22:26 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003