Ejemplo n.º 1
0
 public SQLQueryParser(
     string sqlQuery,
     IParserContext context)
 {
     this.sqlQuery = sqlQuery;
     this.context = context;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Converts the parsed ab1 raw data file into a sequence, with the associated ab1 metadata setup.  I use
 /// this method because only a subset of the data is needed so there is no point in persisting a large amount
 /// of unused metadata.
 /// </summary>
 /// <param name="context"></param>
 /// <returns></returns>
 public static ISequence Convert(IParserContext context)
 {
     ISequence sequence = GetSequence(context);
     Ab1Metadata metadata = GetAb1Metadata(context);
     Ab1Metadata.SetAb1Data(sequence, metadata);
     return sequence;
 }
        public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
        {
            reader.VerifyExpectedTokenAndMoveNext(Keywords.Function);
            if (reader.Next.Value == LuaToken.Colon)
            {
                reader.MoveNext();
                reader.MoveNext();
            }
            var functionName = reader.GetAndMoveNext();
            reader.VerifyExpectedToken(LuaToken.LeftBracket);

            var argumentNames = new List<string>();
            reader.MoveNext();
            while (reader.Current.Value != LuaToken.RightBracket)
            {
                argumentNames.Add(reader.Current.Value);
                reader.MoveNext();
                reader.VerifyExpectedToken(LuaToken.Comma, LuaToken.RightBracket);
                if (reader.Current.Value == LuaToken.RightBracket)
                    break;
                reader.MoveNext();
            }
            reader.VerifyExpectedTokenAndMoveNext(LuaToken.RightBracket);
            var statementsParser = new StatementBlockParser(Keywords.End);
            var body = statementsParser.ParseBlock(reader, context);

            return new FunctionDeclarationStatement(functionName.Value,argumentNames,body);
        }
Ejemplo n.º 4
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression targetValue = _target.Evaluate(context);

            Type targetType = targetValue.Type;
            object targetObject = targetValue.Value;

            ValueExpression[] parameters = EvaluateExpressionArray(_parameters, context);
            Type[] parameterTypes = parameters.ConvertAll(expr => expr.Type);
            object[] parameterValues = parameters.ConvertAll(expr => expr.Value);

            if (targetType.IsArray)
            {
                if (targetType.GetArrayRank() != parameters.Length)
                    throw new Exception("Array has a different rank. Number of arguments is incorrect");

                Type returnType = targetType.GetElementType();

                bool useLong = false;

                foreach (Type t in parameterTypes)
                {
                    if (t == typeof(long) || t == typeof(long?))
                        useLong = true;
                    else if (t != typeof(int) & t != typeof(int?) && t != typeof(short) && t != typeof(short?) && t != typeof(ushort) && t != typeof(ushort?))
                        throw new BadArgumentException(t.GetType().Name + " is not a valid type for array indexers", this);
                }

            #if !WINDOWS_PHONE
                if (useLong)
                {
                    long[] indexes = new long[parameters.Length];

                    for (int i=0;i<parameters.Length;i++)
                        indexes[i] = Convert.ToInt64(parameterValues[i]);

                    return Exp.Value(TokenPosition, ((Array)targetObject).GetValue(indexes), returnType);
                }
                else
            #endif
                {
                    int[] indexes = new int[parameters.Length];

                    for (int i = 0; i < parameters.Length; i++)
                        indexes[i] = Convert.ToInt32(parameterValues[i]);

                    return Exp.Value(TokenPosition, ((Array)targetObject).GetValue(indexes), returnType);
                }
            }
            else
            {
                DefaultMemberAttribute[] att = (DefaultMemberAttribute[]) targetType.GetCustomAttributes(typeof(DefaultMemberAttribute), true);

                MethodInfo methodInfo = targetType.GetMethod("get_" + att[0].MemberName, parameterTypes);

                object value = methodInfo.Invoke(targetObject, parameterValues);

                return new ValueExpression(TokenPosition, value, methodInfo.ReturnType);
            }
        }
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression valueRight = Right.Evaluate(context);

            if (Left is VariableExpression)
            {
                if ((context.AssignmentPermissions & AssignmentPermissions.Variable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to variable not allowed", this);

                VariableExpression varExpr = (VariableExpression)Left;

                bool exists = context.Exists(varExpr.VarName);

                if (exists && (context.AssignmentPermissions & AssignmentPermissions.ExistingVariable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to existing variable not allowed", this);

                if (!exists && (context.AssignmentPermissions & AssignmentPermissions.NewVariable) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to new variable not allowed", this);

                context.Set(varExpr.VarName, valueRight.Value, valueRight.Type);

                return valueRight;
            }

			if (Left is FieldExpression)
			{
				if ((context.AssignmentPermissions & AssignmentPermissions.Property) == AssignmentPermissions.None)
					throw new IllegalAssignmentException("Assignment to property not allowed", this);

				return ((FieldExpression)Left).Assign(context, valueRight.Value);
			}

            throw new IllegalAssignmentException(this);
        }
Ejemplo n.º 6
0
 public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     var token = reader.GetAndMoveNext();
     if (string.IsNullOrWhiteSpace(token.Value) || token.Value == LuaToken.Semicolon)
         return new EmptyStatement();
     throw new UnexpectedTokenException(token);
 }
    void IEvaluableMarkupExtension.Initialize(IParserContext context)
    {
      _resource = ResourceDictionary.FindResourceInParserContext(_resourceKey, context) ?? FindResourceInTheme(_resourceKey, context);

      if (_resource == null)
        ServiceRegistration.Get<ILogger>().Error("StaticResourceMarkupExtension: Resource '{0}' not found", _resourceKey);
    }
		public LanguageItemWindow (ILanguageItem item, IParserContext ctx, Ambience ambience,
		                           string errorInformations) : base (WindowType.Popup)
		{
			Name = "gtk-tooltips";
			
			// Approximate value for usual case
			StringBuilder s = new StringBuilder(150);
			
			if (item != null) {
				if (item is IParameter) {
					s.Append ("<small><i>");
					s.Append (paramStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.Convert ((IParameter)item, WindowConversionFlags));
				} else if (item is LocalVariable) {
					s.Append ("<small><i>");
					s.Append (localStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.Convert ((LocalVariable)item, WindowConversionFlags));
				} else if (item is IField) {				
					s.Append ("<small><i>");
					s.Append (fieldStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.Convert ((IField)item, WindowConversionFlags));
				} else if (item is IProperty) {				
					s.Append ("<small><i>");
					s.Append (propertyStr);
					s.Append ("</i></small>\n");
					s.Append (ambience.Convert ((IProperty)item, WindowConversionFlags));
				} else if (item is Namespace) {
					s.Append ("namespace <b>");
					s.Append (item.Name);
					s.Append ("</b>");
				} else
					s.Append (ambience.Convert (item, WindowConversionFlags));
				
				string doc = GetDocumentation (item.Documentation).Trim ('\n');
				if (!string.IsNullOrEmpty (doc)) {
					s.Append ("\n<small>");
					s.Append (doc);
					s.Append ("</small>");
				}
			}			
			
			if (!string.IsNullOrEmpty (errorInformations)) {
				if (s.Length != 0)
					s.Append ("\n\n");
				s.Append ("<small>");
				s.Append (errorInformations);
				s.Append ("</small>");
			}
			
			Label lab = new Label ();
			lab.Markup = s.ToString ();
			lab.Xalign = 0;
			lab.Xpad = 3;
			lab.Ypad = 3;
			Add (lab);
		}
 public override LuaExpression Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     var leftExpression = SyntaxParser.ReadExpression(reader,context);
     var operation = reader.Current.Value;
     reader.VerifyExpectedTokenAndMoveNext(LuaToken.BinaryOperations);
     var rightExpression = SyntaxParser.ReadExpression(reader, context);
     return new BinaryExpression(leftExpression,rightExpression, operation);
 }
Ejemplo n.º 10
0
 private static void LoadPeakLocations(Ab1Metadata metadata, IParserContext context)
 {
     metadata.PeakLocations =
         ((ShortDataItem)context
                             .DataItems
                             .First(item =>
                                    item.Entry.TagName == Constants.PeakLocationTagName)).Value;
 }
Ejemplo n.º 11
0
		/// <summary>
		/// constructor
		/// </summary>
		/// <param name="context"></param>
		public Debugger(IParserContext context)
		{
			if (context == null)
			{
				throw new ArgumentNullException("context");
			}
			m_Context = context;
		}
Ejemplo n.º 12
0
		/// <summary>
		/// constructor
		/// </summary>
		/// <param name="output"></param>
		public Debugger(TextWriter output)
		{
			if (output == null)
			{
				throw new ArgumentNullException("output");
			}
			m_Context = new DebugContext(output);
		}
Ejemplo n.º 13
0
 private static Ab1Metadata GetAb1Metadata(IParserContext context)
 {
     var metadata = new Ab1Metadata();
     LoadPeakLocations(metadata, context);
     LoadSequenceConfidence(metadata, context);
     LoadColorWheelData(metadata, context);
     return metadata;
 }
Ejemplo n.º 14
0
 protected object FindResourceInTheme(string resourceKey, IParserContext context)
 {
   object result = SkinContext.SkinResources.FindStyleResource(resourceKey);
   if (result == null)
     return null;
   // See comment about the copying in method ResourceDictionary.FindResourceInParserContext()
   return MpfCopyManager.DeepCopyCutLVPs(result);
 }
Ejemplo n.º 15
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression result = _value.Evaluate(context);

            if (context.ToBoolean(result.Value))
                return result;
            else
                return _defaultValue.Evaluate(context);
        }
Ejemplo n.º 16
0
 public override LuaStatement Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     reader.VerifyExpectedTokenAndMoveNext(Keywords.While);
     var conditionExpression = SyntaxParser.ReadExpression(reader, context);
     reader.VerifyExpectedTokenAndMoveNext(Keywords.Do);
     var blockParser = new StatementBlockParser(Keywords.End);
     var bodyBlock = blockParser.ParseBlock(reader, context);
     return new WhileStatement(conditionExpression, bodyBlock);
 }
