Beispiel #1
0
        private static void ParseDictEntry(Water.TextReader reader, Water.Dictionary dict)
        {
            #region ParseDictEntry

            TrimWhitespace(reader);

            string name = ParseName(reader);

            TrimWhitespace(reader);

            if (reader.Peek() == ':')
            {
                reader.Read();
            }
            else
            {
                throw new Water.Error("Parser error: Invalid dictionary entry name: " + name);
            }

            TrimWhitespace(reader);

            dict.Add(name, Parse(reader));

            #endregion
        }
Beispiel #2
0
        public static void Include(string filename)
        {
            string path = Water.FileReader.ResolvePath(filename);

            Water.Dictionary includes = Water.Environment.Includes;
            if (includes[path] == null)
            {
                includes.Add(path, path);



                Water.FileReader reader = null;
                try
                {
                    reader = new Water.FileReader(path);

                    Water.Interpreter.Interpret(new Water.Iterator(reader));
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Pop a stack frame.
        /// </summary>
        public static void Pop()
        {
            Water.Dictionary frame = (Water.Dictionary)_variables[_stackDepth - 1];
            frame.Clear();

            _stackDepth--;
        }
Beispiel #4
0
        //
        // Dictionaries
        //

        private static Water.Dictionary ParseDictionary(Water.TextReader reader)
        {
            #region ParseDictionary

            Water.Dictionary dict = new Water.Dictionary();

            // Read the '{'
            reader.Read();

            TrimWhitespace(reader);

            while (reader.Peek() != -1)
            {
                char ch = (char)reader.Peek();

                if (ch == '}')
                {
                    //Exit state
                    reader.Read();
                    return(dict);
                }
                else
                {
                    ParseDictEntry(reader, dict);
                }

                TrimWhitespace(reader);
            }

            throw new Water.Error("Parser error: End of dictionary expected.");

            #endregion
        }
Beispiel #5
0
        private void SaveSettings()
        {
            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            Settings["FindDialog.Left"] = this.Left;
            Settings["FindDialog.Top"]  = this.Top;
        }
Beispiel #6
0
 private static void SaveSettings(string path)
 {
     Water.Dictionary       Settings = (Water.Dictionary)Water.Environment.Identify("Settings");
     System.IO.StreamWriter writer   = new System.IO.StreamWriter(path);
     Water.Generator.Generate(Settings, writer);
     writer.Flush();
     writer.Close();
 }
        private void LoadSettings()
        {
            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            if (Settings.IsDefined("Project.Path"))
            {
                string path = (string)Settings["Project.Path"];
                Water.Evaluator.Apply("Project.Open", path);
            }
        }
Beispiel #8
0
        private static object ApplyIndexer(string name, object value)
        {
            object index = Evaluate(Water.Parser.Parse(name));

            if (value is Water.Dictionary)
            {
                Water.Dictionary dictionary = (Water.Dictionary)value;

                string key = index.ToString();
                value = dictionary[key];

                //TODO DELETE
//				if(name.StartsWith("\"") && name.EndsWith("\""))
//				{
//					string key = EvaluateString(name.Substring(1, name.Length - 2));
//					value = dictionary[key];
//				}
//				else
//				{
//					string key = (string)Water.Environment.Identify(name);
//					value = dictionary[key];
//				}
            }
            else if (value.GetType().IsArray)
            {
                // Array Indexer
                System.Reflection.MethodInfo methodInfo = value.GetType().GetMethod("GetValue", new System.Type[] { index.GetType() });
                value = methodInfo.Invoke(value, new object[] { index });
            }
            else
            {
                System.Reflection.PropertyInfo propertyInfo = value.GetType().GetProperty("Item", new System.Type[] { index.GetType() });
                if (propertyInfo == null)
                {
                    throw new Water.Error("Unable to apply indexer.");
                }

                if (Water.Instructions.IsInt(index))
                {
                    value = propertyInfo.GetValue(value, new object[] { index });
                }
                else if (name.StartsWith("\"") && name.EndsWith("\""))
                {
                    string key = EvaluateString(name.Substring(1, name.Length - 2));
                    value = propertyInfo.GetValue(value, new object[] { key });
                }
                else
                {
                    string key = (string)Water.Environment.Identify(name);
                    value = propertyInfo.GetValue(value, new object[] { key });
                }
            }
            return(value);
        }
Beispiel #9
0
 public static void Reset()
 {
     _output      = System.Console.Out;
     _break       = false;
     _return      = false;
     _returnValue = null;
     _constants   = new Water.Dictionary();
     _variables   = new Water.List();
     _stackDepth  = 0;
     _includes    = new Water.Dictionary();
 }
Beispiel #10
0
        private void LoadSettings()
        {
            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            if (Settings.IsDefined("FindDialog.Left"))
            {
                this.Left = (int)Settings["FindDialog.Left"];
            }
            if (Settings.IsDefined("FindDialog.Top"))
            {
                this.Top = (int)Settings["FindDialog.Top"];
            }
        }
Beispiel #11
0
 private static void LoadSettings(string path)
 {
     if (!System.IO.File.Exists(path))
     {
         Water.Environment.DefineConstant("Settings", new Water.Dictionary());
     }
     else
     {
         Water.TextReader reader   = new Water.TextReader(new System.IO.StreamReader(path));
         Water.Dictionary Settings = (Water.Dictionary)Water.Parser.Parse(reader);
         Water.Environment.DefineConstant("Settings", Settings);
         reader.Close();
     }
 }
Beispiel #12
0
 /// <summary>
 /// Push a stack frame.
 /// </summary>
 public static void Push()
 {
     Water.Dictionary frame;
     if (_variables.Count == _stackDepth)
     {
         frame = new Water.Dictionary();
         _variables.Add(frame);
     }
     else
     {
         frame = (Water.Dictionary)_variables[_stackDepth];
     }
     _stackDepth++;
 }
Beispiel #13
0
        public static void DefineVariable(string name, object value)
        {
            if (IsConstant(name))
            {
                throw new Water.Error("Constant \"" + name + "\" is already defined.");
            }

            Water.Dictionary frame = (Water.Dictionary)_variables[_stackDepth - 1];
            if (frame.IsDefined(name))
            {
                frame.Remove(name);
            }
            frame.Add(name, value);
        }
Beispiel #14
0
        public static void PrintError(System.Exception exception, System.IO.TextWriter output)
        {
            Water.List statements = new Water.List();
            for (int i = (Water.Environment.Variables.Count - 1); i >= 0; i--)
            {
                Water.Dictionary frame = (Water.Dictionary)Water.Environment.Variables[i];
                if (frame.IsDefined("_Statement"))
                {
                    statements.Add(frame["_Statement"]);
                }
            }

            PrintError(exception, statements, output);
        }
Beispiel #15
0
        private object CheckQuote(object o)
        {
            if (o is Water.List)
            {
                Water.List list = (Water.List)o;

                Water.List results = new Water.List();
                foreach (object item in list)
                {
                    results.Add(CheckQuote(item));
                }
                return(results);
            }
            else if (o is Water.Dictionary)
            {
                Water.Dictionary dictionary = (Water.Dictionary)o;

                Water.Dictionary results = new Water.Dictionary();
                foreach (string key in dictionary)
                {
                    results.Add(key, CheckQuote(dictionary[key]));
                }
                return(results);
            }
            else if (o is Water.Comma)
            {
                Water.Comma comma = (Water.Comma)o;

                return(comma.Evaluate(new Water.List()));
            }
            else if (o is System.String)
            {
                System.String s = (System.String)o;

                return(Water.Evaluator.EvaluateString(s));
            }
            else
            {
                return(o);
            }
        }
        private void SaveSettings()
        {
            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            if (this._treeNode != null)
            {
                if (this._treeNode is TreeNodes.SolutionTreeNode)
                {
                    TreeNodes.SolutionTreeNode solutionTreeNode = (TreeNodes.SolutionTreeNode) this._treeNode;
                    Settings["Project.Path"] = solutionTreeNode.Path;
                }
                else if (this._treeNode is TreeNodes.ProjectTreeNode)
                {
                    TreeNodes.ProjectTreeNode projectTreeNode = (TreeNodes.ProjectTreeNode) this._treeNode;
                    Settings["Project.Path"] = projectTreeNode.Path;
                }
                else
                {
                    throw new System.Exception("Invalid project node.");
                }
            }
        }
Beispiel #17
0
        private void LoadSettings()
        {
            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            if (Settings.IsDefined("WindowState"))
            {
                this.WindowState = (System.Windows.Forms.FormWindowState)System.Enum.Parse(typeof(System.Windows.Forms.FormWindowState), (string)Settings["WindowState"]);
            }
            if (this.WindowState == System.Windows.Forms.FormWindowState.Normal)
            {
                if (Settings.IsDefined("Left"))
                {
                    this.Left = (int)Settings["Left"];
                }
                if (Settings.IsDefined("Top"))
                {
                    this.Top = (int)Settings["Top"];
                }
                if (Settings.IsDefined("Width"))
                {
                    this.Width = (int)Settings["Width"];
                }
                if (Settings.IsDefined("Height"))
                {
                    this.Height = (int)Settings["Height"];
                }
            }


            if (Settings.IsDefined("Commands"))
            {
                Water.List commands = (Water.List)Settings["Commands"];
                foreach (Water.List command in commands)
                {
                    Water.Evaluator.Evaluate(command);
                }
            }
        }
Beispiel #18
0
        public override void Evaluate(Water.List expressions, Water.List statements)
        {
            if (expressions.Count != 1)
            {
                throw new Water.Error("Invalid arguments.\n\t" + expressions.ToString());
            }

            Water.Dictionary block = new Water.Dictionary();
            block["else_if"] = new Water.List();

            Water.List if_block = new Water.List();
            block["if"] = if_block;
            Water.List current_block = if_block;

            foreach (Water.Statement block_statement in statements)
            {
                Water.List statement = (Water.List)block_statement.Expression;
                if (statement.First() is Water.Identifier)
                {
                    string tag = ((Water.Identifier)statement.First()).Value;

                    if (tag.Equals("if"))
                    {
                        current_block.Add(block_statement);
                    }
                    else if (statement.Count == 2 && tag.Equals("else_if"))
                    {
                        Water.Dictionary else_if_block = new Water.Dictionary();
                        //TODO use generics
                        ((Water.List)block["else_if"]).Add(else_if_block);

                        else_if_block["Expressions"] = statement.NotFirst().First();

                        Water.List else_if_block_statements = new Water.List();
                        else_if_block["Statements"] = else_if_block_statements;
                        current_block = else_if_block_statements;
                    }
                    else if (statement.Count == 1 && tag.Equals("else"))                    // && depth == 0
                    {
                        Water.List else_block = new Water.List();
                        block["else"] = else_block;
                        current_block = else_block;
                    }
                    else if (statement.Count == 1 && tag.Equals("end_if"))
                    {
                        current_block.Add(block_statement);
                    }
                    else
                    {
                        current_block.Add(block_statement);
                    }
                }
                else
                {
                    current_block.Add(block_statement);
                }
            }

            if (Water.Evaluator.EvaluateBoolean(expressions[0]))
            {
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["if"], false));
                return;
            }
            //TODO use generics
            foreach (Water.Dictionary elseIf in (Water.List)block["else_if"])
            {
                if (Water.Evaluator.EvaluateBoolean(elseIf["Expressions"]))
                {
                    //TODO use generics
                    Water.Interpreter.Interpret(new StatementIterator((Water.List)elseIf["Statements"], false));
                    return;
                }
            }
            if (block["else"] != null)
            {
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["else"], false));
                return;
            }
        }
