/* * This file is part of leds. * * leds is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * leds is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with leds; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 30, Boston, MA 02111-1307 USA */ module parser.ModulePhp; private import std.stdio; private import std.c.linux.linux; private import dool.String; private import dool.io.Path; private import dool.io.FileBuffer; private import parser.Attributes; private import parser.Class; private import parser.Enum; private import parser.Element; private import parser.ElementOuter; private import parser.Function; private import parser.Import; private import parser.KnownTypes; private import parser.Parameters; private import parser.Parser; private import parser.Stack; //private import parser.Module; //private import parser.Module; //private Parameters parameters; /** * A class to contain a module structure of elements */ public class ModulePhp : Class { String fileName; String moduleName; Attributes.Language language; this(String filename) { debug(parser) { writef("\n#\n#\n#\n#\n#\n#\n"); writefln("new module from file %s", filename); writef("###################################################\n"); writef("\n#\n#\n#\n#\n#\n#\n"); } super(filename, Attribute.NONE, 0); moduleName = new String(); this.fileName = filename.dup; type = Type.MODULE; String input = loadFile(fileName); language = Attributes.getLanguageFromFileName(fileName); parse(); //if ( input !is null ) //{ // Parser parser = new Parser(input, language); // parse(parser); //} //else //{ // throw new FileException(fileName, -1); //} } this(String moduleName, String text, Attribute attributes, Attributes.Language language) { debug(parser) { writef("\n#\n#\n#\n#\n#\n#\n"); writef("\n###################################################\n"); writef("new module from text %s\n", moduleName); writef("###################################################\n"); writef("\n#\n#\n#\n#\n#\n#\n"); } super(moduleName, attributes, 0); this.language = language; this.fileName = new String(); this.moduleName = moduleName is null ? new String() : moduleName.dup; type = type.MODULE; //Parser parser = new Parser(text, language); //parse(parser); parse(); } override public Type getType() { return Type.MODULE; } String getFileName() { return fileName; } /** * Recursive to parse tokens (I had the good idea but...). * we get the class of object that contains the tokens */ void parse( ) { //Element element = parser.getElement(this); //while ( !elementEnd && element !is null ) //{ // addElement(element); // //elementEnd = parser.tokens.length == 1 && parser.tokens[0] == "}"; // if ( ! elementEnd ) // { // element = parser.getElement(this); // } //} //elementEnd = false; writefln("PHP parsing?"); Element element = new Class(new String("fred"), Element.Attribute.PUBLIC, 0, null); element.lastLineInCode = 100; addElement(element); } void setModuleName(String moduleName) { this.moduleName = moduleName; } String getBrowserForm() { if ( language == Attributes.Language.JAVA ) { String pubName = new String(); // for ( int i = 0 ; i>> Module Class %s\n",element.getLongForm()); if ( showSubElements ) { element.printElements(); } } } } void printClasses(bit showClassElements) { printElements(Type.CLASS, showClassElements); } void printElements() { writefln("Module.printElements %s", elements.length); super.printElements(); // foreach(Element element ; elements) // { // writefln("Module.printElements element = %s", element); // writefln("######### >>> Module Element %s",element.getLongForm()); // } } void printTypes() { foreach(String key ; knownTypes.getTypeNames()) { writefln("type = %s",key); } } /** * loads a file into the view * @param fileName the file to load * @return true if sucesseful */ String loadFile(String fileName) { String input; this.fileName = fileName.dup; //try //{ if ( Path.isFile(fileName) ) { input = new String(FileBuffer.read(fileName)); } else { input = new String(); } //} //catch ( Error e) //{ // e.print(); // input = null; //} return input; } }