Ejemplo n.º 17
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ClassName className = TypeExpression.Evaluate(context).Value as ClassName;

            if (className == null)
                throw new ExpressionEvaluationException("type cast requires a type. " + TypeExpression + " is not a type", this);

            return Exp.Value(TokenPosition, Convert.ChangeType(TargetExpression.Evaluate(context).Value, className.Type, null), className.Type);
        }
Ejemplo n.º 18
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression result = _value.Evaluate(context);

            if (result.Value == null)
                return _valueIfNull.Evaluate(context);

            return result;
        }
Ejemplo n.º 19
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ClassName className = _className.Evaluate(context).Value as ClassName;

            if (className == null)
                throw new TypeInitializationException(_className.VarName,null);

            return Exp.Value(TokenPosition, className.Type.Inspector().GetConstructors());
        }
Ejemplo n.º 20
0
 public IEnumerable<LuaExpression> Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     var expressions = new List<LuaExpression>();
     do
     {
         expressions.Add(SyntaxParser.ReadExpression(reader, context));
     } while (reader.Current.Value == LuaToken.Comma && reader.MoveNext());
     return expressions;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Retrieves the user defined sequence.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        private static ISequence GetSequence(IParserContext context)
        {
            char[] value = context.DataItems
                .OfType<CharDataItem>()
                .First(item => item.Entry.TagName == Constants.SequenceTagName)
                .Value;

            return new Sequence(context.Alphabet ?? Alphabets.DNA, new string(value));
        }
 public override LuaExpression Parse(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     reader.VerifyExpectedToken(LuaToken.LeftBracket);
     reader.MoveNext();
     var expression = SyntaxParser.ReadExpression(reader, context);
     reader.VerifyExpectedToken(LuaToken.RightBracket);
     reader.MoveNext();
     return new BracketedExpression(expression);
 }