Beispiel #19
0
        private void SaveSettings()
        {
            if (Water.Environment.IsConstant("Window.CloseAllDocuments"))
            {
                Water.Evaluator.Apply("Window.CloseAllDocuments");
            }



            Water.Dictionary Settings = (Water.Dictionary)Water.Environment.Identify("Settings");

            Settings["WindowState"] = this.WindowState.ToString();
            if (this.WindowState == System.Windows.Forms.FormWindowState.Normal)
            {
                Settings["Left"]   = this.Left;
                Settings["Top"]    = this.Top;
                Settings["Width"]  = this.Width;
                Settings["Height"] = this.Height;
            }



            Water.List commands = new Water.List();
            Settings["Commands"] = commands;

            bool showStartPage = true;

            foreach (TD.SandDock.DockControl dockControl in this.documentContainer.Controls)
            {
                if (dockControl.Controls[0] is bamboo.Controls.Editor.EditorControl)
                {
                    bamboo.Controls.Editor.EditorControl editorControl = (bamboo.Controls.Editor.EditorControl)dockControl.Controls[0];

                    Water.List command = new Water.List();
                    command.Add(new Water.Identifier("File.Open"));
                    command.Add(editorControl.Filename);
                    commands.Add(command);
                    showStartPage = false;
                }
                else if (dockControl.Controls[0] is bamboo.Controls.AssemblyExplorer.AssemblyExplorerControl)
                {
                    bamboo.Controls.AssemblyExplorer.AssemblyExplorerControl assemblyExplorerControl = (bamboo.Controls.AssemblyExplorer.AssemblyExplorerControl)dockControl.Controls[0];

                    Water.List command = new Water.List();
                    command.Add(new Water.Identifier("File.Open"));
                    command.Add(assemblyExplorerControl.Filename);
                    commands.Add(command);
                    showStartPage = false;
                }
                else
                {
                    string tag = (string)dockControl.Controls[0].Tag;
                    if (tag != null)
                    {
                        Water.List command = new Water.List();
                        command.Add(new Water.Identifier(tag));
                        command.Add("Document");
                        commands.Add(command);
                        showStartPage = false;
                    }
                }
            }
            if (showStartPage)
            {
                Water.List command = new Water.List();
                command.Add(new Water.Identifier("View.StartPage"));
                commands.Add(command);
            }

            if (this.leftDockContainer.LayoutSystem.LayoutSystems.Count != 0)
            {
                TD.SandDock.ControlLayoutSystem controlLayoutSystem = (TD.SandDock.ControlLayoutSystem) this.leftDockContainer.LayoutSystem.LayoutSystems[0];
                foreach (TD.SandDock.DockControl dockControl in controlLayoutSystem.Controls)
                {
                    string tag = (string)dockControl.Controls[0].Tag;
                    if (tag != null)
                    {
                        Water.List command = new Water.List();
                        command.Add(new Water.Identifier(tag));
                        command.Add("Left");
                        commands.Add(command);
                    }
                }
            }

            if (this.bottomDockContainer.LayoutSystem.LayoutSystems.Count != 0)
            {
                TD.SandDock.ControlLayoutSystem controlLayoutSystem = (TD.SandDock.ControlLayoutSystem) this.bottomDockContainer.LayoutSystem.LayoutSystems[0];
                foreach (TD.SandDock.DockControl dockControl in controlLayoutSystem.Controls)
                {
                    string tag = (string)dockControl.Controls[0].Tag;
                    if (tag != null)
                    {
                        Water.List command = new Water.List();
                        command.Add(new Water.Identifier(tag));
                        command.Add("Bottom");
                        commands.Add(command);
                    }
                }
            }

            if (this.rightDockContainer.LayoutSystem.LayoutSystems.Count != 0)
            {
                TD.SandDock.ControlLayoutSystem controlLayoutSystem = (TD.SandDock.ControlLayoutSystem) this.rightDockContainer.LayoutSystem.LayoutSystems[0];
                foreach (TD.SandDock.DockControl dockControl in controlLayoutSystem.Controls)
                {
                    string tag = (string)dockControl.Controls[0].Tag;
                    if (tag != null)
                    {
                        Water.List command = new Water.List();
                        command.Add(new Water.Identifier(tag));
                        command.Add("Right");
                        commands.Add(command);
                    }
                }
            }
        }
