Beispiel #1
0
 /// <summary>
 /// 格式化code
 /// </summary>
 /// <returns></returns>
 protected override string FormatCode()
 {
     return(CodeString.Trim().Replace("{{#elseif", ""));
 }
Beispiel #2
0
 /// <summary>
 /// 格式化
 /// </summary>
 /// <returns></returns>
 protected virtual string FormatCode()
 {
     return(CodeString.Trim().Replace("{{#if", ""));
 }
Beispiel #3
0
        public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret)
        {
            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            var OldCode   = Code;
            var State     = Plugin.State;
            var Container = Plugin.Container;
            var Global    = Container.GlobalContainer;

            var RadixSpecified = false;
            var Radix          = 10;

            var Sign = RecognizerHelper.GetSign(ref Code);

            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            if (AtStartStrings != null)
            {
                var Result = Code.StartsWith(AtStartStrings, Skip);
                if (Result.Index != -1)
                {
                    Code = Code.TrimmedSubstring(State, Result.String.Length);
                    if (!Code.IsValid)
                    {
                        return(ExprRecResult.Failed);
                    }

                    RadixSpecified = true;
                    Radix          = AtStart[Result.Index].Radix;
                }
            }

            if (AtEndStrings != null)
            {
                var Result = Code.EndsWith(AtEndStrings, Skip);
                if (Result.Index != -1)
                {
                    if (Radix != -1)
                    {
                        State.Messages.Add(MessageId.MultipleRadix, Code);
                        return(ExprRecResult.Failed);
                    }

                    Code = Code.TrimmedSubstring(State, Result.String.Length);
                    if (!Code.IsValid)
                    {
                        return(ExprRecResult.Failed);
                    }

                    RadixSpecified = true;
                    Radix          = AtStart[Result.Index].Radix;
                }
            }

            if (RecognizerHelper.GetSign(ref Code))
            {
                Sign = !Sign;
            }
            if (Code.Length == 0 || (!char.IsDigit(Code[0]) && !RadixSpecified))
            {
                return(ExprRecResult.Unknown);
            }

            var Options = new ConvStrToNumberOptions();
            var Type    = TypeExtractor(Container, ref Code);

            if (Type == null)
            {
                Options.Type = ConstValueType.Unknown;
            }
            else
            {
                var RType = Type.RealId as Type;
                Options.Type = RType.ConstValueType;
            }

            Code = Code.Trim();
            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            Options.Radix           = Radix;
            Options.Number          = Code.String;
            Options.LetterCase      = LetterCase.OnlyUpper;
            Options.EnableENotation = true;
            Options.Sign            = Sign;

            ConstValue Value;
            var        Res = RecognizerHelper.ConvStrToNumber(State, Code, Options, out Value);

            if (Res == SimpleRecResult.Unknown)
            {
                return(ExprRecResult.Unknown);
            }
            else if (Res == SimpleRecResult.Failed)
            {
                return(ExprRecResult.Failed);
            }

            if (Type == null)
            {
                Type = Constants.GetDefaultType(Container, Value.Type);
                if (Type.RealId is NumberType && !Value.CheckBounds(Type))
                {
                    var SystemType = Type.GetType();

                    do
                    {
                        var RType = Type.RealId as Type;
                        Type = Global.CommonIds.GetIdentifier(SystemType, RType.Size * 2);

                        if (Type == null)
                        {
                            if (typeof(SignedType).IsEquivalentTo(SystemType))
                            {
                                Type = Global.CommonIds.GetLargestType(typeof(UnsignedType));
                            }
                            else
                            {
                                Type = Global.CommonIds.GetLargestType(typeof(SignedType));
                            }
                            break;
                        }
                    } while (!Value.CheckBounds(Type));
                }
            }

            if (!Value.CheckBounds(State, Type, OldCode))
            {
                return(ExprRecResult.Failed);
            }

            var Flags = Options.Type == ConstValueType.Unknown ?
                        ExpressionFlags.AutoConvert : ExpressionFlags.None;

            Ret = new ConstExpressionNode(Type, Value, OldCode, Flags);
            return(ExprRecResult.Succeeded);
        }