Ejemplo n.º 23
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression value = Value.Evaluate(context);

            if (context == null)
                return Exp.Value(TokenPosition, !((bool)value.Value));
            else
                return Exp.Value(TokenPosition, !context.ToBoolean(value.Value));
        }
Ejemplo n.º 24
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression result = Condition.Evaluate(context);

            if (context.ToBoolean(result.Value))
                return Value.Evaluate(context);
            else
                return new ValueExpression(TokenPosition, null, typeof(object));
        }
        public override ValueExpression Evaluate(IParserContext context)
        {
            bool result = context.ToBoolean(_condition.Evaluate(context).Value);

            if (result)
                return _trueValue.Evaluate(context);
            else
                return _falseValue.Evaluate(context);
        }
Ejemplo n.º 26
0
 void IEvaluableMarkupExtension.Initialize(IParserContext context)
 {
   if (Id == null)
     throw new XamlBindingException("GetModelMarkupExtension: Property Id has to be given");
   IModelLoader loader = context.GetContextVariable(typeof(IModelLoader)) as IModelLoader;
   if (loader == null)
     throw new XamlBindingException("GetModelMarkupExtension: No model loader instance present in parser context");
   _model = loader.GetOrLoadModel(new Guid(Id));
 }
Ejemplo n.º 27
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            object value;
            Type type;

            if (!context.Get(VarName, out value, out type))
                return new ValueExpression(TokenPosition, null,typeof(object));

            return new ValueExpression(TokenPosition, value, type);
        }