Beispiel #20
0
        public override void Evaluate(Water.List expressions, Water.List statements)
        {
            if (expressions.Count != 1)
            {
                throw new Water.Error("Invalid arguments.\n\t" + expressions.ToString());
            }

            object switch_expression = Water.Evaluator.Evaluate(expressions[0]);

            Water.Dictionary block = new Water.Dictionary();
            block["case"] = new Water.List();

            Water.List current_block = null;

            int depth = 0;

            foreach (Water.Statement block_statement in statements)
            {
                //TODO use generics
                Water.List statement = (Water.List)block_statement.Expression;
                if (statement.Count == 2 && statement.First() is Water.Identifier && ((Water.Identifier)statement.First()).Value.Equals("case"))
                {
                    Water.Dictionary case_block = new Water.Dictionary();
                    //TODO use generics
                    ((Water.List)block["case"]).Add(case_block);

                    case_block["Expressions"] = statement.NotFirst().First();

                    Water.List case_block_statements = new Water.List();
                    case_block["Statements"] = case_block_statements;
                    current_block            = case_block_statements;
                }
                else if (statement.First() is Water.Identifier)
                {
                    string tag = ((Water.Identifier)statement.First()).Value;

                    if (tag.Equals("switch"))
                    {
                        current_block.Add(block_statement);
                        depth++;
                    }
                    //TODO No good.
                    else if (statement.Count == 1 && tag.Equals("end_switch"))
                    {
                        current_block.Add(block_statement);
                        depth--;
                    }
                    else if (statement.Count == 1 && tag.Equals("default") && depth == 0)
                    {
                        Water.List default_block = new Water.List();
                        block["default"] = default_block;
                        current_block    = default_block;
                    }
                    else
                    {
                        current_block.Add(block_statement);
                    }
                }
                else
                {
                    if (current_block == null)
                    {
                        //TODO file, line, column.
                        throw new Water.Error("Invalid statement in switch statement.");
                    }
                    current_block.Add(block_statement);
                }
            }

            //TODO use generics
            foreach (Water.Dictionary case_ in (Water.List)block["case"])
            {
                if (switch_expression.Equals(Water.Evaluator.Evaluate(case_["Expressions"])))
                {
                    //TODO use generics
                    Water.Interpreter.Interpret(new StatementIterator((Water.List)case_["Statements"], false));
                    return;
                }
            }
            if (block["default"] != null)
            {
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["default"], false));
                return;
            }
        }
