public override void FinishInitialization(IParserContext context) { base.FinishInitialization(context); string path = Path ?? ""; _compiledPath = string.IsNullOrEmpty(path) ? null : PathExpression.Compile(context, path); }
public override void VisitPathExpression(PathExpression node) { // bracketed expressions are not evaluated in scope of the left-hand side if (node.Selector is BracketedExpression) { base.VisitPathExpression(node); return; } else { node.Expression.Accept(this); // result type of left-side expression is in scope after the dot. var oldPathScope = _binder._pathScope; _binder._pathScope = _binder.GetResultTypeOrError(node.Expression); try { node.Selector.Accept(this); } finally { _binder._pathScope = oldPathScope; } BindNode(node); } }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); PropertyAnimationTimeline t = (PropertyAnimationTimeline)source; _propertyExpression = t._propertyExpression; }
public override void FinishInitialization(IParserContext context) { base.FinishInitialization(context); string targetProperty = Storyboard.GetTargetProperty(this); _propertyExpression = String.IsNullOrEmpty(targetProperty) ? null : PathExpression.Compile(context, targetProperty); }
public override RxKqlScalarValue VisitPathExpression(PathExpression node) { return(new RxKqlScalarValue { Left = node.ToString().Trim().Replace(" . ", "_"), Right = node.Accept(new ScalarValueConverter()) }); }
void IEvaluableMarkupExtension.Initialize(IParserContext context) { if (_path == null) { throw new XamlBindingException("CommandBaseMarkupExtension: Path mustn't be null"); } _compiledPath = PathExpression.Compile(context, _path); }
public override ScalarValue VisitPathExpression(PathExpression node) { return(new ScalarPath { Element = node.Expression.Accept(this), Selector = node.Selector.Accept(this) }); }
void IInitializable.FinishInitialization(IParserContext context) { if (_path == null) { throw new XamlBindingException("{0}: Path mustn't be null", GetType().Name); } _compiledPath = PathExpression.Compile(context, _path); ResourceDictionary.RegisterUnmodifiableResourceDuringParsingProcess(this, context); }
public override void VisitPathExpression(PathExpression node) { base.VisitPathExpression(node); // expressions on right-hand side of a dot have path scope if (_position >= node.Selector.TriviaStart) { _binder._pathScope = node.Expression.ResultType; } }
protected override System.Linq.Expressions.Expression VisitPathExpression(PathExpression pex) { return(System.Linq.Expressions.Expression.Call( System.Linq.Expressions.Expression.Constant(this), #if netstandard new Func <BindingContext, string, object>(ResolvePath).GetMethodInfo(), #else new Func <BindingContext, string, object>(ResolvePath).Method, #endif CompilationContext.BindingContext, System.Linq.Expressions.Expression.Constant(pex.Path))); }
public void PathExpressionConstructorWorks() { // Arrange string name = "anyValue"; // Act var path = new PathExpression(name); // Assert Assert.Equal("path.anyValue", path.Expression); Assert.Equal("anyValue", path.Name); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); CommandBaseMarkupExtension cbme = (CommandBaseMarkupExtension) source; _source.Source = copyManager.GetCopy(cbme._source.Source); _source.ElementName = cbme._source.ElementName; _source.RelativeSource = cbme._source.RelativeSource; _path = cbme._path; _compiledPath = cbme._compiledPath; _source.Converter = copyManager.GetCopy(cbme._source.Converter); _source.ConverterParameter = copyManager.GetCopy(cbme._source.ConverterParameter); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); CommandBaseMarkupExtension cbme = (CommandBaseMarkupExtension)source; _source.Source = copyManager.GetCopy(cbme._source.Source); _source.ElementName = cbme._source.ElementName; _source.RelativeSource = cbme._source.RelativeSource; _path = cbme._path; _compiledPath = cbme._compiledPath; _source.Converter = copyManager.GetCopy(cbme._source.Converter); _source.ConverterParameter = copyManager.GetCopy(cbme._source.ConverterParameter); }
private Object evalNewExpression(Object context, NewExpression expression) { CallExpression ctorCallExp; Prototype prototype; if (expression.ctorCall is CallExpression ctorCall) { string typeName = ctorCall.Function.Literal; Object prototypeObj = ExecutionContext.Peek()[typeName]; if (prototypeObj is not Prototype) { throw new System.Exception("The object named \"" + typeName + "\" is not a type"); } ctorCallExp = ctorCall; prototype = prototypeObj as Prototype; } else { // is PathExpression PathExpression typePath = expression.ctorCall as PathExpression; List <Expression> path = typePath.Path; Expression pathCall = path[path.Count - 1]; if (pathCall is not CallExpression) { throw new System.Exception("Need a type"); } // get the parent of prototype PathExpression parentPath = typePath.SubPath(0, -1); Object parent = Eval(ExecutionContext.Peek(), parentPath); ctorCallExp = pathCall as CallExpression; if (parent[ctorCallExp.Function.Literal] is Prototype prototypeTarget) { prototype = prototypeTarget; } else { throw new System.Exception("Need a type"); } } Prototype type = prototype; List <Object> callParams = new List <Object>(); foreach (Expression param in ctorCallExp.Parameters) { callParams.Add(Eval(ExecutionContext.Peek(), param)); } return(type.Create(callParams)); }
public ObjectExpression evalPathExpression(PathExpression exp) { if (exp is VariableExpression) { return(variables[((VariableExpression)exp).name]); } /*else if (exp is MemberAccessExpression) * { * memberExp = (MemberAccessExpression)exp; * }*/ //erreur return(null); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { Detach(); base.DeepCopy(source, copyManager); BindingMarkupExtension bme = (BindingMarkupExtension)source; Source = copyManager.GetCopy(bme.Source); ElementName = bme.ElementName; RelativeSource = bme.RelativeSource; CheckTypeOfSource(); Path = bme.Path; Mode = bme.Mode; UpdateSourceTrigger = bme.UpdateSourceTrigger; Converter = copyManager.GetCopy(bme.Converter); ConverterParameter = copyManager.GetCopy(bme.ConverterParameter); _compiledPath = bme._compiledPath; Attach(); }
public override void VisitPathExpression(PathExpression node) { node.Expression.Accept(this); // result type of left-side expression is in scope after the dot. var oldPathScope = _binder._pathScope; _binder._pathScope = _binder.GetResultTypeOrError(node.Expression); try { node.Selector.Accept(this); } finally { _binder._pathScope = oldPathScope; } BindNode(node); }
public TestedParameter( SemanticModel model, ExpressionSyntax expression ) { Expression = expression; if( expression == null ) { Name = Case.NoParameter; Path = Name; return; } if( model.GetConstantValue( Expression ).Value is string result ) { Name = result; Path = Name; return; } // Lambda? if( !( Expression is ParenthesizedLambdaExpressionSyntax lambda ) ) { Name = Case.NoParameter; Path = Name; return; } IsLambda = true; var parameter = lambda.ParameterList.Parameters[ 0 ]; Type = (ITypeSymbol)model.GetSymbol( parameter.Type ); Name = parameter.Identifier.Text; Path = Name; PathExpression = lambda.Body as ExpressionSyntax; if( PathExpression == null ) PathHasErrors = true; else { var pathVisitor = new PathVisitor( Name ); pathVisitor.Visit( PathExpression ); PathHasErrors = pathVisitor.HasErrors; Path = PathHasErrors ? PathExpression.ToString() : pathVisitor.PathStr; } }
void IEvaluableMarkupExtension.Initialize(IParserContext context) { string localName; string namespaceURI; context.LookupNamespace(_typeName, out localName, out namespaceURI); Type type = context.GetNamespaceHandler(namespaceURI).GetElementType(localName); IDataDescriptor result; try { if (PathExpression.Compile(context, _staticMemberName).Evaluate( new ValueDataDescriptor(type), out result)) { _value = result.Value; } } catch (XamlBindingException e) { ServiceRegistration.Get <ILogger>().Warn("Error evaluating Static markup", e); } }
public void VisitPathExpression(PathExpression pathExpr) { throw new NotImplementedException(); }
internal static LogicalExpression <TSource> CompileLogicalExpression <TSource, TToken>(string text, Func <string, TToken> pathToken) where TToken : Token <TSource> { LogicalExpression <TSource> result = null; var whereMatch = parser.Match(text); if (whereMatch == null || !whereMatch.Success) { throw new ArgumentException("Invalid expression \"" + text + "\"."); } var exprCaptures = whereMatch.Groups["expr"].Captures; var nextCaptures = whereMatch.Groups["next"].Captures; AndExpressionGroup <TSource> andGroup = null; for (var i = 0; i < exprCaptures.Count; i++) { var exprText = exprCaptures[i].Value.Trim(); var nextText = nextCaptures[i].Value.Trim(); IEvaluate <TSource> expr; if (Regex.IsMatch(exprText, @"^\(.*\)$")) { expr = CompileLogicalExpression <TSource, TToken>(exprText.Substring(1, exprText.Length - 2), pathToken); } else { var exprMatch = exprParser.Match(exprText); if (exprMatch == null || !exprMatch.Success) { throw new Exception("Invalid expression \"" + exprText + "\"."); } var leftText = exprMatch.Groups["left"].Value.Trim(); var opText = exprMatch.Groups["op"].Value.Trim(); var rightText = exprMatch.Groups["right"].Value.Trim(); if (string.IsNullOrEmpty(opText)) { // No operator, so this is a truthy property or constant check. object value; if (JavaScriptHelpers.TryParseConstant(leftText, out value)) { expr = new TruthyConstantExpression <TSource>(new ConstantToken <TSource>(value)); } else { expr = new PathExpression <TSource>(pathToken(leftText)); } } else { // Parse the comparison operator. LogicalOperator op = ParseLogicalOperator(opText); // Parse the left-hand token. Token <TSource> leftToken; object leftValue; if (JavaScriptHelpers.TryParseConstant(leftText, out leftValue)) { leftToken = new ConstantToken <TSource>(leftValue); } else { leftToken = pathToken(leftText); } // Parse the right-hand token. Token <TSource> rightToken; object rightValue; if (JavaScriptHelpers.TryParseConstant(rightText, out rightValue)) { rightToken = new ConstantToken <TSource>(rightValue); } else { rightToken = pathToken(rightText); } // Create the expression from "left op right". expr = new CompareExpression <TSource>(leftToken, op, rightToken); } } if (nextText == "&&" && andGroup == null) { // There is currently no active and group and the next expression // will be "ANDed", so start a new and group, beginning with this expression. andGroup = AndExpressionGroup <TSource> .Begin(expr); } else if (andGroup != null) { // There is an active and group expression, so add this expression to it. andGroup.And(expr); } else if (result != null) { // There is currently a result, so or it with this expression. result = result.Or(expr); } else { // There is currently no result, so use this expression as the result. result = new TruthyExpressionWrapper <TSource>(expr); } // Add the existing group if we have reached the end of the expression, or the next expression will be "ORed". if ((string.IsNullOrEmpty(nextText) || nextText == "||") && andGroup != null) { if (result == null) { result = andGroup; } else { result = result.Or(andGroup); } andGroup = null; } } return(result); }
AstType ConvertPathToType(PathExpression path) { AstType type = null; foreach(var item in path.Items){ item.Remove(); if(type == null) type = AstType.MakeSimpleType(item, TextLocation.Empty); else type = AstType.MakeMemberType(type, AstType.MakeSimpleType(item, TextLocation.Empty), TextLocation.Empty); } return type; }
public VariableUpdate(PathExpression varPath, Token.TokenValue opUpdate) { this.variable = varPath; this.op = opUpdate; }
public ObjectExpression evalPathExpression(PathExpression exp) { if (exp is VariableExpression) { return variables[((VariableExpression)exp).name]; } /*else if (exp is MemberAccessExpression) { memberExp = (MemberAccessExpression)exp; }*/ //erreur return null; }
IContentExpression ParseExpression(Queue <DslToken> q, Func <DslToken, bool> terminate) { IContentExpression exp = null; while (q.Count > 0) { var lookAhead = q.Peek(); if (terminate(lookAhead)) { break; } else if (lookAhead.IsConstant()) { if (exp != null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(Utils.ConstantTokens); exp = CreateConstant(token); } else if (lookAhead.TokenType == TokenType.Equals) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.Equals); exp = new EqualToFilter(exp, ParseExpression(q, t => t.TokenType == TokenType.And || t.TokenType == TokenType.Or || terminate(t))); } else if (lookAhead.TokenType == TokenType.Contains) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.Contains); exp = new ContainsFilter(exp, ParseExpression(q, t => t.TokenType == TokenType.And || t.TokenType == TokenType.Or || terminate(t))); } else if (lookAhead.TokenType == TokenType.MatchRegex) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.MatchRegex); var pattern = q.DequeueAndValidate(TokenType.String); exp = new RegexFilter(exp, pattern.Value); } else if (lookAhead.TokenType == TokenType.And) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.And); if (exp is IContentFilter leftBool) { var right = ParseExpression(q, terminate); if (right is IContentFilter rightBool) { exp = new AndFilter(leftBool, rightBool); } else { throw new ParserException("AND cannot have a right operand that does not yield boolean", token); } } else { throw new ParserException("AND cannot have a left operand that does not yield boolean", token); } } else if (lookAhead.TokenType == TokenType.Or) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.Or); if (exp is IContentFilter leftBool) { var right = ParseExpression(q, terminate); if (right is IContentFilter rightBool) { exp = new OrFilter(leftBool, rightBool); } else { throw new ParserException("OR cannot have a right operand that does not yield boolean", token); } } else { throw new ParserException("OR cannot have a left operand that does not yield boolean", token); } } else if (lookAhead.TokenType == TokenType.Path) { if (exp == null) { throw new ParserException($"Unexpected token", lookAhead); } var token = q.DequeueAndValidate(TokenType.Path); exp = new PathExpression(exp, ContentPath.Parse($"$.{token.Value.TrimStart('.')}")); } else if (lookAhead.TokenType == TokenType.DollarSign) { if (exp != null) { throw new ParserException($"Unexpected token", lookAhead); } q.DequeueAndValidate(TokenType.DollarSign); exp = new ScopeRootExpression(); } else if (lookAhead.TokenType == TokenType.OpenCurly) { if (exp != null) { throw new ParserException($"Unexpected token", lookAhead); } exp = CreateObjectExpression(q); } else if (lookAhead.TokenType == TokenType.OpenSquareBracket) { if (exp != null) { throw new ParserException($"Unexpected token", lookAhead); } exp = CreateListExpression(q); } else if (lookAhead.TokenType == TokenType.OpenBracket) { if (exp != null) { throw new ParserException($"Unexpected token", lookAhead); } q.DequeueAndValidate(TokenType.OpenBracket); // open bracket ( exp = ParseExpression(q, t => t.TokenType == TokenType.CloseBracket); q.DequeueAndValidate(TokenType.CloseBracket); // close bracket ) } else { throw new ParserException($"Unexpected token", lookAhead); } } if (exp == null) { throw new ParserException($"Unexpected end", null); } return(exp); }
public override T VisitPathExpression(PathExpression node) { throw new NotImplementedException(); }
void PathExpression(out PathExpression path) { var paths = new List<Identifier>(); Expect(14); paths.Add(AstNode.MakeIdentifier(t.val, CurrentLocation)); while (la.kind == 5) { Get(); Expect(14); paths.Add(AstNode.MakeIdentifier(t.val, CurrentLocation)); } var last_ident = paths.Last(); last_ident.Type = new PlaceholderType(TextLocation.Empty); path = Expression.MakePath(paths); }
/// <summary> /// Creates a new <see cref="PropertyAnimationTimeline"/> for use in Code. /// </summary> public PropertyAnimationTimeline(PathExpression animatePropertyExpression) : this() { _propertyExpression = animatePropertyExpression; }
public override List <RxKqlScalarValue> VisitPathExpression(PathExpression node) { throw new NotImplementedException(); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { Detach(); base.DeepCopy(source, copyManager); BindingMarkupExtension bme = (BindingMarkupExtension) source; Source = copyManager.GetCopy(bme.Source); ElementName = bme.ElementName; RelativeSource = bme.RelativeSource; CheckTypeOfSource(); Path = bme.Path; Mode = bme.Mode; UpdateSourceTrigger = bme.UpdateSourceTrigger; Converter = copyManager.GetCopy(bme.Converter); ConverterParameter = copyManager.GetCopy(bme.ConverterParameter); _compiledPath = bme._compiledPath; Attach(); }
public DeferredBlockAccumulatorContext(Expression startingNode) : base(startingNode) { startingNode = UnwrapStatement(startingNode); _startingNode = (PathExpression)startingNode; }
protected virtual System.Linq.Expressions.Expression VisitPathExpression(PathExpression pex) { return(pex); }
/// <summary> /// Creates a new <see cref="PropertyAnimationTimeline"/> for use in Code. /// </summary> public PropertyAnimationTimeline(PathExpression animatePropertyExpression): this() { _propertyExpression = animatePropertyExpression; }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { base.DeepCopy(source, copyManager); PropertyAnimationTimeline t = (PropertyAnimationTimeline) source; _propertyExpression = t._propertyExpression; }
protected virtual Expression VisitPathExpression(PathExpression pex) { return(pex); }
public override object Visit(PathExpression that, object value) { Storage index = new TemporaryStorage(CreateTemporary()); switch (that.PathKind) { case PathKind.Absolute: break; case PathKind.Instance: //_writer.Write("_"); break; case PathKind.Relative: break; } _writer.Write(index.ToString() + " = "); that.Expression.Visit(this); _writer.WriteLine(); return (object) index; }
public DeferredBlockAccumulatorContext(Expression startingNode) { _startingNode = (PathExpression)UnwrapStatement(startingNode); }
void IEvaluableMarkupExtension.Initialize(IParserContext context) { if (_path == null) throw new XamlBindingException("CommandBaseMarkupExtension: Path mustn't be null"); _compiledPath = PathExpression.Compile(context, _path); }
public void VisitPathExpression(PathExpression pathExpr) { // Side effect: After exiting this method, the symbol_table field will be set to // the type table corresponding to the most descendant type the path represents. if(pathExpr.Items.Count == 1){ pathExpr.AsIdentifier.AcceptWalker(this); }else{ while(symbol_table.Parent != null) symbol_table = symbol_table.Parent; foreach(var ident in pathExpr.Items){ ident.AcceptWalker(this); symbol_table = symbol_table.GetTypeTable(ident.Name); } } }
private static bool IsSectionOrClosingNode(PathExpression pathExpression) { return((pathExpression != null) && pathExpression.Path.IndexOfAny(new[] { '#', '/', '^' }) == 0); }