public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect dialect, TextManager manager)
        {
            if (spec.ParameterName.StartsWith("@"))
            {
                return(new PatternLookupEvaluator
                {
                    Manager = manager,
                    PatternKey = spec.ParameterName.Substring(1),
                    Parameters = spec.Arguments != null?spec.Arguments.Split(',')
                                 .Select(x =>
                    {
                        var parts = x.Trim().Split(':');
                        if (parts.Length > 1)
                        {
                            return new KeyValuePair <string, IValueFormatter>(parts[0], dialect.GetValueFormatter(parts[1], manager));
                        }
                        else
                        {
                            return new KeyValuePair <string, IValueFormatter>(parts[0], null);
                        }
                    }).ToArray() : new KeyValuePair <string, IValueFormatter> [0]
                });
            }

            return(null);
        }
예제 #2
0
        public override void Visit(ParameterSpec spec, object state)
        {
            spec.Evaluator = _dialect.GetParameterEvaluator(spec, _manager);
            spec.Formatter = _dialect.GetValueFormatter(spec.ParameterFormat, _manager);


            base.Visit(spec, null);
        }
예제 #3
0
        private FeatureSpec HandleFeatures()
        {
            if (!ThisToken().Match(TokenTypes.Features))
            {
                return(new NoneFeature
                {
                    BeginPosition = ThisToken().TokenBeginIdx,
                    EndPosition = ThisToken().TokenBeginIdx
                });
            }

            Consume();
            FeatureSpec spec = null;

            TryParseAndResumeToToken(() =>
            {
                if (ThisToken().Match(TokenTypes.None))
                {
                    spec = new NoneFeature
                    {
                        BeginPosition = ThisToken().TokenBeginIdx,
                    };

                    Consume();
                    return;
                }

                // IOType 可能有两个 Token,所以要考虑这两种情况
                if (LookAhead(3).Match(TokenTypes.Parameter) || LookAhead(4).Match(TokenTypes.Parameter))
                {
                    var parameterSpec = new ParameterSpec
                    {
                        BeginPosition = ThisToken().TokenBeginIdx,
                    };
                    spec = parameterSpec;
                    HandleParameterSpec(parameterSpec);
                }
                else
                {
                    var portSpec = new PortSpec
                    {
                        BeginPosition = ThisToken().TokenBeginIdx,
                    };
                    spec = portSpec;
                    HandlePortSpec(portSpec);
                }
            }, TokenTypes.Semicolon);

            var token = ConsumeType(TokenTypes.Semicolon);

            if (spec != null)
            {
                spec.EndPosition = token.TokenEndIdx;
            }

            return(spec);
        }
예제 #4
0
        public virtual IParameterEvaluator GetParameterEvaluator(ParameterSpec spec, TextManager manager)
        {
            IParameterEvaluator evaluator = null;
            if (!ParameterEvaluators.Any(x => (evaluator = x.GetFor(spec, this, manager)) != null))
            {
                throw new LocalizedKeyNotFoundException("Exceptions.ParameterEvaluatorNotFound", "No parameter evaluator found for {0}", new { Text = spec });
            }

            return evaluator;
        }
        public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect dialect, TextManager manager)
        {
            var parts = spec.ParameterName.Split('.');
            if (parts.Length > 1)
            {
                return new ReflectionParameterEvaluator(parts[0], parts.Skip(1).ToArray());
            }

            return null;
        }
예제 #6
0
        public virtual IParameterEvaluator GetParameterEvaluator(ParameterSpec spec, TextManager manager)
        {
            IParameterEvaluator evaluator = null;

            if (!ParameterEvaluators.Any(x => (evaluator = x.GetFor(spec, this, manager)) != null))
            {
                throw new LocalizedKeyNotFoundException("Exceptions.ParameterEvaluatorNotFound", "No parameter evaluator found for {0}", new { Text = spec });
            }

            return(evaluator);
        }
예제 #7
0
        public override void Visit(ParameterSpec spec, JavaScriptExpressionCheckerState state)
        {
            RegisterWriter(spec.Evaluator.GetType(), typeof(IParameterEvaluator), state);

            if (spec.Formatter != null)
            {
                RegisterWriter(spec.Formatter.GetType(), typeof(IValueFormatter), state);
            }

            base.Visit(spec, state);
        }
예제 #8
0
        public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect dialect, TextManager manager)
        {
            var parts = spec.ParameterName.Split('.');

            if (parts.Length > 1)
            {
                return(new ReflectionParameterEvaluator(parts[0], parts.Skip(1).ToArray()));
            }

            return(null);
        }
예제 #9
0
        public override INode DoResolve(ResolveContext rc)
        {
            var ps = rc.Resolver.ResolveParameter(Name);

            if (ps != null)
            {
                ResolveContext.Report.Error(105, Location, "duplicate parameter definition '" + Name + "'");
            }

            ParameterName = new ParameterSpec(Name, rc.CurrentMethod, Location, 4, IsVariable);

            rc.KnowVar(ParameterName);
            return(base.DoResolve(rc));
        }
