public IEnumerable <TReturn> Parse(IEnumerator <DType> tokens, IParserVisitor <TReturn> visitor) { DType current = tokens.Current; if (current == DType.DictEntryEnd || current == DType.StructEnd) { tokens.MoveNext(); return(null); } // May be an array or a dict if (current == DType.Array) { if (!tokens.MoveNext()) { throw new ParseException("An array type is malformed"); } if (tokens.Current == DType.DictEntryBegin) { return(Wrap(ParseDict(tokens, visitor))); } else { return(Wrap(visitor.ParseArrayDefinition(Parse(tokens, visitor).First()))); } } if (current == DType.StructBegin) { if (!tokens.MoveNext()) { throw new ParseException("A structure is malformed"); } return(Wrap(ParseStruct(tokens, visitor))); } IEnumerable <TReturn> result = Wrap(visitor.ParseBaseTypeDefinition(current)); tokens.MoveNext(); return(result); }
public TReturn ParseDBusTypeExpression(string expression, IParserVisitor <TReturn> visitor) { if (string.IsNullOrEmpty(expression)) { return(visitor.Default); } // Assume it's a base type and thus directly return the corresponding type if (expression.Length == 1) { return(visitor.ParseBaseTypeDefinition((DType)(byte)expression[0])); } TReturn temp; IEnumerable <DType> expressionList = expression.Select((c) => (DType)(byte)c); IEnumerator <DType> enumerator = expressionList.GetEnumerator(); enumerator.MoveNext(); try { temp = Parse(enumerator, visitor).First(); } catch { temp = visitor.Error; } return(temp); }