private Block WalkSubModel(ITree datamodel, Block scope) { if (datamodel.ChildCount < 1) { return null; // TODO maybe warn } Block block = new Block(); block.Label = datamodel.GetChild(0); blocks[block.Title] = block; if (scope != null) // not the top datamodel { block.Parent = scope; scope.AddBlock(block.Title, block); } ITree submodel = datamodel; // TODO // extract all type information for this submodel for (int i = 0; i < submodel.ChildCount; ++i) { ITree subtype = submodel.GetChild(i); if (subtype.Type == BlaiseParser.SUB_TYPE) { // add all types to this block for (int j = 0; j < subtype.ChildCount; ++j) { ITree typeItem = subtype.GetChild(j); if (typeItem.Type == BlaiseParser.TYPE_ITEM) { if (typeItem.ChildCount == 2 && typeItem.GetChild(1).Type == BlaiseParser.TYPEDEF) { string typeName = typeItem.GetChild(0).Text; block.AddType(typeName, typeItem.GetChild(1)); } } } } } // extract all field information for this submodel for (int i = 0; i < submodel.ChildCount; ++i) { ITree fields = submodel.GetChild(i); if (fields.Type == BlaiseParser.FIELDS || fields.Type == BlaiseParser.AUXFIELDS || fields.Type == BlaiseParser.SUB_LOCALS) { // add all fields to this block for (int j = 0; j < fields.ChildCount; ++j) { ITree field = fields.GetChild(j); if (field.Type == BlaiseParser.FIELD) // not necessary unless parser changes { if (field.ChildCount < 2) { continue; } ITree idList = field.GetChild(0); List<Field> toadd = new List<Field>(idList.ChildCount); for (int k = 0; k < idList.ChildCount; ++k) { Field f = new Field(); f.Title = idList.GetChild(k).Text; toadd.Add(f); } ITree typedef = null; Collection<LanguageString> fieldTexts = new Collection<LanguageString>(); Collection<LanguageString> fieldDescriptions = new Collection<LanguageString>(); string tag = null; // Do these seperate so we can keep the language ordering int langCount = 0; for (int k = 0; k < field.ChildCount; ++k) { ITree fi = field.GetChild(k); if (fi.Type == BlaiseParser.FIELD_TEXT) { ITree lidString = fi.GetChild(0); LanguageString ls = new LanguageString(lidString); if (string.IsNullOrEmpty(ls.Language) && langCount < options.DefinedLanguagesOrder.Count) { ls.Language = options.DefinedLanguagesOrder[langCount]; langCount++; } fieldTexts.Add(ls); } } langCount = 0; for (int k = 0; k < field.ChildCount; ++k) { ITree fi = field.GetChild(k); if (fi.Type == BlaiseParser.FIELD_DESC) { ITree lidString = fi.GetChild(0); LanguageString ls = new LanguageString(lidString); if (string.IsNullOrEmpty(ls.Language) && langCount < options.DefinedLanguagesOrder.Count) { ls.Language = options.DefinedLanguagesOrder[langCount]; langCount++; } fieldDescriptions.Add(ls); } // tack this on here, there is only one of them if (fi.Type == BlaiseParser.TYPEDEF) { typedef = fi; } else if (fi.Type == BlaiseParser.FIELD_TAG) { if (fi.ChildCount == 1) { ITree tagList = fi.GetChild(0); for (int ti = 0; ti < tagList.ChildCount; ti++) { if (ti == 0) { tag = tagList.GetChild(ti).Text; } else { tag += "," + tagList.GetChild(ti).Text; } } } } } foreach (Field f in toadd) { f.Question = fieldTexts; f.Description = fieldDescriptions; f.Typedef = typedef; f.Parent = block; f.Tag = tag; block.AddField(f.Title, f); } } } } } // extract all child block information for this submodel for (int i = 0; i < submodel.ChildCount; ++i) { ITree child = submodel.GetChild(i); if (child.Type == BlaiseParser.BLOCK || child.Type == BlaiseParser.TABLE || child.Type == BlaiseParser.PROCEDURE) { WalkSubModel(child, block); } } // extract rules for this submodel for (int i = 0; i < submodel.ChildCount; ++i) { ITree child = submodel.GetChild(i); if (child.Type == BlaiseParser.RULES) { block.Rules = child; } } return block; }
private XElement CreateQuestion(Field field, string prefix, Block scope) { XElement question = Ddi.Element(Ddi.QuestionItem); string name = GetQuestionName(field.Title, prefix); question.Add(new XElement(Ddi.QuestionItemName, Ddi.XmlLang(MainLanguage), name)); // Add the question to our cache. if (!this.questionsByBlock.ContainsKey(scope)) { this.questionsByBlock.Add(scope, new Dictionary<string, XElement>()); } var questionsByName = this.questionsByBlock[scope]; questionsByName.Add(name, question); if (!string.IsNullOrEmpty(field.Tag)) { question.Add(new XElement(Ddi.QuestionIntent, field.Tag)); } // Set the question text. foreach (LanguageString ls in field.Question) { AssignQuestionStrings(question, ls, scope); } foreach (LanguageString ls in field.Description) { AssignQuestionStrings(question, ls, scope); } question.Add(ParseTypedefTree(field.Typedef, scope)); return question; }
private XElement GetCCFromVariable(Field field, ITree variable, Block scope, string prefix) { ITree typeDefChild = field.Typedef.GetChild(0); // See if this is a block? if (typeDefChild.Type == BlaiseParser.TYPE_USERDEF || typeDefChild.Type == BlaiseParser.TYPE_ARRAY) { string userdef = null; if (typeDefChild.Type == BlaiseParser.TYPE_USERDEF) { userdef = typeDefChild.GetChild(0).Text; } else if (typeDefChild.Type == BlaiseParser.TYPE_ARRAY && typeDefChild.ChildCount == 2) { ITree typeDef = typeDefChild.GetChild(1); if (typeDef.Type == BlaiseParser.TYPE_USERDEF) { userdef = typeDef.GetChild(0).Text; } } // TODO look for selector and then include question or block if (userdef != null && blocks.ContainsKey(userdef)) { // We are asking a Block //CustomSequenceActivity seq = new CustomSequenceActivity(); // First add a statement with the text of this node. //if (field.Question != null) //{ // seq.Activities.Add(GetStatement(field.Question, prefix, scope)); //} // Now add everything in the block. //seq.Activities.Add(GetControlConstruct(blocks[userdef], userdef)); return GetBlockControlConstruct(blocks[userdef], userdef); } } //TODO this doesn't account for selectors, but that may only be for blocks string questionName = variable.GetChild(0).Text; XElement questionReference = GetQuestionReference(scope, GetQuestionName(questionName, prefix)); if (questionReference != null) { XElement questionActivity = Ddi.Element(Ddi.QuestionConstruct); questionActivity.Add(questionReference); return questionActivity; } //TODO could not find the field? return GetActionForTree(variable); }
/* public System.Collections.Generic.Dictionary<string, Algenta.Data.Parsing.Blaise.BlaiseModel.Block> Blocks { get { return this.blocks; } } public System.Collections.Generic.Dictionary<string, Algenta.Data.Parsing.Blaise.BlaiseModel.Field> Fields { get { return this.fields; } }*/ public void AddField(string name, Field field) { this.fields.Add(name, field); }