예제 #10
0
        protected bool CheckParameters(IList <IParameter> parameters, ResolveContext rc)
        {
            bool error = false;

            for (int i = 0; i < parameters.Count; ++i)
            {
                ParameterSpec p = parameters[i] as ParameterSpec;

                if (p.IsOptional && ((ResolvedEntity as IMember).IsExplicitInterfaceImplementation || this is OperatorDeclaration || (this is IndexerDeclaration && parameters.Count == 1)))
                {
                    rc.Report.Warning(1066, 1, Location,
                                      "The default value specified for optional parameter `{0}' will never be used",
                                      Name);
                }

                if (this.ResolvedEntity.IsAccessibleAs(p.Type))
                {
                    continue;
                }

                IType t = p.Type;

                if (this is IndexerDeclaration)
                {
                    rc.Report.Error(55, Location,
                                    "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
                                    t.ToString(), GetSignatureForError());
                }
                else if (this is OperatorDeclaration)
                {
                    rc.Report.Error(57, Location,
                                    "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
                                    t.ToString(), GetSignatureForError());
                }
                else
                {
                    rc.Report.Error(51, Location,
                                    "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
                                    t.ToString(), GetSignatureForError());
                }
                error = true;
            }
            return(!error);
        }
예제 #11
0
        private void HandleParameterSpec(ParameterSpec spec)
        {
            TryParseAndResumeToToken(() =>
            {
                // identifier
                spec.Identifier = ConsumeType(TokenTypes.Identifier);
            }, TokenTypes.SingleColon);

            TryParseAndResumeToToken(() =>
            {
                ConsumeType(TokenTypes.SingleColon);
                spec.IoType = HandleIoType(spec);
            }, TokenTypes.Parameter);

            ConsumeType(TokenTypes.Parameter);

            spec.Reference    = TryHandleReferenceOrNone();
            spec.Associations = TryHandleAssociationBlock();
        }
        public override void Visit(ParameterSpec spec, JavaScriptExpressionWriterState state)
        {
            var evaulator = Writers[spec.Evaluator.GetType()];

            Output.Write("(function(){var v=");
            evaulator.WriteEvaluator(spec.Evaluator, this, null);
            Output.Write(";return af(v,"); //Apply format
            if (spec.Formatter != null)
            {
                var formatter = Writers[spec.Formatter.GetType()];
                formatter.WriteEvaluator(spec.Formatter, this, () => {
                    Output.Write("val(");
                    evaulator.WriteEvaluator(spec.Evaluator, this, null);
                    Output.Write(")");
                });
            }
            else
            {
                Output.Write(Json.Serialize("") + "+val(v)");
            }
            Output.Write(",true);})()");
        }
        public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect dialect, TextManager manager)
        {                        
            
            if( spec.ParameterName.StartsWith("@") )
            {
                return new PatternLookupEvaluator
                {
                    Manager = manager,
                    PatternKey = spec.ParameterName.Substring(1),
                    Parameters = spec.Arguments != null ? spec.Arguments.Split(',')
                        .Select(x =>
                        {
                            var parts = x.Trim().Split(':');
                            if (parts.Length > 1)
                            {
                                return new KeyValuePair<string, IValueFormatter>(parts[0], dialect.GetValueFormatter(parts[1], manager));
                            }
                            else
                            {
                                return new KeyValuePair<string, IValueFormatter>(parts[0], null);
                            }
                        }).ToArray() : new KeyValuePair<string, IValueFormatter>[0]
                };
            }

            return null;
        }
예제 #14
0
 public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect pattern, TextManager manager)
 {
     return(_factory(spec, pattern, manager));
 }
 public IParameterEvaluator GetFor(ParameterSpec spec, PatternDialect pattern, TextManager manager)
 {
     return _factory(spec, pattern, manager);
 }
예제 #16
0
 public void Visit(ParameterSpec spec, object state)
 {
     Print("PSpec = " + spec.ParameterName + "  :  " + spec.ParameterFormat);
 }
예제 #17
0
            public override void Visit(ParameterSpec spec, State state)
            {
                state.Writer.Write(GetParameterValue(spec.Evaluator.GetValue(state.Context), spec.Formatter, state));

                base.Visit(spec, state);
            }
 public IParameterEvaluator GetFor(ParameterSpec spelling, PatternDialect dialect, TextManager manager)
 {
     return(new SimpleParameterEvaluator(spelling.ParameterName));
 }
        ParameterSpec ParseParameterSpec()
        {
            //PRE: !EOF && _current == '{'
            var spec = new ParameterSpec();

            MoveNext(); //Take '{'

            var lparen = LookAheadFor(StartersParameterNameArgs);
            if (lparen == '(')
            {
                spec.ParameterName = ReadText("(");
                MoveNext(); //Take '('
                spec.Arguments = ReadText(StoppersParameterNameArgs);
                MoveNext(); //Take ')'
            }
            else
            {
                spec.ParameterName = ReadParameterName();
            }
            if (_current == ':')
            {
                MoveNext(); //Take it
                spec.ParameterFormat = ReadParameterFormat();
            }
            else
            {
                spec.ParameterFormat = "";
            }

            if (_current != '}') ExpectedToken("ParameterSpec", "}");

            MoveNext(); //Take '}';

            return spec;
        }
 public IParameterEvaluator GetFor(ParameterSpec spelling, PatternDialect dialect, TextManager manager)
 {
     return new SimpleParameterEvaluator(spelling.ParameterName);
 }
예제 #21
0
 public virtual void Visit(ParameterSpec spec, T state)
 {
 }
예제 #22
0
 public override string ToString()
 {
     return(ParameterSpec.ToString(this));
 }
예제 #23
0
 private static bool PropertiesAreEquivalent(PropertyInfo propertyInfo, ParameterSpec x)
 {
     return(propertyInfo == x.PropertyInfo ||
            propertyInfo.GetBaseDefinition() == x.PropertyInfo.GetBaseDefinition());
 }