Ejemplo n.º 1
0
        public string GetColumn(string path, Project project)
        {
            if (string.IsNullOrEmpty (path)) {
                return ToString ();
            }

            string[] parts = path.Split (new char[] { '.' }, 2);

            if (parts[0].StartsWith ("!")) {
                string mark = parts[0].Substring (1);
                if (Marks.ContainsKey (mark)) {
                    return Marks[mark];
                }
            } else if (parts[0].StartsWith ("*") && project != null) {
                Rule r = project.Rules.GetRuleByName (parts[0].Substring (1));

                Context c = new Context ();
                c._Tokens = new List<string> (this.Tokens);
                r.Execute (c);

                if (parts.Length > 1) {
                    return c.GetColumn (parts[1], project);
                } else {
                    return c.ToString ();
                }
            } else if (Branches.ContainsKey (parts[0])) {
                if (parts.Length > 1) {
                    return Branches[parts[0]].GetColumn (parts[1], project);
                } else {
                    return Branches[parts[0]].ToString ();
                }
            }

            return "N/A";
        }
Ejemplo n.º 2
0
        public Project Compile()
        {
            ProjectNode project = GetProjectNode();
            Project result = new Project(project);

            if (!m_WarningViewHelper.HasWarnings)
            {
                return result;
            }

            return null;
        }
Ejemplo n.º 3
0
        public void Generate(Project project)
        {
            if (project != null)
            {
                if (project.StartRules.Count == 0) {
                    project.StartRules.Add("root", 100);
                }

                foreach (string col in project.Columns.Keys) {
                    m_ResultViewHelper.AddColumn(col, project.Columns[col]);
                }

                foreach (string ruleiter in project.StartRules.Keys) {
                    for (int c = 1; c <= project.StartRules[ruleiter]; c++) {
                        Context item = project.GetWord(ruleiter);
                        m_ResultViewHelper.AddItem(item);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public abstract void CheckSanity(Project project, Whee.WordBuilder.ProjectV2.IProjectSerializer serializer);
Ejemplo n.º 5
0
		public virtual void LoadCommand(Project project, TextReader reader, string line, ref int lineNumber)
		{
			m_lineNumber = lineNumber;
			m_project = project;
	    }
Ejemplo n.º 6
0
        public static Project LoadProject(string path)
        {
            Project result = new Project(Whee.WordBuilder.Helpers.Random.Instance);

            try {
                using (StreamReader tr = new StreamReader(path, System.Text.Encoding.UTF8)) {
                    ReadProject(result, tr);
                }
            }
            catch (Exception ex) {
                result.Warnings.Add(ex.Message);
            }

            return result;
        }
Ejemplo n.º 7
0
        private static void WriteProject(Project project, TextWriter writer)
        {
            foreach (string startRule in project.StartRules.Keys) {
                writer.WriteLine(string.Format("StartingRule {0} {1}", startRule, project.StartRules[startRule]));
            }

            foreach (TokenSet ts in project.TokenSets) {
                writer.WriteLine(string.Format("Tokens {0} {1}", ts.Name, string.Join(" ", ts.Tokens.ToArray())));
            }

            foreach (Rule r in project.Rules) {
                writer.WriteLine(string.Format("Rule {0} {1} {{}", r.Name, r.Probability));
                r.Commands.WriteCommands(writer);
                writer.WriteLine("}");
            }
        }
Ejemplo n.º 8
0
        private static void ReadProject(Project project, TextReader reader)
        {
            //int linenumber = 0;

            //if (!ReadLines(project, reader, ParseProject, ref linenumber)) {
            //    project.Warnings.Add("The code was not read to the end of the document");
            //}

            //if (project.StartRules.Count == 0) {
            //    project.StartRules.Add("root", 100);
            //}

            //foreach (string sr in project.StartRules.Keys) {
            //    if (project.Rules.GetRuleByName(sr) == null) {
            //        project.Warnings.Add(string.Format("The starting rule '{0}' does not exist.", sr));
            //    }
            //}

            //foreach (Rule r in project.Rules) {
            //    foreach (CommandBase c in r.Commands) {
            //        c.CheckSanity(project);
            //    }
            //}
        }
Ejemplo n.º 9
0
 public static void SaveProject(Project project, string path)
 {
     using (StreamWriter tw = new StreamWriter(path, false, System.Text.Encoding.UTF8)) {
         WriteProject(project, tw);
     }
 }
Ejemplo n.º 10
0
        public static Project LoadProjectString(string code)
        {
            Project result = new Project(Whee.WordBuilder.Helpers.Random.Instance);

            try {
                using (StringReader tr = new StringReader(code)) {
                    ReadProject(result, tr);
                }
            }
            catch (Exception ex) {
                result.Warnings.Add(ex.Message);
            }

            return result;
        }