예제 #1
0
 public StringState(IScanner scanner)
 {
     _buffer  = StringBuilderPool.Pull();
     _scanner = scanner;
     _start   = scanner.Position;
     _errors  = null;
 }
예제 #2
0
        /// <summary>
        /// Converts the matrix to a string.
        /// </summary>
        public static String This <T>(T[,] value)
        {
            var sb   = StringBuilderPool.Pull();
            var rows = value.GetLength(0);
            var cols = value.GetLength(1);

            sb.Append('[');

            for (var i = 0; i < rows; i++)
            {
                if (i > 0)
                {
                    sb.Append(';');
                }

                for (var j = 0; j < cols; j++)
                {
                    if (j > 0)
                    {
                        sb.Append(',');
                    }

                    sb.Append(This(value[i, j]));
                }
            }

            sb.Append(']');
            return(sb.Stringify());
        }
예제 #3
0
        public String Serialize(Object value)
        {
            var sb = StringBuilderPool.Pull();

            SerializeTo(value, sb, 0);
            return(sb.Stringify());
        }
예제 #4
0
        private static IToken ScanName(IScanner scanner)
        {
            var position    = scanner.Position;
            var sb          = StringBuilderPool.Pull();
            var current     = scanner.Current;
            var canContinue = true;

            do
            {
                sb.Append(Char.ConvertFromUtf32(current));

                if (!scanner.MoveNext())
                {
                    canContinue = false;
                    break;
                }

                current = scanner.Current;
            }while (current.IsName());

            if (canContinue)
            {
                scanner.MoveBack();
            }

            var name = sb.Stringify();
            var type = Keywords.IsKeyword(name) ? TokenType.Keyword : TokenType.Identifier;

            return(new IdentToken(type, name, position, scanner.Position));
        }
예제 #5
0
        /// <summary>
        /// Converts the matrix to a string.
        /// </summary>
        public static String This(Double[,] value)
        {
            var sb   = StringBuilderPool.Pull();
            var rows = value.GetLength(0);
            var cols = value.GetLength(1);

            sb.Append('[');

            for (var i = 0; i < rows; i++)
            {
                if (i > 0)
                {
                    sb.Append(';');
                }

                for (var j = 0; j < cols; j++)
                {
                    if (j > 0)
                    {
                        sb.Append(',');
                    }

                    sb.Append(value[i, j].ToString(CultureInfo.InvariantCulture));
                }
            }

            sb.Append(']');
            return(sb.Stringify());
        }
예제 #6
0
        /// <summary>
        /// Converts the given matrix to a JSON string.
        /// </summary>
        /// <param name="matrix">The matrix to represent.</param>
        /// <returns>The JSON representation.</returns>
        public static String AsJson(Double[,] matrix)
        {
            var sb   = StringBuilderPool.Pull();
            var rows = matrix.GetRows();
            var cols = matrix.GetColumns();

            sb.Append('[');

            for (var i = 0; i < rows; i++)
            {
                if (i > 0)
                {
                    sb.Append(", ");
                }
                sb.Append('[');

                for (var j = 0; j < cols; j++)
                {
                    if (j > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append(This(matrix[i, j]));
                }

                sb.Append(']');
            }

            sb.Append(']');
            return(sb.Stringify());
        }
예제 #7
0
 public StringState(IScanner scanner, Boolean literal)
 {
     _buffer  = StringBuilderPool.Pull();
     _scanner = scanner;
     _start   = scanner.Position;
     _errors  = null;
     _literal = literal;
 }
예제 #8
0
 public StringState(IScanner scanner, ITokenizer tokenizer)
 {
     _buffer    = StringBuilderPool.Pull();
     _scanner   = scanner;
     _start     = scanner.Position;
     _errors    = null;
     _parts     = new List <List <IToken> >();
     _tokenizer = tokenizer;
 }
예제 #9
0
        private static IToken ScanLine(IScanner scanner, TextPosition start)
        {
            var sb = StringBuilderPool.Pull();

            while (scanner.MoveNext() && scanner.Current != CharacterTable.LineFeed)
            {
                sb.Append(Char.ConvertFromUtf32(scanner.Current));
            }

            return(new CommentToken(TokenType.Comment, sb.Stringify(), start, scanner.Position));
        }
예제 #10
0
        private IToken Preprocessor(IScanner scanner)
        {
            var start = scanner.Position;
            var sb    = StringBuilderPool.Pull();

            while (scanner.MoveNext())
            {
                var current = scanner.Current;

                if (current == CharacterTable.LineFeed)
                {
                    break;
                }

                sb.Append(Char.ConvertFromUtf32(current));
            }

            var end     = scanner.Position;
            var payload = sb.Stringify();

            return(new PreprocessorToken(payload, start, end));
        }
예제 #11
0
        private static IToken ScanBlock(IScanner scanner, TextPosition start)
        {
            var sb = StringBuilderPool.Pull();

            while (scanner.MoveNext())
            {
                if (scanner.Current == CharacterTable.Asterisk)
                {
                    if (!scanner.MoveNext() || scanner.Current == CharacterTable.Slash)
                    {
                        break;
                    }
                    else
                    {
                        sb.Append(Char.ConvertFromUtf32(CharacterTable.Asterisk));
                    }
                }

                sb.Append(Char.ConvertFromUtf32(scanner.Current));
            }

            return(new CommentToken(TokenType.Comment, sb.Stringify(), start, scanner.Position));
        }