Ejemplo n.º 28
0
 public static LuaStatement ReadStatement(INextAwareEnumerator<Token> reader, IParserContext context)
 {
     while (string.IsNullOrEmpty(reader.Current.Value) 
         || reader.Current.Value == "\n"
         || reader.Current.Type == TokenType.Comment)
         reader.MoveNext();
     var statementDiscriminator = new StatementParserDiscriminator();
     var statementParser = statementDiscriminator.Identify(reader);
     return statementParser.Parse(reader, context);
 }
Ejemplo n.º 29
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            object methodObject = _methodExpression.Evaluate(context).Value;

            ValueExpression[] parameters = EvaluateExpressionArray(_parameters, context);
            Type[] parameterTypes = parameters.ConvertAll(expr => expr.Type);
            object[] parameterValues = parameters.ConvertAll(expr => expr.Value);

			if (methodObject is MethodDefinition)
			{
				Type returnType;

                return Exp.Value(TokenPosition, ((MethodDefinition)methodObject).Invoke(parameterTypes, parameterValues, out returnType, new LazyBinder()), returnType);
			}

			if (methodObject is ConstructorInfo[])
			{
				ConstructorInfo[] constructors = (ConstructorInfo[]) methodObject;

                MethodBase method = new LazyBinder().SelectMethod(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, constructors, parameterTypes, null);

				if (method == null)
					throw new ExpressionEvaluationException("No match found for constructor " + constructors[0].Name, this);

				object value = ((ConstructorInfo)method).Invoke(parameterValues);

                return Exp.Value(TokenPosition, value, method.ReflectedType);
			}

			if (methodObject is Delegate[])
			{
				Delegate[] delegates = (Delegate[]) methodObject;
				MethodBase[] methods = delegates.ConvertAll<Delegate, MethodBase>(d => d.Method);

                MethodBase method = new LazyBinder().SelectMethod(BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance, methods, parameterTypes, null);

				if (method == null)
					throw new ExpressionEvaluationException("No match found for delegate " + _methodExpression, this);

				object value = method.Invoke(delegates[Array.IndexOf(methods, method)].Target, parameterValues);

                return Exp.Value(TokenPosition, value, ((MethodInfo)method).ReturnType);
			}

            if (methodObject is Delegate)
            {
                Delegate method = (Delegate) methodObject;

                object value = method.Method.Invoke(method.Target, parameterValues);

                return new ValueExpression(TokenPosition, value, method.Method.ReturnType);
            }

            throw new ExpressionEvaluationException(_methodExpression + " is not a function", this);
        }
