예제 #1
0
        //public ByteString ( ByteStreamMark mark, int length, bool hash = true )
        //{
        //	Mark = mark;
        //	Length = length;
        //	Hash = hash ? MakeHash ( mark.Buffer, mark.Start, mark.Buffer.Length ) : 0;
        //}

        public ByteString(string str)
        {
            var bytes = System.Text.Encoding.UTF8.GetBytes(str);

            Mark   = new ByteStreamMark(bytes, 0);
            Length = bytes.Length;
            Hash   = MakeHash(bytes, 0, Length);
        }
예제 #2
0
파일: ScanIt.cs 프로젝트: erikeidt/Draconum
        /// <summary>
        ///		fetches a String Literal, given that the caller knows it is one already
        /// </summary>
        /// <returns>
        ///		a ByteString containing the string literal's characters
        ///			(the string's hashed, is computed, in support of interning)
        /// </returns>
        public ByteString GetStringLiteral()
        {
            int terminatingCharacter = _curr.Value;

            if (terminatingCharacter != '\"' && terminatingCharacter != '\'')
            {
                throw new AssertionFailedException("thought we were parsing a string here");
            }

            Advance();
            PushMode(TokenModeEnum.SingleLineToken);
            var         mark   = _cps.Mark(_cursor);
            int         length = 0;
            List <byte> copy   = null;

            var esc = false;

            for ( ; ; Advance())
            {
                if (_curr.AtEOF())
                {
                    break;
                }
                if (_curr.Value == terminatingCharacter)
                {
                    break;
                }
                var val = (char)_curr.Value;
                if (esc)
                {
                    esc = false;
                    if (val == '\n')
                    {
                        continue;
                    }
                    switch (val)
                    {
                    case '0':
                        val = '\0';
                        break;

                    case 't':
                        val = '\t';
                        break;

                    case 'b':
                        val = '\b';
                        break;

                    case 'r':
                        val = '\r';
                        break;

                    case 'n':
                        val = '\n';
                        break;
                    }
                }
                else
                {
                    if (val == '\\')
                    {
                        if (copy == null)
                        {
                            copy = mark.MakeList(length);
                        }
                        esc = true;
                        continue;
                    }
                    if (val == '\n')
                    {
                        Error("Literal not terminated by end of line");
                    }
                }

                length++;

                // this will have to upgrade to support CodePoints being added to the list here
                //	CodePoints larger than 1 UTF8 Code Unit will have to each be added in encoded form
                copy?.Add(unchecked ((byte)val));
            }
            if (_curr.AtEOF())
            {
                Error(terminatingCharacter == '"' ? "Unterminated String at EOF" : "Unterminated Quoted Identifier at EOF");
            }
            Advance();
            PopMode();
            if (copy != null)
            {
                mark = new ByteStreamMark(copy.ToArray(), 0);
            }
            return(mark.OfLength(length));
        }
예제 #3
0
 public ByteString(byte [] bytes, int start, int length, bool hash = true)
 {
     Mark   = new ByteStreamMark(bytes, start);
     Length = length;
     Hash   = hash ? MakeHash(bytes, start, length) : 0;
 }