예제 #1
0
파일: Lexer.cs 프로젝트: m2sf/m2sharp
        } /* end GetIdentOrResword */

/* ---------------------------------------------------------------------------
 * private method GetStringLiteral()
 * ------------------------------------------------------------------------ */

        private char GetStringLiteral(out Token token)
        {
            uint  line, column;
            Token intermediate;
            char  nextChar, delimiter;

            intermediate = Token.StringLiteral;

            /* consume opening delimiter */
            delimiter = infile.ReadChar();

            infile.MarkLexeme();
            nextChar = infile.NextChar();

            while (nextChar != delimiter)
            {
                /* check for control character */
                if (ASCII.IsCtrl(nextChar))
                {
                    line   = infile.CurrentLine();
                    column = infile.CurrentColumn();

                    intermediate = Token.MalformedString;

                    /* newline */
                    if (nextChar == ASCII.LF)
                    {
                        // report error with offending position
                        // newline in string literal
                        break;
                    }
                    /* end-of-file marker */
                    else if (infile.EOF())
                    {
                        // report error with offending position
                        // premature end of file within string literal
                        break;
                    }
                    else /* any other control character */
                    {
                        /* invalid input character */
                        // report error with offending character
                    } /* end if */
                }     /* end if */

                if (Capabilities.EscapeTabAndNewline() &&
                    (nextChar == ASCII.BACKSLASH))
                {
                    line     = infile.CurrentLine();
                    column   = infile.CurrentColumn();
                    nextChar = infile.ConsumeChar();

                    if ((nextChar != 'n') && (nextChar != 't') &&
                        (nextChar != ASCII.BACKSLASH))
                    {
                        /* invalid escape sequence */
                        // report error with offending character
                    } /* end if */
                }     /* end if */

                nextChar = infile.ConsumeChar();
            } /* end while */

            /* get lexeme */
            lookaheadSym.lexeme = infile.ReadMarkedLexeme();

            /* consume closing delimiter */
            if (nextChar == delimiter)
            {
                nextChar = infile.ConsumeChar();
            } /* end if */

            /* pass back token */
            token = intermediate;

            return(nextChar);
        } /* end GetStringLiteral */