Beispiel #1
0
 public DataRow MakeVariable(string name, DataType datatype)
 {
     return(DataRow.Create(Table.Heading, new TypedValue[]
                           { TextValue.Create(name),
                             TextValue.Create(datatype.BaseType.Name),
                             TextValue.Create(datatype.GetUniqueName ?? "") }));
 }
Beispiel #2
0
 DataRow MakeOperator(string name, DataType datatype, ExpressionBlock value)
 {
     return(DataRow.Create(Table.Heading, new TypedValue[]
                           { TextValue.Create(name),
                             TextValue.Create(value.ReturnType.BaseType.Name),
                             TextValue.Create(value.ReturnType.GetUniqueName ?? ""),
                             TextValue.Create(value.NumArgs == 0 ? "" : value.SubtypeName) })); // suppress empty arg list
 }
Beispiel #3
0
 public DataRow MakeEntry(CatalogEntry entry)
 {
     return(DataRow.Create(Table.Heading, new TypedValue[] {
         TextValue.Create(entry.Name),
         TextValue.Create(entry.Kind.ToString()),
         TextValue.Create(entry.DataType.BaseType.Name),
         BinaryValue.Create(entry.ToBinary())
     }));
 }
Beispiel #4
0
        // Obtain a text value by reading from the console/standard input output
        public TextValue Read()
        {
            var input = _input.ReadLine();

            if (input == null)
            {
                throw ProgramError.Fatal("Read", "input not available");
            }
            return(TextValue.Create(input));
        }
Beispiel #5
0
        // Pad on left with spaces or truncate to right to length
        public TextValue Right(TextValue arg1, NumberValue arg2)
        {
            if (arg2.Value < 0)
            {
                return(TextValue.Default);
            }
            var str  = arg1.Value;
            var len  = (int)arg2.Value;
            var strx = (len >= str.Length) ? str.PadLeft(len) : str.Substring(str.Length - len, len);

            return(TextValue.Create(strx));
        }
Beispiel #6
0
        // Multiple copies of a string to fill a length
        public TextValue Fill(TextValue arg1, NumberValue arg2)
        {
            if (arg2.Value < 0)
            {
                return(TextValue.Default);
            }
            StringBuilder sb    = new StringBuilder();
            var           times = ((int)arg2.Value + arg1.Value.Length - 1) / arg1.Value.Length;

            while (times-- > 0)
            {
                sb.Append(arg1.Value);
            }
            return(TextValue.Create(sb.ToString(0, (int)arg2.Value)));
        }
Beispiel #7
0
        // Converter driven by source type
        TypedValue Converter(ConversionTypes type, object value)
        {
            switch (type)
            {
            case ConversionTypes.Bool: return(BoolValue.Create((bool)value));

            case ConversionTypes.Int: return(NumberValue.Create((int)value));

            case ConversionTypes.String: return(TextValue.Create((string)value));

            case ConversionTypes.Decimal: return(NumberValue.Create((decimal)value));

            case ConversionTypes.DateTime: return(TimeValue.Create((DateTime)value));

            default: return(TypedValue.Empty);
            }
        }
Beispiel #8
0
        void AddMember(string parent, DataHeading heading)
        {
            int index = 0;

            foreach (var column in heading.Columns)
            {
                var addrow = DataRow.Create(Table.Heading, new TypedValue[]
                                            { TextValue.Create(parent),
                                              NumberValue.Create(++index),
                                              TextValue.Create(column.Name),
                                              TextValue.Create(column.DataType.BaseType.Name),
                                              TextValue.Create(column.DataType.GetUniqueName ?? "") });
                Table.AddRow(addrow);
                // Recursive call. note: may be duplicate, but no matter.
                if (column.DataType.GetUniqueName != null)
                {
                    AddMember(column.DataType.GetUniqueName, column.DataType.Heading);
                }
            }
        }
Beispiel #9
0
 public static TypedValue Parse(DataType type, string value)
 {
     if (type == DataTypes.Bool)
     {
         return(BoolValue.Create(bool.Parse(value)));
     }
     if (type == DataTypes.Number)
     {
         return(NumberValue.Create(Decimal.Parse(value)));
     }
     if (type == DataTypes.Time)
     {
         return(TimeValue.Create(DateTime.Parse(value)));
     }
     if (type == DataTypes.Text)
     {
         return(TextValue.Create(value));
     }
     return(TypedValue.Empty);
 }
Beispiel #10
0
        // special for tables
        public TextValue PrettyPrint(TypedValue value)
        {
            Logger.Assert(value.DataType.IsVariable, "pp non-var");
            Logger.WriteLine(3, "PrettyPrint {0}", value);
            var sb = new StringBuilder();

            if (value.DataType is DataTypeRelation)
            {
                var dss = DataSinkStream.Create(value.AsTable(), new StringWriter(sb));
                dss.OutputTable();
            }
            else
            {
                sb.Append($"{value.Format()} : {value.DataType}");
            }
            var ret = TextValue.Create(sb.ToString());

            Logger.WriteLine(3, "[PP]");
            return(ret);
        }
Beispiel #11
0
 // Return type name as text
 public TextValue Type(TypedValue arg)
 {
     return(TextValue.Create(arg.DataType.ToString()));
 }
Beispiel #12
0
 // fancier string
 public TextValue Format(TypedValue value)
 {
     return(TextValue.Create(value.Format()));
 }
Beispiel #13
0
 public void SetText(int colno, string value)
 {
     _valueholder._values[colno] = TextValue.Create(value);
 }
Beispiel #14
0
        ///=================================================================
        ///
        /// Add-in functions
        ///

        // basic string
        public TextValue Text(TypedValue value)
        {
            return(TextValue.Create(value.ToString()));
        }
Beispiel #15
0
 public TextValue ToLower(TextValue arg1)
 {
     return(TextValue.Create(arg1.Value.ToLower()));
 }
Beispiel #16
0
        // The part of arg1 after arg2, or nothing if not found
        public TextValue After(TextValue arg1, TextValue arg2)
        {
            int pos = arg1.Value.IndexOf(arg2.Value);

            return(pos == -1 ? TextValue.Default : TextValue.Create(arg1.Value.Substring(pos + arg2.Value.Length)));
        }
Beispiel #17
0
        // The part of arg1 before arg2, or arg1 if not found
        public TextValue Before(TextValue arg1, TextValue arg2)
        {
            int pos = arg1.Value.IndexOf(arg2.Value);

            return(pos == -1 ? arg1 : TextValue.Create(arg1.Value.Substring(0, pos)));
        }
Beispiel #18
0
        ///=================================================================
        ///
        /// Text string operations
        ///

        // Concatenate. Converts arguments to string.
        public TextValue Concat(TypedValue arg1, TypedValue arg2)
        {
            return(TextValue.Create(arg1.ToString() + arg2.ToString()));
        }
Beispiel #19
0
 // remove leading and trailing white space
 public TextValue Trim(TextValue arg1)
 {
     return(TextValue.Create(arg1.Value.Trim()));
 }