Ejemplo n.º 30
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            object left = Left.Evaluate(context).Value;

            if (context.ToBoolean(left))
                return Exp.Value(TokenPosition, true);

            object right = Right.Evaluate(context).Value;

            return Exp.Value(TokenPosition, context.ToBoolean(right));
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Attempts to resolve a QName or URI Token into a URI Node and produces appropriate error messages if this fails
        /// </summary>
        /// <param name="context">Parser Context</param>
        /// <param name="t">Token to resolve</param>
        /// <param name="allowDefaultPrefixFallback">Whether when the default prefix is used but not defined it can fallback to the Base URI</param>
        /// <param name="qnameUnescape">QName unescaping function</param>
        /// <returns></returns>
        public static INode TryResolveUri(IParserContext context, IToken t, bool allowDefaultPrefixFallback, Func <String, String> qnameUnescape)
        {
            switch (t.TokenType)
            {
            case Token.QNAME:
                try
                {
                    return(context.Handler.CreateUriNode(UriFactory.Create(Tools.ResolveQName(qnameUnescape(t.Value), context.Namespaces, context.BaseUri, allowDefaultPrefixFallback))));
                }
                catch (UriFormatException formatEx)
                {
                    throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
                }
                catch (RdfException rdfEx)
                {
                    throw new RdfParseException("Unable to resolve the QName '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
                }

            case Token.URI:
                try
                {
                    String uri = Tools.ResolveUri(t.Value, context.BaseUri.ToSafeString());
                    return(context.Handler.CreateUriNode(UriFactory.Create(uri)));
                }
                catch (UriFormatException formatEx)
                {
                    throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + formatEx.Message, t, formatEx);
                }
                catch (RdfException rdfEx)
                {
                    throw new RdfParseException("Unable to resolve the URI '" + t.Value + "' due to the following error:\n" + rdfEx.Message, t, rdfEx);
                }

            default:
                throw ParserHelper.Error("Unexpected Token '" + t.GetType().ToString() + "' encountered, expected a URI/QName Token to resolve into a URI", t);
            }
        }
Ejemplo n.º 32
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression from = _from.Evaluate(context);
            ValueExpression to   = _to.Evaluate(context);

            if (from.Type != typeof(int) && from.Type != typeof(long))
            {
                throw new ExpressionEvaluationException("Expression " + from + " does not evaluate to int or long", from);
            }

            if (to.Type != typeof(int) && to.Type != typeof(long))
            {
                throw new ExpressionEvaluationException("Expression " + from + " does not evaluate to int or long", from);
            }

            if (from.Type == typeof(long) || to.Type == typeof(long))
            {
                return(Exp.Value(TokenPosition, Range((long)Convert.ChangeType(from.Value, typeof(long), null), (long)Convert.ChangeType(to.Value, typeof(long), null))));
            }
            else
            {
                return(Exp.Value(TokenPosition, Range((int)Convert.ChangeType(from.Value, typeof(int), null), (int)Convert.ChangeType(to.Value, typeof(int), null))));
            }
        }
Ejemplo n.º 33
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression value = _value.Evaluate(context);

            if (value.Type == typeof(decimal))
            {
                return(Exp.Value(TokenPosition, -(decimal)value.Value));
            }

            if (value.Type == typeof(double))
            {
                return(Exp.Value(TokenPosition, -(double)value.Value));
            }

            if (value.Type == typeof(float))
            {
                return(Exp.Value(TokenPosition, -(float)value.Value));
            }

            if (value.Type == typeof(uint))
            {
                return(Exp.Value(TokenPosition, -(uint)value.Value));
            }

            if (value.Type == typeof(int))
            {
                return(Exp.Value(TokenPosition, -(int)value.Value));
            }

            if (value.Type == typeof(long))
            {
                return(Exp.Value(TokenPosition, -(long)value.Value));
            }

            throw new IllegalOperandsException("Unary minus is not supported for " + _value, this);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Parser data.
        /// </summary>
        /// <param name="context"></param>
        public void ParseData(IParserContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (context.Header.MajorVersion != MajorVersion)
            {
                throw new InvalidFileVersionException(MajorVersion, context.Header.MajorVersion);
            }

            Context = context;

            Context.Header.DirectoryEntries.ForEach(
                entry =>
            {
                IAb1DataItem item = DataItemFactory.TryCreateDataItem(entry);
                if (item == null)
                {
                    return;
                }
                item.Accept(this);
            });
        }