Beispiel #21
0
        public override void Evaluate(Water.List expressions, Water.List statements)
        {
            if (expressions.Count != 0)
            {
//TODO				throw new Water.Error("Invalid arguments.\n\t" + expressions.ToString());
            }

            string exception_name = null;

            Water.Dictionary block = new Water.Dictionary();             // TODO block = GroupBlock(tags);

            Water.List try_block = new Water.List();
            block["try"] = try_block;
            Water.List current_block = try_block;

            foreach (Water.Statement block_statement in statements)
            {
                //TODO use generics
                Water.List statement = (Water.List)block_statement.Expression;
                if (statement.First() is Water.Identifier)
                {
                    string tag = ((Water.Identifier)statement.First()).Value;

                    if (statement.Count == 2 && tag.Equals("catch"))                    // && depth == 0
                    {
                        //TODO check the number of expressions.

                        Water.List catch_block = new Water.List();
                        block["catch"] = catch_block;
                        current_block  = catch_block;

                        exception_name = ((Water.Identifier)statement[1]).Value;
                    }
                    else
                    {
                        current_block.Add(block_statement);
                    }
                }
                else
                {
                    current_block.Add(block_statement);
                }
            }

            if (exception_name == null)
            {
                //TODO throw exception.
            }

            try
            {
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["try"], false));
            }
            catch (System.Reflection.TargetInvocationException exception)
            {
                Water.Environment.Push();
                Water.Environment.DefineVariable(exception_name, exception.InnerException);
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["catch"], false));
                Water.Environment.Pop();
            }
            catch (System.Exception exception)
            {
                Water.Environment.Push();
                Water.Environment.DefineVariable(exception_name, exception);
                //TODO use generics
                Water.Interpreter.Interpret(new StatementIterator((Water.List)block["catch"], false));
                Water.Environment.Pop();
            }
        }