コード例 #1
0
ファイル: Context.cs プロジェクト: alfar/WordBuilder
        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";
        }
コード例 #2
0
        public Project Compile()
        {
            ProjectNode project = GetProjectNode();
            Project result = new Project(project);

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

            return null;
        }
コード例 #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);
                    }
                }
            }
        }
コード例 #4
0
ファイル: CommandBase.cs プロジェクト: alfar/WordBuilder
 public abstract void CheckSanity(Project project, Whee.WordBuilder.ProjectV2.IProjectSerializer serializer);
コード例 #5
0
ファイル: CommandBase.cs プロジェクト: alfar/WordBuilder
		public virtual void LoadCommand(Project project, TextReader reader, string line, ref int lineNumber)
		{
			m_lineNumber = lineNumber;
			m_project = project;
	    }
コード例 #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;
        }
コード例 #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("}");
            }
        }
コード例 #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);
            //    }
            //}
        }
コード例 #9
0
 public static void SaveProject(Project project, string path)
 {
     using (StreamWriter tw = new StreamWriter(path, false, System.Text.Encoding.UTF8)) {
         WriteProject(project, tw);
     }
 }
コード例 #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;
        }