Пример #1
0
 static LiteralConversion FromNumberLiteral(byte[] dest, INumberLiteral numberLiteral)
 {
     if (numberLiteral.FitsUnsigned(byteCount: 8))
     {
         Array.Copy(numberLiteral.ToUnsigned(byteCount: 8), dest, length: 8);
         return(LiteralConversion.Ok);
     }
     return(LiteralConversion.Failed);
 }
Пример #2
0
        public string TypeToSuffix(INumberLiteral numberLiteral)
        {
            if (!numberLiteral.HasExplicitTypeModifier)
            {
                return(string.Empty);
            }

            else
            {
                Type     type     = numberLiteral.Value.GetType();
                TypeCode typeCode = Type.GetTypeCode(type);

                try
                {
                    return(typeCodeToSuffix[typeCode]);
                }
                catch (KeyNotFoundException)
                {
                    throw new UnparseException(string.Format("Type suffix not found for type: {0}", typeCode));
                }
            }
        }
Пример #3
0
        public IEnumerable <UtokenValue> NumberLiteralToText(UnparsableAst reference, IFormatProvider formatProvider)
        {
            INumberLiteral numberLiteral = (INumberLiteral)reference.AstValue;

            string prefix = BaseToPrefix(numberLiteral.Base);
            string body   = NumberToText(numberLiteral.Value, (int)numberLiteral.Base, formatProvider, numberLiteral.HasExplicitTypeModifier);
            string suffix = TypeToSuffix(numberLiteral);

            if (!string.IsNullOrEmpty(prefix))
            {
                yield return(UtokenValue.CreateText(prefix, reference).SetDiscriminator(Formatter.NumberLiteralBasePrefix));

                yield return(UtokenValue.NoWhitespace());
            }

            yield return(UtokenValue.CreateText(body, reference).SetDiscriminator(Formatter.NumberLiteralContent));

            if (!string.IsNullOrEmpty(suffix))
            {
                yield return(UtokenValue.NoWhitespace());

                yield return(UtokenValue.CreateText(suffix, reference).SetDiscriminator(Formatter.NumberLiteralTypeModifierSuffix));
            }
        }
Пример #4
0
            private void CrazySyntaxHighlight(Utoken utoken, UnparsableAst target, IDecoration decoration)
            {
                if (target.AstValue is D.Color)
                {
                    Color color;

                    if (Enum.TryParse <Color>(target.AstValue.ToString(), out color))
                    {
                        decoration
                        .Add(DecorationKey.Background, color)
                        ;

                        if (color.EqualToAny(Color.Black, Color.Blue, Color.Green, Color.Red))
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.White)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Black)
                            ;
                        }
                    }
                }
                else if (utoken.Discriminator == CommentContent)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Pink)
                    .Add(DecorationKey.TextDecoration, TextDecoration.Strikethrough)
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    ;
                }
                else if (utoken.Discriminator == CommentStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Yellow)
                    .Add(DecorationKey.Background, Color.Violet)
                    ;
                }
                else if (utoken.Discriminator == CommentEndSymbol)
                {
                    decoration
                    .Add(DecorationKey.Foreground, Color.Blue)
                    .Add(DecorationKey.Background, Color.Yellow)
                    ;
                }
                else if (utoken.Discriminator == StringLiteralStartSymbol)
                {
                    decoration
                    .Add(DecorationKey.FontSizeRelativePercent, 2)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Blue)
                    ;
                }
                else if (target.AstValue is D.If)
                {
                    if (target.BnfTerm == B.LEFT_PAREN)
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.FontSizeRelativePercent, 2)
                        .Add(DecorationKey.Foreground, Color.Blue)
                        ;
                    }
                    else
                    {
                        decoration
                        .Add(DecorationKey.FontWeight, FontWeight.Bold)
                        .Add(DecorationKey.TextDecoration, TextDecoration.Underline)
                        ;
                    }
                }
                else if (target.BnfTerm == B.PROGRAM)
                {
                    decoration
                    .Add(DecorationKey.FontStyle, FontStyle.Italic)
                    .Add(DecorationKey.Foreground, Color.Red)
                    .Add(DecorationKey.Background, Color.Yellow)
                    .Add(DecorationKey.FontSize, 30);
                }
                else if (target.AstValue is D.Type)
                {
                    decoration
                    .Add(DecorationKey.BaselineAlignment, BaselineAlignment.Subscript)
                    .Add(DecorationKey.FontSizeRelativePercent, 0.75);
                }
                else if (target.AstValue is INumberLiteral)
                {
                    INumberLiteral number = (INumberLiteral)target.AstValue;

                    if (number.Value is int)
                    {
                        if (((int)number.Value) % 2 == 0)
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Red)
                            ;
                        }
                        else
                        {
                            decoration
                            .Add(DecorationKey.Foreground, Color.Green)
                            .Add(DecorationKey.Background, Color.Yellow)
                            ;
                        }
                    }
                }
            }
Пример #5
0
        public string TypeToSuffix(INumberLiteral numberLiteral)
        {
            if (!numberLiteral.HasExplicitTypeModifier)
                return string.Empty;

            else
            {
                Type type = numberLiteral.Value.GetType();
                TypeCode typeCode = Type.GetTypeCode(type);

                try
                {
                    return typeCodeToSuffix[typeCode];
                }
                catch (KeyNotFoundException)
                {
                    throw new UnparseException(string.Format("Type suffix not found for type: {0}", typeCode));
                }
            }
        }
Пример #6
0
 // ReSharper disable once UnusedParameter.Local
 static string Dynamic(INumberLiteral numberLiteral, ICppScope scope)
 {
     return(numberLiteral.IntegerPart);
 }
Пример #7
0
 void AssertExpression(INumberLiteral expected, INumberLiteral actual, string label)
 {
     Assert.AreEqual(expected.IntegerPart, actual.IntegerPart, $"{label}.IntegerPart");
 }