Beispiel #1
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // OBJECT
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <c>LuatLexicalParser</c> class.
        /// </summary>

        public LuatLexicalParser()
        {
            // Initialize keywords
            for (int index = (int)LuatTokenId.KeywordStart + 1; index < (int)LuatTokenId.KeywordEnd; index++)
            {
                keywords.Add(LuatTokenId.GetTokenKey(index).ToLowerInvariant(), index);
            }
        }
        /// <summary>
        /// Gets the token string representation for the specified token ID.
        /// </summary>
        /// <param name="tokenId">The ID of the token to examine.</param>
        /// <returns>The token string representation for the specified token ID.</returns>
        public override string GetTokenString(int tokenId)
        {
            if ((tokenId > LuatTokenId.KeywordStart) && (tokenId < LuatTokenId.KeywordEnd))
            {
                return(LuatTokenId.GetTokenKey(tokenId).ToLower());
            }

            switch (tokenId)
            {
            // General
            case LuatTokenId.DocumentEnd:
                return("Document end");

            case LuatTokenId.Whitespace:
                return("Whitespace");

            case LuatTokenId.LineTerminator:
                return("Line terminator");

            case LuatTokenId.SingleLineComment:
                return("Single-line comment");

            case LuatTokenId.MultiLineComment:
                return("Multi-line comment");

            case LuatTokenId.Number:
                return("Number");

            case LuatTokenId.Identifier:
                return("Identifier");

            // Operators
            case LuatTokenId.OpenCurlyBrace:
                return("{");

            case LuatTokenId.CloseCurlyBrace:
                return("}");

            case LuatTokenId.OpenParenthesis:
                return("(");

            case LuatTokenId.CloseParenthesis:
                return(")");

            case LuatTokenId.OpenSquareBracket:
                return("[");

            case LuatTokenId.CloseSquareBracket:
                return("]");

            case LuatTokenId.Comma:
                return(",");

            case LuatTokenId.SemiColon:
                return(";");

            case LuatTokenId.Addition:
                return("+");

            case LuatTokenId.Subtraction:
                return("-");

            case LuatTokenId.Multiplication:
                return("*");

            case LuatTokenId.Division:
                return("/");

            case LuatTokenId.Assignment:
                return("=");

            case LuatTokenId.Equality:
                return("==");

            case LuatTokenId.Inequality:
                return("!=");
            }

            return(null);
        }