/*
 *  Copyright 2006-2008 Mikhail Kryshen
 *
 *  This file is part of Tema.
 *
 *  Tema is free software: you can redistribute it and/or modify it
 *  under the terms of the GNU Lesser General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  Tema 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 Lesser General Public License for more details.
 *
 *  You should have received a copy of the 
 *  GNU Lesser General Public License along with Tema.  
 *  If not, see <http://www.gnu.org/licenses/>.
 *
 *  $Id: GlobalContext.java,v 1.16 2008/02/19 16:21:00 mikhail Exp $
 */

package kryshen.tema;

import java.io.File;
import kryshen.tema.functions.Database;
import kryshen.tema.functions.Define;
import kryshen.tema.functions.IO;
import kryshen.tema.functions.ImageConverter;
import kryshen.tema.functions.Control;
import kryshen.tema.functions.Standard;
import kryshen.tema.functions.Strings;

/**
 * Context to hold exported variables and standard Tema definitions.
 *
 * @author Mikhail Kryshen
 */
class GlobalContext extends Context {    
    
    GlobalContext() {
        super(new File(System.getProperty("user.dir")));
        
        // Register all standard functions.
        // TODO: arithmetics
        
        set("tema",       Standard.TEMA);
        set("echo",       Standard.ECHO);
        set("",           Standard.ECHO);
        set("!",          Standard.SKIP);
        set("silent",     Standard.SILENT);
        set("set",        Standard.SET);        
        set("unset",      Standard.UNSET);
        set("export",     Standard.EXPORT);
        set("assign",     Standard.ASSIGN);
        set("invoke",     Standard.INVOKE);
        set("load",       Standard.LOAD);
        
        set("to_upper",   Strings.TO_UPPER);
        set("to_lower",   Strings.TO_LOWER);
        set("substring",  Strings.SUBSTRING);
        set("equal",      Strings.EQUAL);
        set("xml_escape", Strings.XML_ESCAPE);
        set("xml_cdata",  Strings.XML_CDATA);
        set("char",       Strings.CHAR);
        set("replace",    Strings.REPLACE);
        set("regex_match",         Strings.REGEX_MATCH);
        set("regex_replace_first", Strings.REGEX_REPLACE_FIRST);
        set("regex_replace_all",   Strings.REGEX_REPLACE_ALL);
        
        set("define",     Define.DEFINE);
        
        set("write",      IO.WRITE);
        set("read",       IO.READ);
        set("include",    IO.INCLUDE);
        set("copy",       IO.COPY);
        set("file",       IO.FILE);
        
        set("false",      Control.FALSE);
        set("true",       Control.TRUE);
        set("not",        Control.NOT);
        set("optional",   Control.OPTIONAL);
        set("if",         Control.IF);
        set("if_else",    Control.IF_ELSE);
        set("while",      Control.WHILE);
        
        set("db_connect",    Database.CONNECT);
        set("db_prepare",    Database.PREPARE);
        set("db_query",      Database.QUERY);
        
        set("convert_image", ImageConverter.CONVERT_IMAGE);
        
        // Other functions are defined in classes Database and Define.
    }
}