public object Resolve(Tokenizer tok, object scope) { if (index == -1 && length == -1) { return(meta); } if (meta == null) { throw new NullReferenceException(); } if (meta is string) { return(ToString((string)meta)); } TokenSubstitution ss = meta as TokenSubstitution; if (ss != null) { return(ss.value); } Delim d = meta as Delim; if (d != null) { return(d.text); } Context.Entry pce = meta as Context.Entry; if (pce != null) { return(pce.Resolve(tok, scope)); } throw new DecoderFallbackException(); }
private bool TryGetValue_TokenSubstitution(Token token, TokenSubstitution sub) { 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); }
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); }