Ejemplo n.º 35
0
        public static void RegisterUnmodifiableResourceDuringParsingProcess(IUnmodifiableResource resource, IParserContext context)
        {
            IEnumerator <ElementContextInfo> enumer = ((IEnumerable <ElementContextInfo>)context.ContextStack).GetEnumerator();

            if (!enumer.MoveNext())
            {
                return;
            }
            if (!enumer.MoveNext())
            {
                return;
            }
            ResourceDictionary rd = enumer.Current.Instance as ResourceDictionary;

            if (rd != null)
            {
                MPF.SetOwner(resource, rd, false);
            }
        }
Ejemplo n.º 36
0
 void IInitializable.StartInitialization(IParserContext context)
 {
 }
Ejemplo n.º 37
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            var value = _expression.Evaluate(context);

            return(new ReturnValueExpression(TokenPosition, value.Value, value.Type));
        }
Ejemplo n.º 38
0
        public override ValueExpression Evaluate(IParserContext context)
        {
            ValueExpression[] values = new[] { Left.Evaluate(context), Right.Evaluate(context) };

            Type type1 = values[0].Type;
            Type type2 = values[1].Type;

            bool nullable1 = type1.IsGenericType && type1.GetGenericTypeDefinition() == typeof(Nullable <>);
            bool nullable2 = type2.IsGenericType && type2.GetGenericTypeDefinition() == typeof(Nullable <>);

            type1 = Nullable.GetUnderlyingType(type1) ?? type1;
            type2 = Nullable.GetUnderlyingType(type2) ?? type2;

            bool isNullable = (nullable1 || nullable2);

            OperatorMethod operatorMethod = FindOperatorMethod(type1, type2);

            if (operatorMethod == null)
            {
                Type promotionType = null;

                if (type1 == typeof(decimal) || type2 == typeof(decimal))
                {
                    promotionType = typeof(decimal);
                }
                else if (type1 == typeof(double) || type2 == typeof(double))
                {
                    promotionType = typeof(double);
                }
                else if (type1 == typeof(float) || type2 == typeof(float))
                {
                    promotionType = typeof(float);
                }
                else if (type1 == typeof(ulong) || type2 == typeof(ulong))
                {
                    promotionType = typeof(ulong);
                }
                else if (type1 == typeof(long) || type2 == typeof(long))
                {
                    promotionType = typeof(long);
                }
                else if (type1 == typeof(uint) || type2 == typeof(uint) && (type1 == typeof(sbyte) || type2 == typeof(sbyte) || type1 == typeof(short) || type2 == typeof(short) || type1 == typeof(int) || type2 == typeof(int)))
                {
                    promotionType = typeof(long);
                }
                else if (type1 == typeof(uint) || type2 == typeof(uint))
                {
                    promotionType = typeof(uint);
                }
                else if (type1.IsPrimitive && type2.IsPrimitive && type1 != typeof(bool) && type2 != typeof(bool))
                {
                    promotionType = typeof(int);
                }

                if (promotionType != null)
                {
                    type1 = promotionType;
                    type2 = promotionType;
                }

                operatorMethod = FindOperatorMethod(type1, type2);
            }

            if (operatorMethod == null)
            {
                MethodInfo customOperatorMethod = type1.GetMethod(_operatorOverloadNames[_operator], new[] { type1, type2 });

                if (customOperatorMethod != null)
                {
                    return(new ValueExpression(TokenPosition, customOperatorMethod.Invoke(null, new[] { values[0].Value, values[1].Value }), customOperatorMethod.ReturnType));
                }

                if (_operator == "==" || _operator == "!=")
                {
                    return(new ValueExpression(TokenPosition, BinaryExpressionHelper.CalcObject(_operator, values[0].Value, values[1].Value, context.StringComparison, this), typeof(bool)));
                }

                throw new IllegalOperandsException("Operator " + _operator + " is not supported on " + values[0] + " and " + values[1], this);
            }

            Type returnType = operatorMethod.ReturnType;

            if (isNullable)
            {
                returnType = typeof(Nullable <>).MakeGenericType(returnType);

                //TODO: check specs for bool? values

                if (values[0].Value == null || values[1].Value == null)
                {
                    return(new ValueExpression(TokenPosition, null, returnType));
                }
            }

            object value1 = Convert.ChangeType(values[0].Value, operatorMethod.Type1);
            object value2 = Convert.ChangeType(values[1].Value, operatorMethod.Type2);

            return(new ValueExpression(TokenPosition, operatorMethod.Function(_operator, value1, value2, context.StringComparison, this), returnType));
        }
