private IProp <bool> ParsePropBool(WordReader wordReader) { var word = wordReader.GetWord(); if (word[0] == '$') { return(PropBoolDict[word]); } if (word == EqualKeyword) { var prop1 = ParsePropInt(wordReader); var prop2 = ParsePropInt(wordReader); return(new EqualProp(prop1, prop2)); } if (word == OrKeyword) { var list = ParseList(wordReader, ParsePropBool); return(new OrProp(list)); } if (word == PersInsightKeyword) { var persIndex = ParsePersIndex(wordReader); var day = ParseDay(wordReader); var insightName = wordReader.GetWord(); return(PersList[persIndex].GetInsight(insightName, day, GetFullState())); } else { throw new Exception(string.Format("Can't parse PropBool '{0}'", word)); } }
private IProp <int> ParsePropInt(WordReader wordReader) { var word = wordReader.GetWord(); if (word[0] == '$') { return(PropIntDict[word]); } if (word == GetKeyword) { var stateVarName = wordReader.GetWord(); var stateVarIndex = GetStateVarIndex(stateVarName); return(new GetProp(stateVarIndex)); } if (word == ConstKeyword) { var stateVarName = wordReader.GetWord(); var value = wordReader.GetWord(); return(new ConstProp(GetStateVarValueIndex(stateVarName, value))); } else { throw new Exception(word); } }
private void ParseKnowledgeVar(WordReader wordReader) { var name = wordReader.GetWord(); wordReader.GetWord("="); var prop = ParseKnowledge(wordReader); wordReader.GetEnd(); AddKnowledge(name, prop); }
private void ParsePropBoolVar(WordReader wordReader) { var name = wordReader.GetWord(); wordReader.GetWord("="); var prop = ParsePropBool(wordReader); wordReader.GetEnd(); AddPropBool(name, prop); }
private int ParsePersIndex(WordReader wordReader) { var persName = wordReader.GetWord(); var persIndex = PersList.FindIndex(p => p.Name == persName); return(persIndex); }
private IKnowledge ParseKnowledge(WordReader wordReader) { var word = wordReader.GetWord(); if (word[0] == '&') { return(KnowledgeDict[word]); } if (word == AboutIntKeyword) { var propInt = ParsePropInt(wordReader); return(new AboutKnowledge <int>(propInt, new IntComparer())); } if (word == AboutBoolKeyword) { var propBool = ParsePropBool(wordReader); return(new AboutKnowledge <bool>(propBool, new BoolComparer())); } if (word == IsTrueKeyword) { var propBool = ParsePropBool(wordReader); return(new IsTrueKnowledge(propBool)); } if (word == CombineKeyword) { var knowledgeArray = ParseList <IKnowledge>(wordReader, ParseKnowledge); return(new CombineKnowledge(knowledgeArray)); } else { throw new Exception(word); } }
private void ParsePers(WordReader wordReader) { var name = wordReader.GetWord(); wordReader.GetEnd(); AddPers(name); }
private void ParseStateVar(WordReader wordReader) { var name = wordReader.GetWord(); var valueList = ParseList <string>(wordReader, ParseString); wordReader.GetEnd(); AddStateVar(name, valueList); }
private int ParseDay(WordReader wordReader) { var word = wordReader.GetWord(); if (word.StartsWith(DayKeyword) == false) { throw new Exception(); } return(int.Parse(word.Substring(DayKeyword.Length))); }
private void ParseInsight(WordReader wordReader) { var persIndex = ParsePersIndex(wordReader); var day = ParseDay(wordReader); var insightName = wordReader.GetWord(); var knowledge = ParseKnowledge(wordReader); wordReader.GetEnd(); AddInsightKeyword(persIndex, day, insightName, knowledge); }
private T[] ParseList <T>(WordReader wordReader, Func <WordReader, T> reader) { wordReader.GetWord(ListKeyword); var count = wordReader.GetInt(); var result = new T[count]; foreach (var i in count.Traverse()) { result[i] = reader(wordReader); } return(result); }
private void LoadFile(string fileName) { try { var comment = false; var lineArray = File.ReadAllLines(Application.streamingAssetsPath + "/" + fileName); foreach (var line in lineArray) { try { var wordReader = new WordReader(line); if (wordReader.IsEnd()) { continue; } var word = wordReader.GetWord(); if (word == CommentEndKeyword && comment) { comment = false; } else if (comment) { } else if (word == CommentStartKeyword) { comment = true; } else if (word == LineCommentKeyword) { } else if (word == StateVarKeyword) { ParseStateVar(wordReader); } else if (word == PersKeyword) { ParsePers(wordReader); } else if (word == StateKeyword) { ParseState(wordReader); } else if (word == PropIntKeyword) { ParsePropIntVar(wordReader); } else if (word == PropBoolKeyword) { ParsePropBoolVar(wordReader); } else if (word == KnowledgeKeyword) { ParseKnowledgeVar(wordReader); } else if (word == DayKnowledgeKeyword) { ParseDayKnowledge(wordReader); } else if (word == InsightKeyword) { ParseInsight(wordReader); } else if (word == PrintPersInsightKeyword) { ParsePrintPersInsight(wordReader); } else if (word == PrintPropIntKeyword) { ParsePrintPropInt(wordReader); } else if (word == PrintPropBoolKeyword) { ParsePrintPropBool(wordReader, (b) => true); } else if (word == PrintPropBoolTrueKeyword) { ParsePrintPropBool(wordReader, (b) => b); } else if (word == PrintPropBoolFalseKeyword) { ParsePrintPropBool(wordReader, (b) => !b); } else if (word == PrintKnowledgeKeyword) { ParsePrintKnowledge(wordReader, (b) => true); } else if (word == PrintKnowledgeTrueKeyword) { ParsePrintKnowledge(wordReader, (b) => b); } else if (word == PrintKnowledgeFalseKeyword) { ParsePrintKnowledge(wordReader, (b) => !b); } else { Debug.LogError(line); } } catch (Exception e) { throw new ParseException(line, e); } } } catch (ParseException e) { Log(""); Log("Error: " + e.Exception.Message); Log(""); Log("Code line: " + e.Line); Debug.LogError(e.Exception); } }
private static string ParseString(WordReader wordReader) { return(wordReader.GetWord()); }