IPBXProjExpression ParseExpression() { // int, string, bool, quoted string, dictionary or array IPBXProjExpression expression = null; if (_currentToken.Type == PBXProjTokenType.Symbol) { if (_currentToken.Value == "{") { expression = ParseDictionary(); } else if (_currentToken.Value == "(") { expression = ParseArray(); } } else { expression = ParseBaseExpression(); } if (_currentToken != null && _currentToken.Type == PBXProjTokenType.Comment) { expression.Comment = _currentToken.Value; ReadNextToken(); } return(expression); }
void SetSettingsEntry(string key, IPBXProjExpression value) { var settings = Dict.DictionaryValue(SETTINGS_KEY); if (settings == null) { settings = new PBXProjDictionary(); Dict.Add(SETTINGS_KEY, settings); } settings[key] = value; }
PBXProjArray ParseArray() { // (expression,expression) // _current = ( PBXProjArray array = new PBXProjArray(); ReadNextToken(); // skip '(' while (!(_currentToken.Type == PBXProjTokenType.Symbol && _currentToken.Value == ")")) { IPBXProjExpression expression = ParseExpression(); SkipExpected(PBXProjTokenType.Symbol, ","); array.Add(expression); } ReadNextToken(); return(array); }
PBXProjDictionary ParseDictionary() { // {assignment assignment assignment}; // { variable = expression; variable = expression; variable = expression;}; // _current = { PBXProjDictionary dic = new PBXProjDictionary(); ReadNextToken(); while (!(_currentToken.Type == PBXProjTokenType.Symbol && _currentToken.Value == "}")) //doing !symbol && !} means that other symbols break the loop. { // assignment: // variable = expression; // comment variable comment = expresssion comment; comment string preComment = "", keyComment = "", postComment = ""; if (_currentToken != null && _currentToken.Type == PBXProjTokenType.Comment) { preComment = _currentToken.Value; ReadNextToken(); } if (_currentToken.Type != PBXProjTokenType.String) { throw new PBXProjParserException("Expected a variable name, but got " + _currentToken.Value); } string key = _currentToken.Value; // Debug.Log(key); ReadNextToken(); if (_currentToken != null && _currentToken.Type == PBXProjTokenType.Comment) { keyComment = _currentToken.Value; ReadNextToken(); } CheckForUnexpectedEndOfSource(); SkipExpected(PBXProjTokenType.Symbol, "="); IPBXProjExpression exp = ParseExpression(); if (exp == null) { throw new PBXProjParserException("Expected an expression to be assigned to " + key); } SkipExpected(PBXProjTokenType.Symbol, ";"); if (_currentToken != null && _currentToken.Type == PBXProjTokenType.Comment) { postComment = _currentToken.Value; ReadNextToken(); } CheckForUnexpectedEndOfSource(); dic.Add(key, exp); dic.SetPreCommentForKey(key, preComment); dic.SetCommentForKey(key, keyComment); dic.SetPostCommentForKey(key, postComment); } ReadNextToken(); return(dic); }