Ejemplo n.º 39
0
 public override ValueExpression Evaluate(IParserContext context)
 {
     return(this);
 }
Ejemplo n.º 40
0
 protected internal override IExpression DoParseExpression(string expressionString, IParserContext context)
 {
     return(new InternalSpelExpressionParser(_configuration).DoParseExpression(expressionString, context));
 }
Ejemplo n.º 41
0
 public SQLQueryParser(ISessionFactoryImplementor factory, string sqlQuery, IParserContext context)
 {
     this.factory        = factory;
     originalQueryString = sqlQuery;
     this.context        = context;
 }
Ejemplo n.º 42
0
        private static void ValidateDataItems(AB_Root xmlData, IParserContext rawData)
        {
            var validator = new Ab1DataValidator(xmlData.Items.OfType <AB_RootData>().First().Tag);

            rawData.DataItems.ForEach(item => item.Accept(validator));
        }
Ejemplo n.º 43
0
 protected override string OnEvalExpression(ExpressionParser.Parser.ExpressionParser parser, TemplateToken templateToken, IParserContext context)
 {
     return(ReplaceEscapes(base.OnEvalExpression(parser, templateToken, context)));
 }
Ejemplo n.º 44
0
 void INativeXamlObject.HandleChildren(IParserContext context, XmlElement thisElement)
 {
     _xmlString = thisElement.InnerXml;
 }
Ejemplo n.º 45
0
 /// <summary>
 /// Removes event handlers
 /// </summary>
 /// <param name="context"></param>
 public void RemoveContext(IParserContext context)
 {
     PreParse  -= new PreParseEventHandler(context.PreParse);
     PostParse -= new PostParseEventHandler(context.PostParse);
 }
Ejemplo n.º 46
0
 public SQLQueryParser(string sqlQuery, IParserContext context)
 {
     originalQueryString = sqlQuery;
     this.context        = context;
 }
Ejemplo n.º 47
0
 public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
 {
     return(new StringConstantExpression(reader.GetAndMoveNext().Value));
 }
