protected bool TryGetValue() { memberValue = null; Token token = Current.Token; object meta = token.meta; if (SkipStructuredDelimiters(meta as Delim)) { return(true); } Context.Entry context = meta as Context.Entry; if (context != null) { bool subContextUsingSameList = context.tokens == Current.tokens; if (context.IsText()) { memberValue = context.GetText(); } else { int index = Current.tokenIndex; List <Token> parseNext = subContextUsingSameList ? Current.tokens.GetRange(index, context.tokenCount) : context.tokens; if (memberType == typeof(Expression)) { memberValue = new Expression(new List <Token>() { token }); } else { if (CodeConvert.IsConvertable(memberType)) { //Show.Log(memberId + " :: " + memberValue); memberValue = context.Resolve(tok, scope); } else { //Show.Log(memberId+" : "+memberValue); if (!CodeConvert.TryParseTokens(memberType, parseNext, ref memberValue, scope, tok)) { return(false); } } } } if (subContextUsingSameList) { Current.tokenIndex += context.tokenCount - 1; // -1 because increment happens after this method } return(true); } string s = meta as string; if (s != null) { memberValue = token.ToString(s); if (!CodeConvert.TryConvert(ref memberValue, memberType)) { AddError("unable to convert (" + memberValue + ") to type '" + memberType + "'"); return(false); } return(true); } TokenSubstitution sub = meta as TokenSubstitution; if (sub != null) { memberValue = sub.value; if (!memberType.IsAssignableFrom(memberValue.GetType()) && !CodeConvert.TryConvert(ref memberValue, memberType)) { AddError("unable to convert substitution (" + memberValue + ") to type '" + memberType + "'"); return(false); } return(true); } AddError("unable to parse token with meta data " + meta); return(false); }
private bool TryGetValue_Syntax(Token token, SyntaxTree syntax) { bool subContextUsingSameList = syntax.tokens == Current.tokens; if (syntax.IsTextLiteral) { memberValue = syntax.GetText(); } else { int index = Current.tokenIndex; List <Token> parseNext = subContextUsingSameList ? Current.tokens.GetRange(index, syntax.TokenCount) : syntax.tokens; if (memberType == typeof(Expression)) { Expression expr = new Expression(new List <Token>() { token }); if (scope != null) { List <object> resolved = expr.Resolve(tok, scope); if (resolved.Count == 1) { switch (resolved[0]) { case string partiallyResolvedExpressionAsString: expr = new Expression(partiallyResolvedExpressionAsString); break; case Expression partiallyResolvedExpression: expr = partiallyResolvedExpression; break; } } //Show.Log(resolved.JoinToString() + " " + resolved[0].GetType()+ " >><< " + expr+ " " + expr.GetType()); } memberValue = expr; } else { if (CodeConvert.IsConvertable(memberType)) { //Show.Log(memberId + " :: " + memberValue); memberValue = syntax.Resolve(tok, scope); } else { //Show.Log(memberId+" : "+memberValue); if (!CodeConvert.TryParseTokens(memberType, parseNext, ref memberValue, scope, tok)) { return(false); } } } } if (subContextUsingSameList) { Current.tokenIndex += syntax.TokenCount - 1; // -1 because increment happens after this method } return(true); }