Ejemplo n.º 48
0
 public void StartInitialization(IParserContext context)
 {
 }
        public static IExpressionParser Identify(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            if (reader.Current.Type == TokenType.StringConstant)
            {
                return(new StringConstantExpressionParser());
            }

            if (LuaToken.IsIdentifier(reader.Current.Value) && reader.HasNext &&
                (reader.Next.Value == LuaToken.Dot || reader.Next.Value == LuaToken.LeftSquareBracket))
            {
                TableExpressionParserDiscriminator.Identify(reader, context);
            }

            if (reader.Current.Value == LuaToken.LeftBracket)
            {
                return(new BracketedExpressionParser());
            }
            if (LuaToken.IsIdentifier(reader.Current.Value) && reader.HasNext &&
                reader.Next.Value == LuaToken.LeftBracket)
            {
                return(new FunctionCallExpressionParser());
            }
            if (reader.Current.Type == TokenType.BooleanConstant)
            {
                return(new BooleanConstantExpressionParser());
            }
            if (LuaToken.IsIdentifier(reader.Current.Value))
            {
                return(new SingleVariableExpressionParser());
            }
            if (LuaToken.IsNumericConstant(reader.Current.Value))
            {
                return(new NumericConstantExpressionParser());
            }
            if (reader.Current.Value == LuaToken.LeftCurlyBrace)
            {
                return(new TableInitializerExpressionParser());
            }
            throw new UnexpectedTokenException(reader.Current);
        }
        public static IExpressionParser Identify(INextAwareEnumerator <Token> reader, IParserContext context)
        {
            var tableExpression = new TableIndexExpressionParser().Parse(reader, context);

            if (reader.HasNext && reader.Next.Value == LuaToken.LeftBracket)
            {
                return(new FunctionCallExpressionParser());
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 51
0
 public override ValueExpression Evaluate(IParserContext context)
 {
     return(Exp.Value(TokenPosition, new Converter <ClassName, Type>(GetTypeOfClassName)));
 }
 public LuaExpression Parse(INextAwareEnumerator <Token> reader, IParserContext context)
 {
     return(_expression);
 }
 public StandardServiceExpressionResolver()
 {
     _expressionParser = new SpelExpressionParser();
     _serviceExpressionParserContext = new ServiceExpressionParserContext(this);
 }
Ejemplo n.º 54
0
 void IEvaluableMarkupExtension.Initialize(IParserContext context)
 {
 }
 protected internal abstract IExpression DoParseExpression(string expressionString, IParserContext context);
Ejemplo n.º 56
0
 public ValueExpression Assign(IParserContext context, object value)
 {
     return(Evaluate(context, true, value));
 }
Ejemplo n.º 57
0
 public override void FinishInitialization(IParserContext context)
 {
     base.FinishInitialization(context);
     ResourceDictionary.RegisterUnmodifiableResourceDuringParsingProcess(this, context);
 }
Ejemplo n.º 58
0
 public override ValueExpression Evaluate(IParserContext context)
 {
     return(Evaluate(context, false, null));
 }
Ejemplo n.º 59
0
 static Delegate parser_GetEventHandler(IParserContext context, MethodInfo signature, string value)
 {
     throw new XamlBindingException("GetEventHandler delegate implementation not supported yet");
 }
Ejemplo n.º 60
0
        private ValueExpression Evaluate(IParserContext context, bool assign, object newValue)
        {
            ValueExpression targetValue = Target.Evaluate(context);
            object          targetObject;
            Type            targetType;

            if (targetValue.Value is ClassName)
            {
                targetType   = ((ClassName)targetValue.Value).Type;
                targetObject = null;
            }
            else
            {
                targetType   = targetValue.Type;
                targetObject = targetValue.Value;

                if (targetObject == null)
                {
                    return(new ValueExpression(TokenPosition, null, targetType));
                }
            }

            if (targetObject is IDynamicObject)
            {
                object value;
                Type   type;

                if (((IDynamicObject)targetObject).TryGetValue(Member, out value, out type))
                {
                    return(new ValueExpression(TokenPosition, value, type));
                }
            }

            MemberInfo[] members = FindMemberInHierarchy(targetType, Member);        // targetType.GetMember(_member);

            if (members.Length == 0)
            {
                PropertyInfo indexerPropInfo = targetType.Inspector().GetIndexer(new[] { typeof(string) });

                if (indexerPropInfo != null)
                {
                    return(new ValueExpression(TokenPosition, indexerPropInfo.GetValue(targetObject, new object[] { Member }), indexerPropInfo.PropertyType));
                }

                throw new UnknownPropertyException("Unknown property " + Member + " for object " + Target + " (type " + targetType.Name + ")", this);
            }

            if (members.Length >= 1 && members[0] is MethodInfo)
            {
                if (targetObject == null)
                {
                    return(Exp.Value(TokenPosition, new StaticMethod(targetType, Member)));
                }
                else
                {
                    return(Exp.Value(TokenPosition, new InstanceMethod(targetType, Member, targetObject)));
                }
            }

            MemberInfo member = members[0];

            if (members.Length > 1 && targetObject != null)     // CoolStorage, ActiveRecord and Dynamic Proxy frameworks sometimes return > 1 member
            {
                foreach (MemberInfo mi in members)
                {
                    if (mi.DeclaringType == targetObject.GetType())
                    {
                        member = mi;
                    }
                }
            }

            if (assign)
            {
                if (member is FieldInfo)
                {
                    ((FieldInfo)member).SetValue(targetObject, newValue);
                }

                if (member is PropertyInfo)
                {
                    ((PropertyInfo)member).SetValue(targetObject, newValue, null);
                }

                // Fall through to get the new property/field value below
            }

            if (member is FieldInfo)
            {
                return(new ValueExpression(TokenPosition, ((FieldInfo)member).GetValue(targetObject), ((FieldInfo)member).FieldType));
            }

            if (member is PropertyInfo)
            {
                return(new ValueExpression(TokenPosition, ((PropertyInfo)member).GetValue(targetObject, null), ((PropertyInfo)member).PropertyType));
            }

            throw new ExpressionEvaluationException(Member + " is not a field or property", this);
        }